/* --- DESIGN TOKENS --- */
:root {
  /* Colors — Dark Palette */
  --bg-primary: #09090b;
  --bg-secondary: #0f0f13;
  --bg-tertiary: #18181c;
  --bg-surface: rgba(24, 24, 28, 0.65);
  --bg-surface-hover: rgba(36, 36, 42, 0.75);
  --bg-glass: rgba(15, 15, 19, 0.7);

  /* Borders */
  --border-subtle: rgba(255, 255, 255, 0.04);
  --border-medium: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(129, 140, 248, 0.4);

  /* Text */
  --text-primary: rgba(255, 255, 255, 0.92);
  --text-secondary: rgba(255, 255, 255, 0.65);
  --text-tertiary: rgba(255, 255, 255, 0.45);
  --text-accent: #a5b4fc;

  /* Accent (Default Indigo) */
  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-secondary: #a855f7;
  --accent-gradient: linear-gradient(
    135deg,
    #6366f1 0%,
    #a855f7 50%,
    #ec4899 100%
  );
  --accent-gradient-subtle: linear-gradient(
    135deg,
    rgba(99, 102, 241, 0.15),
    rgba(168, 85, 247, 0.15)
  );

  /* Status */
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;
}

[data-theme="emerald"] {
  --accent-primary: #34d399;
  --accent-primary-hover: #10b981;
  --accent-gradient: linear-gradient(
    135deg,
    #34d399 0%,
    #10b981 50%,
    #059669 100%
  );
  --accent-gradient-subtle: linear-gradient(
    135deg,
    rgba(52, 211, 153, 0.15),
    rgba(16, 185, 129, 0.15)
  );
}

[data-theme="rose"] {
  --accent-primary: #fb7185;
  --accent-primary-hover: #f43f5e;
  --accent-gradient: linear-gradient(
    135deg,
    #fb7185 0%,
    #f43f5e 50%,
    #e11d48 100%
  );
  --accent-gradient-subtle: linear-gradient(
    135deg,
    rgba(251, 113, 133, 0.15),
    rgba(244, 63, 94, 0.15)
  );
}

[data-theme="amber"] {
  --accent-primary: #fbbf24;
  --accent-primary-hover: #f59e0b;
  --accent-gradient: linear-gradient(
    135deg,
    #fbbf24 0%,
    #f59e0b 50%,
    #d97706 100%
  );
  --accent-gradient-subtle: linear-gradient(
    135deg,
    rgba(251, 191, 36, 0.15),
    rgba(245, 158, 11, 0.15)
  );
}

:root {
  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 40px rgba(129, 140, 248, 0.15);

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Sidebar */
  --sidebar-width: 280px;

  /* Typography */
  --font-sans:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", Consolas, Monaco, monospace;

  /* Transitions */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --duration-fast: 160ms;
  --duration-normal: 260ms;
  --duration-slow: 420ms;
}

/* ==============================
   RESET & BASE
   ============================== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  overscroll-behavior: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent-primary);
  text-decoration: none;
  transition: color var(--duration-fast) ease;
}
a:hover {
  color: var(--accent-secondary);
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

input,
textarea {
  font-family: inherit;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 3px;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18);
}

/* --- BACKGROUND --- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 72px 72px;
  z-index: 0;
  pointer-events: none;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(160px);
  opacity: 0.18;
  z-index: 0;
  pointer-events: none;
  contain: paint;
}

.bg-glow-1 {
  width: 800px;
  height: 800px;
  background: radial-gradient(
    circle,
    rgba(99, 102, 241, 0.08) 0%,
    transparent 70%
  );
  top: -20%;
  left: -15%;
}

.bg-glow-2 {
  width: 600px;
  height: 600px;
  background: radial-gradient(
    circle,
    rgba(168, 85, 247, 0.06) 0%,
    transparent 70%
  );
  bottom: -15%;
  right: -10%;
}

.bg-glow-3 {
  display: none;
}

/* ==============================
   MODAL (ENGINE SELECTION & API KEY)
   ============================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.modal-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-xl);
  padding: 40px;
  max-width: 440px;
  width: 90%;
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  overscroll-behavior: contain;
  text-align: center;
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  animation: modalIn var(--duration-slow) var(--ease-spring);
  will-change: transform, opacity;
}

.modal.modal-large {
  max-width: 800px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.modal-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 24px;
}

.modal-hint {
  color: var(--text-tertiary);
  font-size: 0.78rem;
  margin-top: 16px;
}

.input-group {
  text-align: left;
  margin-bottom: 20px;
}

.input-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  color: var(--text-primary);
  transition:
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-normal) var(--ease-out);
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

.input-group input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
}

/* Engine Selection Specifics */
.engine-options {
  display: flex;
  gap: 20px;
  text-align: left;
}

@media (max-width: 768px) {
  .engine-options {
    flex-direction: column;
  }
}

.engine-card {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition:
    transform var(--duration-normal) var(--ease-out),
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-normal) var(--ease-out);
}

.engine-card:hover {
  border-color: var(--border-accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.engine-badge {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-gradient);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  box-shadow: 0 2px 8px rgba(129, 140, 248, 0.4);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.engine-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.engine-header h3 {
  font-size: 1.15rem;
  color: var(--text-primary);
}

.engine-tag {
  font-size: 0.7rem;
  padding: 4px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-accent);
  font-weight: 600;
}

.engine-desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 16px;
  line-height: 1.5;
}

.engine-pros-cons {
  list-style: none;
  margin-bottom: 24px;
  flex: 1;
}

.engine-pros-cons li {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hardware-warning {
  color: var(--error);
  font-size: 0.8rem;
  margin-top: 12px;
  text-align: center;
}

/* Progress Bar */
.progress-container {
  margin-bottom: 16px;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  width: 0%;
  transition: width var(--duration-normal) var(--ease-out);
}

.compiling-pulse {
  animation: compilePulse 1.5s ease-in-out infinite;
}

@keyframes compilePulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  text-align: center;
}

/* Tier Selector */
.tier-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
  letter-spacing: 0.02em;
}

.tier-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.tier-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 2px solid var(--border-subtle);
  cursor: pointer;
  transition:
    transform var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-fast) ease;
}

.tier-btn:hover {
  border-color: var(--border-medium);
  background: var(--bg-surface-hover);
}

.tier-btn.tier-btn-active {
  border-color: var(--accent-primary);
  background: var(--accent-gradient-subtle);
  box-shadow: 0 0 16px rgba(129, 140, 248, 0.15);
}

.tier-btn.tier-btn-disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.tier-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.tier-size {
  font-size: 0.7rem;
  color: var(--text-tertiary);
}

.tier-details {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  transition:
    border-color var(--duration-fast) ease,
    background-color var(--duration-fast) ease;
}

.tier-detail-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.5;
}

.tier-specs {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.tier-spec {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-accent);
  background: rgba(129, 140, 248, 0.1);
  padding: 3px 10px;
  border-radius: var(--radius-full);
}

.tier-rec {
  margin-top: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--success);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* --- BUTTONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  transition:
    transform var(--duration-normal) var(--ease-out),
    box-shadow var(--duration-normal) var(--ease-out),
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
  letter-spacing: 0.01em;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(129, 140, 248, 0.2);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(129, 140, 248, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition:
    opacity var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.btn-text {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--text-tertiary);
  border-radius: var(--radius-sm);
  transition:
    opacity var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
  width: 100%;
}

.btn-text:hover {
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.btn-send {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--accent-gradient);
  color: white;
  flex-shrink: 0;
  transition:
    transform var(--duration-normal) var(--ease-out),
    opacity var(--duration-fast) ease,
    box-shadow var(--duration-normal) var(--ease-out);
  box-shadow: 0 2px 12px rgba(129, 140, 248, 0.3);
}

.btn-send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-send:not(:disabled):hover {
  transform: scale(1.08);
  box-shadow: 0 4px 20px rgba(129, 140, 248, 0.45);
}

/* --- APP LAYOUT --- */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  position: relative;
  z-index: 1;
}

/* --- SIDEBAR --- */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--border-subtle);
  padding: 16px;
  transition:
    width var(--duration-slow) var(--ease-out),
    padding var(--duration-slow) var(--ease-out),
    border-color var(--duration-fast) ease,
    transform var(--duration-slow) var(--ease-out),
    opacity var(--duration-normal) ease;
  flex-shrink: 0;
  overflow: hidden;
  transform: translateZ(0);
  will-change: transform;
}

.sidebar.closed {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-color: transparent;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.logo-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-gradient-subtle);
  border: 1px solid var(--border-accent);
  color: var(--accent-primary);
}

.logo-text {
  font-size: 1.15rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-new-chat {
  width: 100%;
  justify-content: center;
  padding: 10px 12px;
  color: var(--text-accent);
  background: var(--accent-gradient-subtle);
  border: 1px solid var(--border-accent);
}

.btn-new-chat:hover {
  color: var(--text-primary);
  background: rgba(129, 140, 248, 0.18);
}

.sidebar-close {
  flex-shrink: 0;
}

.sidebar-section {
  margin-bottom: 20px;
}

.sidebar-section-grow {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.sidebar-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
  padding-left: 4px;
}

/* Subject Chips */
.subject-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 500;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition:
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.chip:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.chip-active {
  background: var(--accent-gradient-subtle);
  border-color: var(--border-accent);
  color: var(--text-accent);
}

.chip-emoji {
  font-size: 0.85rem;
}

.chip-locked {
  opacity: 0.45;
  cursor: not-allowed;
  background: transparent;
  border-style: dashed;
}

.chip-locked:hover {
  background: rgba(255, 0, 0, 0.05);
  border-color: var(--error);
  color: var(--text-secondary);
}

.chip-lock-icon {
  font-size: 0.7rem;
  margin-left: 2px;
}

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.84rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition:
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover {
  background: var(--bg-surface);
  color: var(--text-primary);
}

.history-item.active {
  background: var(--accent-gradient-subtle);
  color: var(--text-accent);
}

.history-item-icon {
  flex-shrink: 0;
  opacity: 0.5;
}

.history-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-empty {
  color: var(--text-tertiary);
  font-size: 0.8rem;
  text-align: center;
  padding: 20px 0;
  font-style: italic;
}

.sidebar-footer {
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* --- MAIN CONTENT --- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.sidebar-toggle {
  display: flex;
}

.topbar-info {
  flex: 1;
  min-width: 0;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-subject {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* --- CHAT AREA --- */
.chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Welcome */
.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  animation: fadeIn var(--duration-slow) var(--ease-out);
}

.welcome.hidden {
  display: none;
}

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

.welcome-icon {
  margin-bottom: 24px;
  opacity: 0.7;
}

.welcome-title {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.welcome-subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  max-width: 480px;
  margin-bottom: 40px;
}

/* Prompt Cards */
.prompt-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  max-width: 720px;
  width: 100%;
}

.prompt-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  text-align: left;
  transition:
    transform var(--duration-normal) var(--ease-out),
    background-color var(--duration-fast) ease,
    border-color var(--duration-fast) ease,
    box-shadow var(--duration-normal) var(--ease-out);
  cursor: pointer;
}

.prompt-card:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-accent);
  transform: translateY(-2px);
  box-shadow:
    var(--shadow-md),
    0 0 20px rgba(129, 140, 248, 0.08);
}

.prompt-card-emoji {
  font-size: 1.3rem;
  flex-shrink: 0;
  margin-top: 2px;
}

.prompt-card-text {
  font-size: 0.84rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.prompt-card:hover .prompt-card-text {
  color: var(--text-primary);
}

/* Messages */
.messages {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px 0;
  flex: 1;
  contain: layout style;
}

.messages.hidden {
  display: none;
}

.message {
  padding: 8px 24px;
  animation: msgIn var(--duration-normal) var(--ease-out);
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  contain: layout paint;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

.message-user {
  display: flex;
  justify-content: flex-end;
  padding: 12px 24px;
}

.message-user .message-content {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  box-shadow:
    inset 0 1px 1px rgba(255, 255, 255, 0.05),
    0 2px 8px rgba(0, 0, 0, 0.2);
  border-radius: 20px 20px 4px 20px;
  padding: 14px 20px;
  max-width: 75%;
  font-size: 0.95rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
  color: var(--text-primary);
}

.message-ai {
  display: flex;
  gap: 16px;
  padding: 16px 24px;
}

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow:
    inset 0 0 10px rgba(255, 255, 255, 0.05),
    0 0 15px rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 4px;
}

.message-ai .message-content {
  flex: 1;
  min-width: 0;
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-primary);
  overflow-wrap: anywhere;
}

/* Markdown Styling inside messages */
.message-content h1,
.message-content h2,
.message-content h3 {
  font-weight: 700;
  margin: 20px 0 8px 0;
  color: var(--text-primary);
}

.message-content h1 {
  font-size: 1.3rem;
}
.message-content h2 {
  font-size: 1.15rem;
}
.message-content h3 {
  font-size: 1rem;
}

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

.message-content ul,
.message-content ol {
  margin: 8px 0 12px 20px;
}

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

.message-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.message-content em {
  color: var(--text-accent);
}

.message-content code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(129, 140, 248, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent-secondary);
}

.message-content pre {
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  overflow-x: auto;
  max-width: 100%;
  margin: 12px 0;
  position: relative;
}

.message-content pre code {
  background: none;
  padding: 0;
  font-size: 0.84rem;
  color: var(--text-primary);
  line-height: 1.6;
}

.message-content blockquote {
  border-left: 3px solid var(--accent-primary);
  padding: 8px 16px;
  margin: 12px 0;
  background: rgba(129, 140, 248, 0.05);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
}

.message-content hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 16px 0;
}

.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 0.88rem;
}

.message-content th,
.message-content td {
  padding: 8px 12px;
  border: 1px solid var(--border-subtle);
  text-align: left;
}

.message-content th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Copy button for code blocks */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-tertiary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  opacity: 0;
  transition:
    opacity var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    color var(--duration-fast) ease;
}

.message-content pre:hover .code-copy-btn {
  opacity: 1;
}

.code-copy-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

/* Loading Dots */
.loading-dots {
  display: inline-flex;
  gap: 6px;
  padding: 8px 0;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: dotPulse 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.loading-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: scale(0.4);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* --- INPUT AREA --- */
.input-area {
  padding: 0 20px 20px;
  flex-shrink: 0;
}

.input-form {
  max-width: 860px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: rgba(20, 20, 44, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  transition:
    border-color var(--duration-fast) ease,
    background-color var(--duration-fast) ease,
    box-shadow var(--duration-normal) var(--ease-out);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.input-wrapper:focus-within {
  background: rgba(24, 24, 52, 0.88);
  border-color: rgba(165, 180, 252, 0.38);
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.24),
    0 0 0 1px rgba(129, 140, 248, 0.16);
}

.input-wrapper textarea {
  flex: 1;
  resize: none;
  font-size: 0.94rem;
  line-height: 1.5;
  max-height: 200px;
  padding: 6px 4px;
  color: var(--text-primary);
  box-shadow: none;
  overflow-y: auto;
  scrollbar-width: thin;
}

.input-wrapper textarea:focus,
.input-wrapper textarea:focus-visible {
  outline: none;
  box-shadow: none;
}

.input-wrapper textarea::placeholder {
  color: var(--text-tertiary);
}

.input-hint {
  text-align: center;
  font-size: 0.73rem;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* Attach Button */
.btn-attach {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition:
    color var(--duration-fast) ease,
    background-color var(--duration-fast) ease;
}

.btn-attach:hover {
  color: var(--text-accent);
  background: var(--accent-gradient-subtle);
}

/* Attachment Preview */
.attachment-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  border-bottom: none;
  animation: fadeIn var(--duration-fast) var(--ease-out);
}

.attachment-preview + .input-wrapper {
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.attachment-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.attachment-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.attachment-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.attachment-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-size {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

.attachment-remove {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  flex-shrink: 0;
  transition:
    color var(--duration-fast) ease,
    background-color var(--duration-fast) ease;
}

.attachment-remove:hover {
  color: var(--error);
  background: rgba(248, 113, 113, 0.1);
}

/* Image in chat messages */
.message-image {
  max-width: 300px;
  max-height: 250px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 8px;
  object-fit: contain;
  background: var(--bg-tertiary);
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 12px;
  }

  .modal {
    width: 100%;
    max-height: calc(100dvh - 24px);
    padding: 22px 16px;
    border-radius: var(--radius-lg);
  }

  .modal-icon {
    font-size: 34px;
    margin-bottom: 8px;
  }

  .modal-title {
    font-size: 1.25rem;
  }

  .modal-desc {
    font-size: 0.82rem;
    margin-bottom: 16px;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 100;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.closed {
    width: min(var(--sidebar-width), 100%);
    padding: 16px;
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .engine-options {
    gap: 12px;
  }

  .engine-card {
    padding: 18px;
  }

  .engine-header {
    gap: 10px;
  }

  .engine-pros-cons {
    margin-bottom: 16px;
  }

  .tier-selector {
    flex-direction: column;
    gap: 6px;
  }

  .tier-btn {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 12px;
  }

  .welcome-title {
    font-size: 1.35rem;
  }

  .prompt-cards {
    grid-template-columns: 1fr;
  }

  .message-user .message-content {
    max-width: 85%;
  }

  .message-ai {
    padding: 12px 16px;
  }

  .message-user {
    padding: 8px 16px;
  }

  .input-area {
    padding: 0 12px 12px;
  }
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: 8px;
  }

  .modal {
    max-height: calc(100dvh - 16px);
    padding: 18px 12px;
  }

  .engine-card {
    padding: 16px;
  }

  .sidebar {
    width: 100%;
  }

  .welcome {
    padding: 24px 16px;
  }

  .welcome-title {
    font-size: 1.2rem;
  }

  .prompt-cards {
    gap: 8px;
  }

  .prompt-card {
    padding: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  .chat-area {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--duration-normal) ease;
}

.sidebar-overlay.visible {
  display: block;
  opacity: 1;
}

/* --- UTILITIES --- */
.hidden:not(.modal-overlay) {
  display: none !important;
}

/* Selection */
::selection {
  background: rgba(129, 140, 248, 0.3);
}

/* ==============================
   UPDATE BANNER & SETTINGS
   ============================== */
.update-banner {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: var(--success);
  padding: 12px 24px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    opacity var(--duration-normal) var(--ease-out),
    transform var(--duration-normal) var(--ease-spring);
}

.update-banner.hidden {
  opacity: 0;
  transform: translate(-50%, -20px);
  pointer-events: none;
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group h3 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
}

.theme-selector {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.theme-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-fast);
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-btn::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--btn-color);
}

.theme-btn:hover {
  background: var(--bg-surface-hover);
}

.theme-btn.theme-active {
  border-color: var(--btn-color);
  background: rgba(255, 255, 255, 0.05);
}

.setting-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  color: var(--text-primary);
}

.setting-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--accent-primary);
}
