/* ============================================================
   Cognitive Labs AI — design system (blue, per mockup)
   Cloudy-blue gradient backdrop, white app card, sea-blue accent
   ============================================================ */

:root {
  --bg-1: #e8f1fb;
  --bg-2: #f4f9ff;
  --bg-3: #e3eefb;
  --panel: #ffffff;
  --surface: #f2f7fd;
  --surface-2: #e9f2fc;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #0284c7;
  --accent-strong: #0369a1;
  --accent-soft: rgba(2, 132, 199, 0.10);
  --accent-softer: rgba(2, 132, 199, 0.06);
  --border: #e2e8f0;
  --border-strong: #0f172a;
  --radius-lg: 40px;
  --radius-md: 20px;
  --radius-sm: 14px;
  --shadow-soft: 0 30px 60px -20px rgba(2, 132, 199, 0.18), 0 8px 24px -8px rgba(15, 23, 42, 0.08);
  --shadow-pill: 0 6px 16px -6px rgba(2, 132, 199, 0.25);
  --font: 'Raleway', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg-1: #0b1220;
  --bg-2: #0f1a2e;
  --bg-3: #0b1526;
  --panel: #101c30;
  --surface: #16233a;
  --surface-2: #1b2c47;
  --text: #e8eef7;
  --muted: #8fa3bd;
  --faint: #64748b;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --accent-softer: rgba(56, 189, 248, 0.08);
  --border: #22334d;
  --border-strong: #e8eef7;
  --shadow-soft: 0 30px 60px -20px rgba(0, 0, 0, 0.5), 0 8px 24px -8px rgba(0, 0, 0, 0.35);
  --shadow-pill: 0 6px 16px -6px rgba(56, 189, 248, 0.3);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 700px at 15% 10%, var(--bg-2) 0%, transparent 60%),
    radial-gradient(1000px 700px at 90% 90%, var(--bg-3) 0%, transparent 55%),
    linear-gradient(135deg, var(--bg-1) 0%, var(--bg-2) 50%, var(--bg-3) 100%);
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px 16px;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- App card ---------- */
.app {
  width: 100%;
  max-width: 430px;
  height: min(860px, calc(100vh - 56px));
  background: var(--panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---------- Header ---------- */
.header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 20px 24px 14px;
  flex-shrink: 0;
  position: relative;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-pills {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.header-pills::-webkit-scrollbar { display: none; }

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

.brand-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: linear-gradient(145deg, #0ea5e9 0%, #0284c7 55%, #0369a1 100%);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.45),
    inset 0 -3px 5px rgba(2, 62, 102, 0.45),
    0 6px 14px -4px rgba(2, 132, 199, 0.5);
  position: relative;
  flex-shrink: 0;
  overflow: hidden;
}
.brand-icon img {
  width: 30px; height: 30px;
  border-radius: 50%;
  object-fit: cover;
  position: relative;
  z-index: 1;
}
.brand-icon::after {
  content: '';
  position: absolute;
  top: 4px; left: 7px;
  width: 14px; height: 7px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  filter: blur(1px);
}

.brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-controls { display: flex; align-items: center; gap: 10px; position: relative; }

/* "Get Pro" style pill (model picker trigger) */
.pill-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.pill-btn:hover { background: var(--surface-2); transform: translateY(-1px); box-shadow: var(--shadow-pill); }
.pill-btn:active { transform: translateY(0); }

.round-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s ease, transform 0.15s ease;
}
.round-btn:hover { background: var(--surface-2); transform: translateY(-1px); }
.round-btn:active { transform: translateY(0); }

/* ---------- Dropdown menus ---------- */
.picker { position: relative; flex-shrink: 0; }

.picker-menu {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: 236px;
  max-width: calc(100vw - 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 50px -16px rgba(15, 23, 42, 0.25);
  padding: 8px;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 60;
}
.picker-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.picker-menu.flip-up {
  top: auto;
  bottom: calc(100% + 10px);
}

.picker-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font);
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease;
}
.picker-option:hover { background: var(--accent-softer); }
.picker-option:active { background: var(--accent-soft); }
.picker-option i { font-size: 18px; color: var(--accent); flex-shrink: 0; }
.picker-option span { font-size: 13.5px; font-weight: 700; }
.picker-option small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }

/* ---------- Menu panel (hamburger) ---------- */
.menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 230px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 24px 50px -16px rgba(15, 23, 42, 0.25);
  padding: 8px;
  opacity: 0;
  transform: translateY(-8px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  z-index: 60;
}
.menu-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  font-family: var(--font);
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease;
}
.menu-item:hover { background: var(--accent-softer); }
.menu-item:active { background: var(--accent-soft); }
.menu-item i { font-size: 18px; color: var(--accent); flex-shrink: 0; }
.menu-item span { font-size: 13.5px; font-weight: 700; }
.menu-item small { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }
.menu-item.active { background: var(--accent-soft); }

.menu-sub {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding-left: 8px;
}
.menu-sub.open { max-height: 420px; overflow-y: auto; }

/* ---------- Empty state (hero) ---------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px 32px 12px;
  animation: fade-in 0.5s ease both;
}
.empty-state.hidden { display: none; }

/* brain image — sized to fit the old bouncing-ball (orb) spot */
.brain-icon {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  object-fit: cover;
  position: relative;
  margin-bottom: 34px;
  display: block;
  border: 4px solid rgba(255, 255, 255, 0.9);
  box-shadow:
    0 0 45px 12px rgba(56, 189, 248, 0.35),
    0 18px 40px -12px rgba(2, 132, 199, 0.45),
    inset 0 -14px 26px rgba(3, 105, 161, 0.35);
  animation: orbFloat 5s ease-in-out infinite;
}
.brain-icon::before {
  content: '';
  position: absolute;
  inset: -18px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.22) 0%, transparent 65%);
  animation: orbPulse 3.2s ease-in-out infinite;
  z-index: -1;
}

.empty-title {
  font-size: 27px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.25;
  max-width: 300px;
  margin-bottom: 30px;
}

/* suggestion chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 9px;
  max-width: 330px;
}
.chip {
  font-family: var(--font);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s ease;
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.08);
}
.chip i { font-size: 14px; color: var(--accent); }
.chip:hover {
  border-color: var(--accent);
  background: var(--accent-softer);
  transform: translateY(-2px);
  box-shadow: var(--shadow-pill);
}
.chip:active { transform: translateY(-1px) scale(0.98); }

/* ---------- Chat / messages ---------- */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 8px 24px 16px;
  scroll-behavior: smooth;
  display: block;
}
.chat.has-messages { display: block; }
.chat:not(.has-messages) { display: none; }

.messages { display: flex; flex-direction: column; gap: 18px; }

/* follow-up row */
.follow-up {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px 4px;
  animation: slide-up 0.35s ease both;
}
.follow-label { font-size: 12px; color: var(--faint); font-weight: 500; }
.follow-text { font-size: 13px; font-weight: 700; color: var(--text); line-height: 1.4; }

.message { animation: slide-up 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.1) both; }

.message.user { display: flex; flex-direction: column; align-items: flex-end; }
.message.bot { display: flex; flex-direction: column; align-items: flex-start; }

.message-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.message.user .message-row { justify-content: flex-end; }
.message.bot .message-row { align-items: flex-start; }

/* user bubble: soft blue with dark border + avatar (per mockup) */
.message.user .message-bubble {
  background: var(--accent-softer);
  border: 1.5px solid var(--border-strong);
  border-radius: 18px 18px 4px 18px;
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
  max-width: 78%;
  word-break: break-word;
}
[data-theme="dark"] .message.user .message-bubble { border-color: var(--border-strong); }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(145deg, #38bdf8, #0284c7);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  flex-shrink: 0;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), 0 4px 10px -3px rgba(2,132,199,0.4);
}

/* bot: "Ai" pill + text (per mockup) */
.message.bot > .message-row > .message-bubble {
  background: transparent;
  border: none;
  padding: 0;
  font-size: 13.5px;
  line-height: 1.6;
  max-width: 84%;
  word-break: break-word;
}
.bot-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  border-radius: 999px;
  padding: 5px 13px;
  letter-spacing: 0.01em;
  flex-shrink: 0;
}
[data-theme="dark"] .bot-pill { color: var(--accent); }

.message.bot .message-bubble p { margin: 0 0 6px; }
.message.bot .message-bubble p:last-child { margin-bottom: 0; }

.message-meta {
  font-size: 10.5px;
  color: var(--faint);
  margin-top: 5px;
  padding: 0 4px;
  font-weight: 500;
}

/* message action buttons */
.msg-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.message:hover .msg-actions { opacity: 1; transform: translateY(0); }
/* touch devices have no hover — keep actions visible */
@media (hover: none) {
  .msg-actions { opacity: 1; transform: none; }
}

.msg-action {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.msg-action:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-softer); transform: translateY(-1px); }

/* good / bad feedback buttons */
.msg-feedback {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.fb-btn {
  font-family: var(--font);
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
}
.fb-btn:hover { transform: translateY(-1px); }
.fb-btn.good:hover, .fb-btn.good.active { color: #059669; border-color: #059669; background: rgba(16, 185, 129, 0.1); }
.fb-btn.bad:hover, .fb-btn.bad.active { color: #dc2626; border-color: #dc2626; background: rgba(239, 68, 68, 0.1); }
[data-theme="dark"] .fb-btn.good:hover, [data-theme="dark"] .fb-btn.good.active { color: #34d399; }
[data-theme="dark"] .fb-btn.bad:hover, [data-theme="dark"] .fb-btn.bad.active { color: #f87171; }

.system-note {
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 12px;
  padding: 8px 12px;
  display: inline-block;
}

/* ---------- Card mode ---------- */
.card-bubble {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  animation: slide-up 0.35s ease both;
}
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  flex-wrap: wrap;
}
.card-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(145deg, #0ea5e9, #0369a1);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  box-shadow: inset 0 1px 2px rgba(255,255,255,0.4), 0 4px 10px -3px rgba(2,132,199,0.4);
}
.card-name { font-size: 13px; font-weight: 800; }
.card-model {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 9px;
}
.card-time { font-size: 10.5px; color: var(--faint); margin-left: auto; }
.card-body { font-size: 13.5px; line-height: 1.6; }
.message .card-bubble .card-body p { margin: 0 0 6px; }
[data-theme="dark"] .card-model { color: var(--accent); }

/* ---------- Typing indicator ---------- */
.typing {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 12px 4px;
}
.typing span {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.35;
  animation: dotFlashing 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

/* ---------- Train bar ---------- */
.train-bar {
  display: none;
  align-items: center;
  gap: 8px;
  margin: 0 24px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 10px 8px 16px;
  flex-shrink: 0;
  animation: slide-down 0.25s ease both;
}
.train-bar.open { display: flex; }
.train-bar > i { color: var(--accent); font-size: 17px; flex-shrink: 0; }
.train-bar input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.train-bar input::placeholder { color: var(--faint); }
.train-bar button {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s ease;
  flex-shrink: 0;
}
[data-theme="dark"] .train-bar button { color: var(--accent); }
.train-bar button:hover { background: var(--accent); color: #fff; }

/* ---------- Composer ---------- */
.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 6px 6px 12px;
  flex-shrink: 0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-softer), var(--shadow-pill);
}
.composer input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  min-width: 0;
}
.composer input::placeholder { color: var(--faint); }

.composer-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s ease;
  flex-shrink: 0;
}
.composer-btn:hover { color: var(--accent); background: var(--accent-softer); }
.composer-btn.active { color: var(--accent); background: var(--accent-soft); }

.mic-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.18s ease;
  flex-shrink: 0;
}
.mic-btn:hover { color: var(--accent); background: var(--accent-softer); }

#sendBtn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(145deg, #0ea5e9 0%, #0284c7 55%, #0369a1 100%);
  color: #fff;
  font-size: 17px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.4),
    inset 0 -3px 5px rgba(2, 62, 102, 0.4),
    0 8px 18px -6px rgba(2, 132, 199, 0.55);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  flex-shrink: 0;
}
#sendBtn:hover { transform: translateY(-2px) scale(1.04); box-shadow: inset 0 2px 3px rgba(255,255,255,0.4), inset 0 -3px 5px rgba(2,62,102,0.4), 0 12px 24px -6px rgba(2,132,199,0.6); }
#sendBtn:active { transform: translateY(0) scale(0.96); }
#sendBtn.sent { animation: sendPop 0.5s ease; }

/* ---------- Price cards ---------- */
.price-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin: 8px 0;
  animation: slide-up 0.35s ease both;
}
.price-card .price-title { font-size: 13px; font-weight: 800; margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
.price-card .price-title i { color: var(--accent); }
.price-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.price-row:last-of-type { border-bottom: none; }
.price-row .sym { font-weight: 800; color: var(--accent-strong); }
[data-theme="dark"] .price-row .sym { color: var(--accent); }
.price-row .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.price-note { font-size: 10.5px; color: var(--faint); margin-top: 8px; }

/* ---------- Weather card ---------- */
.weather-card {
  background: linear-gradient(145deg, var(--accent-soft), var(--surface));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px 0;
  animation: slide-up 0.35s ease both;
}
.weather-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.weather-head .price-title { margin-bottom: 2px; }
.weather-desc { font-size: 12px; color: var(--muted); }
.weather-icon { font-size: 34px; }
.weather-temp { font-size: 30px; font-weight: 800; margin: 8px 0 4px; letter-spacing: -0.02em; }
.weather-meta { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.weather-card .weather-meta span { display: inline-flex; align-items: center; gap: 5px; }
.weather-card .weather-meta i { color: var(--accent); }

/* ---------- Code blocks ---------- */
.code-block {
  position: relative;
  margin: 8px 0;
  background: #0d1117;
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  max-width: 100%;
  word-break: break-word;
}
[data-theme="dark"] .code-block { background: #0b1220; border: 1px solid var(--border); }
.code-block pre { padding: 14px 16px; overflow-x: auto; }
.code-block code {
  font-size: 12px;
  line-height: 1.5;
  color: #e2e8f0;
  white-space: pre;
  word-wrap: break-word;
}
.code-block .token { color: #e2e8f0; }
.code-block .token.comment { color: #6272a4; font-style: italic; }
.code-block .token.property { color: #f8f8f2; }
.code-block .token.string { color: #fd971f; }
.code-block .token.keyword { color: #ff79c6; }
.code-block .token.selector { color: #ff79c6; }
.code-block .token.operator { color: #50fa7b; }
.code-block .token.number { color: #ffb86c; }
.code-block .token.bool { color: #ff79c6; }
.code-block .token.null { color: #50fa7b; }
.code-block .token.annotation { color: #6272a4; }

/* Collapsed state — limit height */
.code-block.collapsed {
  max-height: 300px;
  overflow: hidden;
}
.code-block.collapsed::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 60px;
  background: linear-gradient(to bottom, transparent, #0d1117);
  pointer-events: none;
}

/* Code header styling */
.code-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #161b22;
  border-bottom: 1px solid #30363d;
  font-size: 11px;
  font-weight: 600;
  color: #f8f8f2;
}
.code-header .code-lang {
  color: #f8f8f2;
}
.code-header .code-actions {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

/* Code actions (Copy, Expand) */
.code-actions {
  display: flex;
  gap: 6px;
}
.code-action {
  font-size: 11px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: #6272a4;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s ease;
}
.code-action:hover { background: #30363d; color: #f8f8f2; }
.code-action:focus { outline: none; background: #30363d; color: #f8f8f2; }

/* Copy button feedback */
.code-copy:hover { background: #30363d; color: #f8f8f2; }
.code-copy:active { background: #4d5566; }
.code-tick { color: #50fa7b; }

/* Expand/collapse button */
.code-expand:hover { color: #f8f8f2; }

/* Responsive code block on mobile */
@media (max-width: 480px) {
  .code-block { font-size: 11px; }
  .code-block pre { padding: 10px 12px; }
  .code-header { padding: 6px 10px; font-size: 10px; }
}

.math-detail {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 11px;
  margin-top: 8px;
  line-height: 1.5;
}

.sentiment-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 4px 11px;
  margin-top: 6px;
}
.sentiment-badge.positive { background: rgba(16, 185, 129, 0.12); color: #059669; }
.sentiment-badge.negative { background: rgba(239, 68, 68, 0.12); color: #dc2626; }
.sentiment-badge.neutral { background: var(--surface); color: var(--muted); }
[data-theme="dark"] .sentiment-badge.positive { color: #34d399; }
[data-theme="dark"] .sentiment-badge.negative { color: #f87171; }

/* ---------- Status bar ---------- */
.status-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 24px 8px;
  font-size: 11.5px;
  color: var(--muted);
  flex-shrink: 0;
}
.status-bar.sr-only { display: none; }
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
  transition: background 0.3s ease;
}
.status-bar.searching .status-dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); animation: pulse 1s infinite; }

/* ---------- Scrollbars ---------- */
.chat::-webkit-scrollbar, .menu-sub::-webkit-scrollbar { width: 5px; }
.chat::-webkit-scrollbar-thumb, .menu-sub::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
.chat::-webkit-scrollbar-track { background: transparent; }

/* ---------- Animations ---------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slide-up {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slide-down {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes dotFlashing {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-4px); }
}
@keyframes orbFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes orbPulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.08); }
}
@keyframes sendPop {
  0% { transform: scale(1); }
  40% { transform: scale(0.88) rotate(-12deg); }
  100% { transform: scale(1) rotate(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ---------- Mode / thinking pills ---------- */
.brand-sub {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.2px;
}
.mode-pill, .think-pill {
  padding: 8px 12px;
  font-size: 12px;
}
.mode-pill i, .think-pill i { font-size: 14px; }

/* ---------- Stop button ---------- */
.stop-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: #fee2e2;
  color: #dc2626;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
  flex-shrink: 0;
}
.stop-btn:hover { background: #fecaca; transform: scale(1.05); }
.stop-btn[hidden] { display: none; }
.send-btn:disabled, #sendBtn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Streaming cursor ---------- */
.streaming-cursor {
  display: inline-block;
  width: 8px; height: 16px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: pulse 0.9s ease-in-out infinite;
}
.sentiment-badge { margin-top: 8px; }
.error-note { color: #dc2626; font-weight: 600; }

/* ---------- Panels (model manager + image gen) ---------- */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  animation: panelFade 0.18s ease;
}
.panel-overlay[hidden] { display: none; }
@keyframes panelFade {
  from { opacity: 0; }
  to { opacity: 1; }
}
.panel {
  background: var(--surface);
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  max-height: 84dvh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px -18px rgba(2, 6, 23, 0.4);
  animation: panelSlide 0.22s ease;
}
@keyframes panelSlide {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head h2 i { color: var(--accent); }
.panel-close {
  border: none;
  background: transparent;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.panel-close:hover { background: var(--accent-softer); color: var(--accent); }
.panel-body {
  padding: 16px 18px;
  overflow-y: auto;
}
.panel-hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.5;
}

/* model manager */
.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-softer);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}
.model-status i { color: var(--accent); font-size: 16px; }
.model-list { display: flex; flex-direction: column; gap: 10px; }
.model-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.model-row-info { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.model-row-info strong { font-size: 14px; }
.model-row-info small { font-size: 11px; color: var(--muted); line-height: 1.4; }
.model-warning {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef3c7;
  color: #92400e;
  font-size: 12px;
  line-height: 1.5;
  margin-top: 4px;
}

/* Chat image with watermark blur */
.chat-image {
  position: relative;
  display: inline-block;
  width: 100%;
  max-width: 320px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 14px;
}
.chat-image img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  object-fit: cover;
}
.img-blur-overlay {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 72%;
  height: 34%;
  background: rgba(0,0,0,0.16);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom-right-radius: 14px;
  border-top-left-radius: 16px;
  pointer-events: none;
}
.img-watermark {
  position: absolute;
  bottom: 8px;
  right: 10px;
  color: rgba(255,255,255,0.95);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgba(0,0,0,0.75);
  pointer-events: none;
  z-index: 2;
}
.img-blur-overlay {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 90px;
  height: 32px;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-top-left-radius: 12px;
  pointer-events: none;
  z-index: 1;
}
.model-warning i { flex-shrink: 0; margin-top: 1px; }
.model-actions { margin-top: 14px; }

/* progress */
.model-progress, .image-progress { margin-top: 14px; }
.model-progress[hidden], .image-progress[hidden] { display: none; }
.progress-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--border);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), #0ea5e9);
  transition: width 0.3s ease;
}
.progress-fill.progress-indeterminate {
  width: 40% !important;
  animation: indeterminate 1.4s ease-in-out infinite;
}
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(320%); }
}
.progress-text {
  font-size: 12px;
  color: var(--muted);
  margin: 6px 0 8px;
  font-weight: 600;
}

/* skeleton loading shown while the image is being generated */
.image-skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.skel-line {
  height: 12px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-3) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: skel-shimmer 1.4s ease-in-out infinite;
}
.skel-line.short { width: 60%; }
/* glassy shimmering placeholder while the image is generated */
.skel-img {
  height: 200px;
  border-radius: 10px;
  background:
    linear-gradient(120deg, transparent 30%, rgba(255,255,255,0.35) 50%, transparent 70%),
    linear-gradient(90deg, var(--border) 25%, var(--surface-3) 50%, var(--border) 75%);
  background-size: 200% 100%, 200% 100%;
  animation: skel-shimmer 1.6s ease-in-out infinite;
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}
@keyframes skel-shimmer {
  0% { background-position: 200% 0, 200% 0; }
  100% { background-position: -200% 0, -200% 0; }
}


/* buttons */
.btn-primary, .btn-secondary, .btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 9px 16px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary { background: var(--accent-softer); color: var(--accent); }
.btn-danger { background: #fee2e2; color: #dc2626; }
.btn-danger:hover { background: #fecaca; }

/* image generation */
.image-form { display: flex; flex-direction: column; gap: 10px; }
.image-form textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: vertical;
  background: var(--surface);
  color: inherit;
}
.image-form textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.image-ratios { display: flex; gap: 8px; }
.ratio-btn {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 0;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.ratio-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.image-result { margin-top: 14px; }
.image-result[hidden] { display: none; }
.image-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
  font-weight: 600;
}
.image-result img {
  width: 100%;
  border-radius: 12px;
  display: block;
  border: 1px solid var(--border);
}
.image-result-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  align-items: center;
}
.image-result-actions a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}
.image-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fee2e2;
  color: #b91c1c;
  font-size: 13px;
  font-weight: 600;
}
.image-error[hidden] { display: none; }

/* offline composer hint */
.composer.offline { border-color: #f59e0b; }

/* ---------- Image Card (in-chat) ---------- */
.image-card {
  max-width: 420px;
  margin: 12px 0;
  border-radius: 14px;
  overflow: hidden;
  background: #161b22;
  border: 1px solid #30363d;
  box-shadow: 0 0 24px rgba(56, 139, 253, 0.08);
}
.image-card-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px 6px;
  font-size: 13px;
  font-weight: 600;
  color: #58a6ff;
}
.image-card-label .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #58a6ff;
  animation: pulse-dot 1.2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
.image-card-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 14px;
  background: #0d1117;
}

.image-card-placeholder {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.image-card-placeholder::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(56, 139, 253, 0.07) 50%, transparent 70%);
  animation: shimmer 2.5s infinite;
  z-index: 1;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.image-card-placeholder.ready::before {
  display: none;
}
.image-card-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  opacity: 0;
  transition: opacity 0.3s ease;
  z-index: 2;
}
.image-card-img.visible {
  opacity: 1;
}
.image-card-watermark {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  line-height: 1.2;
  pointer-events: none;
}
.image-card {
  max-width: 100%;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #0d1117;
}
.image-card-label {
  padding: 8px 12px 4px;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.image-card-actions {
  padding: 6px 12px 10px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.image-card-actions button {
  flex: 1;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.image-card-actions button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.image-card-error {
  padding: 12px;
  text-align: center;
  color: #dc2626;
  font-size: 12px;
}
.image-card-error button {
  margin-top: 8px;
  padding: 6px 14px;
  border: 1px solid #dc2626;
  border-radius: 8px;
  background: transparent;
  color: #dc2626;
  font-size: 12px;
  cursor: pointer;
}
.image-card-error button:hover {
  background: #dc2626;
  color: #fff;
}
@media (prefers-reduced-motion: reduce) {
  .image-card-placeholder::before { animation: none; }
  .image-card-label .dot { animation: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
  body { padding: 0; }
  .app {
    max-width: none;
    height: 100dvh;
    border-radius: 0;
  }
  .header { padding: 18px 18px 10px; }
  .chat { padding: 8px 18px 12px; }
  .composer { margin: 6px 18px 18px; }
  .train-bar { margin: 0 18px 10px; }
  .empty-title { font-size: 24px; }
  .brain-icon { width: 120px; height: 120px; margin-bottom: 26px; }
  .image-card { max-width: 100%; margin: 8px 0; border-radius: 12px; }
  .image-card-label { padding: 8px 12px 4px; font-size: 12px; }
  .image-card-actions { padding: 6px 12px 10px; }
  .image-card-watermark { right: 8px; bottom: 8px; font-size: 11px; padding: 5px 8px; }
}
