/* ThermIQ — interface styles
   Design system: cool "condenser grey" paper, feedwater blue for anything
   actionable, and a heat ramp (amber → ember → flue red) reserved strictly
   for risk magnitude. One typeface (Archivo), with its width axis doing the
   work: condensed for gauge-like figures, normal width for reading. */

/* ─── Tokens ──────────────────────────────────────────────────────────────── */
:root {
  --paper: #EDF0F2;
  --surface: #FFFFFF;
  --surface-2: #F5F7F8;
  --ink: #182028;
  --ink-2: #3A4651;
  --muted: #64717C;
  --line: #D6DCE1;
  --line-strong: #B9C2CA;
  --water: #1D5C87;
  --water-hover: #164A6E;
  --water-ink: #FFFFFF;
  --water-soft: #E3EDF4;
  --heat-1: #D98E1F;
  --heat-2: #D5642A;
  --heat-3: #B3311E;
  --heat-soft: #FBEDE4;
  --ok: #2B7A57;
  --ok-soft: #E2F1E9;
  --warn-soft: #FBF1DD;
  --bad-soft: #F8E3DF;
  --overlay: rgba(16, 22, 28, 0.55);
  --shadow-float: 0 18px 48px rgba(16, 24, 32, 0.18), 0 2px 6px rgba(16, 24, 32, 0.08);

  --font: 'Archivo', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius-lg: 12px;
  --radius: 8px;
  --radius-sm: 6px;

  --rail-w: 232px;
  --topbar-h: 60px;
  --tabbar-h: 0px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #101519;
  --surface: #172027;
  --surface-2: #1C262E;
  --ink: #E3E8EB;
  --ink-2: #C0C9D0;
  --muted: #8C99A4;
  --line: #27323B;
  --line-strong: #37454F;
  --water: #7DB6DE;
  --water-hover: #9CC8E8;
  --water-ink: #0D1A23;
  --water-soft: #1B3244;
  --heat-1: #EEAD45;
  --heat-2: #EE7B3B;
  --heat-3: #E4553D;
  --heat-soft: #35231B;
  --ok: #5DBA8D;
  --ok-soft: #173327;
  --warn-soft: #33291A;
  --bad-soft: #3A1F1B;
  --overlay: rgba(4, 7, 10, 0.66);
  --shadow-float: 0 18px 48px rgba(0, 0, 0, 0.5), 0 2px 6px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

/* ─── Base ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  font-variation-settings: 'wdth' 100;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: var(--water); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { flex-shrink: 0; }
code { font-size: 0.9em; background: var(--surface-2); padding: 0.05em 0.35em; border-radius: 4px; }
[hidden] { display: none !important; }
.hidden { display: none !important; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; border-radius: 4px; }
.skip-link {
  position: fixed; left: 12px; top: -60px; z-index: 5000;
  background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: var(--radius-sm);
}
.skip-link:focus { top: 12px; }

/* Icons drawn as strokes everywhere, sized by their container. */
.rail svg, .topbar svg, .tabbar svg, .icon-btn svg, .btn svg, .btn-send svg,
.scroll-bottom-btn svg, .upload-icon, .msg-action-btn svg, .chat-item-icon svg,
.chat-item-delete svg, .btn-delete-doc svg {
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.brand-mark { fill: initial; stroke: none; }

/* ─── Shell ───────────────────────────────────────────────────────────────── */
body {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "rail top" "rail main";
}
.rail { grid-area: rail; }
.topbar { grid-area: top; }
.views { grid-area: main; min-width: 0; }

.rail {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  background: var(--paper);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  padding: 4px 8px 20px;
}
.brand-mark { width: 30px; height: 30px; color: var(--ink); }
.brand-name {
  font-size: 1.2rem; font-weight: 750; letter-spacing: -0.02em;
  font-variation-settings: 'wdth' 88;
}
.rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: var(--radius);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav-item svg { width: 20px; height: 20px; }
.nav-item:hover { background: var(--surface); color: var(--ink); }
.nav-item.active { background: var(--surface); color: var(--ink); box-shadow: inset 3px 0 0 var(--water); font-weight: 620; }
.nav-item.active svg { color: var(--water); }
.rail-foot { margin-top: auto; display: grid; gap: 14px; }
.rail-upload {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1px dashed var(--line-strong); background: transparent;
  color: var(--ink-2); font-weight: 560;
}
.rail-upload svg { width: 18px; height: 18px; }
.rail-upload:hover { border-color: var(--water); color: var(--water); background: var(--surface); }
.rail-meta { font-size: 0.75rem; color: var(--muted); line-height: 1.5; padding: 0 8px; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand--compact { display: none; padding: 0; }
.plant-picker {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 4px 4px 12px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--surface);
}
.plant-picker-label { font-size: 0.8rem; color: var(--muted); }
.plant-selector {
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent; font-weight: 620;
  padding: 4px 26px 4px 2px; max-width: 220px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 8px) 55%;
  background-size: 5px 5px; background-repeat: no-repeat;
  cursor: pointer;
}
.plant-selector:focus-visible { outline-offset: 0; }
.plant-selector option { background: var(--surface); color: var(--ink); }
.readings { display: flex; align-items: center; gap: 24px; margin-left: auto; }
.reading { display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.reading-v {
  font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums;
  font-variation-settings: 'wdth' 75;
}
.reading--heat .reading-v { color: var(--heat-2); }
.reading-l { font-size: 0.8rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  border: 0; background: transparent; color: var(--ink-2);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface); color: var(--ink); }
.only-chat, .only-chat-mobile { display: none; }
body[data-view="chat"] .only-chat { display: inline-grid; }
[data-theme="light"] .icon-moon, [data-theme="dark"] .icon-sun { display: none; }

.tabbar { display: none; }

/* ─── Views ───────────────────────────────────────────────────────────────── */
.spa-view { display: none; }
.spa-view.active { display: block; }
.page { max-width: 1120px; margin: 0 auto; padding: 32px 32px 64px; }
.page--wide { max-width: 1320px; }
.view-head { margin-bottom: 20px; }
.view-head--row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.view-head h1 { margin-bottom: 10px; }
.view-sub { color: var(--ink-2); max-width: 72ch; }
.view-sub--tight { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.page > .view-sub { margin-bottom: 20px; }
.footnote { color: var(--muted); font-size: 0.8rem; max-width: 80ch; margin-top: 16px; }
.last-updated:empty { display: none; }

/* ─── Controls ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius);
  border: 1px solid transparent; font-weight: 600; font-size: 0.925rem;
  text-decoration: none; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn svg { width: 17px; height: 17px; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 0.875rem; }
.btn-primary { background: var(--water); color: var(--water-ink); }
.btn-primary:hover { background: var(--water-hover); }
.btn-quiet { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-quiet:hover { border-color: var(--water); color: var(--water); }
.btn-danger { background: transparent; color: var(--heat-3); border-color: color-mix(in srgb, var(--heat-3) 45%, transparent); }
.btn-danger:hover { background: var(--bad-soft); }
.btn:disabled, .btn[disabled] { opacity: 0.5; cursor: not-allowed; }
/* legacy class names generated by app.js */
.btn-add-docs:not(.btn) {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 12px; border-radius: var(--radius);
  border: 0; background: var(--water); color: var(--water-ink); font-weight: 600; font-size: 0.875rem;
}
.btn-sync-drive:not(.btn), .btn-sheet-csv:not(.btn) {
  display: inline-flex; align-items: center; min-height: 34px; padding: 0 12px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; font-size: 0.875rem;
}
.btn-sheet-csv:not(.btn):hover, .btn-sync-drive:not(.btn):hover { border-color: var(--water); color: var(--water); }
.text-link {
  background: none; border: 0; padding: 0; color: var(--water); font-weight: 600; font-size: 0.9rem;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; cursor: pointer;
}
.text-link:hover { text-decoration-thickness: 2px; }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2);
  font-size: 0.85rem; font-weight: 500; line-height: 1.3; text-align: left;
}
button.chip:hover { border-color: var(--water); color: var(--water); }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.segment {
  padding: 6px 14px; border-radius: 999px; border: 0; background: transparent;
  color: var(--ink-2); font-weight: 560; font-size: 0.9rem; text-decoration: none; white-space: nowrap;
}
.segment:hover { color: var(--ink); }
.segment.is-on, .segment.selected { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.08), 0 0 0 1px var(--line); }
.segmented--full { display: flex; }
.segmented--full .segment { flex: 1; }

.live-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); flex-shrink: 0;
}

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 20px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-head h2 { display: flex; align-items: center; gap: 10px; }
.panel-sub { color: var(--ink-2); font-size: 0.9rem; margin: 6px 0 14px; }
.panel-foot { color: var(--muted); font-size: 0.85rem; margin-top: 14px; }
.panel-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 14px; }

/* ─── Overview ────────────────────────────────────────────────────────────── */
.exposure { padding: 8px 0 28px; }
.exposure-plant { color: var(--muted); font-size: 0.95rem; margin-bottom: 6px; }
.exposure-title { display: block; font-weight: 500; }
.exposure-figure {
  display: block;
  font-size: clamp(3.4rem, 9vw, 6.4rem); line-height: 0.95; font-weight: 760;
  letter-spacing: -0.035em; font-variant-numeric: tabular-nums;
  font-variation-settings: 'wdth' 68;
  color: var(--heat-2);
}
.exposure-caption {
  display: block; max-width: 34ch; margin-top: 10px;
  font-size: clamp(1.15rem, 2.2vw, 1.5rem); line-height: 1.3; font-weight: 520; color: var(--ink);
}
.heatstrip {
  display: flex; gap: 3px; height: 44px; margin-top: 28px;
  border-radius: var(--radius); overflow: hidden;
}
.heatstrip-empty {
  flex: 1; display: grid; place-items: center; font-size: 0.85rem; color: var(--muted);
  background: var(--surface-2); border: 1px dashed var(--line-strong); border-radius: var(--radius);
}
.heat-seg {
  position: relative; min-width: 6px; border: 0; padding: 0;
  background: var(--seg, var(--heat-2));
  transition: filter 0.15s, transform 0.15s;
}
.heat-seg:hover, .heat-seg:focus-visible { filter: brightness(1.12) saturate(1.1); transform: scaleY(1.08); outline: none; z-index: 1; }
.heat-seg[data-crit="5"] { --seg: var(--heat-3); }
.heat-seg[data-crit="4"] { --seg: color-mix(in srgb, var(--heat-3) 50%, var(--heat-2)); }
.heat-seg[data-crit="3"] { --seg: var(--heat-2); }
.heat-seg[data-crit="2"] { --seg: color-mix(in srgb, var(--heat-2) 50%, var(--heat-1)); }
.heat-seg[data-crit="1"] { --seg: var(--heat-1); }
.heat-seg .seg-tip {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%);
  width: max-content; max-width: 260px; padding: 8px 10px; border-radius: var(--radius-sm);
  background: var(--ink); color: var(--paper); font-size: 0.8rem; line-height: 1.4; text-align: left;
  display: none; pointer-events: none; white-space: normal; z-index: 5;
}
.heat-seg:hover .seg-tip, .heat-seg:focus-visible .seg-tip { display: block; }
.heat-seg:nth-child(-n+2) .seg-tip { left: 0; transform: none; }
.heat-seg:nth-last-child(-n+3) .seg-tip { left: auto; right: 0; transform: none; }
.heatstrip { overflow: visible; }
.heat-seg:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.heat-seg:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.heatstrip-scale { margin-top: 10px; font-size: 0.85rem; color: var(--muted); }
.exposure--pending .exposure-figure { color: var(--ink); }
.exposure--pending .heatstrip-scale { display: none; }

.overview-grid {
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  grid-template-areas: "gaps ask" "gaps corpus";
}
.panel--gaps { grid-area: gaps; }
.panel--ask { grid-area: ask; }
.panel--corpus { grid-area: corpus; }

.priority-list { list-style: none; margin: 0; padding: 0; counter-reset: pri; }
.priority-list li { border-top: 1px solid var(--line); }
.priority-list li:first-child { border-top: 0; }
.priority-empty { padding: 12px 0; color: var(--muted); }
.priority-item {
  display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline;
  width: 100%; padding: 12px 0; border: 0; background: none; text-align: left; color: inherit;
}
.priority-item:hover .priority-name { color: var(--water); }
.priority-rank { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' 75; }
.priority-name { font-weight: 600; line-height: 1.35; }
.priority-meta { grid-column: 2; font-size: 0.82rem; color: var(--muted); }
.priority-risk {
  grid-row: 1 / span 2; grid-column: 3; align-self: center;
  font-weight: 720; font-size: 1.15rem; color: var(--heat-2); white-space: nowrap;
  font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' 72;
}

.ask-form { display: flex; gap: 8px; }
.ask-form input {
  flex: 1; min-width: 0; min-height: 44px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface-2);
}
.ask-form input:focus { outline: none; border-color: var(--water); background: var(--surface); box-shadow: 0 0 0 3px var(--water-soft); }
.ask-form .btn { min-height: 44px; }
.ask-suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

.corpus-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; margin: 14px 0 0; }
.corpus-stats div { display: flex; flex-direction: column-reverse; gap: 2px; }
.corpus-stats dt { font-size: 0.82rem; color: var(--muted); }
.corpus-stats dd {
  margin: 0; font-size: 1.6rem; font-weight: 720; line-height: 1.1;
  font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' 72;
}

.outages { margin-top: 16px; }
.outage-feed { list-style: none; margin: 0; padding: 0; }
.outage-feed .tick-item {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto auto; gap: 4px 16px; align-items: baseline;
  padding: 10px 0; border-top: 1px solid var(--line); font-size: 0.9rem; color: var(--ink-2);
}
.outage-feed .tick-item:first-child { border-top: 0; padding-top: 0; }
.outage-feed .tick-item:only-child { display: block; color: var(--muted); }
.tick-station { font-weight: 600; color: var(--ink); }
.tick-loss { font-weight: 700; color: var(--heat-2); font-variant-numeric: tabular-nums; }
.tick-date { color: var(--muted); font-variant-numeric: tabular-nums; }
.hub-outages-panel { margin-top: 14px; }

/* ─── Tables ──────────────────────────────────────────────────────────────── */
.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; margin-top: 16px; }
.table-card h2 { margin-bottom: 0; }
.docs-list-header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -20px; padding: 0 20px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th {
  text-align: left; font-weight: 600; font-size: 0.8rem; color: var(--muted);
  padding: 8px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table .num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.skeleton-row { color: var(--muted); text-align: center; padding: 28px 12px !important; }
.skeleton-cta { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; }
.explainer { color: var(--muted); font-size: 0.82rem; margin-top: 12px; }

/* ─── Copilot ─────────────────────────────────────────────────────────────── */
.app-layout.active {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  height: calc(100dvh - var(--topbar-h));
}
.sidebar {
  width: 272px; min-width: 200px; max-width: 600px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--surface-2);
  overflow: hidden;
}
.sidebar-header { display: flex; align-items: center; gap: 6px; padding: 12px 12px 8px; }
.sidebar-header h2 { flex: 1; font-size: 0.95rem; }
.btn-new-chat span { font-size: 0.85rem; }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px 16px; }
.chat-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-radius: var(--radius);
  cursor: pointer; color: var(--ink-2);
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
.chat-item-icon { color: var(--muted); display: grid; }
.chat-item-icon svg { width: 16px; height: 16px; }
.chat-item-content { flex: 1; min-width: 0; }
.chat-item-title { font-size: 0.9rem; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 0.75rem; color: var(--muted); }
.chat-item-delete {
  display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted); opacity: 0;
}
.chat-item-delete svg { width: 15px; height: 15px; }
.chat-item:hover .chat-item-delete, .chat-item:focus-within .chat-item-delete, .chat-item.active .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: var(--heat-3); background: var(--bad-soft); }
.chat-list-empty { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 32px 8px; }
.chat-list-empty-icon { display: none; }
.sidebar-resizer { width: 5px; margin-left: -3px; cursor: col-resize; position: relative; z-index: 2; }
.sidebar-resizer:hover, .sidebar-resizer.is-dragging { background: var(--water); }
.sidebar-overlay { display: none; }

/* collapsed: keep a slim strip with just the expand + new-chat buttons */
.app-layout.sidebar-collapsed .sidebar { width: 56px !important; min-width: 56px; }
.app-layout.sidebar-collapsed .sidebar-header { flex-direction: column; padding: 12px 8px; }
.app-layout.sidebar-collapsed .sidebar-header h2,
.app-layout.sidebar-collapsed .chat-list,
.app-layout.sidebar-collapsed .btn-new-chat span { display: none; }
.app-layout.sidebar-collapsed .btn-new-chat { padding: 0; width: 38px; }
.app-layout.sidebar-collapsed .sidebar-resizer { display: none; }

.chat-main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  padding: 28px max(24px, calc((100% - 780px) / 2)) 24px;
  display: flex; flex-direction: column; gap: 18px;
}
.chat-empty { margin: auto 0; padding: 24px 0; max-width: 560px; }
.chat-empty-icon { display: none; }
.chat-empty-title { font-size: clamp(1.5rem, 3.4vw, 2.1rem); font-weight: 680; letter-spacing: -0.02em; margin-bottom: 10px; }
.chat-empty-text { color: var(--ink-2); font-size: 1rem; }
.chat-empty-nodocs {
  margin-top: 18px; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft);
  color: var(--ink); font-size: 0.9rem; display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
}

.chat-bubble { position: relative; max-width: 100%; }
.user-bubble {
  align-self: flex-end; max-width: min(85%, 620px);
  background: var(--water); color: var(--water-ink);
  padding: 10px 14px; border-radius: 16px 16px 4px 16px;
}
.user-bubble .bubble-text { white-space: pre-wrap; word-wrap: break-word; }
.user-bubble .msg-actions { justify-content: flex-end; color: var(--water-ink); }
.user-bubble .msg-action-btn, .user-bubble .msg-timestamp, .user-bubble .edit-limit { color: color-mix(in srgb, var(--water-ink) 80%, transparent); }
.user-bubble .msg-action-btn:hover { background: color-mix(in srgb, var(--water-ink) 16%, transparent); color: var(--water-ink); }
.user-bubble.editing { background: var(--surface); color: var(--ink); border: 1px solid var(--water); width: min(85%, 620px); }
.assistant-bubble { align-self: stretch; }
.assistant-bubble .bubble-text { color: var(--ink); line-height: 1.65; overflow-wrap: anywhere; }
.bubble-text > :first-child { margin-top: 0; }
.bubble-text > :last-child { margin-bottom: 0; }
.bubble-text p, .bubble-text ul, .bubble-text ol { margin: 0 0 0.75em; }
.bubble-text ul, .bubble-text ol { padding-left: 1.3em; }
.bubble-text li { margin: 0.2em 0; }
.bubble-text h1, .bubble-text h2, .bubble-text h3, .bubble-text h4 { font-size: 1rem; margin: 1em 0 0.4em; }
.bubble-text table { border-collapse: collapse; margin: 0.5em 0 1em; font-size: 0.88rem; display: block; overflow-x: auto; }
.bubble-text th, .bubble-text td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; }
.bubble-text th { background: var(--surface-2); }
.bubble-text pre { background: var(--surface-2); padding: 10px; border-radius: var(--radius-sm); overflow-x: auto; }
.bubble-text blockquote { margin: 0 0 0.75em; padding-left: 12px; border-left: 3px solid var(--line-strong); color: var(--ink-2); }
.bubble-text.collapsed {
  max-height: 320px; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 72%, transparent 100%);
}
.bubble-expand-btn {
  margin-top: 6px; border: 0; background: none; padding: 4px 0; color: var(--water); font-weight: 600; font-size: 0.875rem;
}
.bubble-meta { margin-top: 6px; font-size: 0.78rem; color: var(--muted); }

.msg-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; margin-top: 8px; }
.msg-timestamp { font-size: 0.75rem; color: var(--muted); padding: 0 6px 0 0; white-space: nowrap; }
.msg-action-btn, .edit-limit {
  display: inline-flex; align-items: center; gap: 4px; min-height: 30px; padding: 0 8px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); font-size: 0.8rem; font-weight: 550;
}
.msg-action-btn svg { width: 15px; height: 15px; }
.msg-action-btn:hover { background: var(--surface); color: var(--ink); }
.msg-action-btn.copied { color: var(--ok); }
.msg-quick-btn { border: 1px solid var(--line); margin-left: 4px; }
.edit-count { font-size: 0.7rem; }
.msg-edit-textarea {
  width: 100%; min-height: 80px; border: 0; background: transparent; resize: vertical; outline: none; line-height: 1.5;
}
.msg-edit-controls { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn-cancel-edit, .btn-rerun {
  min-height: 32px; padding: 0 12px; border-radius: var(--radius-sm); font-weight: 600; font-size: 0.85rem;
  border: 1px solid var(--line-strong); background: var(--surface);
}
.btn-rerun { background: var(--water); border-color: var(--water); color: var(--water-ink); }

.sources-toggle { margin-top: 10px; font-size: 0.85rem; }
.sources-toggle summary {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--ink-2); font-weight: 600;
  list-style: none; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line);
}
.sources-toggle summary::-webkit-details-marker { display: none; }
.sources-toggle summary::before { content: ''; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s; }
.sources-toggle[open] summary::before { transform: rotate(45deg); }
.sources-list { display: grid; gap: 8px; margin-top: 10px; }
.source-card { padding: 10px 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); }
.source-meta { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); font-size: 0.82rem; }
.source-meta span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }
.score-bar-track { height: 4px; border-radius: 2px; background: var(--surface-2); margin-top: 8px; overflow: hidden; }
.score-bar-fill { height: 100%; background: var(--water); border-radius: 2px; }

.followup-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -6px; }
.chip-followup { font-size: 0.82rem; }
.chip-graph-link { border-color: var(--water); color: var(--water); background: var(--water-soft); }

.typing-bubble {
  align-self: flex-start; display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line);
}
.typing-bubble .dot, .typing-bubble .typing-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--heat-2); animation: tq-pulse 1.2s infinite ease-in-out;
}
.typing-bubble .dot:nth-child(2), .typing-bubble .typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble .dot:nth-child(3), .typing-bubble .typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes tq-pulse { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }
.typing-status { margin-left: 6px; font-size: 0.875rem; color: var(--ink-2); }
.btn-stop-gen {
  margin-left: 10px; min-height: 30px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface-2); font-size: 0.8rem; font-weight: 600;
}
.btn-stop-gen:hover { border-color: var(--heat-3); color: var(--heat-3); }

.chat-input-area {
  padding: 12px max(24px, calc((100% - 780px) / 2)) 14px;
  border-top: 1px solid var(--line); background: var(--paper);
}
.chat-input-area .chip-row { margin-bottom: 10px; }
.input-row {
  display: flex; align-items: flex-end; gap: 8px; padding: 6px 6px 6px 14px;
  border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface);
}
.input-row:focus-within { border-color: var(--water); box-shadow: 0 0 0 3px var(--water-soft); }
#chat-input {
  flex: 1; min-height: 36px; max-height: 160px; padding: 7px 0; border: 0; background: transparent; resize: none; outline: none;
  line-height: 1.45; font-size: 1rem;
}
.btn-send {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: var(--water); color: var(--water-ink);
}
.btn-send svg { width: 20px; height: 20px; stroke-width: 2.2; }
.btn-send:disabled { opacity: 0.45; cursor: progress; }
.input-hint { margin-top: 6px; font-size: 0.75rem; color: var(--muted); text-align: center; }
.scroll-bottom-btn {
  position: absolute; right: 24px; bottom: 150px; z-index: 5;
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-float);
  opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity 0.15s, transform 0.15s;
}
.scroll-bottom-btn svg { width: 18px; height: 18px; }
.scroll-bottom-btn.visible { opacity: 1; pointer-events: auto; transform: none; }

/* ─── Knowledge graph ─────────────────────────────────────────────────────── */
.graph-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-bottom: 12px; font-size: 0.85rem; color: var(--ink-2); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.legend-dot { width: 12px; height: 12px; border-radius: 3px; border: 2px solid; }
.legend-equipment   { border-color: #3B82C4; background: rgba(59,130,196,0.15); }
.legend-failuremode { border-color: #8A96A0; background: rgba(138,150,160,0.15); }
.legend-gap         { border-color: var(--heat-3); border-style: dashed; background: var(--bad-soft); }
.legend-procedure   { border-color: #2B8A5E; background: rgba(43,138,94,0.15); }
.legend-regulation  { border-color: #7A5BB5; background: rgba(122,91,181,0.15); }
.legend-outage      { border-color: var(--heat-1); background: rgba(217,142,31,0.2); border-radius: 50%; }
.graph-shell {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: stretch;
}
.graph-canvas-wrap {
  position: relative; min-height: 600px; height: calc(100dvh - 300px);
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); overflow: hidden;
  background-image: radial-gradient(var(--line) 1px, transparent 1px); background-size: 22px 22px;
}
#graph-canvas { position: absolute; inset: 0; }
.graph-status {
  position: absolute; left: 12px; top: 12px; z-index: 2; padding: 5px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 0.8rem; color: var(--ink-2);
}
.graph-panel {
  border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
  padding: 18px; overflow-y: auto; max-height: calc(100dvh - 300px); min-height: 600px;
}
.graph-panel-empty p { color: var(--ink-2); font-size: 0.9rem; margin-bottom: 8px; }
.graph-panel-empty strong { color: var(--ink); }
.graph-panel-content h3 { font-size: 1.15rem; margin: 8px 0 12px; }
.graph-panel-content h4 { font-size: 0.9rem; margin: 18px 0 8px; }
.panel-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 650;
  background: var(--water-soft); color: var(--water);
}
.panel-badge.gap { background: var(--bad-soft); color: var(--heat-3); }
.panel-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 0.85rem; }
.panel-key { color: var(--muted); overflow-wrap: anywhere; }
.panel-val { overflow-wrap: anywhere; }
.panel-chain { font-size: 0.9rem; color: var(--ink-2); line-height: 1.6; }
.panel-total { margin-top: 10px; font-size: 0.9rem; }
.panel-reg-list { margin: 0; padding-left: 1.2em; font-size: 0.88rem; }
.panel-reg-list li { margin: 4px 0; }
.risk-hi { color: var(--heat-3); font-weight: 700; }
.sheet-mini { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.sheet-mini th { text-align: left; color: var(--muted); font-weight: 600; padding: 5px 6px; border-bottom: 1px solid var(--line-strong); }
.sheet-mini td { padding: 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.btn-ask-thermiq {
  display: flex; width: 100%; justify-content: center; align-items: center; margin-top: 18px; min-height: 40px; padding: 0 14px;
  border: 0; border-radius: var(--radius); background: var(--water); color: var(--water-ink); font-weight: 600;
}
.btn-ask-thermiq:hover { background: var(--water-hover); }

/* ─── Documents ───────────────────────────────────────────────────────────── */
.docs-view-toolbar { display: flex; flex-wrap: wrap; gap: 8px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.doc-skeleton { grid-column: 1 / -1; color: var(--muted); padding: 32px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); }
.doc-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
  cursor: pointer; transition: border-color 0.15s;
}
.doc-card:hover { border-color: var(--water); }
.doc-card-top { display: flex; align-items: flex-start; gap: 8px; }
.doc-card-name { flex: 1; font-weight: 620; line-height: 1.35; overflow-wrap: anywhere; }
.btn-delete-doc {
  display: grid; place-items: center; width: 32px; height: 32px; margin: -4px -6px 0 0; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--muted);
}
.btn-delete-doc svg { width: 16px; height: 16px; }
.btn-delete-doc:hover { color: var(--heat-3); background: var(--bad-soft); }
.doc-card-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; font-size: 0.82rem; }
.doc-card-meta > div { display: flex; flex-direction: column; }
.m-label { color: var(--muted); font-size: 0.75rem; }
.m-val { font-weight: 560; font-variant-numeric: tabular-nums; }
.doc-card-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.doc-chip { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 560; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.doc-chip--system { background: var(--water-soft); color: var(--water); border-color: transparent; }
.doc-chip--plant { background: var(--warn-soft); color: var(--ink); border-color: transparent; }
.doc-source-link { margin-left: auto; font-weight: 700; text-decoration: none; padding: 2px 6px; border-radius: var(--radius-sm); }
.doc-source-link:hover { background: var(--water-soft); }
.doc-card--job { cursor: default; border-style: dashed; }
.doc-card--job-failed { border-color: var(--heat-3); background: var(--bad-soft); }
.btn-dismiss-job { border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-sm); font-size: 0.78rem; padding: 3px 8px; }
.doc-card--gap {
  cursor: default; gap: 8px; background: var(--surface);
  border: 1px dashed color-mix(in srgb, var(--heat-3) 55%, var(--line));
  box-shadow: inset 4px 0 0 var(--heat-3);
}
.doc-card--gap:hover { border-color: color-mix(in srgb, var(--heat-3) 55%, var(--line)); }
.gap-flag-badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; color: var(--heat-3); background: var(--bad-soft); }
.gap-flag-title { font-weight: 640; overflow-wrap: anywhere; }
.gap-flag-desc { font-size: 0.85rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.gap-flag-meta { font-size: 0.78rem; color: var(--muted); }
.docs-empty {
  grid-column: 1 / -1; padding: 32px; text-align: center; border: 1px dashed var(--line-strong); border-radius: var(--radius-lg);
  background: var(--surface);
}
.docs-empty-icon { display: none; }
.docs-empty h3 { font-size: 1.15rem; margin-bottom: 8px; }
.docs-empty p { color: var(--ink-2); max-width: 56ch; margin: 0 auto 16px; }
.docs-empty-btns { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.danger-zone { margin-top: 32px; border-top: 1px solid var(--line); padding-top: 16px; }
.danger-zone summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 0.9rem; width: max-content; }
.danger-zone p { color: var(--ink-2); font-size: 0.875rem; margin: 10px 0 12px; max-width: 70ch; }
.danger-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ─── Risk register ───────────────────────────────────────────────────────── */
.live-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.summary-cards { display: grid; grid-template-columns: 1.6fr repeat(3, 1fr); gap: 12px; }
.summary-card { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.summary-label { font-size: 0.85rem; color: var(--muted); }
.summary-value {
  margin-top: 4px; font-size: 2rem; line-height: 1.05; font-weight: 740; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; font-variation-settings: 'wdth' 70;
}
.summary-card--hero .summary-value { font-size: 2.6rem; }
.summary-value.orange { color: var(--heat-2); }
.summary-value.red { color: var(--heat-3); }
.summary-value.green { color: var(--ok); }
.sim-card-note { display: block; margin-top: 6px; font-size: 0.75rem; font-weight: 600; color: var(--muted); letter-spacing: 0; font-variation-settings: 'wdth' 100; }

.sim-strip {
  margin-top: 16px; padding: 14px 18px; border-radius: var(--radius-lg);
  background: var(--water-soft); border: 1px solid color-mix(in srgb, var(--water) 25%, transparent);
  display: grid; gap: 8px;
}
.sim-recommended-text { font-size: 0.925rem; }
.sim-strip-bottom { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sim-strip-left { display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0; }
.sim-strip-text { font-size: 0.85rem; color: var(--ink-2); }
.sim-badge { padding: 2px 8px; border-radius: 999px; background: var(--water); color: var(--water-ink); font-size: 0.75rem; font-weight: 700; white-space: nowrap; }

.method-note summary { cursor: pointer; color: var(--water); font-weight: 600; font-size: 0.875rem; }
.method-note p { margin-top: 8px; font-size: 0.85rem; color: var(--ink-2); max-width: 80ch; }
.method-note[open] { flex-basis: 100%; }

.gaps-table td:nth-child(1) { color: var(--muted); font-variant-numeric: tabular-nums; width: 36px; }
.gaps-table td:nth-child(2) { font-weight: 600; white-space: nowrap; }
.gaps-table td:nth-child(3) { min-width: 300px; }
.gaps-table td:nth-child(4) { min-width: 170px; }
.gaps-table td:nth-child(5) { text-align: right; font-variant-numeric: tabular-nums; }
.gaps-table td:nth-child(6) { min-width: 210px; text-align: right; }
.gap-desc { line-height: 1.45; }
.gap-meta { font-size: 0.78rem; color: var(--muted); line-height: 1.5; }
.gap-meta--chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.gap-meta--chips .chip { padding: 3px 9px; font-size: 0.75rem; background: var(--surface-2); border-color: var(--line); color: var(--ink-2); }
.gap-meta--chips .chip b { font-weight: 560; }
.methodology-toggle { border: 0; background: none; padding: 3px 4px; color: var(--water); font-weight: 600; font-size: 0.78rem; }
.methodology-detail { margin-top: 10px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius); font-size: 0.8rem; color: var(--ink-2); }
.method-section + .method-section { margin-top: 6px; }
.method-label { display: block; font-weight: 650; color: var(--ink); }
.consequence-label { display: inline-block; margin-top: 4px; font-size: 0.72rem; font-weight: 650; padding: 1px 7px; border-radius: 999px; }
.consequence-label--derived { background: var(--ok-soft); color: var(--ok); }
.consequence-label--assumed { background: var(--warn-soft); color: var(--heat-1); }

.cov-status { display: flex; align-items: center; gap: 7px; font-size: 0.85rem; font-weight: 600; }
.cov-dot { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.coverage-gap { color: var(--heat-3); }
.coverage-partial { color: var(--heat-1); }
.coverage-covered { color: var(--ok); }
.cov-label { color: var(--ink); }
.cov-bar { height: 5px; margin-top: 8px; border-radius: 3px; background: var(--surface-2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.cov-bar span { display: block; height: 100%; background: currentColor; border-radius: 3px; }
.cov-sub { font-size: 0.75rem; color: var(--muted); margin-top: 4px; font-variant-numeric: tabular-nums; }

.risk-badge {
  display: inline-block; font-weight: 740; font-size: 1.35rem; line-height: 1.1; font-variant-numeric: tabular-nums;
  font-variation-settings: 'wdth' 70; letter-spacing: -0.01em;
}
.risk-critical { color: var(--heat-3); }
.risk-high { color: var(--heat-2); }
.risk-low { color: var(--heat-1); }
.priority-row { display: flex; justify-content: flex-end; align-items: center; margin-top: 8px; }
.priority-chip { padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 650; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.priority-chip--top { background: var(--heat-soft); color: var(--heat-3); border-color: transparent; }
.sim-fix-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; margin-top: 8px; }
.sim-fix-btn {
  min-height: 30px; padding: 0 10px; border-radius: var(--radius-sm); font-size: 0.8rem; font-weight: 600;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
.sim-fix-btn:hover { border-color: var(--water); color: var(--water); }
.sim-fix-btn--active { background: var(--water); border-color: var(--water); color: var(--water-ink); }
.sim-fix-btn--active:hover { color: var(--water-ink); }
.sim-delta { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.gap-row--simfixed td { background: color-mix(in srgb, var(--water-soft) 70%, transparent); }
.gap-row--simfixed .risk-badge { text-decoration: line-through; text-decoration-thickness: 2px; opacity: 0.6; }

.tiq-info {
  position: relative; display: inline-grid; place-items: center; width: 16px; height: 16px; margin-left: 5px;
  border-radius: 50%; border: 1px solid var(--line-strong); color: var(--muted);
  font-size: 10px; font-weight: 700; font-style: normal; line-height: 1; cursor: help; vertical-align: middle;
}
.tiq-info:hover, .tiq-info:focus, .tiq-info.show { color: var(--water); border-color: var(--water); outline: none; }
.tiq-info .tip {
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 60;
  width: 250px; padding: 10px 12px; border-radius: var(--radius); background: var(--ink); color: var(--paper);
  font-size: 0.78rem; font-weight: 400; line-height: 1.5; text-align: left; white-space: normal;
  display: none; pointer-events: none;
}
.tiq-info .tip b { color: inherit; font-weight: 650; }
.tiq-info--right .tip { left: auto; right: -6px; transform: none; }
.tiq-info:hover .tip, .tiq-info:focus .tip, .tiq-info.show .tip { display: block; }

/* ─── Document viewer ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 3000; display: none; place-items: center; padding: 24px;
  background: var(--overlay);
}
.modal-overlay.active { display: grid; }
.modal-content {
  width: min(1000px, 100%); height: min(86dvh, 900px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-float);
}
.modal-header { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal-header h3 { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-head-actions { display: flex; align-items: center; gap: 6px; }
.viewer-body { position: relative; flex: 1; background: var(--surface-2); }
#viewer-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-fallback { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 10px; padding: 32px; max-width: 520px; margin: 0 auto; color: var(--ink-2); }
.viewer-fallback strong { color: var(--ink); font-size: 1.1rem; }
.viewer-embed-hint { position: absolute; left: 12px; bottom: 12px; padding: 6px 10px; border-radius: var(--radius-sm); background: var(--surface); font-size: 0.8rem; color: var(--muted); }

/* ─── Upload panel & queue ────────────────────────────────────────────────── */
.upload-float {
  position: fixed; right: 24px; bottom: 24px; z-index: 2500;
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-float);
}
.upload-float-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 12px 12px 18px; border-bottom: 1px solid var(--line); cursor: grab; touch-action: none; }
.upload-float-head > div:first-child { flex: 1; min-width: 0; }
.upload-float-head p { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.upload-float-btns { display: flex; gap: 2px; }
.upload-float-body { padding: 16px 18px 18px; overflow-y: auto; display: grid; gap: 14px; }
.dest-note { font-size: 0.85rem; color: var(--ink-2); }
.dest-note--attn { padding: 10px 12px; border-radius: var(--radius); background: var(--warn-soft); color: var(--ink); }
.upload-drop-zone {
  display: grid; justify-items: center; gap: 4px; padding: 22px 16px; text-align: center;
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg); background: var(--surface-2);
  transition: border-color 0.15s, background-color 0.15s;
}
.upload-drop-zone.drag-over { border-color: var(--water); background: var(--water-soft); }
.upload-drop-zone.has-file { border-style: solid; border-color: var(--ok); background: var(--ok-soft); }
.upload-icon { width: 28px; height: 28px; color: var(--water); margin-bottom: 4px; }
.drop-text { font-weight: 600; }
.drop-link { color: var(--water); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.drop-hint { font-size: 0.8rem; color: var(--muted); }
.upload-row-2 { display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px; }
.upload-label { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--ink); }
.upload-label > .upload-input { flex: 1 1 100%; }
.required { color: var(--heat-3); }
.optional { font-weight: 400; color: var(--muted); }
.upload-input {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); font-weight: 400; font-size: 0.925rem;
}
.upload-input:focus { outline: none; border-color: var(--water); box-shadow: 0 0 0 3px var(--water-soft); }
.upload-textarea { min-height: 70px; resize: vertical; }
.upload-check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--ink-2); }
.upload-check input { width: 16px; height: 16px; accent-color: var(--water); }
.upload-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.sync-note { font-size: 0.8rem; color: var(--muted); }
.upload-status { padding: 10px 12px; border-radius: var(--radius); font-size: 0.85rem; background: var(--surface-2); }
.upload-status--error { background: var(--bad-soft); color: var(--heat-3); }
.upload-status--success { background: var(--ok-soft); color: var(--ok); }

.upload-dock {
  position: fixed; right: 24px; bottom: 24px; z-index: 2400; width: min(340px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-float);
}
.upload-dock-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--line); font-weight: 620; font-size: 0.9rem; }
.upload-dock-head > div { display: flex; }
.upload-queue { max-height: 260px; overflow-y: auto; padding: 8px 14px 12px; display: grid; gap: 10px; }
.upq-row { display: flex; justify-content: space-between; gap: 10px; font-size: 0.85rem; }
.upq-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upq-state { color: var(--muted); text-transform: capitalize; }
.upq-bar { height: 4px; margin-top: 6px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.upq-bar i { display: block; height: 100%; width: 0; background: var(--water); }
.upq-item.uploading .upq-bar i { width: 40%; animation: tq-indeterminate 1.1s infinite ease-in-out; }
.upq-item.done .upq-bar i { width: 100%; background: var(--ok); }
.upq-item.failed .upq-bar i { width: 100%; background: var(--heat-3); }
.upq-item.done .upq-state { color: var(--ok); }
.upq-item.failed .upq-state { color: var(--heat-3); }
.upq-error { margin-top: 4px; font-size: 0.78rem; color: var(--heat-3); }
@keyframes tq-indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }

/* ─── Guided tour ─────────────────────────────────────────────────────────── */
/* Ring and card stay invisible until app.js has measured the target — the
   9999px spotlight shadow would otherwise flash across the whole screen. */
.tour-ring {
  position: fixed; z-index: 4000; pointer-events: none; opacity: 0;
  border: 2px solid var(--water); border-radius: var(--radius-lg);
  box-shadow: 0 0 0 9999px var(--overlay);
  transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease, opacity 0.2s ease;
}
.tour-ring.tour-visible { opacity: 1; }
.tour-card {
  position: fixed; z-index: 4001; opacity: 0; pointer-events: none;
  padding: 16px 16px 14px; border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-float);
  transition: left 0.25s ease, top 0.25s ease, opacity 0.2s ease;
}
.tour-card.tour-visible { opacity: 1; pointer-events: auto; }
.tour-step-badge { font-size: 0.8rem; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.tour-card h4 { font-size: 1.05rem; margin: 4px 0 6px; }
.tour-card p { font-size: 0.875rem; color: var(--ink-2); margin-bottom: 14px; }
.tour-card-btns { display: flex; gap: 8px; align-items: center; }
.tour-btn { min-height: 34px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; font-size: 0.85rem; }
.tour-btn-skip { border: 0; background: none; color: var(--muted); padding-left: 0; margin-right: auto; }
.tour-btn-next { background: var(--water); border-color: var(--water); color: var(--water-ink); }

/* ─── Tablet: icon rail ───────────────────────────────────────────────────── */
@media (max-width: 1180px) {
  .readings .reading--wide { display: none; }
  .graph-shell { grid-template-columns: minmax(0, 1fr) 300px; }
}
@media (max-width: 1023px) {
  :root { --rail-w: 76px; }
  .rail { padding: 16px 10px; align-items: center; }
  .brand { padding: 4px 0 20px; }
  .brand-name, .rail-meta { display: none; }
  .rail-list .nav-item span, .rail-upload span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .rail-list .nav-item { justify-content: center; width: 48px; height: 44px; padding: 0; }
  .nav-item.active { box-shadow: inset 0 -3px 0 var(--water); }
  .rail-upload { width: 48px; height: 44px; padding: 0; }
  .overview-grid { grid-template-columns: 1fr 1fr; grid-template-areas: "gaps gaps" "ask corpus"; }
  .summary-cards { grid-template-columns: 1fr 1fr; }
  .graph-shell { grid-template-columns: 1fr; }
  .graph-canvas-wrap { min-height: 480px; height: 60dvh; }
  .graph-panel { min-height: 0; max-height: none; }
  .sidebar { width: 240px; }
}

/* ─── Phone: bottom tab bar ───────────────────────────────────────────────── */
@media (max-width: 767px) {
  :root { --topbar-h: 56px; --tabbar-h: 62px; }
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "main";
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
  }
  .rail { display: none; }
  .topbar { gap: 8px; padding: 0 8px 0 12px; }
  .brand--compact { display: flex; }
  .brand--compact .brand-mark { width: 28px; height: 28px; }
  .plant-picker { flex: 1; min-width: 0; padding-left: 10px; }
  .plant-picker-label { display: none; }
  .plant-selector { max-width: none; width: 100%; font-size: 0.925rem; }
  .readings { display: none; }
  .icon-btn { width: 40px; height: 40px; }
  body[data-view="chat"] .only-chat-mobile { display: inline-grid; }
  body[data-view="chat"] .brand--compact { display: none; }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    display: grid; grid-template-columns: repeat(5, 1fr);
    height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  .tabbar .nav-item {
    flex-direction: column; justify-content: center; gap: 3px; padding: 6px 2px; border-radius: 0;
    font-size: 0.72rem; font-weight: 560; color: var(--muted);
  }
  .tabbar .nav-item svg { width: 22px; height: 22px; }
  .tabbar .nav-item:hover { background: none; }
  .tabbar .nav-item.active { background: none; box-shadow: none; color: var(--water); }

  .page { padding: 20px 16px 32px; }
  h1, .view-head h1 { font-size: 1.5rem; }
  .view-head--row { align-items: flex-start; flex-direction: column; }
  .panel, .table-card { padding: 16px; border-radius: var(--radius); }
  .table-scroll { margin: 0 -16px; padding: 0 16px; }

  .exposure { padding: 4px 0 20px; }
  .heatstrip { height: 36px; margin-top: 20px; gap: 2px; }
  .heat-seg .seg-tip { display: none; }
  .overview-grid { grid-template-columns: 1fr; grid-template-areas: "gaps" "ask" "corpus"; gap: 12px; }
  .outages { margin-top: 12px; }
  .outage-feed .tick-item { grid-template-columns: minmax(0, 1fr) auto; }
  .outage-feed .tick-item .tick-equip { grid-column: 1; color: var(--muted); font-size: 0.85rem; }
  .outage-feed .tick-item .tick-date { grid-column: 2; grid-row: 2; text-align: right; font-size: 0.85rem; }
  .outage-feed .tick-item .tick-loss { grid-column: 2; grid-row: 1; text-align: right; }

  .summary-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .summary-label { font-size: 0.78rem; line-height: 1.3; }
  #docs-needed-section .table-scroll { overflow: visible; margin: 0; padding: 0; }
  #docs-needed-section thead { display: none; }
  #docs-needed-section table, #docs-needed-section tbody { display: block; }
  #docs-needed-section tr { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
  #docs-needed-section tr:last-child { border-bottom: 0; }
  #docs-needed-section td { display: block; padding: 0; border: 0; }
  #docs-needed-section td:nth-child(1) { font-weight: 650; }
  #docs-needed-section td:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  #docs-needed-section td:nth-child(3) { grid-column: 2; grid-row: 1; }
  #docs-needed-section td:nth-child(4) { grid-column: 1 / -1; }
  #docs-needed-section td:nth-child(4) .btn-sheet-csv { width: 100%; justify-content: center; }
  .summary-card { padding: 12px 14px; }
  .summary-card--hero { grid-column: 1 / -1; }
  .summary-value { font-size: 1.75rem; }
  .summary-card--hero .summary-value { font-size: 2.4rem; }
  .live-actions { width: 100%; }
  .live-actions .btn { flex: 1; }

  /* Gap table becomes a stack of cards */
  .table-scroll--cards { overflow: visible; margin: 0; padding: 0; }
  .gaps-table thead { display: none; }
  .gaps-table, .gaps-table tbody { display: block; }
  .gaps-table tr.gap-row {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 10px;
    padding: 14px 0; border-bottom: 1px solid var(--line);
  }
  .gaps-table tr.gap-row:last-child { border-bottom: 0; }
  .gaps-table tr.gap-row td { display: block; padding: 0; border: 0; min-width: 0; width: auto; text-align: left; }
  .gaps-table tr.gap-row td:nth-child(1) { grid-column: 1; grid-row: 1; }
  .gaps-table tr.gap-row td:nth-child(2) { grid-column: 2; grid-row: 1; white-space: normal; }
  .gaps-table tr.gap-row td:nth-child(6) { grid-column: 1 / -1; grid-row: 4; text-align: left; min-width: 0; }
  .gaps-table tr.gap-row td:nth-child(5) { grid-column: 3; grid-row: 1; color: var(--muted); font-size: 0.8rem; }
  .gaps-table tr.gap-row td:nth-child(5)::after { content: ' outages'; }
  .gaps-table tr.gap-row td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  .gaps-table tr.gap-row td:nth-child(4) { grid-column: 1 / -1; grid-row: 3; margin-top: 6px; }
  .gaps-table tr.gap-row .priority-row, .gaps-table tr.gap-row .sim-fix-wrap { justify-content: flex-start; align-items: flex-start; }
  .gaps-table tr.gap-row .sim-fix-wrap { flex-direction: row; align-items: center; gap: 10px; }
  .gaps-table tr.gap-row td:nth-child(6) { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; margin-top: 8px; }
  .gaps-table tr.gap-row td:nth-child(6) .gap-meta { grid-column: 2; margin: 0 !important; }
  .gaps-table tr.gap-row td:nth-child(6) .priority-row,
  .gaps-table tr.gap-row td:nth-child(6) .sim-fix-wrap { grid-column: 1 / -1; margin-top: 4px; }
  .gaps-table tr.gap-row td:nth-child(6) .priority-row { justify-content: flex-start; }
  .sim-fix-btn { min-height: 36px; }
  .tiq-info .tip { width: min(250px, 70vw); }

  /* Copilot fills the space between the top bar and the tab bar */
  .app-layout.active { height: calc(100dvh - var(--topbar-h) - var(--tabbar-h) - var(--safe-b)); grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 1200; width: min(86vw, 320px) !important;
    transform: translateX(-102%); transition: transform 0.22s ease, visibility 0.22s; visibility: hidden;
    padding-top: env(safe-area-inset-top, 0px);
  }
  .sidebar.open { transform: none; visibility: visible; box-shadow: var(--shadow-float); }
  .app-layout.sidebar-collapsed .sidebar { width: min(86vw, 320px) !important; min-width: 0; }
  .app-layout.sidebar-collapsed .sidebar-header { flex-direction: row; padding: 12px 12px 8px; }
  .app-layout.sidebar-collapsed .sidebar-header h2,
  .app-layout.sidebar-collapsed .chat-list { display: block; }
  .app-layout.sidebar-collapsed .btn-new-chat span { display: inline; }
  .app-layout.sidebar-collapsed .btn-new-chat { width: auto; padding: 0 12px; }
  .sidebar-collapse-btn { display: none; }
  .sidebar-resizer { display: none !important; }
  .sidebar-overlay.visible { display: block; position: fixed; inset: 0; z-index: 1100; background: var(--overlay); }
  .chat-item-delete { opacity: 1; }
  .chat-messages { padding: 20px 14px 16px; gap: 16px; }
  .chat-input-area { padding: 8px 10px 10px; }
  .chat-input-area .chip-row { flex-wrap: nowrap; overflow-x: auto; margin: 0 -10px 8px; padding: 0 10px; scrollbar-width: none; }
  .chat-input-area .chip-row::-webkit-scrollbar { display: none; }
  .chat-input-area .chip { white-space: nowrap; flex-shrink: 0; }
  .input-hint { display: none; }
  #chat-input { font-size: 16px; }
  .user-bubble { max-width: 90%; }
  .scroll-bottom-btn { right: 14px; bottom: 96px; }

  .graph-canvas-wrap { min-height: 380px; height: 58dvh; }
  .graph-legend { gap: 6px 14px; font-size: 0.8rem; }

  .doc-grid { grid-template-columns: 1fr; }
  .modal-overlay { padding: 0; align-items: end; }
  .modal-content { height: 92dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }

  /* Upload panel and queue become bottom sheets above the tab bar */
  .upload-float {
    left: 0 !important; right: 0 !important; top: auto !important; bottom: 0 !important; width: 100%;
    max-height: 92dvh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; z-index: 2600;
    padding-bottom: var(--safe-b);
  }
  .upload-float-head { cursor: default; }
  .upload-row-2 { grid-template-columns: 1fr; }
  .upload-input { font-size: 16px; }
  .upload-dock { right: 8px; left: 8px; width: auto; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); }
  .tour-card { max-width: calc(100vw - 24px); }
}

@media (max-width: 380px) {
  .summary-cards { grid-template-columns: 1fr; }
  .corpus-stats dd { font-size: 1.35rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media print {
  .rail, .topbar, .tabbar, .upload-float, .upload-dock { display: none !important; }
  body { display: block; background: #fff; }
}
