:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #ffffff; --ink-2: #c3c2b7;
    --muted: #898781; --hairline: #2c2c2a; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5;
    --good-text: #0ca30c; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #ffffff; --ink-2: #c3c2b7;
  --muted: #898781; --hairline: #2c2c2a; --border: rgba(255, 255, 255, 0.10); --accent: #3987e5;
  --good-text: #0ca30c; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 15px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -0.01em; }
.icon-btn {
  border: 0; background: transparent; width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 20px; height: 20px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; }

/* Bottom navigation */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--hairline);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 500;
}
.nav a svg { width: 22px; height: 22px; }
.nav a.active { color: var(--accent); }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 21;
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgba(42, 120, 214, 0.35);
  display: grid; place-items: center;
}
.fab svg { width: 26px; height: 26px; }

/* Cards & layout */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.card h2 { font-size: 13px; font-weight: 600; margin: 0 0 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; display: flex; align-items: center; gap: 8px; }
.card h2 .spacer { flex: 1; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (max-width: 420px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :last-child { grid-column: span 2; } }

.stat { background: var(--surface-2); border-radius: 12px; padding: 12px; min-width: 0; }
.stat .label { font-size: 12px; color: var(--ink-2); }
.stat .value { font-size: 18px; font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.stat .sub { font-size: 12px; color: var(--muted); }

.hero { text-align: left; }
.hero .label { color: var(--ink-2); font-size: 13px; }
.hero .big { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0; }
.hero .big.neg { color: var(--critical); }
.hero .sub { color: var(--ink-2); font-size: 13px; }
.breakdown { margin-top: 14px; border-top: 1px solid var(--hairline); padding-top: 10px; font-size: 13px; }
.breakdown .row { display: flex; justify-content: space-between; padding: 3px 0; color: var(--ink-2); }
.breakdown .row.total { color: var(--ink); font-weight: 600; border-top: 1px solid var(--hairline); margin-top: 4px; padding-top: 7px; }

.month-switch { display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 12px; }
.month-switch strong { min-width: 150px; text-align: center; font-size: 15px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--hairline); }
.list li:last-child { border-bottom: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { font-size: 12px; color: var(--muted); }
.list .amt { font-weight: 600; white-space: nowrap; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { background: var(--surface-2); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.amt.in { color: var(--good-text); }
.day-head { font-size: 12px; color: var(--muted); font-weight: 600; padding: 12px 0 2px; text-transform: uppercase; letter-spacing: 0.04em; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.badge.critical { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); }
.badge.warning { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--ink); }
.badge.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good-text); }

/* Alerts: status color always paired with an icon and text */
.alerts { border-left: 4px solid var(--accent); }
.alerts.critical { border-left-color: var(--critical); }
.alerts.warning { border-left-color: var(--warning); }
.alert { align-items: flex-start !important; }
.alert-icon {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff; background: var(--muted); margin-top: 2px;
}
.alert.critical .alert-icon { background: var(--critical); }
.alert.warning .alert-icon { background: var(--warning); color: #0b0b0b; }
.alert.info .alert-icon { background: var(--accent); }

.alert.good .alert-icon { background: var(--good); }

.journey-top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.journey .big-num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.journey .streak { text-align: right; }
.journey .streak .big-num { color: var(--good-text); }

.banner { display: flex; gap: 10px; align-items: center; text-decoration: none; color: var(--ink); border-left: 4px solid var(--accent); font-size: 14px; }

.quick { display: flex; gap: 8px; }
.quick .input { flex: 1; }
.quick-wrap { background: var(--surface-2); border-radius: 12px; padding: 10px; margin-bottom: 14px; }
.quick-wrap .hint { font-size: 12px; color: var(--muted); margin-top: 6px; min-height: 1em; }

.review { margin-top: 12px; font-size: 14.5px; }
.review h4 { margin: 14px 0 4px; font-size: 15px; }
.review ul, .review ol { margin: 4px 0; padding-left: 20px; }
.review p { margin: 0 0 6px; }

.impact {
  border: 1px solid color-mix(in srgb, var(--warning) 60%, transparent);
  background: color-mix(in srgb, var(--warning) 10%, var(--surface));
  border-radius: 12px; padding: 12px; margin-top: 4px;
}
.impact-title { font-weight: 700; }

.avatar { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 17px; flex: none; }

/* Meters (single-series progress, status colored with label) */
.meter { margin: 10px 0 14px; }
.meter .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; gap: 8px; }
.meter .top .v { color: var(--ink-2); white-space: nowrap; }
.meter .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.meter .fill { height: 100%; border-radius: 4px; background: var(--accent); }
.meter .fill.good { background: var(--good); }
.meter .fill.warning { background: var(--warning); }
.meter .fill.critical { background: var(--critical); }

/* Forecast bars (diverging around zero) */
.fc-row { display: grid; grid-template-columns: 58px 1fr 92px; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; border-bottom: 1px solid var(--hairline); cursor: default; }
.fc-row:last-child { border-bottom: 0; }
.fc-row:hover { background: var(--surface-2); }
.fc-bar { position: relative; height: 14px; }
.fc-bar::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--muted); }
.fc-bar span { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.fc-bar span.pos { left: calc(50% + 1px); background: var(--good); border-radius: 0 4px 4px 0; }
.fc-bar span.neg { right: calc(50% + 1px); background: var(--critical); border-radius: 4px 0 0 4px; }
.fc-row .v { text-align: right; }

/* Buttons & forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 550; font-size: 14px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--critical); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: default; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; font-weight: 600; font-size: 13px; padding: 0; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 550; color: var(--ink-2); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--hairline);
  background: var(--surface); outline: none; min-height: 42px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.input.amount { font-size: 22px; font-weight: 650; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.seg { display: flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; font-weight: 550; color: var(--ink-2); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* Modal sheet */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .backdrop { align-items: center; } }
.sheet {
  background: var(--surface); width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .sheet { border-radius: 18px; } }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet .actions .btn { flex: 1; }
.form-error { color: var(--critical); font-size: 13px; margin-top: 8px; min-height: 1em; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 90px); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px);
}

.empty { text-align: center; color: var(--muted); padding: 18px 8px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.spaced { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Login */
.auth { max-width: 380px; margin: 12vh auto 0; padding: 16px; }
.auth .logo { font-size: 44px; }
.auth h1 { margin: 8px 0 4px; }
.auth p { color: var(--ink-2); margin: 0 0 20px; }

/* Advisor chat */
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; font-size: 14.5px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.msg.model { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.model p { margin: 0 0 8px; }
.msg.model p:last-child { margin-bottom: 0; }
.msg.model ul, .msg.model ol { margin: 4px 0 8px; padding-left: 20px; }
.msg.model h4 { margin: 8px 0 4px; font-size: 15px; }
.msg.error { align-self: center; background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chip { border: 1px solid var(--hairline); background: var(--surface); border-radius: 999px; padding: 7px 12px; font-size: 13px; cursor: pointer; text-align: left; }
.chip:hover { border-color: var(--accent); }
.composer {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 8px);
  display: flex; gap: 8px; margin-top: 14px; background: var(--page); padding-top: 8px;
}
.composer textarea { flex: 1; resize: none; min-height: 46px; max-height: 140px; }
.typing { color: var(--muted); font-size: 13px; align-self: flex-start; }
.disclaimer { font-size: 11.5px; color: var(--muted); text-align: center; margin-top: 8px; }
