/* Root Variables */
:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-chat: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Reset and Global Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
}

/* Hidden elements helper */
.hidden {
  display: none !important;
}

/* --- Auth Page Layout --- */
.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  width: 100vw;
  background: radial-gradient(circle at 50% 50%, #e0e7ff 0%, #f1f5f9 100%);
}

.auth-card {
  width: 420px;
  background-color: #ffffff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 40px;
  animation: fadeIn 0.4s ease;
}

.auth-header {
  text-align: center;
  margin-bottom: 30px;
}

.auth-logo {
  max-width: 140px;
  max-height: 140px;
  display: inline-block;
  margin-bottom: 12px;
  object-fit: contain;
}

.auth-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-main);
}

.auth-header p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-toggle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 14px;
}

.auth-toggle a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

.auth-toggle a:hover {
  text-decoration: underline;
}

.auth-error {
  background-color: #fef2f2;
  border: 1px solid #fee2e2;
  border-radius: var(--radius-sm);
  padding: 12px;
  color: #991b1b;
  font-size: 13px;
  margin-top: 20px;
  text-align: center;
  animation: fadeIn 0.2s ease;
}

/* --- Layout Container --- */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar Styles */
.sidebar {
  width: 380px;
  min-width: 380px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow-y: auto;
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-logo {
  max-width: 120px;
  max-height: 40px;
  object-fit: contain;
}

.sidebar-header .icon {
  font-size: 32px;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.sidebar-header .subtitle {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.user-badge-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  background-color: #f8fafc;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.user-badge {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  text-transform: capitalize;
}

.logout-btn-link {
  background: none;
  border: none;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  color: #ef4444;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background-color 0.2s;
}

.logout-btn-link:hover {
  background-color: #fef2f2;
}

/* Config Form */
.config-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #334155;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group select,
.form-group textarea {
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background-color: #f8fafc;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s ease;
}

.form-group input[type="file"] {
  background-color: #ffffff;
  cursor: pointer;
  padding: 8px;
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.form-group textarea {
  resize: vertical;
  line-height: 1.5;
}

.form-group .help-text {
  font-size: 11px;
  color: var(--text-muted);
}

/* Custom Highlight Codes */
code {
  font-family: var(--font-mono);
  background-color: #f1f5f9;
  padding: 2px 4px;
  border-radius: 4px;
  color: #e11d48;
  font-weight: 500;
}

/* Submit Button */
.submit-btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background-color: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  margin-top: 10px;
  box-shadow: var(--shadow-md);
}

.submit-btn:hover {
  background-color: var(--primary-hover);
}

.submit-btn:active {
  transform: scale(0.98);
}

.submit-btn:disabled {
  background-color: var(--text-muted);
  cursor: not-allowed;
  opacity: 0.7;
}

/* Chat Area Container */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-chat);
  position: relative;
  height: 100vh;
}

/* Chat Header */
.chat-header {
  background-color: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 0px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.agent-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-logo {
  max-height: 70px;
  max-width: 150px;
  object-fit: contain;
}

.status-indicator {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  position: relative;
}

.status-indicator.online {
  background-color: #10b981;
}

.status-indicator.online::after {
  content: '';
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #10b981;
  opacity: 0.4;
  animation: pulse 2s infinite;
}

.agent-status h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.agent-status p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 1px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
}

.icon-btn:hover {
  background-color: #f1f5f9;
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-bottom: 24px;
}

/* Chat Input Area */
.chat-input-area {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  background-color: #ffffff;
  border-top: 1px solid var(--border);
  align-items: center;
  position: relative;
  padding-bottom: 56px;
  /* Extra padding so the collapsed console drawer at bottom doesn't cover it */
  z-index: 5;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.02);
}

.chat-input-area input {
  flex: 1;
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 24px;
  /* Rounded pill style */
  background-color: #f8fafc;
  color: var(--text-main);
  outline: none;
  transition: all 0.2s ease;
}

.chat-input-area input:focus {
  border-color: var(--primary);
  background-color: #ffffff;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chat-input-area .send-btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background-color: var(--primary);
  border: none;
  border-radius: 24px;
  padding: 12px 24px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-input-area .send-btn:hover {
  background-color: var(--primary-hover);
}

.chat-input-area .send-btn:active {
  transform: scale(0.97);
}

.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: fadeIn 0.3s ease;
}

.message.assistant {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background-color: #ffffff;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  overflow: hidden;
}

.message .avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.message.user .avatar {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
}

.message-content {
  background-color: #ffffff;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  border-top-left-radius: 4px;
  font-size: 14px;
  line-height: 1.6;
  box-shadow: var(--shadow-sm);
  color: var(--text-main);
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.message.user .message-content {
  background-color: var(--primary);
  color: #ffffff;
  border-radius: var(--radius-lg);
  border-top-right-radius: 4px;
  border-top-left-radius: var(--radius-lg);
}

.message-content p {
  margin-bottom: 8px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content ol,
.message-content ul {
  margin-left: 20px;
  margin-bottom: 8px;
}

.message-content li {
  margin-bottom: 4px;
}

/* Download Result Box inside chat bubble */
.download-box {
  background-color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.message.user .download-box {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.download-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.download-icon {
  font-size: 28px;
}

.download-title {
  font-weight: 600;
  font-size: 14px;
}

.download-subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.message.user .download-subtitle {
  color: rgba(255, 255, 255, 0.7);
}

.download-btn {
  background-color: #10b981;
  color: #ffffff;
  border: none;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.2s ease;
  box-shadow: var(--shadow-sm);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.download-btn:hover {
  background-color: #059669;
}

/* Live Progress Indicator */
.progress-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background-color: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: var(--primary);
  width: 0%;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Console Logs Drawer */
.console-drawer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #0f172a;
  border-top: 1px solid #1e293b;
  color: #f1f5f9;
  display: flex;
  flex-direction: column;
  z-index: 20;
  transition: height 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.console-drawer.collapsed {
  height: 40px;
}

.console-drawer.expanded {
  height: 280px;
}

.console-header {
  height: 40px;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  user-select: none;
  background-color: #1e293b;
}

.console-header:hover {
  background-color: #334155;
}

.console-logs {
  flex: 1;
  padding: 12px 16px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  background-color: #020617;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.console-line {
  word-break: break-all;
  white-space: pre-wrap;
}

.console-line.system {
  color: #38bdf8;
}

.console-line.error {
  color: #ef4444;
}

.console-line.success {
  color: #4ade80;
}

/* Animations */
@keyframes pulse {
  0% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  }

  70% {
    transform: scale(1);
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }

  100% {
    transform: scale(0.95);
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsiveness */
@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 40%;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-container {
    height: 60%;
  }

  .console-drawer.expanded {
    height: 180px;
  }
}

/* Download Card in Chat */
.download-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 12px 0;
  box-shadow: var(--shadow-sm);
  max-width: 450px;
}

.download-card .file-icon {
  font-size: 32px;
}

.download-card .file-details {
  display: flex;
  flex-direction: column;
  flex: 1;
}

.download-card .file-name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-main);
  word-break: break-all;
}

.download-card .file-action {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.download-card .download-btn-link {
  display: inline-block;
  background-color: var(--primary);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 20px;
  transition: background-color 0.2s;
  box-shadow: var(--shadow-sm);
}

.download-card .download-btn-link:hover {
  background-color: var(--primary-hover);
}