/* ============================================================
   Design system — premium, calm, high-contrast.
   Dark = true black with raised surfaces; light = soft grey with white cards.
   Chart series colours are the validated categorical palette (unchanged).
   ============================================================ */
/* Palette: deep navy + warm beige. Light = beige paper with navy ink; dark = navy with beige ink. */
:root {
  color-scheme: light;
  --page: #f5f3ee; --surface: #fdfcf9; --surface-2: #ebe8df; --surface-3: #dfdbcf;
  --ink: #0b1633; --ink-2: #4f566b; --ink-3: #7c8194;
  --grid: #e5e2d8; --axis: #cfcbbd; --border: rgba(11,22,51,.07);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --crit: #d03b3b;
  --good-ink: #0a7a3a; --crit-ink: #c4261f; --warn-ink: #8a5a00;
  --accent: #14296b; --accent-2: #c99a2e; --accent-ink: #fffaf0; --accent-soft: rgba(20,41,107,.09);
  --hero-from: #08142e; --hero-to: #28489f;
  --radius: 24px; --radius-sm: 16px;
  --shadow: 0 1px 2px rgba(20,25,45,.05), 0 12px 30px rgba(20,25,45,.07);
  --tab-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #060c1d; --surface: #0e1830; --surface-2: #16223f; --surface-3: #22305a;
    --ink: #f5f3ee; --ink-2: #aeb2c4; --ink-3: #7d839b;
    --grid: #1a2748; --axis: #2b3a66; --border: rgba(240,205,110,.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-ink: #34d27b; --crit-ink: #ff6b62; --warn-ink: #fab219;
    --accent: #f0c75e; --accent-2: #c9962f; --accent-ink: #0a1430; --accent-soft: rgba(240,199,94,.14);
    --hero-from: #070f26; --hero-to: #2a4aa6; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #060c1d; --surface: #0e1830; --surface-2: #16223f; --surface-3: #22305a;
  --ink: #f5f3ee; --ink-2: #aeb2c4; --ink-3: #7d839b;
  --grid: #1a2748; --axis: #2b3a66; --border: rgba(240,205,110,.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-ink: #34d27b; --crit-ink: #ff6b62; --warn-ink: #fab219;
  --accent: #f0c75e; --accent-2: #c9962f; --accent-ink: #0a1430; --accent-soft: rgba(240,199,94,.14);
  --hero-from: #070f26; --hero-to: #2a4aa6; --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--page); }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 16px/1.45 -apple-system, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -.02em; }
h1 { font-size: 1.9rem; font-weight: 750; } h2 { font-size: 1.15rem; font-weight: 700; } h3 { font-size: .98rem; font-weight: 650; }
a { color: var(--accent); }
a.card, a.tab, a.btn, a.qbtn { text-decoration: none; }
a.card { color: var(--ink); }
a.card.health { color: #fff; }
a.btn.ghost { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--ink-2); } .small { font-size: .84rem; } .xs { font-size: .74rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- layout ---------- */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.main { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 10px 16px calc(var(--tab-h) + env(safe-area-inset-bottom) + 40px); }
.page-head { display: flex; align-items: center; gap: 10px; margin: 10px 0 18px; }
.page-head h1 { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) {
  .grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid.md-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
a.card, .card.tap { transition: transform .12s ease, background .12s ease; }
a.card:active, .card.tap:active { transform: scale(.985); }

/* ---------- floating glass tab bar ---------- */
.tabbar {
  position: fixed; z-index: 20; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 8px);
  height: var(--tab-h); display: flex; align-items: stretch; padding: 6px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: saturate(1.8) blur(22px); backdrop-filter: saturate(1.8) blur(22px);
  border: 1px solid var(--border); border-radius: 32px; box-shadow: 0 10px 34px rgba(0,0,0,.18);
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  text-decoration: none; color: var(--ink-3); font-size: .66rem; font-weight: 600; position: relative; border: 0; background: none; border-radius: 26px; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--ink); background: var(--surface-2); }
.tab[aria-current="page"] svg { color: var(--accent); }
.btn.primary:active { filter: brightness(.95); }
.badge { position: absolute; top: 3px; left: calc(50% + 4px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--crit); color: #fff; font-size: .66rem; line-height: 18px; text-align: center; font-weight: 700; }
@media (min-width: 900px) {
  .tabbar { top: 16px; bottom: 16px; right: auto; left: 16px; width: 84px; height: auto; flex-direction: column; justify-content: flex-start; gap: 6px; padding: 10px 6px; }
  .tab { flex: 0 0 auto; padding: 12px 0; }
  .main { padding-left: 120px; padding-bottom: 40px; max-width: 1200px; }
  .quick { max-width: 520px; }
}

/* ---------- controls ---------- */
.btn { border: 0; background: var(--surface-2); border-radius: 999px; padding: 10px 18px; font-weight: 650; min-height: 44px; transition: transform .1s ease, opacity .15s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--crit-ink); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 6px 14px; min-height: 34px; font-size: .86rem; }
.btn:disabled { opacity: .45; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { background: var(--surface-2); border: 1px solid transparent; border-radius: 14px; padding: 11px 14px; min-height: 46px; width: 100%; font-size: 16px; }
input:focus, select:focus { border-color: var(--accent); outline: none; }
select { appearance: none; -webkit-appearance: none; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%238a8a96' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: .78rem; color: var(--ink-2); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 13px; border-radius: 999px; font-size: .84rem; color: var(--ink-2); font-weight: 650; min-height: 32px; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--page); }
.chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 11px; font-size: .78rem; font-weight: 650; background: var(--surface-2); color: var(--ink-2); }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }

/* ---------- hero (overview) ---------- */
.balance { padding: 6px 2px 2px; }
.balance .label { color: var(--ink-2); font-size: .88rem; font-weight: 600; }
.balance .amount { font-size: clamp(2.6rem, 11vw, 3.6rem); font-weight: 750; letter-spacing: -.045em; line-height: 1.05; margin: 2px 0 8px; }
.balance .amount small { font-size: .5em; letter-spacing: -.02em; color: var(--ink-2); font-weight: 650; margin-left: 2px; }
.delta { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; font-size: .84rem; font-weight: 650; background: var(--surface-2); }
.delta.pos { color: var(--good-ink); } .delta.neg { color: var(--crit-ink); }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.qbtn { display: flex; flex-direction: column; align-items: center; gap: 7px; color: var(--ink); font-size: .76rem; font-weight: 650; position: relative; }
.qbtn .ic { width: 54px; height: 54px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.qbtn .ic svg { width: 24px; height: 24px; }
.qbtn:active .ic { transform: scale(.94); }
.qbtn .badge { top: -4px; left: calc(50% + 10px); }

.health { color: #fff; border: 0; position: relative; overflow: hidden;
  background: radial-gradient(130% 150% at 0% 0%, var(--hero-to) 0%, var(--hero-from) 62%, #040a1a 100%); }
.health .muted, .health .small { color: rgba(245,243,238,.76); }
.health .grade .g { color: #f5d77f; }
.health h2 { color: #fff; font-size: 1.35rem; }
.health .go { margin-top: 8px; display: inline-flex; gap: 6px; padding: 6px 14px; border-radius: 999px; background: #f0c75e; font-weight: 700; font-size: .84rem; color: #0a1430; }
.hero { display: flex; gap: 18px; align-items: center; }
.ring { position: relative; width: 112px; height: 112px; flex: none; }
.ring canvas { width: 100%; height: 100%; }
.ring .grade { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.grade .g { font-size: 2.3rem; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.grade .n { font-size: .78rem; opacity: .75; }

/* ---------- KPI ---------- */
.kpi .label { color: var(--ink-2); font-size: .8rem; font-weight: 600; }
.kpi .value { font-size: 1.6rem; font-weight: 750; margin-top: 4px; letter-spacing: -.03em; }
.kpi .sub { font-size: .8rem; color: var(--ink-2); margin-top: 2px; }
.pos { color: var(--good-ink); } .neg { color: var(--crit-ink); }

.dim { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; padding: 12px 0; border-top: 1px solid var(--grid); }
.dim:first-of-type { border-top: 0; }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; grid-column: 1 / -1; margin: 3px 0; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--s1); }
.bar > i.bad { background: var(--crit); } .bar > i.mid { background: var(--serious); } .bar > i.ok { background: var(--s1); } .bar > i.good { background: var(--good); }

/* ---------- lists & activity ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; gap: 13px; align-items: center; padding: 12px 0; }
.item + .item { border-top: 1px solid var(--grid); }
.item.tap { cursor: pointer; }
.item .amt { font-weight: 700; text-align: right; flex: none; letter-spacing: -.01em; }
.item .title { font-weight: 650; }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-weight: 750; font-size: 1.02rem; background: var(--surface-2); color: var(--ink); position: relative; overflow: hidden; }
.avatar::after { content: ""; position: absolute; inset: 0; background: var(--tint, transparent); opacity: .24; }
.avatar b { position: relative; z-index: 1; }
.avatar.sm { width: 36px; height: 36px; font-size: .9rem; }
.day-head { font-size: .8rem; font-weight: 650; color: var(--ink-2); padding: 16px 0 2px; display: flex; justify-content: space-between; }
.day-head:first-child { padding-top: 2px; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; color: var(--ink-2); }
.state { font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--surface-2); color: var(--ink-2); }
.state.confirmed { color: var(--good-ink); } .state.review { color: var(--warn-ink); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: .78rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.h200 { height: 200px; } .chart-wrap.h240 { height: 240px; } .chart-wrap.h160 { height: 160px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 7px 0; }
.hbar .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .track > i { display: block; height: 100%; background: var(--s1); border-radius: 4px; }

/* ---------- advice / anomalies ---------- */
.advice { position: relative; padding-left: 22px; }
.advice::before { content: ""; position: absolute; left: 0; top: 18px; bottom: 18px; width: 4px; border-radius: 0 4px 4px 0; background: var(--s1); }
.advice.p1::before { background: var(--crit); } .advice.p2::before { background: var(--serious); } .advice.p3::before { background: var(--s4); }
.advice .action { margin-top: 10px; padding: 11px 13px; background: var(--surface-2); border-radius: 14px; font-size: .9rem; }
.sev { font-size: .7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: capitalize; }
.sev.high { background: color-mix(in srgb, var(--crit) 20%, transparent); color: var(--crit-ink); }
.sev.warn { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn-ink); }
.sev.info { background: var(--surface-2); color: var(--ink-2); }

/* ---------- sheet / toast ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s ease; }
.sheet { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 28px 28px 0 0;
  padding: 12px 20px calc(20px + env(safe-area-inset-bottom)); animation: rise .28s cubic-bezier(.2,.9,.3,1); }
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 28px; } }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--axis); margin: 0 auto 16px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(env(safe-area-inset-top) + 12px); z-index: 60;
  background: var(--ink); color: var(--page); padding: 11px 18px; border-radius: 999px; font-size: .9rem; font-weight: 600; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
@keyframes fade { from { opacity: 0; } } @keyframes rise { from { transform: translateY(40px); opacity: .4; } }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: radial-gradient(90% 60% at 50% -10%, rgba(70,110,255,.26), transparent 70%), var(--page); }
.login .card { width: 100%; max-width: 400px; padding: 28px 24px; background: transparent; border: 0; box-shadow: none; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 22px; box-shadow: 0 12px 40px rgba(60,100,255,.40); }
.login h1 { font-size: 2.1rem; margin-bottom: 6px; }
.login .btn.primary { min-height: 52px; font-size: 1.02rem; }
.error { color: var(--crit-ink); font-size: .88rem; min-height: 1.3em; }
.empty { text-align: center; padding: 30px 8px; color: var(--ink-2); }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 3px; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 37%, var(--surface) 63%); background-size: 400% 100%; border-radius: var(--radius); animation: shimmer 1.4s ease infinite; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .scrim, .sheet { animation: none; } }
@media (prefers-reduced-motion: no-preference) { .bar > i, .hbar .track > i, .progress > i { transition: width .6s cubic-bezier(.2,.8,.2,1); } }
