/* ══════════════════════════════════════════════════════════════════════
   JasperChat — design system
   Light-first, dark-ready. No external fonts, no CDN dependencies.
   ══════════════════════════════════════════════════════════════════════ */

/* ─────────────────────────── 1. Tokens ─────────────────────────── */
:root {
  /* Accent (overridable at runtime from Settings → Appearance) */
  --accent-h: 243;
  --accent-s: 75%;
  --accent: hsl(var(--accent-h) var(--accent-s) 58%);
  --accent-soft: hsl(var(--accent-h) var(--accent-s) 58% / 0.12);
  --accent-softer: hsl(var(--accent-h) var(--accent-s) 58% / 0.07);
  --accent-strong: hsl(var(--accent-h) var(--accent-s) 48%);
  --accent-2: hsl(calc(var(--accent-h) + 34) 82% 62%);
  --accent-grad: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  --accent-ring: hsl(var(--accent-h) var(--accent-s) 58% / 0.35);

  /* Semantic */
  --ok: #16a34a;
  --ok-soft: #16a34a1a;
  --warn: #d97706;
  --warn-soft: #d977061a;
  --danger: #dc2626;
  --danger-soft: #dc26261a;
  --info: #0284c7;
  --info-soft: #0284c71a;

  /* Surfaces */
  --bg: #eef0f6;
  --bg-deep: #e6e9f2;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --surface-3: #eef1f8;
  --surface-glass: rgba(255, 255, 255, 0.72);
  --surface-inset: #f1f3f9;

  /* Text */
  --text: #0e1526;
  --text-2: #48536b;
  --text-3: #7a86a0;
  --text-inv: #ffffff;

  /* Lines */
  --line: #e2e6f0;
  --line-2: #eef1f7;
  --line-strong: #cdd4e3;

  /* Effects */
  --shadow-xs: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.07), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 18px 44px rgba(16, 24, 40, 0.14), 0 6px 14px rgba(16, 24, 40, 0.07);
  --shadow-xl: 0 32px 72px rgba(11, 18, 32, 0.24), 0 10px 24px rgba(11, 18, 32, 0.12);
  --shadow-accent: 0 8px 22px hsl(var(--accent-h) var(--accent-s) 58% / 0.32);

  /* Geometry */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* Layout */
  --sidebar-w: 286px;
  --panel-w: 336px;
  --topbar-h: 58px;
  --content-max: 830px;

  /* Motion */
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --dur: 220ms;
  --dur-fast: 130ms;

  /* Type */
  --font: "Inter var", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", "Noto Sans", "Noto Sans ID", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --fs-base: 15px;
  --lh: 1.62;

  /* Code tokens — light */
  --tk-c: #7c8598;
  --tk-k: #cf222e;
  --tk-s: #0a3069;
  --tk-n: #0550ae;
  --tk-f: #8250df;
  --tk-t: #953800;
  --tk-p: #0550ae;
  --tk-o: #0550ae;
  --tk-b: #8250df;
  --tk-d: #116329;
  --tk-v: #24292f;
  --tk-i: #1a7f37;
  --tk-x: #cf222e;
  --tk-m: #6e7781;

  --code-bg: #f7f8fc;
  --code-head: #eef1f8;
}

[data-theme="dark"] {
  --bg: #08090d;
  --bg-deep: #05060a;
  --surface: #11141c;
  --surface-2: #171b25;
  --surface-3: #1e2330;
  --surface-glass: rgba(17, 20, 28, 0.72);
  --surface-inset: #0d1017;

  --text: #e9edf6;
  --text-2: #a3adc2;
  --text-3: #6f7a91;
  --text-inv: #0b0e14;

  --line: #242a38;
  --line-2: #1b202b;
  --line-strong: #333b4d;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.6);
  --shadow-xl: 0 34px 80px rgba(0, 0, 0, 0.72);

  --accent-soft: hsl(var(--accent-h) var(--accent-s) 62% / 0.18);
  --accent-softer: hsl(var(--accent-h) var(--accent-s) 62% / 0.1);

  --ok-soft: #16a34a26;
  --warn-soft: #d9770626;
  --danger-soft: #dc262626;
  --info-soft: #0284c726;

  --tk-c: #8b949e;
  --tk-k: #ff7b72;
  --tk-s: #a5d6ff;
  --tk-n: #79c0ff;
  --tk-f: #d2a8ff;
  --tk-t: #ffa657;
  --tk-p: #79c0ff;
  --tk-o: #ff7b72;
  --tk-b: #d2a8ff;
  --tk-d: #7ee787;
  --tk-v: #c9d1d9;
  --tk-i: #7ee787;
  --tk-x: #ff7b72;
  --tk-m: #8b949e;

  --code-bg: #0c0f16;
  --code-head: #151924;
}

/* ─────────────────────────── 2. Reset ─────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-base);
  line-height: var(--lh);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  overscroll-behavior: none;
}
h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
kbd {
  font-family: var(--mono); font-size: 11px; line-height: 1;
  padding: 3px 6px; border-radius: var(--r-xs);
  background: var(--surface-3); border: 1px solid var(--line);
  color: var(--text-2); white-space: nowrap;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--accent-soft); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong); border-radius: 999px;
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

.skip-link {
  position: fixed; top: 8px; left: 8px; z-index: 400;
  transform: translateY(-200%); transition: transform var(--dur-fast);
  background: var(--surface); padding: 8px 14px; border-radius: var(--r-sm);
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 13px;
}
.skip-link:focus { transform: none; }
.hidden, [hidden] { display: none !important; }

/* Icons */
.ic {
  width: 1.15em; height: 1.15em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  display: inline-block; vertical-align: middle;
}
.flip-v { transform: rotate(-90deg); }
.flip-h { transform: scaleX(-1); }

/* ─────────────────────────── 3. Primitives ─────────────────────────── */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border-radius: var(--r-sm);
  background: var(--btn-bg); color: var(--btn-fg);
  font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em;
  border: 1px solid var(--line);
  transition: background var(--dur-fast), border-color var(--dur-fast),
              transform var(--dur-fast), box-shadow var(--dur-fast), color var(--dur-fast);
  white-space: nowrap; user-select: none;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(0.5px) scale(0.99); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn .ic { width: 15px; height: 15px; }

.btn--primary {
  background: var(--accent-grad); color: #fff; border-color: transparent;
  box-shadow: var(--shadow-accent);
}
.btn--primary:hover { filter: brightness(1.06); background: var(--accent-grad); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--outline { background: transparent; border-color: var(--line-strong); }
.btn--outline:hover { background: var(--surface-3); border-color: var(--accent); color: var(--accent-strong); }
.btn--danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--block { width: 100%; }
.btn--sm { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn--lg { height: 42px; padding: 0 18px; font-size: 14.5px; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--r-sm);
  color: var(--text-2); font-size: 17px;
  transition: background var(--dur-fast), color var(--dur-fast), transform var(--dur-fast);
  position: relative;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.is-on { background: var(--accent-soft); color: var(--accent-strong); }
.icon-btn--xs { width: 26px; height: 26px; font-size: 14px; }
.icon-btn--danger:hover { background: var(--danger-soft); color: var(--danger); }

.input, .select, .textarea {
  width: 100%; height: 36px; padding: 0 11px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 13.5px;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.textarea { height: auto; min-height: 78px; padding: 9px 11px; resize: vertical; line-height: 1.55; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.select {
  appearance: none; cursor: pointer; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a86a0' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 14px;
}

.switch {
  position: relative; flex: none; width: 38px; height: 22px;
  border-radius: 999px; background: var(--line-strong); cursor: pointer;
  transition: background var(--dur);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: var(--shadow-xs); transition: transform var(--dur) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 19px; padding: 0 7px; border-radius: var(--r-pill);
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--surface-3); color: var(--text-2);
}
.badge--ok { background: var(--ok-soft); color: var(--ok); }
.badge--warn { background: var(--warn-soft); color: var(--warn); }
.badge--danger { background: var(--danger-soft); color: var(--danger); }
.badge--info { background: var(--info-soft); color: var(--info); }
.badge--accent { background: var(--accent-soft); color: var(--accent-strong); }

.divider { height: 1px; background: var(--line); margin: 14px 0; border: 0; }
.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 0.92em; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─────────────────────────── 4. Layout ─────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0px;
  height: 100dvh;
  background: var(--bg);
  transition: grid-template-columns var(--dur) var(--ease);
}
.app.panel-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--panel-w); }
.app.sidebar-collapsed { grid-template-columns: 0px minmax(0, 1fr) 0px; }
.app.sidebar-collapsed.panel-open { grid-template-columns: 0px minmax(0, 1fr) var(--panel-w); }

.scrim {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(9, 13, 22, 0.44); backdrop-filter: blur(2px);
  animation: fade var(--dur) var(--ease);
}

/* ─────────────────────────── 5. Sidebar ─────────────────────────── */
.sidebar {
  position: relative; z-index: 100;
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  background: var(--bg-deep);
  border-right: 1px solid var(--line);
}
.sidebar__brand {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: var(--topbar-h); padding: 0 12px 0 14px; flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand__mark { display: grid; place-items: center; }
.brand__logo { width: 30px; height: 30px; border-radius: 9px; box-shadow: var(--shadow-sm); }
.brand__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand__text strong { font-size: 14.5px; font-weight: 750; letter-spacing: -0.02em; }
.brand__text small { font-size: 10.5px; color: var(--text-3); letter-spacing: 0.01em; }

.sidebar__cta { padding: 4px 12px 10px; flex: none; }

.sidebar__search {
  position: relative; margin: 0 12px 8px; flex: none;
  display: flex; align-items: center;
}
.sidebar__search-icon {
  position: absolute; left: 9px; font-size: 15px; color: var(--text-3); pointer-events: none;
}
.sidebar__search input {
  width: 100%; height: 34px; padding: 0 30px 0 30px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 13px;
}
.sidebar__search input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
.sidebar__search input::-webkit-search-cancel-button { display: none; }
.sidebar__search .icon-btn { position: absolute; right: 4px; }

.sidebar__list { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 0 8px 12px; }
.navgroup { margin-top: 12px; }
.navgroup__label {
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px 5px; font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-3);
}
.convitem {
  position: relative; display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 8px 7px 9px; margin-bottom: 1px;
  border-radius: var(--r-sm); text-align: left;
  color: var(--text-2); font-size: 13.2px; cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.convitem:hover { background: var(--surface-3); color: var(--text); }
.convitem.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.convitem.is-active::before {
  content: ""; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 17px; border-radius: 0 3px 3px 0; background: var(--accent-grad);
}
.convitem__icon { font-size: 14px; color: var(--text-3); flex: none; }
.convitem.is-active .convitem__icon { color: var(--accent-strong); }
.convitem__body { flex: 1; min-width: 0; }
.convitem__title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convitem__meta {
  display: flex; align-items: center; gap: 5px;
  font-size: 10.8px; color: var(--text-3); margin-top: 1px;
}
.convitem__meta .dot { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .6; }
.convitem__actions {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  display: none; align-items: center; gap: 1px;
  background: linear-gradient(90deg, transparent, var(--surface) 22%);
  padding-left: 16px; border-radius: var(--r-sm);
}
.convitem:hover .convitem__actions { display: flex; }
.convitem__actions .icon-btn { width: 25px; height: 25px; font-size: 13.5px; }

.emptystate {
  padding: 26px 16px; text-align: center; color: var(--text-3); font-size: 12.5px; line-height: 1.6;
}
.emptystate .ic { font-size: 26px; opacity: .5; margin-bottom: 8px; }

.sidebar__foot {
  flex: none; padding: 9px 12px 11px; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
.keypill {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.keypill:hover { border-color: var(--line-strong); }
.keypill__dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none;
  background: var(--text-3); box-shadow: 0 0 0 3px var(--surface-3);
}
.keypill__dot.is-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.keypill__dot.is-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.keypill__dot.is-bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.keypill__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.sidebar__foot-row { display: flex; align-items: center; gap: 2px; }

/* ─────────────────────────── 6. Main / topbar ─────────────────────────── */
.main {
  position: relative; display: flex; flex-direction: column;
  min-width: 0; min-height: 0; background: var(--bg);
}
.topbar {
  flex: none; height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: var(--surface-glass); backdrop-filter: blur(14px) saturate(1.6);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 30;
}
.topbar__spacer { flex: 1; }

.modelchip {
  display: flex; align-items: center; gap: 9px;
  height: 38px; padding: 0 11px; max-width: min(46vw, 380px);
  border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface); text-align: left;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background var(--dur-fast);
}
.modelchip:hover { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.modelchip__dot {
  width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--accent-grad);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.modelchip__dot[data-prov="xkiro"] { background: linear-gradient(135deg, #f59e0b, #ef4444); box-shadow: 0 0 0 3px #f59e0b26; }
.modelchip__body { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.modelchip__name {
  font-size: 13.2px; font-weight: 650; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.modelchip__prov { font-size: 10.3px; color: var(--text-3); letter-spacing: .02em; }
.modelchip__caret { font-size: 14px; color: var(--text-3); }

.ctxmeter { position: relative; display: grid; place-items: center; width: 36px; height: 36px; }
.ctxmeter__ring { width: 36px; height: 36px; transform: rotate(-90deg); }
.ctxmeter__track { fill: none; stroke: var(--line); stroke-width: 3; }
.ctxmeter__fill {
  fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round;
  stroke-dasharray: 97.4; stroke-dashoffset: 97.4;
  transition: stroke-dashoffset var(--dur) var(--ease), stroke var(--dur);
}
.ctxmeter.is-warn .ctxmeter__fill { stroke: var(--warn); }
.ctxmeter.is-bad .ctxmeter__fill { stroke: var(--danger); }
.ctxmeter__label {
  position: absolute; font-size: 8.6px; font-weight: 750; color: var(--text-3);
  letter-spacing: -0.02em;
}

/* ─────────────────────────── 7. Chat area ─────────────────────────── */
.chat { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.chat__scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  scroll-behavior: smooth; padding: 22px 20px 8px;
}
.chat__fade {
  position: absolute; left: 0; right: 0; height: 18px; pointer-events: none; z-index: 5;
}
.chat__fade--top { top: 0; background: linear-gradient(var(--bg), transparent); opacity: .85; }

.jumpbtn {
  position: absolute; bottom: 14px; right: 20px; z-index: 20;
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-md); color: var(--text-2);
  display: grid; place-items: center; font-size: 17px;
  animation: pop var(--dur) var(--ease-out);
}
.jumpbtn:hover { color: var(--accent-strong); border-color: var(--accent); }

.findbar {
  position: absolute; top: 10px; right: 18px; z-index: 25;
  display: flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 10px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-lg);
  animation: pop var(--dur) var(--ease-out);
}
.findbar .ic { color: var(--text-3); font-size: 15px; }
.findbar input {
  width: 190px; height: 26px; border: 0; background: transparent; font-size: 13px;
}
.findbar input:focus { outline: none; }
.findbar__count { font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; padding: 0 2px; }

/* Welcome hero */
.welcome { max-width: var(--content-max); margin: 0 auto; padding: 30px 0 8px; animation: rise var(--dur) var(--ease-out); }
.hero { text-align: center; margin-bottom: 26px; }
.hero__mark {
  width: 60px; height: 60px; margin: 0 auto 16px; border-radius: 18px;
  background: var(--accent-grad); display: grid; place-items: center;
  box-shadow: var(--shadow-accent); font-size: 28px; color: #fff;
}
.hero h1 {
  font-size: 27px; font-weight: 750; letter-spacing: -0.035em; line-height: 1.2;
  background: linear-gradient(135deg, var(--text) 20%, var(--accent-strong) 130%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.hero p { color: var(--text-2); margin-top: 8px; font-size: 14px; }
.hero__providers { display: flex; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.provbadge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 11px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
}
.provbadge__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-grad); }
.provbadge--xkiro .provbadge__dot { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.provbadge--muted { opacity: .55; }

.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(228px, 1fr)); gap: 10px; }
.suggcard {
  display: flex; flex-direction: column; gap: 5px; text-align: left;
  padding: 14px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
}
.suggcard:hover {
  border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-md);
}
.suggcard__icon { font-size: 18px; color: var(--accent-strong); }
.suggcard__title { font-size: 13.4px; font-weight: 650; letter-spacing: -0.01em; }
.suggcard__desc { font-size: 12px; color: var(--text-3); line-height: 1.5; }

/* Thread */
.thread { max-width: var(--content-max); margin: 0 auto; }
.thread__tail { height: 6px; }

.msg { padding: 9px 0; animation: rise var(--dur) var(--ease-out); }
.msg--user { display: flex; justify-content: flex-end; }
.msg--user .msg__bubble {
  max-width: 86%;
  padding: 11px 15px; border-radius: 17px 17px 5px 17px;
  background: var(--accent-grad); color: #fff;
  box-shadow: var(--shadow-accent);
  font-size: 14.6px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg--user .msg__bubble a { color: #fff; text-decoration: underline; }
.msg--user .msg__bubble code {
  background: rgba(255, 255, 255, 0.2); padding: 1px 5px; border-radius: 5px;
  font-family: var(--mono); font-size: 0.88em;
}
.msg--user .msg__bubble img { border-radius: 10px; margin-top: 6px; display: block; }

.msg--assistant { display: flex; gap: 12px; }
.avatar {
  flex: none; width: 30px; height: 30px; border-radius: 10px;
  display: grid; place-items: center; font-size: 15px; margin-top: 2px;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--line);
}
.avatar--ai { background: var(--accent-grad); color: #fff; border-color: transparent; box-shadow: var(--shadow-sm); }
.avatar--err { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.msg__main { flex: 1; min-width: 0; }
.msg__head {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--text-3); margin-bottom: 3px; min-height: 18px;
}
.msg__author { font-weight: 680; color: var(--text-2); font-size: 12.5px; }
.msg__model { font-size: 10.8px; color: var(--text-3); }
.msg__body { font-size: 14.8px; overflow-wrap: anywhere; }

/* Message actions */
.msg__actions {
  display: flex; align-items: center; gap: 1px; margin-top: 5px;
  opacity: 0; transition: opacity var(--dur-fast);
}
.msg:hover .msg__actions, .msg.is-active .msg__actions, .msg__actions:focus-within { opacity: 1; }
.msg__actions .icon-btn { width: 28px; height: 28px; font-size: 14px; }
.msg__stats {
  display: flex; align-items: center; gap: 9px; margin-left: 4px;
  font-size: 10.8px; color: var(--text-3); font-variant-numeric: tabular-nums;
}
.msg__stats .sep { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .5; }
.msg__error {
  display: flex; gap: 9px; padding: 11px 13px; border-radius: var(--r-md);
  background: var(--danger-soft); border: 1px solid var(--danger);
  color: var(--danger); font-size: 13px; line-height: 1.55;
}
.msg__error .ic { flex: none; margin-top: 2px; }
.msg__error pre {
  margin: 6px 0 0; font-family: var(--mono); font-size: 11.5px;
  white-space: pre-wrap; opacity: .85; max-height: 180px; overflow: auto;
}
.msg__edit { display: flex; flex-direction: column; gap: 8px; }
.msg__edit .textarea {
  min-height: 110px; font-size: 14.5px; background: var(--surface);
  border-color: var(--accent);
}
.msg__edit-actions { display: flex; gap: 7px; justify-content: flex-end; }

/* Reasoning / thinking */
.think {
  margin-bottom: 8px; border: 1px dashed var(--line-strong);
  border-radius: var(--r-md); background: var(--surface-inset); overflow: hidden;
}
.think__toggle {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 11px; font-size: 12.2px; font-weight: 600; color: var(--text-2);
  transition: background var(--dur-fast);
}
.think__toggle:hover { background: var(--surface-3); }
.think__toggle .ic { font-size: 14px; transition: transform var(--dur) var(--ease); }
.think.is-open .think__toggle .ic { transform: rotate(90deg); }
.think__meta { margin-left: auto; font-size: 10.5px; color: var(--text-3); font-weight: 500; }
.think__body {
  display: none; padding: 2px 13px 12px;
  font-size: 13.2px; color: var(--text-2); line-height: 1.65;
  border-top: 1px dashed var(--line-strong); margin-top: -1px; padding-top: 10px;
}
.think.is-open .think__body { display: block; }
.think.is-live .think__toggle::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); animation: pulse 1.1s infinite;
}

/* Streaming caret + status */
.caret {
  display: inline-block; width: 7px; height: 1.05em; margin-left: 2px;
  background: var(--accent); border-radius: 1.5px; vertical-align: text-bottom;
  animation: blink 1s steps(2, start) infinite;
}
.streamnote {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--text-3); padding: 4px 0;
}
.spinner {
  width: 12px; height: 12px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
.skeleton { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.skel-line {
  height: 10px; border-radius: 5px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
.skel-line:nth-child(2) { width: 88%; }
.skel-line:nth-child(3) { width: 64%; }

/* ─────────────────────────── 8. Markdown ─────────────────────────── */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 20px 0 9px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.3;
}
.md h1 { font-size: 1.5em; }
.md h2 { font-size: 1.28em; padding-bottom: 5px; border-bottom: 1px solid var(--line); }
.md h3 { font-size: 1.13em; }
.md h4 { font-size: 1.02em; }
.md h5, .md h6 { font-size: 0.95em; color: var(--text-2); }
.md ul, .md ol { margin: 0 0 10px; padding-left: 1.45em; }
.md li { margin: 3px 0; }
.md li > ul, .md li > ol { margin: 3px 0; }
.md ul { list-style: disc; }
.md ul ul { list-style: circle; }
.md ul ul ul { list-style: square; }
.md ol { list-style: decimal; }
.md li::marker { color: var(--text-3); }
.md li.task { list-style: none; margin-left: -1.25em; display: flex; gap: 8px; align-items: flex-start; }
.md li.task input { margin-top: 5px; accent-color: var(--accent); flex: none; }
.md blockquote {
  margin: 0 0 10px; padding: 4px 0 4px 14px;
  border-left: 3px solid var(--accent); color: var(--text-2);
  background: var(--accent-softer); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.md blockquote p:last-child { margin-bottom: 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.md a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.md strong { font-weight: 700; color: var(--text); }
.md em { font-style: italic; }
.md del { color: var(--text-3); }
.md img { border-radius: var(--r-md); margin: 6px 0; border: 1px solid var(--line); }
.md code:not(pre code) {
  font-family: var(--mono); font-size: 0.87em;
  padding: 1.5px 5.5px; border-radius: 5px;
  background: var(--surface-3); border: 1px solid var(--line-2);
  color: var(--accent-strong); overflow-wrap: break-word;
}
.md table {
  width: 100%; border-collapse: collapse; margin: 0 0 12px; font-size: 13.4px;
  display: block; overflow-x: auto; border-radius: var(--r-sm);
}
.md th, .md td { padding: 7px 11px; border: 1px solid var(--line); text-align: left; }
.md th { background: var(--surface-3); font-weight: 680; white-space: nowrap; }
.md tr:nth-child(even) td { background: var(--surface-2); }
.md .katex-like { font-family: var(--mono); }

/* Code blocks */
.codeblock {
  margin: 0 0 12px; border-radius: var(--r-md); overflow: hidden;
  border: 1px solid var(--line); background: var(--code-bg);
}
.codeblock__head {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px 5px 12px; background: var(--code-head);
  border-bottom: 1px solid var(--line);
  font-size: 11px; color: var(--text-3);
}
.codeblock__lang { font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 10px; }
.codeblock__title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 10.5px; }
.codeblock__btns { display: flex; gap: 1px; margin-left: auto; }
.codeblock__btns .icon-btn { width: 26px; height: 26px; font-size: 13.5px; }
.codeblock pre { margin: 0; overflow-x: auto; }
.codeblock code {
  display: block; padding: 12px 14px;
  font-family: var(--mono); font-size: 12.8px; line-height: 1.62;
  tab-size: 2; white-space: pre; color: var(--tk-v);
}

/* ── Code preview modal ──────────────────────────────────────────── */
.modal--preview { max-width: 1000px; max-height: min(92dvh, 1000px); }
.modal--preview .modal__body { padding: 0; overflow: hidden; display: flex; flex-direction: column; }

.codepreview { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.codepreview__bar {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.codepreview__vp {
  height: 26px; padding: 0 10px; border-radius: var(--r-xs);
  font-family: var(--mono); font-size: 11.5px; font-weight: 600;
  color: var(--text-3); background: transparent; border: 1px solid transparent;
  cursor: pointer; transition: color var(--dur-fast), background var(--dur-fast);
}
.codepreview__vp:hover { color: var(--text); background: var(--surface-3); }
.codepreview__vp.is-on { color: var(--accent-strong); background: var(--accent-soft); }

.codepreview__frame {
  flex: 1; display: block; width: 100%; min-height: 440px; margin: 0 auto;
  border: 0; background: #fff;
  transition: width var(--dur) var(--ease-out);
}
.codepreview__frame.is-narrow { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }

.codepreview__doc { flex: 1; overflow: auto; padding: 20px 24px; }
.codepreview__pre {
  flex: 1; overflow: auto; margin: 0; padding: 16px 20px;
  background: var(--code-bg); font-family: var(--mono);
  font-size: 12.8px; line-height: 1.62;
}
.codepreview__pre code { color: var(--tk-v); }

.codepreview__notice {
  flex: none; display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 14px; font-size: 12.2px; line-height: 1.5;
  color: var(--text-2); background: var(--warn-soft);
  border-bottom: 1px solid var(--line);
}
.codepreview__notice .ic { flex: none; width: 15px; height: 15px; margin-top: 1px; color: var(--warn); }
/* `display: flex` above would otherwise beat the browser's [hidden] rule, so
   the notice would be visible even while it is logically hidden. */
.codepreview__notice[hidden] { display: none; }
.tk-c { color: var(--tk-c); font-style: italic; }
.tk-k { color: var(--tk-k); }
.tk-s { color: var(--tk-s); }
.tk-n { color: var(--tk-n); }
.tk-f { color: var(--tk-f); }
.tk-t { color: var(--tk-t); }
.tk-p { color: var(--tk-p); }
.tk-o { color: var(--tk-o); }
.tk-b { color: var(--tk-b); }
.tk-d { color: var(--tk-d); }
.tk-v { color: var(--tk-v); }
.tk-i { color: var(--tk-i); }
.tk-x { color: var(--tk-x); }
.tk-m { color: var(--tk-m); }
.diff-add { background: color-mix(in srgb, var(--ok) 13%, transparent); display: block; }
.diff-del { background: color-mix(in srgb, var(--danger) 13%, transparent); display: block; }

mark.hit { background: #fde68a; color: #78350f; border-radius: 3px; padding: 0 1px; }
[data-theme="dark"] mark.hit { background: #78350f; color: #fde68a; }
mark.hit.is-current { background: var(--accent); color: #fff; }

/* ─────────────────────────── 9. Composer ─────────────────────────── */
.dock { flex: none; padding: 0 20px 12px; background: linear-gradient(transparent, var(--bg) 34%); }
.dock__inner { max-width: var(--content-max); margin: 0 auto; }

.attachments { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.attachchip {
  position: relative; display: flex; align-items: center; gap: 7px;
  height: 52px; padding: 5px 9px 5px 5px; border-radius: var(--r-sm);
  background: var(--surface); border: 1px solid var(--line); font-size: 12px;
  max-width: 230px; animation: pop var(--dur) var(--ease-out);
}
.attachchip__thumb {
  width: 42px; height: 42px; border-radius: var(--r-xs); object-fit: cover;
  background: var(--surface-3); flex: none;
}
.attachchip__icon {
  width: 42px; height: 42px; border-radius: var(--r-xs); flex: none;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-strong);
  font-size: 18px;
}
.attachchip__body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.attachchip__name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.attachchip__size { font-size: 10.5px; color: var(--text-3); }
.attachchip__x {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--text); color: var(--surface);
  display: grid; place-items: center; font-size: 11px; box-shadow: var(--shadow-sm);
}
.attachchip__x:hover { background: var(--danger); }

.composer {
  position: relative; border-radius: var(--r-lg);
  background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring), var(--shadow-md); }
.composer.is-dragover { border-color: var(--accent); border-style: dashed; background: var(--accent-softer); }
.composer.is-busy { border-color: var(--accent); }
.composer textarea {
  display: block; width: 100%; max-height: 42vh; min-height: 52px;
  padding: 13px 15px 4px; border: 0; background: transparent; resize: none;
  font-size: 14.8px; line-height: 1.6; overflow-y: auto;
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: var(--text-3); }

.composer__bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px 8px 8px;
}
.composer__tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; min-width: 0; }
.chipbtn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: 12.2px; font-weight: 600; color: var(--text-2);
  border: 1px solid transparent; transition: all var(--dur-fast); position: relative;
}
.chipbtn:hover { background: var(--surface-3); color: var(--text); }
.chipbtn .ic { font-size: 14.5px; }
.chipbtn.is-on { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
.chipbtn__flag {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  position: absolute; top: 5px; right: 5px;
}
.chipbtn--params span { font-family: var(--mono); font-size: 11px; }

.composer__send { display: flex; align-items: center; gap: 9px; margin-left: auto; flex: none; }
.composer__tokens {
  font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums;
  font-family: var(--mono); white-space: nowrap;
}
.btn--send {
  width: 36px; height: 36px; padding: 0; border-radius: var(--r-md);
  background: var(--accent-grad); color: #fff; border-color: transparent;
  box-shadow: var(--shadow-accent);
}
.btn--send:hover { filter: brightness(1.07); background: var(--accent-grad); }
.btn--send:disabled { opacity: .45; box-shadow: none; }
.btn--send .ic { width: 17px; height: 17px; }
.btn--send .stop-ic { display: none; }
.composer.is-busy .btn--send { background: var(--danger); box-shadow: 0 6px 18px var(--danger-soft); }
.composer.is-busy .btn--send .send-ic { display: none; }
.composer.is-busy .btn--send .stop-ic { display: inline-block; }

.dock__hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 3px 0; font-size: 11px; color: var(--text-3);
}
.dock__hint-right { display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }

/* ─────────────────────────── 10. Right panel ─────────────────────────── */
.panel {
  position: relative; z-index: 95; display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(16, 24, 40, 0.05);
}
.panel__head {
  flex: none; height: var(--topbar-h); padding: 0 10px 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.panel__head h2 { font-size: 13.6px; font-weight: 700; letter-spacing: -0.01em; }
.panel__body { flex: 1; overflow-y: auto; padding: 14px 16px 20px; }
.panel__foot { flex: none; padding: 10px 16px; border-top: 1px solid var(--line); }

.field { margin-bottom: 15px; }
.field__label {
  display: flex; align-items: center; gap: 6px; justify-content: space-between;
  font-size: 12.2px; font-weight: 650; color: var(--text-2); margin-bottom: 6px;
}
.field__value {
  font-family: var(--mono); font-size: 11.2px; color: var(--accent-strong);
  background: var(--accent-soft); padding: 1px 7px; border-radius: var(--r-pill);
  font-weight: 600;
}
.field__hint { font-size: 11.2px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }
.field__row { display: flex; align-items: center; gap: 9px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 22px;
  background: transparent; cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--line-strong);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%; margin-top: -5.5px;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: var(--shadow-sm); transition: transform var(--dur-fast);
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-strong); }
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--surface); box-shadow: var(--shadow-sm);
}

.panelsec { margin-bottom: 20px; }
.panelsec__title {
  display: flex; align-items: center; gap: 7px;
  font-size: 10.6px; font-weight: 750; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 12px;
}
.panelsec__title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.toggle-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--line-2);
}
.toggle-row:last-child { border-bottom: 0; }
.toggle-row__body { flex: 1; min-width: 0; }
.toggle-row__title { font-size: 12.8px; font-weight: 600; }
.toggle-row__desc { font-size: 11.2px; color: var(--text-3); line-height: 1.45; margin-top: 1px; }

.statgrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.stat {
  padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--surface-2); border: 1px solid var(--line);
}
.stat__k { font-size: 10.4px; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 650; }
.stat__v { font-size: 16px; font-weight: 720; letter-spacing: -0.02em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat__s { font-size: 10.5px; color: var(--text-3); }

.bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; margin-top: 6px; }
.bar__fill { height: 100%; border-radius: 3px; background: var(--accent-grad); transition: width var(--dur) var(--ease); }
.bar__fill--warn { background: var(--warn); }
.bar__fill--danger { background: var(--danger); }

/* ─────────────────────────── 11. Modals ─────────────────────────── */
.modal-root {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center; padding: 20px;
  background: rgba(9, 13, 22, 0.5); backdrop-filter: blur(4px);
  animation: fade var(--dur-fast) var(--ease);
}
.modal {
  width: 100%; max-width: 620px; max-height: min(86dvh, 800px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-xl); box-shadow: var(--shadow-xl);
  overflow: hidden; animation: pop var(--dur) var(--ease-out);
}
.modal--wide { max-width: 860px; }
.modal--tall { max-height: min(90dvh, 900px); }
.modal__head {
  flex: none; display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 20px 14px; border-bottom: 1px solid var(--line);
}
.modal__icon {
  flex: none; width: 36px; height: 36px; border-radius: var(--r-md);
  display: grid; place-items: center; font-size: 18px;
  background: var(--accent-soft); color: var(--accent-strong);
}
.modal__icon--danger { background: var(--danger-soft); color: var(--danger); }
.modal__titles { flex: 1; min-width: 0; }
.modal__title { font-size: 16px; font-weight: 720; letter-spacing: -0.02em; }
.modal__sub { font-size: 12.6px; color: var(--text-3); margin-top: 2px; line-height: 1.5; }
.modal__body { flex: 1; overflow-y: auto; padding: 18px 20px; }
.modal__foot {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 13px 20px; border-top: 1px solid var(--line); background: var(--surface-2);
}
.modal__foot .spacer { flex: 1; }

.tabs { display: flex; gap: 2px; padding: 4px; background: var(--surface-3); border-radius: var(--r-md); margin-bottom: 16px; }
.tab {
  flex: 1; height: 30px; border-radius: var(--r-xs); font-size: 12.6px; font-weight: 620;
  color: var(--text-2); transition: all var(--dur-fast); display: inline-flex;
  align-items: center; justify-content: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.tabpanel { display: none; }
.tabpanel.is-active { display: block; animation: fade var(--dur-fast) var(--ease); }

.keyfield { position: relative; display: flex; align-items: center; }
.keyfield .input { padding-right: 74px; font-family: var(--mono); font-size: 12.4px; }
.keyfield__btns { position: absolute; right: 4px; display: flex; gap: 1px; }

.providercard {
  padding: 14px; border-radius: var(--r-md); border: 1px solid var(--line);
  background: var(--surface-2); margin-bottom: 12px;
}
.providercard__head { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; }
.providercard__logo {
  width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center;
  font-size: 15px; font-weight: 800; color: #fff; flex: none;
}
.providercard__logo--openrouter { background: linear-gradient(135deg, #6366f1, #a855f7); }
.providercard__logo--xkiro { background: linear-gradient(135deg, #f59e0b, #ef4444); }
.providercard__name { font-size: 14px; font-weight: 700; }
.providercard__url { font-size: 11px; color: var(--text-3); font-family: var(--mono); }
.providercard__state { margin-left: auto; }
.providercard__foot {
  display: flex; align-items: center; gap: 10px; margin-top: 10px;
  font-size: 11.5px; color: var(--text-3);
}
.providercard__foot a { display: inline-flex; align-items: center; gap: 4px; }

.note {
  display: flex; gap: 9px; padding: 11px 13px; border-radius: var(--r-sm);
  font-size: 12.4px; line-height: 1.55; margin-bottom: 12px;
  background: var(--info-soft); border: 1px solid color-mix(in srgb, var(--info) 40%, transparent);
  color: var(--text-2);
}
.note .ic { flex: none; color: var(--info); margin-top: 2px; }
.note--warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 42%, transparent); }
.note--warn .ic { color: var(--warn); }
.note--danger { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 42%, transparent); }
.note--danger .ic { color: var(--danger); }
.note--ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.note--ok .ic { color: var(--ok); }
.note code { font-family: var(--mono); font-size: .92em; background: var(--surface-3); padding: 1px 5px; border-radius: 4px; }

.codewrap { position: relative; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); }
.codewrap pre { margin: 0; max-height: 260px; overflow: auto; background: var(--code-bg); }
.codewrap code { display: block; padding: 12px 14px; font-family: var(--mono); font-size: 11.8px; line-height: 1.6; white-space: pre; color: var(--text-2); }
.codewrap__copy { position: absolute; top: 7px; right: 7px; }

.steps { counter-reset: s; display: flex; flex-direction: column; gap: 11px; }
.step { display: flex; gap: 11px; }
.step__n {
  flex: none; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: grid; place-items: center; font-size: 11.5px; font-weight: 750;
}
.step__body { flex: 1; font-size: 13px; line-height: 1.6; color: var(--text-2); }
.step__body strong { color: var(--text); }

/* ─────────────────────────── 12. Command palette ─────────────────────────── */
.palette {
  position: fixed; inset: 0; z-index: 210;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 20px 20px;
  background: rgba(9, 13, 22, 0.44); backdrop-filter: blur(4px);
  animation: fade var(--dur-fast) var(--ease);
}
.palette__box {
  width: 100%; max-width: 560px; max-height: 62dvh;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-xl);
  animation: pop var(--dur) var(--ease-out);
}
.palette__input {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--line);
}
.palette__input .ic { color: var(--text-3); font-size: 17px; }
.palette__input input { flex: 1; border: 0; background: transparent; font-size: 15px; }
.palette__input input:focus { outline: none; }
.palette__list { flex: 1; overflow-y: auto; padding: 7px; }
.palette__group {
  padding: 9px 10px 4px; font-size: 10.4px; font-weight: 750;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}
.palette__item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 10px; border-radius: var(--r-sm); text-align: left;
  font-size: 13.4px; color: var(--text-2);
  transition: background var(--dur-fast);
}
.palette__item .ic { font-size: 16px; color: var(--text-3); flex: none; }
.palette__item.is-sel, .palette__item:hover { background: var(--accent-soft); color: var(--text); }
.palette__item.is-sel .ic, .palette__item:hover .ic { color: var(--accent-strong); }
.palette__item-body { flex: 1; min-width: 0; }
.palette__item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__item-sub { font-size: 11px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__item kbd { flex: none; }
.palette__empty { padding: 30px 16px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ─────────────────────────── 13. Popover ─────────────────────────── */
.popover-root { position: fixed; inset: 0; z-index: 190; pointer-events: none; }
.popover-root > * { pointer-events: auto; }
.popover {
  position: absolute; min-width: 220px; max-width: min(94vw, 460px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  overflow: hidden; animation: pop var(--dur-fast) var(--ease-out);
  display: flex; flex-direction: column;
}
.popover__head { flex: none; padding: 10px 12px 8px; border-bottom: 1px solid var(--line-2); }
.popover__search { position: relative; display: flex; align-items: center; }
.popover__search .ic { position: absolute; left: 9px; color: var(--text-3); font-size: 15px; }
.popover__search input {
  width: 100%; height: 33px; padding: 0 10px 0 30px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); font-size: 13px;
}
.popover__search input:focus { outline: none; border-color: var(--accent); }
.popover__tabs { display: flex; gap: 3px; padding: 8px 12px 0; }
.popover__tab {
  height: 26px; padding: 0 10px; border-radius: var(--r-pill); font-size: 11.8px; font-weight: 640;
  color: var(--text-2); background: var(--surface-3); display: inline-flex; align-items: center; gap: 5px;
}
.popover__tab.is-active { background: var(--accent); color: #fff; }
.popover__tab .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.popover__list { overflow-y: auto; max-height: 340px; padding: 6px; }
.popover__item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border-radius: var(--r-sm); text-align: left; font-size: 13px; color: var(--text-2);
}
.popover__item:hover, .popover__item.is-sel { background: var(--surface-3); color: var(--text); }
.popover__item.is-active { background: var(--accent-soft); color: var(--accent-strong); }
.popover__item-body { flex: 1; min-width: 0; }
.popover__item-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.popover__item-sub { font-size: 10.6px; color: var(--text-3); display: flex; gap: 6px; align-items: center; margin-top: 1px; }
.popover__item-sub .sep { width: 3px; height: 3px; border-radius: 50%; background: currentColor; opacity: .5; }
.popover__star { flex: none; width: 24px; height: 24px; border-radius: var(--r-xs); display: grid; place-items: center; color: var(--text-3); font-size: 14px; }
.popover__star:hover { background: var(--warn-soft); color: var(--warn); }
.popover__star.is-on { color: var(--warn); }
.popover__foot { flex: none; padding: 8px 12px; border-top: 1px solid var(--line-2); font-size: 11px; color: var(--text-3); display: flex; gap: 10px; align-items: center; }
.popover__empty { padding: 24px 14px; text-align: center; color: var(--text-3); font-size: 12.5px; }
.popover__group {
  padding: 8px 9px 3px; font-size: 10.2px; font-weight: 750;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}

.menu { padding: 6px; min-width: 190px; }
.menu__item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 9px; border-radius: var(--r-sm); text-align: left;
  font-size: 13px; color: var(--text-2); transition: background var(--dur-fast);
}
.menu__item:hover { background: var(--surface-3); color: var(--text); }
.menu__item .ic { font-size: 15px; color: var(--text-3); }
.menu__item:hover .ic { color: var(--accent-strong); }
.menu__item--danger { color: var(--danger); }
.menu__item--danger .ic { color: var(--danger); }
.menu__item--danger:hover { background: var(--danger-soft); }
.menu__item kbd { margin-left: auto; }
.menu__sep { height: 1px; background: var(--line-2); margin: 5px 4px; }

/* ─────────────────────────── 14. Toasts ─────────────────────────── */
.toasts {
  position: fixed; bottom: 18px; right: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 9px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  min-width: 250px; max-width: 380px; padding: 11px 13px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  font-size: 13px; pointer-events: auto;
  animation: slidein var(--dur) var(--ease-out);
}
.toast.is-out { animation: slideout var(--dur-fast) var(--ease) forwards; }
.toast__icon { flex: none; margin-top: 1px; font-size: 16px; }
.toast--ok .toast__icon { color: var(--ok); }
.toast--err .toast__icon { color: var(--danger); }
.toast--warn .toast__icon { color: var(--warn); }
.toast--info .toast__icon { color: var(--info); }
.toast__body { flex: 1; min-width: 0; }
.toast__title { font-weight: 650; }
.toast__msg { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.5; overflow-wrap: anywhere; }
.toast__x { flex: none; color: var(--text-3); font-size: 14px; }

/* ─────────────────────────── 15. Prompt library ─────────────────────────── */
.promptgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(238px, 1fr)); gap: 10px; }
.promptcard {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 12px 13px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line);
  transition: border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  position: relative;
}
.promptcard:hover { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.promptcard__top { display: flex; align-items: center; gap: 7px; }
.promptcard__cat {
  font-size: 9.6px; font-weight: 750; letter-spacing: .06em; text-transform: uppercase;
  color: var(--accent-strong); background: var(--accent-soft); padding: 2px 7px; border-radius: var(--r-pill);
}
.promptcard__del { margin-left: auto; opacity: 0; transition: opacity var(--dur-fast); }
.promptcard:hover .promptcard__del { opacity: 1; }
.promptcard__title { font-size: 13.4px; font-weight: 660; letter-spacing: -0.01em; }
.promptcard__body {
  font-size: 11.8px; color: var(--text-3); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ─────────────────────────── 16. Usage / charts ─────────────────────────── */
.chart {
  display: flex; align-items: flex-end; gap: 3px; height: 108px;
  padding: 10px 0 0; border-bottom: 1px solid var(--line);
}
.chart__bar {
  flex: 1; min-height: 2px; border-radius: 3px 3px 0 0;
  background: var(--accent-grad); opacity: .85; position: relative;
  transition: opacity var(--dur-fast), transform var(--dur-fast);
}
.chart__bar:hover { opacity: 1; transform: scaleY(1.02); }
.chart__labels { display: flex; gap: 3px; margin-top: 5px; }
.chart__label { flex: 1; font-size: 9px; color: var(--text-3); text-align: center; overflow: hidden; }

.usagelist { display: flex; flex-direction: column; gap: 7px; margin-top: 14px; }
.usagerow {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px;
  border-radius: var(--r-sm); background: var(--surface-2); border: 1px solid var(--line);
  font-size: 12.4px;
}
.usagerow__label { font-weight: 620; min-width: 76px; }
.usagerow__bar { flex: 1; }
.usagerow__val { font-family: var(--mono); font-size: 11.4px; color: var(--text-2); text-align: right; min-width: 92px; }

/* ─────────────────────────── 17. Animations ─────────────────────────── */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.965) translateY(-4px); } to { opacity: 1; transform: none; } }
@keyframes slidein { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes slideout { to { opacity: 0; transform: translateX(24px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.8); } }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .chat__scroll { scroll-behavior: auto; }
}

/* ─────────────────────────── 18. Density & type scale ─────────────────────────── */
[data-density="compact"] { --fs-base: 14px; --topbar-h: 52px; }
[data-density="compact"] .msg { padding: 6px 0; }
[data-density="compact"] .msg__body { font-size: 14.1px; }
[data-density="compact"] .sidebar__brand,
[data-density="compact"] .panel__head { height: var(--topbar-h); }
[data-density="comfortable"] { --fs-base: 15px; }
[data-density="spacious"] { --fs-base: 16px; --topbar-h: 64px; --lh: 1.72; }
[data-density="spacious"] .msg { padding: 14px 0; }
[data-density="spacious"] .msg__body { font-size: 15.8px; }

[data-width="narrow"] { --content-max: 680px; }
[data-width="wide"] { --content-max: 1060px; }
[data-width="full"] { --content-max: 100%; }

/* ─────────────────────────── 19. Responsive ─────────────────────────── */
.only-mobile { display: none !important; }

@media (max-width: 1100px) {
  .app.panel-open { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) 0px; }
  .panel {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(92vw, var(--panel-w));
    z-index: 110; box-shadow: var(--shadow-xl);
    animation: slidein var(--dur) var(--ease-out);
  }
}

@media (max-width: 860px) {
  .only-mobile { display: inline-flex !important; }
  .app, .app.panel-open, .app.sidebar-collapsed, .app.sidebar-collapsed.panel-open {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(88vw, var(--sidebar-w));
    z-index: 110; box-shadow: var(--shadow-xl);
    transform: translateX(-102%); transition: transform var(--dur) var(--ease);
  }
  .app.sidebar-mobile-open .sidebar { transform: none; }
  .chat__scroll { padding: 16px 13px 8px; }
  .dock { padding: 0 12px 10px; }
  .dock__hint { display: none; }
  .modelchip { max-width: 46vw; }
  .msg--user .msg__bubble { max-width: 92%; }
  .topbar { padding: 0 8px; gap: 5px; }
  .hero h1 { font-size: 23px; }
  .suggestions { grid-template-columns: 1fr; }
  .modal-root { padding: 10px; align-items: flex-end; }
  .modal { max-height: 92dvh; border-radius: var(--r-lg); }
  .palette { padding: 6vh 12px 12px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }
  .statgrid { grid-template-columns: 1fr; }
  .promptgrid { grid-template-columns: 1fr; }
  .findbar input { width: 120px; }
}

@media (max-width: 520px) {
  .ctxmeter { display: none; }
  .composer__tokens { display: none; }
  .chipbtn span:not(.chipbtn__flag) { display: none; }
  .chipbtn { padding: 0 8px; }
}

/* ─────────────────────────── 20. Print ─────────────────────────── */
@media print {
  .sidebar, .panel, .topbar, .dock, .jumpbtn, .findbar, .toasts, .msg__actions { display: none !important; }
  .app { display: block; height: auto; }
  .chat__scroll { overflow: visible; height: auto; padding: 0; }
  body { background: #fff; overflow: visible; }
  .msg { break-inside: avoid; page-break-inside: avoid; }
  .codeblock { border-color: #ddd; }
  .msg--user .msg__bubble { background: #f1f3f9 !important; color: #000 !important; box-shadow: none; }
}
