:root {
  --bg: #0b0f1a;
  --bg-2: #121826;
  --bg-3: #1a2233;
  --line: #263149;
  --text: #e6ebf5;
  --muted: #8b96ad;
  --accent: #6ea8fe;
  --accent-2: #7ee0c0;
  --warn: #f5b971;
  --danger: #f28b82;
  --user: #23406b;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: radial-gradient(circle at 30% 30%, var(--accent), #3f6fd1);
  border-radius: 10px; color: #06122b; font-weight: 800;
}
.title { font-weight: 700; }
.subtitle { color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 6px; }

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); }
button.ghost { background: var(--bg-3); color: var(--text); padding: 7px 10px; }
button.ghost:hover { border-color: var(--accent); }
button.ghost.on { color: var(--warn); border-color: var(--warn); }
button.ghost.wide { width: 100%; margin-top: 10px; }

/* Layout — the side panel is toggled by the ☰ button (JS opens it by default on desktop). */
.layout { flex: 1; display: grid; grid-template-columns: 1fr; min-height: 0; }
#app.panel-open .layout { grid-template-columns: 1fr 320px; }
.chat { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }

/* Messages */
.msg { max-width: 82%; padding: 10px 13px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .meta { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }

.chip {
  font-size: 12px; color: var(--muted); background: var(--bg-3);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; align-self: flex-start;
}
.chip.done { color: var(--accent-2); }
.chip.approval { color: var(--warn); border-color: var(--warn); }
.chip.error { color: var(--danger); border-color: var(--danger); }

details.thinking { color: var(--muted); font-size: 13px; }
details.thinking summary { cursor: pointer; }
details.thinking .body { margin-top: 6px; padding-left: 10px; border-left: 2px solid var(--line); white-space: pre-wrap; }

.empty { color: var(--muted); text-align: center; margin: auto; padding: 24px; }

/* Composer */
.composer { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--bg-2);
  padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 11px 12px; border-radius: 12px;
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line); font: inherit;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.composer button { background: var(--accent); color: #06122b; font-weight: 700; padding: 0 18px; border: none; }
.composer button:disabled { opacity: 0.5; cursor: default; }

/* Panel */
.panel { overflow-y: auto; padding: 16px; background: var(--bg); display: none; }
#app.panel-open .panel { display: block; }
.panel-section { margin-bottom: 20px; }
.panel-section h3 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.connectors, .tasks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.connectors li, .tasks li { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.dot.ready { background: var(--accent-2); }
.dot.not_configured { background: var(--muted); }
.dot.error { background: var(--danger); }
.cname { font-weight: 600; }
.cdesc { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tasks .due { color: var(--warn); font-size: 12px; }
.connectors a { color: var(--accent); text-decoration: none; }
.connectors a.connect { font-weight: 600; }
.connectors a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Settings dialog */
dialog { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 18px; max-width: 420px; width: 92%; }
dialog::backdrop { background: rgba(0,0,0,0.5); }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.settings input { padding: 9px; border-radius: 8px; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); }
.settings textarea { padding: 9px; border-radius: 8px; background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font: inherit; resize: vertical; }
.settings textarea:focus, .settings input:focus { outline: none; border-color: var(--accent); }
#prefsSection, #connectorsSection { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.prefs-title { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.prefs-fields { display: flex; flex-direction: column; gap: 14px; }
.prefs-fields label { font-size: 13px; font-weight: 600; }
.prefs-desc { font-weight: 400; color: var(--muted); font-size: 12px; }
.pref-src { font-weight: 400; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
#prefsMsg { margin: 8px 0 0; }
#prefsMsg.ok { color: var(--accent-2); }
#prefsMsg.err { color: var(--danger); }
.settings menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 14px 0 0; }
.settings button[value="save"] { background: var(--accent); color: #06122b; border: none; padding: 8px 14px; font-weight: 700; }
code { background: var(--bg-3); padding: 1px 5px; border-radius: 5px; }

/* Responsive: stack the panel under the chat on phones */
@media (max-width: 820px) {
  /* On mobile the open panel overlays the chat as a drawer, not a reserved column. */
  #app.panel-open .layout { grid-template-columns: 1fr; }
  #app.panel-open .panel { position: fixed; inset: 56px 0 0 0; z-index: 20; }
  .chat { border-right: none; }
  .msg { max-width: 90%; }
}

/* ── Command Center dashboard ─────────────────────────────────────────────── */
button.ghost.accent { color: var(--accent); border-color: var(--accent); font-weight: 600; }
button.ghost.accent:hover { background: var(--accent); color: #06122b; }

#app.dash-open .layout { display: none; }
.dashboard { flex: 1; min-height: 0; overflow-y: auto; background: var(--bg);
  padding: 16px 18px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.dashboard[hidden] { display: none; }
.dash-inner { max-width: 1100px; margin: 0 auto; }

.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  max-width: 1100px; margin: 0 auto 14px; }
.dash-head h2 { margin: 0; font-size: 20px; letter-spacing: -0.01em; }
.dash-actions { display: flex; gap: 6px; flex: none; }

.attention { max-width: 1100px; margin: 0 auto 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--bg-2); }
.att-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.att-chip.info { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.att-chip.info::before { background: var(--accent); }
.att-chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.att-chip.warn::before { background: var(--warn); }
.att-chip.critical { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, var(--line)); }
.att-chip.critical::before { background: var(--danger); }
.attention .allclear { color: var(--accent-2); font-size: 13px; padding: 7px 2px; }

.quick-add { max-width: 1100px; margin: 0 auto 14px; display: flex; gap: 8px; }
.quick-add input#qaTitle { flex: 1; min-width: 0; }
.quick-add input { padding: 9px 11px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line); color: var(--text); font: inherit; }
.quick-add input:focus { outline: none; border-color: var(--accent); }
.quick-add input[type="date"] { color: var(--muted); flex: none; }
.quick-add button { flex: none; }

.dash-grid { max-width: 1100px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; align-items: start; }
.dcard { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.dcard-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.dcard-head .ico { font-size: 15px; }
.dcard-head h3 { margin: 0; font-size: 14px; font-weight: 700; flex: 1; }
.dcard-head .count { font-size: 12px; font-weight: 700; color: var(--bg); background: var(--muted);
  border-radius: 999px; padding: 1px 8px; min-width: 20px; text-align: center; }
.dcard-head .count.hot { background: var(--warn); }
.dcard-head .count.crit { background: var(--danger); }
.dcard-body { padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 2px; }

.drow { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.dcard-body .drow:first-child { border-top: none; }
.drow .when { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; flex: none; min-width: 52px; }
.drow .main { flex: 1; min-width: 0; }
.drow .main .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow .sub { color: var(--muted); font-size: 12px; }
.drow .badge { font-size: 11px; color: var(--muted); background: var(--bg-3); border-radius: 6px; padding: 1px 6px; flex: none; }
.drow.od .when { color: var(--danger); }
.drow.imp .t { font-weight: 600; }
.drow.read .t { color: var(--muted); font-weight: 400; }
.drow.read .imp-dot { box-shadow: none; opacity: 0.6; }
.drow .badge.new { color: var(--accent-2); border: 1px solid color-mix(in srgb, var(--accent-2) 45%, var(--line)); background: color-mix(in srgb, var(--accent-2) 12%, var(--bg-3)); }
.drow .badge.urgent { color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 50%, var(--line)); background: color-mix(in srgb, var(--danger) 14%, var(--bg-3)); font-variant-numeric: tabular-nums; }
.dcard-body a.t { color: inherit; text-decoration: none; }
.dcard-body a.t:hover { color: var(--accent); text-decoration: underline; }
.imp-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--danger);
  margin-right: 7px; vertical-align: middle; box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
.dcard-empty { color: var(--muted); font-size: 13px; padding: 10px 0 6px; }
.dgroup { color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; padding: 9px 0 2px; }
.dgroup:first-child { padding-top: 2px; }
.trow-acts { display: inline-flex; gap: 4px; flex: none; opacity: 0; transition: opacity 0.12s; }
.drow:hover .trow-acts { opacity: 1; }
.trow-act { background: var(--bg-3); border: 1px solid var(--line); color: var(--muted); border-radius: 7px;
  width: 24px; height: 24px; line-height: 1; padding: 0; font-size: 12px; }
.trow-act:hover { color: var(--text); border-color: var(--accent); }
.trow-act:disabled { opacity: 0.4; cursor: default; }
@media (hover: none) { .trow-acts { opacity: 1; } }

.dgroup-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 8px 0 2px; }
.dgroup-label:first-child { margin-top: 2px; }

/* Daily Focus card */
.dcard-head .count.good { background: var(--accent-2); }
.focus-row { align-items: center; }
.focus-check { background: none; border: none; padding: 0; margin: 0; font-size: 15px; line-height: 1; cursor: pointer; flex: none; }
.focus-check:disabled { opacity: 0.5; cursor: default; }
.focus-row.done .t { text-decoration: line-through; color: var(--muted); }
.focus-set { padding: 8px 0 2px; }
.dbtn { background: var(--bg-3); border: 1px solid var(--line); color: var(--text); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; cursor: pointer; }
.dbtn:hover { border-color: var(--accent); }

.fin-net { display: flex; align-items: baseline; justify-content: space-between; padding: 8px 0 10px; border-bottom: 1px solid var(--line); }
.fin-net .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.fin-net .val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fin-amt { font-variant-numeric: tabular-nums; color: var(--muted); flex: none; }
.fin-amt.neg { color: var(--danger); }
.grade-val { font-weight: 700; font-variant-numeric: tabular-nums; flex: none; color: var(--text); }
.grade-val.good { color: var(--accent-2); }
.grade-val.warn { color: var(--warn); }
.grade-val.crit { color: var(--danger); }

/* ── Heart-rate graph card ── */
.hr-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 2px 0 8px; }
.hr-now { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--danger); line-height: 1; }
.hr-now small { font-size: 12px; font-weight: 400; color: var(--muted); }
.hr-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hr-chart { width: 100%; height: 96px; display: block; overflow: visible; }
.hr-line { fill: none; stroke: var(--danger); stroke-width: 1.6; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.hr-area { fill: color-mix(in srgb, var(--danger) 16%, transparent); stroke: none; }
.hr-dot { fill: var(--danger); stroke: var(--bg-2); stroke-width: 1.5; }

/* ── Interactive Budget ── */
#app.budget-open .layout { display: none; }
.budget { flex: 1; min-height: 0; overflow-y: auto; background: var(--bg);
  padding: 16px 18px 40px; padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.budget[hidden] { display: none; }

.budget-summary { display: flex; flex-wrap: wrap; align-items: stretch; gap: 10px;
  max-width: 900px; margin: 0 auto 18px; }
.bsum-item { flex: 1 1 0; min-width: 90px; display: flex; flex-direction: column; gap: 2px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.bsum-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.bsum-val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.bsum-item.pos .bsum-val { color: var(--accent-2); }
.bsum-item.neg .bsum-val { color: var(--danger); }
.bsum-item.rate .bsum-val { color: var(--accent); }
.bsum-op { display: flex; align-items: center; font-size: 22px; color: var(--muted); flex: none; }

.budget-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; max-width: 900px; margin: 0 auto; }
.budget-col { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.budget-col-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.budget-col-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.budget-col-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.budget-rows { display: flex; flex-direction: column; gap: 8px; }
.budget-empty { padding: 6px 2px; }

.budget-row { display: flex; align-items: center; gap: 8px; }
.brow-name { flex: 1 1 auto; min-width: 0; padding: 8px 10px; border-radius: 9px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font: inherit; }
.brow-amtwrap { position: relative; flex: 0 0 108px; display: flex; align-items: center; }
.brow-cur { position: absolute; left: 9px; color: var(--muted); pointer-events: none; }
.brow-amt { width: 100%; padding: 8px 10px 8px 18px; border-radius: 9px; text-align: right;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font: inherit; font-variant-numeric: tabular-nums; }
.brow-name:focus, .brow-amt:focus { outline: none; border-color: var(--accent); }
.brow-actual { flex: none; font-size: 11px; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.brow-actual.over { color: var(--danger); }
.brow-actual.under { color: var(--accent-2); }
.brow-del { flex: none; padding: 6px 9px; color: var(--muted); }
.brow-del:hover { color: var(--danger); border-color: var(--danger); }

.budget-add { display: flex; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.badd-name { flex: 1 1 auto; min-width: 0; padding: 8px 10px; border-radius: 9px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font: inherit; }
.badd-amt { flex: 0 0 96px; padding: 8px 10px; border-radius: 9px; text-align: right;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text); font: inherit; font-variant-numeric: tabular-nums; }
.badd-name:focus, .badd-amt:focus { outline: none; border-color: var(--accent); }
.budget-add button { flex: none; padding: 0 14px; font-weight: 700; }
.budget-actual-note { max-width: 900px; margin: 16px auto 0; }

@media (max-width: 820px) {
  .dash-grid { grid-template-columns: 1fr; }
  button.ghost.accent { padding: 7px 10px; }
  .budget-cols { grid-template-columns: 1fr; }
  .bsum-op { display: none; }
}
@media (max-width: 460px) {
  .btxt { display: none; }
}
