/* ==========================================================================
   Green AI — design system
   Light is the default theme; [data-theme="dark"] overrides the token layer.
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f4f6f4;
  --bg-grid: rgba(15, 26, 20, 0.035);
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --surface-3: #f0f3f1;
  --surface-inset: #f6f8f7;
  --overlay: rgba(255, 255, 255, 0.72);

  --line: rgba(15, 26, 20, 0.09);
  --line-strong: rgba(15, 26, 20, 0.16);

  --text: #0d1712;
  --text-2: #3d4a43;
  --text-3: #6b7a72;
  --text-4: #96a29b;

  --accent: #0f8a63;
  --accent-hover: #0c7454;
  --accent-soft: rgba(15, 138, 99, 0.1);
  --accent-line: rgba(15, 138, 99, 0.28);
  --accent-contrast: #ffffff;

  --teal: #0e8f8f;
  --sky: #2b7fd4;
  --violet: #7357d6;
  --amber: #c98a12;
  --rose: #d0455f;

  --ok: #0f8a63;
  --warn: #c98a12;
  --danger: #d0455f;

  --shadow-1: 0 1px 2px rgba(15, 26, 20, 0.05), 0 1px 3px rgba(15, 26, 20, 0.04);
  --shadow-2: 0 2px 4px rgba(15, 26, 20, 0.04), 0 8px 24px -12px rgba(15, 26, 20, 0.16);
  --shadow-3: 0 18px 48px -20px rgba(15, 26, 20, 0.32);

  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;

  --sidebar-w: 254px;
  --topbar-h: 60px;

  --font: "Inter", "Noto Sans JP", "Noto Sans KR", -apple-system, BlinkMacSystemFont,
    "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #080b0a;
  --bg-grid: rgba(255, 255, 255, 0.028);
  --surface: #101613;
  --surface-2: #141b18;
  --surface-3: #1a221e;
  --surface-inset: #0c1210;
  --overlay: rgba(16, 22, 19, 0.76);

  --line: rgba(255, 255, 255, 0.085);
  --line-strong: rgba(255, 255, 255, 0.16);

  --text: #e9f1ec;
  --text-2: #b6c4bc;
  --text-3: #8b9a92;
  --text-4: #64726a;

  --accent: #2fc48c;
  --accent-hover: #48d29d;
  --accent-soft: rgba(47, 196, 140, 0.13);
  --accent-line: rgba(47, 196, 140, 0.32);
  --accent-contrast: #04120c;

  --teal: #2bc0c0;
  --sky: #5aa6ef;
  --violet: #9b85f0;
  --amber: #e0ab3c;
  --rose: #ef6f86;

  --ok: #2fc48c;
  --warn: #e0ab3c;
  --danger: #ef6f86;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 24px 56px -24px rgba(0, 0, 0, 0.75);
}

/* --------------------------------------------------------------- reset ---- */

*,
*::before,
*::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--bg-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -0.017em; line-height: 1.3; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
ul { margin: 0; padding: 0; list-style: none; }
table { border-collapse: collapse; width: 100%; }

/* Inline icons default to a safe size; components override where needed. */
svg { width: 16px; height: 16px; flex: none; }
.chip svg, .trend svg { width: 12px; height: 12px; }

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-4); background-clip: content-box; }

.num { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- layout --- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ------------------------------------------------------------- sidebar ---- */

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 14px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 4px 8px 18px;
  cursor: pointer;
}

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--accent), var(--teal));
  box-shadow: 0 4px 12px -4px var(--accent-line);
}
.brand-mark svg { width: 18px; height: 18px; color: var(--accent-contrast); }

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 14.5px; font-weight: 650; letter-spacing: -0.02em; }
.brand-sub { font-size: 10.5px; color: var(--text-4); letter-spacing: 0.06em; text-transform: uppercase; }

.nav-group { padding: 12px 8px 5px; font-size: 10.5px; font-weight: 620; letter-spacing: 0.09em; text-transform: uppercase; color: var(--text-4); }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-md);
  color: var(--text-2);
  font-size: 13.4px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item svg { width: 16px; height: 16px; flex: 0 0 16px; opacity: 0.72; }

.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 570; }
.nav-item.active svg { opacity: 1; }
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 17px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}

.nav-badge {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: 99px;
  background: var(--surface-3);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
}
.nav-item.active .nav-badge { background: var(--accent); color: var(--accent-contrast); }

.sidebar-foot { margin-top: auto; padding: 12px 10px 2px; border-top: 1px solid var(--line); }
.health { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-3); }
.dot { width: 6px; height: 6px; border-radius: 99px; background: var(--ok); box-shadow: 0 0 0 3px var(--accent-soft); }
.health-host { font-family: var(--mono); font-size: 10.5px; color: var(--text-4); }

/* -------------------------------------------------------------- topbar ---- */

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 24px;
  background: var(--overlay);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.crumbs { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-4); white-space: nowrap; min-width: 0; }
.crumbs svg { width: 13px; height: 13px; }
.crumbs strong { color: var(--text); font-weight: 570; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; }

.topbar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 340px;
  margin-left: auto;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  color: var(--text-3);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.topbar-search:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.topbar-search svg { width: 15px; height: 15px; flex: 0 0 15px; }
.topbar-search input { width: 100%; border: 0; background: none; outline: none; font-size: 13px; }
.topbar-search input::placeholder { color: var(--text-4); }
.kbd {
  padding: 1px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-4);
}

.seg {
  display: flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}
.seg button {
  padding: 4px 9px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  letter-spacing: 0.01em;
  transition: background 0.15s, color 0.15s;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  color: var(--text-2);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); border-color: var(--line-strong); }
.icon-btn svg { width: 16px; height: 16px; }
[data-theme="dark"] .icon-sun { display: none; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.avatar {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 99px;
  background: linear-gradient(145deg, var(--sky), var(--violet));
  color: #fff;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}

/* --------------------------------------------------------------- views ---- */

.view { padding: 26px 24px 56px; max-width: 1520px; width: 100%; }
.view.flush { padding: 0; max-width: none; }

.page-head { display: flex; align-items: flex-end; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; letter-spacing: -0.025em; }
.page-head p { margin-top: 5px; font-size: 13px; color: var(--text-3); max-width: 66ch; }
.page-head .spacer { margin-left: auto; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 12.5px;
  font-weight: 570;
  color: var(--text-2);
  box-shadow: var(--shadow-1);
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover { color: var(--text); border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-contrast); }
.btn.primary:hover { background: var(--accent-hover); color: var(--accent-contrast); }
.btn.ghost { background: none; box-shadow: none; }

/* --------------------------------------------------------------- cards ---- */

.grid { display: grid; gap: 14px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.g-1-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }
.span-2 { grid-column: span 2; }
.mt { margin-top: 14px; }
.sticky-col { position: sticky; top: calc(var(--topbar-h) + 14px); align-self: start; }

.card {
  position: relative;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
.card.pad-0 { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { font-size: 13.5px; }
.card-head .sub { font-size: 11.5px; color: var(--text-4); }
.card-head .spacer { margin-left: auto; }
.card-note { margin-top: 11px; padding-top: 11px; border-top: 1px dashed var(--line); font-size: 11.5px; color: var(--text-4); }

.kpi { display: flex; flex-direction: column; gap: 9px; overflow: hidden; }
.kpi-top { display: flex; align-items: center; gap: 9px; }
.kpi-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background: var(--accent-soft);
  color: var(--accent);
}
.kpi-icon svg { width: 15px; height: 15px; }
.kpi-icon.teal { background: color-mix(in srgb, var(--teal) 12%, transparent); color: var(--teal); }
.kpi-icon.sky { background: color-mix(in srgb, var(--sky) 12%, transparent); color: var(--sky); }
.kpi-icon.violet { background: color-mix(in srgb, var(--violet) 13%, transparent); color: var(--violet); }
.kpi-icon.amber { background: color-mix(in srgb, var(--amber) 14%, transparent); color: var(--amber); }
.kpi-label { font-size: 11.5px; font-weight: 560; color: var(--text-3); letter-spacing: 0.01em; }
.kpi-value { display: flex; align-items: baseline; gap: 5px; font-size: 27px; font-weight: 640; letter-spacing: -0.03em; }
.kpi-unit { font-size: 12.5px; font-weight: 560; color: var(--text-3); letter-spacing: 0; }
.kpi-foot { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--text-4); }

.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 620; }
.trend.up { color: var(--ok); }
.trend.down { color: var(--danger); }
.trend.flat { color: var(--text-4); }

.spark { height: 34px; margin: -4px -4px -6px; }

.chart { width: 100%; height: 260px; }
.chart.tall { height: 320px; }
.chart.short { height: 196px; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-3); }
.legend i { width: 8px; height: 8px; border-radius: 3px; }

/* --------------------------------------------------------------- table ---- */

.table-wrap { overflow: auto; }
table.data { font-size: 12.8px; }
table.data thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 11px;
  font-weight: 620;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-4);
  white-space: nowrap;
}
table.data tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--text-2); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background 0.12s; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.strong { color: var(--text); font-weight: 560; }
table.data td.r, table.data th.r { text-align: right; font-variant-numeric: tabular-nums; }

.bar-cell { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.bar-track { position: relative; flex: 1; height: 5px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface-inset);
  font-size: 11px;
  font-weight: 560;
  color: var(--text-3);
  white-space: nowrap;
}
.chip.ok { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.chip.warn { border-color: transparent; background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.chip.info { border-color: transparent; background: color-mix(in srgb, var(--sky) 14%, transparent); color: var(--sky); }
.chip.violet { border-color: transparent; background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet); }
.chip.mono { font-family: var(--mono); font-size: 10.5px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.filter-btn {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 550;
  color: var(--text-3);
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); border-color: var(--line-strong); }
.filter-btn.on { background: var(--text); border-color: var(--text); color: var(--surface); }
.filter-sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }

/* ---------------------------------------------------------------- chat ---- */

.chat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 372px;
  height: calc(100vh - var(--topbar-h));
}
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.chat-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.model-pick {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-inset);
  font-size: 12px;
  font-weight: 550;
}
.model-pick select { border: 0; background: none; outline: none; font-size: 12px; font-weight: 550; }
.model-pick .glyph { width: 15px; height: 15px; color: var(--accent); }

.thread { flex: 1; min-height: 0; overflow-y: auto; padding: 24px 22px 8px; }
.thread-inner { max-width: 840px; margin: 0 auto; display: flex; flex-direction: column; gap: 22px; }

.msg { display: flex; gap: 12px; }
.msg-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 650;
}
.msg.user .msg-avatar { background: var(--surface-3); color: var(--text-2); }
.msg.ai .msg-avatar { background: linear-gradient(145deg, var(--accent), var(--teal)); color: var(--accent-contrast); }
.msg.ai .msg-avatar svg { width: 15px; height: 15px; }
.msg-body { min-width: 0; flex: 1; }
.msg-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; font-size: 11.5px; color: var(--text-4); }
.msg-meta b { color: var(--text-2); font-weight: 600; font-size: 12.5px; }
.msg-text { font-size: 13.8px; color: var(--text); line-height: 1.72; }
.msg-text p + p { margin-top: 9px; }
.msg-text ul { margin: 9px 0; display: flex; flex-direction: column; gap: 6px; }
.msg-text li { position: relative; padding-left: 15px; color: var(--text-2); }
.msg-text li::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 9px;
  width: 4px;
  height: 4px;
  border-radius: 99px;
  background: var(--accent);
}
.msg.user .msg-text {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 4px var(--r-md) var(--r-md) var(--r-md);
  background: var(--surface);
}

.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  margin: 0 1px;
  padding: 0 4px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 680;
  vertical-align: 1px;
  cursor: pointer;
  transition: background 0.15s;
}
.cite-ref:hover { background: var(--accent); color: var(--accent-contrast); }
/* Consecutive references must not read as a single multi-digit number. */
.cite-ref + .cite-ref { margin-left: 3px; }

.answer-card {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.answer-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-2);
}
.answer-card-head svg { width: 14px; height: 14px; color: var(--accent); }
.answer-card-head .spacer { margin-left: auto; }
.answer-card-body { padding: 12px 14px 14px; }

.msg-actions { display: flex; gap: 4px; margin-top: 11px; }
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 11.5px;
  font-weight: 550;
  color: var(--text-4);
  transition: background 0.15s, color 0.15s;
}
.msg-action:hover { background: var(--surface-3); color: var(--text-2); }
.msg-action svg { width: 13px; height: 13px; }

.composer { padding: 12px 22px 20px; border-top: 1px solid var(--line); background: var(--surface); }
.composer-inner { max-width: 840px; margin: 0 auto; }
.suggests { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 10px; }
.suggest {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface-inset);
  font-size: 12px;
  color: var(--text-2);
  transition: all 0.15s;
}
.suggest:hover { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface-inset);
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer-box:focus-within { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-box textarea {
  flex: 1;
  max-height: 148px;
  min-height: 24px;
  border: 0;
  background: none;
  outline: none;
  resize: none;
  font-size: 13.8px;
  line-height: 1.6;
}
.composer-box textarea::placeholder { color: var(--text-4); }
.send {
  display: grid;
  place-items: center;
  width: 31px;
  height: 31px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-contrast);
  transition: background 0.15s, opacity 0.15s;
}
.send:hover { background: var(--accent-hover); }
.send svg { width: 15px; height: 15px; }
.composer-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: 11px; color: var(--text-4); }

.evidence { display: flex; flex-direction: column; border-left: 1px solid var(--line); background: var(--surface-2); min-width: 0; min-height: 0; }
.evidence-head { display: flex; align-items: center; gap: 8px; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.evidence-head svg { width: 15px; height: 15px; color: var(--text-4); }
.evidence-head h3 { font-size: 12.5px; }
.evidence-head .spacer { margin-left: auto; }
.evidence-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 11px; }

.src {
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.src:hover { border-color: var(--accent-line); box-shadow: var(--shadow-1); }
.src.active { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.src-top { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.src-idx {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 680;
}
.src-name { font-size: 12px; font-weight: 570; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-page { margin-left: auto; font-size: 10.5px; color: var(--text-4); font-variant-numeric: tabular-nums; white-space: nowrap; }
.src-quote {
  padding: 8px 10px;
  border-left: 2px solid var(--accent-line);
  border-radius: 0 6px 6px 0;
  background: var(--surface-inset);
  font-size: 11.8px;
  line-height: 1.62;
  color: var(--text-2);
}
.src-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.score-track { flex: 1; height: 3px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.score-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--teal), var(--accent)); }
.score-val { font-size: 10.5px; font-weight: 620; color: var(--text-3); font-variant-numeric: tabular-nums; }

.pipeline { display: flex; flex-direction: column; gap: 0; }
.step { display: flex; gap: 10px; }
.step-rail { display: flex; flex-direction: column; align-items: center; flex: 0 0 16px; }
.step-node { width: 8px; height: 8px; margin-top: 5px; border-radius: 99px; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.step-line { flex: 1; width: 1px; background: var(--line); margin: 3px 0; }
.step-body { padding-bottom: 12px; min-width: 0; }
.step-title { font-size: 12px; font-weight: 570; }
.step-desc { font-size: 11.2px; color: var(--text-4); }
.step-ms { font-family: var(--mono); font-size: 10.5px; color: var(--accent); }

/* ------------------------------------------------------------ workflow ---- */

.phases { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.phase {
  position: relative;
  padding: 13px 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  text-align: left;
  transition: all 0.15s;
  overflow: hidden;
}
.phase:hover { border-color: var(--line-strong); box-shadow: var(--shadow-1); }
.phase.on { border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.phase::after { content: ""; position: absolute; inset: auto 0 0 0; height: 2px; background: var(--accent); opacity: 0.14; }
.phase.on::after { opacity: 1; }
.phase-id { font-family: var(--mono); font-size: 10.5px; font-weight: 600; color: var(--accent); letter-spacing: 0.04em; }
.phase-name { margin-top: 3px; font-size: 12.8px; font-weight: 580; }
.phase-count { margin-top: 7px; font-size: 11px; color: var(--text-4); }

.qa-list { display: flex; flex-direction: column; gap: 8px; }
.qa {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s;
}
.qa:hover { border-color: var(--line-strong); }
.qa.open { border-color: var(--accent-line); }
.qa-q { display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 12px 14px; text-align: left; }
.qa-q .mark {
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  flex: 0 0 19px;
  margin-top: 1px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10.5px;
  font-weight: 700;
}
.qa-q span { font-size: 13px; font-weight: 530; color: var(--text); }
.qa-q .caret { margin-left: auto; width: 15px; height: 15px; color: var(--text-4); transition: transform 0.2s; flex: 0 0 15px; }
.qa.open .qa-q .caret { transform: rotate(180deg); }
.qa-a { display: none; padding: 0 14px 14px 43px; }
.qa.open .qa-a { display: block; }
.qa-a-inner {
  padding: 11px 13px;
  border-left: 2px solid var(--accent-line);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--surface-inset);
  font-size: 12.8px;
  line-height: 1.72;
  color: var(--text-2);
}
.qa-foot { display: flex; align-items: center; gap: 8px; margin-top: 9px; }

/* -------------------------------------------------------------- system ---- */

.flow { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding: 4px 0 8px; }
.flow-node {
  flex: 1;
  min-width: 168px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
}
.flow-node .n-top { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; }
.flow-node .n-ico { display: grid; place-items: center; width: 25px; height: 25px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.flow-node .n-ico svg { width: 14px; height: 14px; }
.flow-node h4 { font-size: 12.3px; }
.flow-node p { font-size: 11.2px; color: var(--text-4); line-height: 1.55; }
.flow-node .n-tag { margin-top: 8px; }
.flow-arrow { display: grid; place-items: center; flex: 0 0 30px; color: var(--text-4); }
.flow-arrow svg { width: 15px; height: 15px; }

.kv { display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr); gap: 9px 16px; font-size: 12.8px; }
.kv dt { color: var(--text-4); }
.kv dd { margin: 0; color: var(--text); font-weight: 530; }
.kv dd.mono { font-family: var(--mono); font-size: 12px; }

.callout {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  background: var(--accent-soft);
}
.callout svg { width: 16px; height: 16px; flex: 0 0 16px; margin-top: 2px; color: var(--accent); }
.callout p { font-size: 12.5px; color: var(--text-2); line-height: 1.62; }
.callout b { color: var(--text); }
.callout code { font-family: var(--mono); font-size: 11.5px; color: var(--text-3); }
.callout.info { border-color: color-mix(in srgb, var(--sky) 30%, transparent); background: color-mix(in srgb, var(--sky) 8%, transparent); }
.callout.info svg { color: var(--sky); }
.callout.error { border-color: color-mix(in srgb, var(--danger) 34%, transparent); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.callout.error svg { color: var(--danger); }
.mb { margin-bottom: 14px; }

/* ------------------------------------------------------ live/async states -- */

.loading-wrap {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 320px; font-size: 12.8px; color: var(--text-3);
}
.spinner {
  width: 20px; height: 20px; border-radius: 99px;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-box {
  display: flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 148px; padding: 18px;
  font-size: 12.3px; color: var(--text-4);
  border: 1px dashed var(--line-strong); border-radius: var(--r-md);
  background: var(--surface-inset);
}
.empty-box svg { width: 15px; height: 15px; }
.empty-box.side { min-height: 96px; text-align: center; line-height: 1.6; }
.empty-cell { padding: 26px 16px !important; text-align: center; color: var(--text-4); font-size: 12px; }

.chip.err { border-color: transparent; background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.chip.live { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.chip.live svg { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.dot-inline { display: inline-block; width: 6px; height: 6px; border-radius: 99px; margin-right: 7px; vertical-align: 1px; }
.dot-inline.on { background: var(--ok); box-shadow: 0 0 0 3px var(--accent-soft); }
.dot-inline.off { background: var(--text-4); }
.health.off .dot { background: var(--text-4); box-shadow: none; }

.btn.busy { opacity: 0.6; pointer-events: none; }
.msg-action.on { background: var(--accent-soft); color: var(--accent); }
.msg-action.done { color: var(--accent); }

/* Answer placeholder while the first token is in flight. */
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 99px; background: var(--text-4);
  animation: bounce 1.1s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.16s; }
.typing span:nth-child(3) { animation-delay: 0.32s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.step.pending { opacity: 0.45; }

.chat-empty { padding: 64px 24px; text-align: center; }
.chat-empty-mark {
  width: 46px; height: 46px; margin: 0 auto 16px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: var(--accent-soft); color: var(--accent);
}
.chat-empty-mark svg { width: 24px; height: 24px; }
.chat-empty h2 { font-size: 16.5px; font-weight: 620; letter-spacing: -0.02em; color: var(--text); }
.chat-empty p { margin-top: 7px; font-size: 12.8px; color: var(--text-3); line-height: 1.7; max-width: 440px; margin-inline: auto; }

.msg-text ol { margin: 8px 0 0 18px; display: grid; gap: 5px; }
.msg-text ol li { font-size: 13px; color: var(--text-2); line-height: 1.72; }
.msg-text code { font-family: var(--mono); font-size: 11.8px; padding: 1px 5px; border-radius: 5px; background: var(--surface-3); }
.msg-text em { font-style: normal; color: var(--text); font-weight: 560; }

/* Headings inside an answer stay visually subordinate to the page's own. */
.msg-text .answer-h {
  margin: 14px 0 6px;
  color: var(--text);
  font-weight: 620;
  letter-spacing: -0.01em;
}
.msg-text .answer-h:first-child { margin-top: 0; }
.msg-text .answer-rule { margin: 12px 0; border: 0; border-top: 1px solid var(--line); }
.msg-text .table-wrap { margin: 10px 0; border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
.msg-text .answer-table { font-size: 12.4px; }
.msg-text h4.answer-h { font-size: 13.6px; }
.msg-text h5.answer-h { font-size: 12.8px; color: var(--text-2); }

/* ---------------------------------------------------------- responsive ---- */

@media (max-width: 1440px) {
  .chat { grid-template-columns: minmax(0, 1fr) 330px; }
}
@media (max-width: 1240px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-3, .g-2-1, .g-1-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .phases { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 1024px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .chat { grid-template-columns: minmax(0, 1fr); }
  .evidence { display: none; }
}
@media (max-width: 720px) {
  .g-4, .g-2 { grid-template-columns: minmax(0, 1fr); }
  .phases { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view { padding: 18px 14px 40px; }
  .topbar { padding: 0 14px; }
  .topbar-search { display: none; }
}

.fade-in { animation: fade-in 0.28s cubic-bezier(0.22, 0.61, 0.36, 1); }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Fact citations — every dashboard number that came from an indexed chunk. */
.fact-num {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}
.fact-cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-inset);
  color: var(--text-4);
  cursor: pointer;
  vertical-align: middle;
  flex-shrink: 0;
}
.fact-cite svg { width: 10px; height: 10px; }
.fact-cite:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.kpi-foot .fact-cite { margin-left: 2px; }

#factDrawer {
  position: fixed;
  inset: 0;
  z-index: 80;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}
#factDrawer.open {
  pointer-events: auto;
  opacity: 1;
}
.fact-drawer-backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
}
.fact-drawer {
  position: absolute;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100%;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: -18px 0 40px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  transform: translateX(12px);
  transition: transform 0.2s ease;
}
#factDrawer.open .fact-drawer { transform: none; }
.fact-drawer-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.fact-drawer-head h3 {
  margin: 4px 0 2px;
  font-size: 15px;
  font-weight: 640;
  line-height: 1.35;
  word-break: break-all;
}
.fact-drawer-body {
  padding: 16px 18px 24px;
  overflow: auto;
  flex: 1;
}
.fact-quote {
  margin: 12px 0 0;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--text-2);
  background: var(--surface-inset);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.btn.icon-only {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
}
