/* ── Reset ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Design Tokens ───────────────────────────────────── */
:root {
  --radius:    8px;
  --radius-sm: 5px;
  --radius-lg: 12px;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  --font-ui:   'Inter', system-ui, sans-serif;
  --transition: 0.18s ease;
}

/* ── Dark Theme (default) ────────────────────────────── */
[data-theme="dark"] {
  --bg:           #0d0f17;
  --bg2:          #111420;
  --surface:      #161923;
  --surface2:     #1c2033;
  --surface3:     #222640;
  --border:       #252a3f;
  --border2:      #2e3450;
  --border3:      #3a4060;

  --text:         #e4e8f5;
  --text-muted:   #7880a0;
  --text-dim:     #404668;

  --accent:       #6366f1;
  --accent-h:     #818cf8;
  --accent-glow:  rgba(99,102,241,0.18);
  --accent-soft:  rgba(99,102,241,0.12);

  /* JSON tokens */
  --c-key:        #7dd3fc;
  --c-str:        #86efac;
  --c-num:        #fbbf24;
  --c-bool:       #f472b6;
  --c-null:       #94a3b8;
  --c-brace:      #c084fc;
  --c-bracket:    #34d399;
  --c-punct:      #475569;
  --c-comment:    #5a6a8a;

  --status-ok:    #22c55e;
  --status-err:   #f87171;
  --status-warn:  #f59e0b;
  --status-ok-bg: rgba(34,197,94,0.10);
  --status-err-bg:rgba(248,113,113,0.10);
  --status-warn-bg:rgba(245,158,11,0.10);

  --invalid-char-bg: rgba(248, 113, 113, 0.35);
  --invalid-char-border: rgba(248, 113, 113, 0.8);

  --shadow:       0 2px 12px rgba(0,0,0,0.5);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.6);
}

/* ── Light Theme ─────────────────────────────────────── */
[data-theme="light"] {
  --bg:           #f0f2f8;
  --bg2:          #e8eaf2;
  --surface:      #ffffff;
  --surface2:     #f5f6fb;
  --surface3:     #eceef8;
  --border:       #dde0ee;
  --border2:      #cdd0e3;
  --border3:      #bbbfd8;

  --text:         #1a1d2e;
  --text-muted:   #5a6080;
  --text-dim:     #adb2cc;

  --accent:       #5254cc;
  --accent-h:     #6366f1;
  --accent-glow:  rgba(82,84,204,0.12);
  --accent-soft:  rgba(82,84,204,0.08);

  --c-key:        #0369a1;
  --c-str:        #16a34a;
  --c-num:        #b45309;
  --c-bool:       #be185d;
  --c-null:       #64748b;
  --c-brace:      #7c3aed;
  --c-bracket:    #0d7a55;
  --c-punct:      #94a3b8;
  --c-comment:    #8896b0;

  --status-ok:    #16a34a;
  --status-err:   #dc2626;
  --status-warn:  #d97706;
  --status-ok-bg: rgba(22,163,74,0.08);
  --status-err-bg:rgba(220,38,38,0.08);
  --status-warn-bg:rgba(217,119,6,0.08);

  --invalid-char-bg: rgba(220, 38, 38, 0.18);
  --invalid-char-border: rgba(220, 38, 38, 0.7);

  --shadow:       0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg:    0 8px 32px rgba(0,0,0,0.12);
}

/* ── Base ────────────────────────────────────────────── */
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

/* ── App Shell ───────────────────────────────────────── */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 20;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  height: 52px;
  gap: 16px;
}

/* Logo */
.logo { display: flex; align-items: center; gap: 9px; flex-shrink: 0; }
.logo-mark { display: flex; align-items: center; }
.logo-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #a5b4fc 0%, #c084fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Stats bar */
.header-center { flex: 1; display: flex; justify-content: center; }
.stats-bar {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  gap: 10px;
}
.stat {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.stat-div {
  width: 1px;
  height: 10px;
  background: var(--border2);
}

/* Header actions */
.header-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.divider-v { width: 1px; height: 20px; background: var(--border2); margin: 0 2px; }

/* ── Main Layout — horizontal (side by side) ─────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: row;   /* ← horizontal split */
  overflow: hidden;
  position: relative;
}

/* ── Input Section (left pane) ───────────────────────── */
.input-section {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  width: 50%;            /* default 50/50 split */
  flex-shrink: 0;
  min-width: 180px;
}

.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 40px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.section-toolbar-left, .section-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-toolbar-center { flex: 1; display: flex; justify-content: center; }

.toolbar-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  text-transform: uppercase;
}

.input-panel {
  display: flex;
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ── Gutter / Resize Handle (vertical) ──────────────── */
.gutter {
  width: 6px;             /* vertical bar */
  flex-shrink: 0;
  background: var(--border);
  cursor: col-resize;     /* left–right resize cursor */
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 5;
  transition: background var(--transition);
}
.gutter:hover, .gutter.dragging { background: var(--accent); }
.gutter-handle {
  width: 2px;
  height: 40px;           /* vertical pill */
  border-radius: 999px;
  background: var(--border3);
  pointer-events: none;
}
.gutter:hover .gutter-handle,
.gutter.dragging .gutter-handle { background: rgba(255,255,255,0.5); }

/* ── Output Section (right pane) ────────────────────── */
.output-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  min-width: 180px;
}

/* ── Status Pill ─────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface3);
  border: 1px solid var(--border2);
  font-size: 11.5px;
  color: var(--text-muted);
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
  transition: background var(--transition);
}
.status-pill.ok    { background: var(--status-ok-bg);   border-color: var(--status-ok);   color: var(--status-ok); }
.status-pill.ok .status-dot   { background: var(--status-ok); }
.status-pill.err   { background: var(--status-err-bg);  border-color: var(--status-err);  color: var(--status-err); }
.status-pill.err .status-dot  { background: var(--status-err); }
.status-pill.warn  { background: var(--status-warn-bg); border-color: var(--status-warn); color: var(--status-warn); }
.status-pill.warn .status-dot { background: var(--status-warn); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  transition: background var(--transition), color var(--transition), border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
  line-height: 1;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border2);
}
.btn-ghost:hover {
  background: var(--surface3);
  color: var(--text);
  border-color: var(--border3);
}

.btn-icon {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border2);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
}
.btn-icon:hover { background: var(--surface3); color: var(--text); border-color: var(--border3); }

.btn-format {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
  padding: 6px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.btn-format:hover {
  background: var(--accent-h);
  box-shadow: 0 0 0 4px var(--accent-glow);
}
.btn-format kbd {
  font-family: var(--font-mono);
  font-size: 10px;
  background: rgba(255,255,255,0.18);
  border-radius: 3px;
  padding: 1px 4px;
  color: rgba(255,255,255,0.85);
}

.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-copy svg { flex-shrink: 0; }

/* Theme button — icon switching */
[data-theme="dark"]  .icon-sun  { display: none; }
[data-theme="dark"]  .icon-moon { display: block; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: block; }

/* ── Line Numbers ────────────────────────────────────── */
.line-numbers {
  width: 44px;
  flex-shrink: 0;
  padding: 12px 8px 12px 0;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-dim);
  background: var(--surface2);
  border-right: 1px solid var(--border);
  overflow: hidden;
  user-select: none;
}

/* ── Editor overlay (invalid char highlights) ────────── */
.editor-overlay {
  position: absolute;
  top: 0;
  left: 44px; /* match line-numbers width + border */
  right: 0;
  bottom: 0;
  pointer-events: none;
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  padding: 12px 16px 12px 12px;
  white-space: pre-wrap;
  word-break: break-all;
  color: transparent; /* text is invisible — only highlights show */
  z-index: 2;
}

/* Invalid character highlight spans */
.invalid-char {
  background: var(--invalid-char-bg);
  border-bottom: 2px solid var(--invalid-char-border);
  border-radius: 2px;
  color: transparent;
}

/* ── Editor ──────────────────────────────────────────── */
.editor {
  position: relative;
  z-index: 3;
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: transparent; /* overlay shows through */
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  padding: 12px 16px 12px 12px;
  tab-size: 2;
  overflow: auto;
  width: 100%;
  transition: background var(--transition);
  caret-color: var(--accent-h);
}
/* Actual editor background sits on the panel, not the textarea */
.input-panel {
  background: var(--surface);
}
.editor::placeholder { color: var(--text-dim); font-size: 12.5px; }

/* ── Output ──────────────────────────────────────────── */
.output-wrap {
  flex: 1;
  overflow: auto;
  background: var(--surface);
  position: relative;
  width: 100%;
}

.output-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
}
.output-placeholder.hidden { display: none; }
.placeholder-graphic { color: var(--border3); }
.placeholder-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
}
.placeholder-sub {
  font-size: 12.5px;
  color: var(--text-dim);
}
.placeholder-sub strong { color: var(--text-muted); font-weight: 500; }

.output-tree {
  padding: 12px 16px 16px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.7;
  min-height: 100%;
}

/* ── Tree Nodes ──────────────────────────────────────── */
.tree-node { display: block; }

.tree-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border: none;
  background: none;
  padding: 0 1px;
  font: inherit;
  color: inherit;
  line-height: inherit;
  border-radius: 3px;
}
.tree-toggle:hover { background: var(--accent-soft); }
.tree-toggle:hover .toggle-icon { color: var(--accent-h); }

.toggle-icon {
  display: inline-block;
  width: 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 9px;
  transition: transform 0.15s, color 0.15s;
  flex-shrink: 0;
}
.toggle-icon.collapsed { transform: rotate(-90deg); }

.tree-children {
  padding-left: 18px;
  border-left: 1.5px solid var(--border2);
  margin-left: 5px;
  transition: border-color var(--transition);
}
.tree-children:hover { border-left-color: var(--border3); }
.tree-children.hidden { display: none; }

/* Collapsed inline summary: map {..} or array [..] */
.tree-summary {
  display: none;
  align-items: center;
  gap: 0;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  line-height: inherit;
}
.tree-summary:hover .summary-bracket { color: var(--accent-h); }
.tree-summary:hover .summary-dots    { color: var(--text-muted); }
.summary-bracket { color: var(--c-brace); transition: color 0.15s; }
.summary-bracket.arr { color: var(--c-bracket); }
.summary-dots {
  color: var(--text-dim);
  font-size: 11px;
  padding: 0 1px;
  background: var(--surface3);
  border-radius: 2px;
  margin: 0 1px;
  transition: color 0.15s;
}
.summary-count {
  font-size: 10px;
  color: var(--text-dim);
  margin-left: 4px;
  font-family: var(--font-ui);
}

/* ── Comment lines ───────────────────────────────────── */
.j-comment {
  color: var(--c-comment);
  font-style: italic;
  display: block;
  opacity: 0.8;
}

/* ── Labelled block headers ──────────────────────────── */
.block-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 6px;
  user-select: none;
}
.block-header:first-child { margin-top: 4px; }

.block-label {
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--accent-h);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 2px 9px;
  white-space: nowrap;
  opacity: 0.9;
}

.block-label-line {
  flex: 1;
  height: 1px;
  background: var(--border2);
  border-radius: 1px;
}

.block-wrap { }
.block-gap  { margin-bottom: 8px; }

/* ── JSON Tokens ─────────────────────────────────────── */
.j-key     { color: var(--c-key); }
.j-str     { color: var(--c-str); }
.j-num     { color: var(--c-num); }
.j-bool    { color: var(--c-bool); }
.j-null    { color: var(--c-null); font-style: italic; }
.j-brace   { color: var(--c-brace); }
.j-bracket { color: var(--c-bracket); }
.j-colon   { color: var(--c-punct); margin: 0 5px 0 1px; }
.j-comma   { color: var(--c-punct); }

/* ── Footer ──────────────────────────────────────────── */
.footer {
  flex-shrink: 0;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.01em;
}

/* ── Fullscreen Output ───────────────────────────────── */
.output-section.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.output-section.fullscreen .output-wrap {
  flex: 1;
}
/* Hide app chrome behind fullscreen overlay */
.app.output-fullscreen > :not(.main),
.app.output-fullscreen .main > :not(.output-section) {
  visibility: hidden;
  pointer-events: none;
}

/* ── Toast ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Scrollbars ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border3); }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 700px) {
  .header-center { display: none; }

  /* On mobile, stack vertically again */
  .main { flex-direction: column; }
  .input-section { width: 100% !important; border-right: none; border-bottom: 1px solid var(--border); height: 45%; flex-shrink: 0; }
  .gutter { width: 100%; height: 6px; cursor: row-resize; }
  .gutter-handle { width: 40px; height: 2px; }
}

/* ── Invalid character banner in output tree ─────────── */
.invalid-banner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 7px 12px;
  margin: 6px 0;
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-left: 3px solid #f87171;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 11.5px;
  line-height: 1.4;
}

[data-theme="light"] .invalid-banner {
  background: rgba(220, 38, 38, 0.06);
  border-color: rgba(220, 38, 38, 0.3);
  border-left-color: #dc2626;
}

.invalid-banner-icon {
  color: #f87171;
  font-size: 13px;
  flex-shrink: 0;
}
[data-theme="light"] .invalid-banner-icon { color: #dc2626; }

.invalid-banner-label {
  color: var(--status-err);
  font-weight: 600;
  white-space: nowrap;
}

.invalid-banner-chars {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.invalid-char-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(248, 113, 113, 0.18);
  border: 1px solid rgba(248, 113, 113, 0.55);
  color: #fca5a5;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: default;
  letter-spacing: 0.03em;
}
[data-theme="light"] .invalid-char-pill {
  background: rgba(220, 38, 38, 0.10);
  border-color: rgba(220, 38, 38, 0.4);
  color: #dc2626;
}
.invalid-char-pill:hover {
  background: rgba(248, 113, 113, 0.28);
}

/* ── AI Button wrap + animated glow ring ─────────────── */
.ai-btn-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* The rotating conic-gradient ring — border only via clip-path mask */
.ai-glow-ring {
  position: absolute;
  inset: -2px;
  border-radius: 9px;
  /* Conic gradient fills the ring element */
  background: conic-gradient(
    from var(--glow-angle, 0deg),
    #6366f1,
    #a855f7,
    #ec4899,
    #6366f1
  );
  /* Mask out the interior so only a thin border-width strip glows */
  -webkit-mask:
    linear-gradient(#fff 0 0) content-box,
    linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  padding: 2px;          /* controls the border thickness */
  filter: blur(1px);
  opacity: 0.9;
  animation: spin-glow 2.4s linear infinite;
  z-index: 0;
}
@property --glow-angle {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}
@keyframes spin-glow {
  to { --glow-angle: 360deg; }
}

/* Fallback for browsers without @property */
@supports not (background: conic-gradient(from 0deg, red, red)) {
  .ai-glow-ring { animation: spin-glow-fallback 2.4s linear infinite; }
  @keyframes spin-glow-fallback {
    0%   { transform: rotate(0deg);   }
    100% { transform: rotate(360deg); }
  }
}

/* Brighter when drawer is open */
.ai-btn-wrap.active .ai-glow-ring {
  opacity: 1;
  filter: blur(0.5px);
}
.ai-btn-wrap:hover .ai-glow-ring { animation-duration: 1.4s; }

.btn-ai {
  position: relative;
  z-index: 1;
  background: transparent;
  border: none;
  font-weight: 600;
  font-size: 12.5px;
  padding: 5px 13px;
  border-radius: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.15s, transform 0.12s;
  cursor: pointer;
  letter-spacing: 0.02em;
  /* Dark mode: gradient text */
  color: #a5b4fc;
}
.btn-ai svg {
  color: #a5b4fc;
  flex-shrink: 0;
}
.btn-ai:hover  { opacity: 0.85; }
.btn-ai:active { transform: scale(0.96); }

/* Light mode: use a darker readable colour */
[data-theme="light"] .btn-ai       { color: #4f46e5; }
[data-theme="light"] .btn-ai svg   { color: #4f46e5; }

/* ── AI Backdrop ─────────────────────────────────────── */
.ai-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 49;
  backdrop-filter: blur(3px);
}
.ai-backdrop.open { display: block; }

/* ── AI Drawer ───────────────────────────────────────── */
.ai-drawer {
  position: fixed;
  right: 0; top: 0; bottom: 0;
  width: 460px;
  max-width: 96vw;
  background: var(--bg);
  border-left: 1px solid var(--border2);
  box-shadow: -12px 0 60px rgba(0,0,0,0.55);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.26s cubic-bezier(0.4,0,0.2,1);
}
.ai-drawer.open { transform: translateX(0); }

/* ── Drawer header ───────────────────────────────────── */
.ai-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px 0 18px;
  height: 54px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ai-drawer-title {
  display: flex;
  align-items: center;
  gap: 9px;
}
.ai-title-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #4f52b8 0%, #8b3fc9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.08) inset;
}
.ai-title-icon svg { color: #fff; }
.ai-drawer-title span {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, #a5b4fc, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.ai-drawer-actions { display: flex; align-items: center; gap: 4px; }
.ai-icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
}
.ai-icon-btn:last-child { width: auto; padding: 0 10px; }

/* ── API key bar ─────────────────────────────────────── */
.ai-key-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: rgba(99,102,241,0.05);
  border-bottom: 1px solid rgba(99,102,241,0.15);
  flex-shrink: 0;
}
.ai-key-bar-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
}
.ai-key-icon { flex-shrink: 0; color: #818cf8; }
.ai-key-bar-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ai-key-bar.hidden { display: none; }
.ai-key-input {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 12px;
  outline: none;
  min-width: 0;
}
.ai-key-input:focus { border-color: #818cf8; box-shadow: 0 0 0 3px rgba(129,140,248,0.12); }
.btn-ai-save {
  background: linear-gradient(135deg, #5254cc, #8b3fc9);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 12px;
  padding: 8px 16px;
  white-space: nowrap;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
}
.btn-ai-save:hover { filter: brightness(1.1); }
.btn-ai-save:hover { filter: brightness(1.1); }

/* ── Prompt section ──────────────────────────────────── */
.ai-prompt-bar {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.ai-prompt-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.ai-prompt-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.ai-prompt-input {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border2);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 9px 13px;
  outline: none;
  min-width: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.ai-prompt-input:focus {
  border-color: #818cf8;
  box-shadow: 0 0 0 3px rgba(129,140,248,0.1);
}
.ai-prompt-input::placeholder { color: var(--text-dim); }

.btn-ai-send {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #5254cc, #8b3fc9);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: filter 0.15s, box-shadow 0.15s, transform 0.12s;
  cursor: pointer;
}
.btn-ai-send:hover { filter: brightness(1.12); box-shadow: 0 0 0 3px rgba(129,140,248,0.2); }
.btn-ai-send:active { transform: scale(0.93); }
.btn-ai-send:disabled { opacity: 0.4; cursor: not-allowed; filter: none; }

/* Quick chips */
.ai-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 11px;
}
.ai-chip {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.ai-chip:hover {
  background: rgba(129,140,248,0.1);
  border-color: rgba(129,140,248,0.5);
  color: #a5b4fc;
  box-shadow: 0 0 0 3px rgba(129,140,248,0.06);
}

/* ── Response wrap ───────────────────────────────────── */
.ai-response-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
}

/* Idle state */
.ai-idle {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
}
.ai-idle-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
  color: var(--text-dim);
}
.ai-idle-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
}
.ai-idle-sub {
  font-size: 12.5px;
  color: var(--text-dim);
  max-width: 240px;
  line-height: 1.5;
}

/* Loading dots */
.ai-loading {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.ai-loading-dots {
  display: flex;
  gap: 7px;
}
.ai-loading-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, #818cf8, #c084fc);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.ai-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.ai-loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}
.ai-loading-text {
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Result markdown ─────────────────────────────────── */
.ai-result {
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.78;
  color: var(--text);
}
.ai-result h1, .ai-result h2, .ai-result h3 {
  font-weight: 700;
  margin: 18px 0 6px;
  line-height: 1.3;
}
.ai-result h1 { font-size: 16px; color: var(--text); }
.ai-result h2 { font-size: 14px; color: #a5b4fc; }
.ai-result h3 { font-size: 13.5px; color: var(--text-muted); }
.ai-result p { margin: 0 0 10px; }
.ai-result ul, .ai-result ol { margin: 4px 0 10px 0; padding-left: 20px; }
.ai-result li { margin-bottom: 5px; }
.ai-result code {
  font-family: var(--font-mono);
  font-size: 11.5px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 4px;
  padding: 1px 5px;
  color: #86efac;
}
.ai-result pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 8px 0 14px;
}
.ai-result pre code { background: none; border: none; padding: 0; font-size: 12px; }
.ai-result strong { font-weight: 600; color: var(--text); }
.ai-result em { color: var(--text-muted); font-style: italic; }
.ai-result hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.ai-result blockquote {
  border-left: 3px solid #818cf8;
  margin: 8px 0;
  padding: 6px 14px;
  color: var(--text-muted);
  background: rgba(129,140,248,0.06);
  border-radius: 0 6px 6px 0;
}

/* Result meta bar */
.ai-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.ai-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(129,140,248,0.1);
  border: 1px solid rgba(129,140,248,0.25);
  color: #a5b4fc;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.ai-meta-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}

/* Light theme */
[data-theme="light"] .ai-result code { color: #16a34a; }
[data-theme="light"] .ai-result h2 { color: #4f46e5; }
[data-theme="light"] .ai-result h3 { color: #6366f1; }
[data-theme="light"] .ai-result blockquote { background: rgba(99,102,241,0.06); border-color: #6366f1; }
[data-theme="light"] .ai-idle-icon { background: var(--surface3); }

@media (max-width: 700px) { .ai-drawer { width: 100vw; } }
