:root {
  --ink: #191D21;
  --paper: #F5F1E6;
  --paper-raised: #FFFFFF;
  --paper-sunken: #EDE7D8;
  --line: rgba(25,29,33,0.12);
  --line-strong: rgba(25,29,33,0.22);
  --text-muted: #6B655A;
  --accent: #2F6659;
  --accent-strong: #234E43;
  --accent-soft: rgba(47,102,89,0.12);
  --signal-high: #B8862F;
  --signal-high-soft: rgba(184,134,47,0.14);
  --signal-critical: #B5482F;
  --signal-critical-soft: rgba(181,72,47,0.13);
  --shadow: 0 1px 2px rgba(25,29,33,0.06), 0 6px 20px rgba(25,29,33,0.06);
  --font-display: 'Iowan Old Style','Palatino Linotype',Palatino,Georgia,serif;
  --font-body: -apple-system,BlinkMacSystemFont,'Segoe UI',Helvetica,Arial,sans-serif;
  --font-mono: ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;
  --header-h: 72px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #ECE7D9; --paper: #14171A; --paper-raised: #1B1F22; --paper-sunken: #101214;
    --line: rgba(236,231,217,0.12); --line-strong: rgba(236,231,217,0.22); --text-muted: #9C9585;
    --accent: #4C9484; --accent-strong: #6BB0A0; --accent-soft: rgba(76,148,132,0.16);
    --signal-high: #D9A54A; --signal-high-soft: rgba(217,165,74,0.16);
    --signal-critical: #D4694A; --signal-critical-soft: rgba(212,105,74,0.16);
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
  }
}
:root[data-theme="dark"] {
  --ink: #ECE7D9; --paper: #14171A; --paper-raised: #1B1F22; --paper-sunken: #101214;
  --line: rgba(236,231,217,0.12); --line-strong: rgba(236,231,217,0.22); --text-muted: #9C9585;
  --accent: #4C9484; --accent-strong: #6BB0A0; --accent-soft: rgba(76,148,132,0.16);
  --signal-high: #D9A54A; --signal-high-soft: rgba(217,165,74,0.16);
  --signal-critical: #D4694A; --signal-critical-soft: rgba(212,105,74,0.16);
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --ink: #191D21; --paper: #F5F1E6; --paper-raised: #FFFFFF; --paper-sunken: #EDE7D8;
  --line: rgba(25,29,33,0.12); --line-strong: rgba(25,29,33,0.22); --text-muted: #6B655A;
  --accent: #2F6659; --accent-strong: #234E43; --accent-soft: rgba(47,102,89,0.12);
  --signal-high: #B8862F; --signal-high-soft: rgba(184,134,47,0.14);
  --signal-critical: #B5482F; --signal-critical-soft: rgba(181,72,47,0.13);
  --shadow: 0 1px 2px rgba(25,29,33,0.06), 0 6px 20px rgba(25,29,33,0.06);
}

* { box-sizing: border-box; min-width: 0; }
html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a, button { font: inherit; color: inherit; }

/* The `hidden` attribute has the same cascade specificity as a class
   selector — .login-screen{display:flex} (and any future `display` rule
   on a hideable element) silently wins and the element stays visible.
   Force it explicit so toggling `.hidden` in JS is actually reliable. */
[hidden] { display: none !important; }
input, textarea { font: inherit; color: inherit; }

/* ── Login screen ─────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.login-brand img { width: 44px; height: 44px; border-radius: 12px; object-fit: cover; }
.login-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 20px; }
.login-card h1 { font-family: var(--font-display); font-size: 22px; margin: 0 0 6px; font-weight: 600; }
.login-card .sub { color: var(--text-muted); font-size: 13.5px; margin: 0 0 22px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--paper); color: var(--ink); font-size: 14px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.login-error {
  background: var(--signal-critical-soft); color: var(--signal-critical);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; margin-bottom: 14px; display: none;
}
.login-error.visible { display: block; }
.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--text-muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.btn-google {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 10px; border: 1px solid var(--line-strong); border-radius: 8px;
  background: var(--paper-raised); cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn-google:hover { background: var(--accent-soft); }
.btn-google img { width: 18px; height: 18px; }
.login-toggle { text-align: center; margin-top: 18px; font-size: 13px; color: var(--text-muted); }
.login-toggle a { color: var(--accent-strong); font-weight: 600; cursor: pointer; text-decoration: underline; }

/* ── Top header (full width) ─────────────────────────── */
.appheader {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 0 clamp(16px, 3vw, 32px);
  background: var(--paper-sunken);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 80;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand .mark {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 12px; overflow: hidden;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.brand .mark img { width: 100%; height: 100%; object-fit: cover; }
.wordmark {
  font-family: var(--font-display); font-weight: 700;
  font-size: clamp(18px, 2.2vw, 22px);
  letter-spacing: .01em;
  white-space: nowrap;
}
.wordmark small {
  display: block; font-family: var(--font-body); font-weight: 500;
  font-size: 11px; color: var(--text-muted); letter-spacing: .02em;
}
.headmeta { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.persona-pill {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 600;
  background: var(--paper-raised); border: 1px solid var(--line);
  padding: 5px 13px 5px 5px; border-radius: 999px;
  white-space: nowrap; cursor: pointer;
}
.avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-strong);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 11.5px; font-weight: 700;
  flex-shrink: 0;
}
.live {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted);
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
}
.live-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent); display: inline-block;
  box-shadow: 0 0 0 3px var(--accent-soft); flex-shrink: 0;
}
.theme-toggle {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--paper-raised);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
  transition: background .15s ease, border-color .15s ease;
}
.theme-toggle:hover { background: var(--accent-soft); border-color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }

/* ── App shell ────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 92px 1fr;
  min-height: calc(100vh - var(--header-h));
}

/* ── Rail ─────────────────────────────────────────────── */
.rail {
  background: var(--paper-sunken);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
  gap: 6px;
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
}
.rail-btn {
  width: 62px; height: 62px;
  border: none;
  background: transparent;
  border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 5px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background .15s ease, color .15s ease;
}
.rail-btn svg { width: 24px; height: 24px; }
.rail-btn span { font-size: 10px; letter-spacing: .03em; font-weight: 600; }
.rail-btn:hover { background: var(--line); color: var(--ink); }
.rail-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.rail-btn[aria-current="page"] { background: var(--accent-soft); color: var(--accent-strong); }

/* ── Main ─────────────────────────────────────────────── */
main {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 34px clamp(20px, 3.6vw, 48px) 64px;
}
.topbar {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 30px; flex-wrap: wrap; gap: 10px;
}
.topbar h1 {
  font-family: var(--font-display);
  font-size: clamp(27px, 3.4vw, 38px);
  margin: 0;
  text-wrap: balance;
  font-weight: 600;
}
.topbar .meta {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}

.view { display: none; }
.view.active { display: block; animation: rise .32s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px);} to { opacity: 1; transform: none; } }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.empty-note { color: var(--text-muted); font-size: 13.5px; font-style: italic; padding: 8px 0; }
.spinner-note { color: var(--text-muted); font-size: 13px; font-family: var(--font-mono); padding: 8px 0; }

/* ── Cards / grid (Control Center) ───────────────────── */
.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 18px; }
.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.col-7 { grid-column: span 7; }
.col-5 { grid-column: span 5; }
.col-12 { grid-column: span 12; }
@media (max-width: 900px) { .col-7, .col-5 { grid-column: span 12; } }

.priority-row, .list-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.priority-row:last-child, .list-row:last-child { border-bottom: none; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.priority-row .t { flex: 1 1 160px; min-width: 0; }
.priority-row .t .title { font-weight: 600; }
.priority-row .t .sub { color: var(--text-muted); font-size: 13px; }
.priority-row time { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.insight {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14.5px;
  line-height: 1.55;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.insight:last-child { border-bottom: none; }

.btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }

.reminder-row time { color: var(--signal-high); font-weight: 700; }

/* ── Chips ────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: .03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.chip[data-tier="high"] { background: var(--signal-high-soft); color: var(--signal-high); }
.chip[data-tier="medium"] { background: transparent; border: 1px solid var(--signal-high); color: var(--signal-high); }
.chip[data-tier="low"] { background: transparent; border: 1px solid var(--line-strong); color: var(--text-muted); }
.chip[data-tier="critical"] { background: var(--signal-critical-soft); color: var(--signal-critical); }
.chip::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

/* ── Chat view ────────────────────────────────────────── */
.transcript { display: flex; flex-direction: column; gap: 14px; max-width: min(640px, 100%); }
.turn { display: flex; flex-direction: column; gap: 6px; }
.turn.user { align-items: flex-end; }
.turn.ai { align-items: flex-start; }
.bubble {
  padding: 11px 15px;
  border-radius: 14px;
  max-width: min(480px, 88%);
  font-size: 14.5px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.turn.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.turn.ai .bubble { background: var(--paper-raised); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.turn .annot { display: flex; align-items: center; gap: 8px; padding: 0 3px; }

.chat-composer {
  display: flex; gap: 10px; margin-top: 20px; max-width: min(640px, 100%);
  position: sticky; bottom: 20px;
}
.chat-composer input {
  flex: 1; padding: 12px 16px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--paper-raised);
  font-size: 14px;
}
.chat-composer input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.chat-composer button { border-radius: 999px; padding: 10px 20px; }

/* ── Split layout: main column + sticky side panel ───── */
.view-split { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 32px; align-items: start; }
@media (max-width: 980px) { .view-split { grid-template-columns: 1fr; } }
.side-panel { display: flex; flex-direction: column; gap: 16px; position: sticky; top: calc(var(--header-h) + 34px); }
@media (max-width: 980px) { .side-panel { position: static; } }
.side-panel .card h6 { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 0 0 12px; }
.side-list { display: flex; flex-direction: column; gap: 10px; }
.side-item { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 13px; }
.side-item .k { flex: 1; min-width: 0; }
.side-item .v { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.conn-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: 13px; padding: 6px 0; }
.conn-status { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.conn-status.on { color: var(--accent-strong); }
.conn-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Knowledge Hub ────────────────────────────────────── */
.k-card { display: flex; flex-direction: column; gap: 8px; }
.k-card .k-top { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.k-card h4 { font-family: var(--font-display); font-size: 16.5px; margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.k-card time { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 11.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--text-muted); }
.tag.none { font-style: italic; border-style: dashed; }
.stack { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }

/* ── Tasks ────────────────────────────────────────────── */
.task-composer { display: flex; gap: 10px; margin-bottom: 24px; }
.task-composer input {
  flex: 1; padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--paper-raised); font-size: 14px;
}
.task-composer input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.task-group { margin-bottom: 24px; }
.task-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.task-row:last-child { border-bottom: none; }
.task-status {
  width: 17px; height: 17px; border-radius: 5px; border: 1.5px solid var(--line-strong);
  flex-shrink: 0; cursor: pointer; background: transparent;
}
.task-status.done { background: var(--accent); border-color: var(--accent); }
.task-row .t { flex: 1 1 200px; min-width: 0; }
.task-row .title { font-weight: 600; }
.task-row .src { color: var(--text-muted); font-size: 12px; }
.task-row .due { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); white-space: nowrap; margin-left: auto; }

/* ── Decision Assistant ───────────────────────────────── */
.decision-composer { display: flex; gap: 10px; margin-bottom: 28px; max-width: min(660px, 100%); }
.decision-composer input {
  flex: 1; padding: 12px 16px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: var(--paper-raised); font-size: 14px;
}
.decision-composer input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.decision-doc { max-width: min(660px, 100%); }
.decision-doc h2 {
  font-family: var(--font-display); font-size: clamp(21px, 2.6vw, 25px); font-weight: 600;
  margin: 0 0 4px; text-wrap: balance;
}
.decision-doc .understanding { color: var(--text-muted); margin-bottom: 22px; font-size: 14.5px; }
.ctx-list, .pcr-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.ctx-list li { padding-left: 16px; position: relative; font-size: 14px; }
.ctx-list li::before { content: '–'; position: absolute; left: 0; color: var(--text-muted); }
.pcr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 18px 0; }
@media (max-width: 640px) { .pcr-grid { grid-template-columns: 1fr; } }
.pcr-grid h5 { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; margin: 0 0 8px; color: var(--text-muted); }
.risk h5 { color: var(--signal-critical); }
.pcr-list li { font-size: 13.5px; padding-left: 14px; position: relative; }
.pcr-list li::before { content: '·'; position: absolute; left: 0; font-weight: 700; }
.recommendation {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 16px 18px;
  margin: 20px 0 10px;
}
.recommendation .eyebrow { color: var(--accent-strong); margin-bottom: 8px; }
.recommendation p { margin: 0; font-size: 14.5px; }
.reasoning-note { font-size: 12.5px; color: var(--text-muted); font-style: italic; margin-top: 22px; }

footer.credit {
  max-width: 1480px; margin: 0 auto; padding: 0 clamp(20px, 3.6vw, 48px) 34px;
  font-family: var(--font-mono); font-size: 11px; color: var(--text-muted);
}

/* ── Tablet ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 80px 1fr; }
  .rail-btn { width: 54px; height: 54px; }
  .rail-btn svg { width: 21px; height: 21px; }
}

/* ── Mobile: rail becomes a bottom tab bar ───────────── */
@media (max-width: 680px) {
  .appheader { padding: 0 14px; }
  .brand .mark { width: 36px; height: 36px; border-radius: 10px; }
  .wordmark small { display: none; }
  .persona-pill { padding: 4px 11px 4px 4px; font-size: 12px; }
  .live { display: none; }

  .app { grid-template-columns: 1fr; min-height: 0; }
  .rail {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0;
    height: auto; width: 100%;
    flex-direction: row; justify-content: space-around; align-items: center;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--line);
    z-index: 90;
  }
  .rail-btn { width: auto; flex: 1 1 0; height: 56px; border-radius: 12px; }
  main { padding: 24px 18px 100px; }
  .topbar { margin-bottom: 22px; }
  .card { padding: 17px 18px; }
  .task-row .due { margin-left: 0; }
}
