/* Nornvi Money prototype. Brand tokens come from brand.nornvi.com/brand.css; these are the
   interface tokens approved with the design direction (money-plan.md section 14). */
:root {
  --bg: #F1EAF1;
  --card: #FBF8FB;
  --line: #E2D5E0;
  --control: #CDB9C8;
  --text: #50133B;
  --soft: #6B4862;
  --primary: #0F5E4B;
  --on-primary: #FFFFFF;
  --warn: #A10A3F;
  --sel: #50133B;
  --on-sel: #FFFFFF;
  --track: #E2D5E0;
  --flex: #9A6F8E;
  --input: #FFFFFF;
  --today: #50133B;
  --on-today: #FFFFFF;
  --today-soft: #E8DCE5;
  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
:root[data-nv-theme="dark"] {
  --bg: #000000;
  --card: #160A12;
  --line: #3A2433;
  --control: #6A4E60;
  --text: #D7C7D3;
  --soft: #B9A6B4;
  --warn: #D9577F;
  --sel: #D7C7D3;
  --on-sel: #000000;
  --track: #3A2433;
  --flex: #8E6A84;
  --input: #0C0509;
  --today: #2A1622;
  --on-today: #EFE6ED;
  --today-soft: #C9B5C4;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-nv-theme="auto"] {
    --bg: #000000;
    --card: #160A12;
    --line: #3A2433;
    --control: #6A4E60;
    --text: #D7C7D3;
    --soft: #B9A6B4;
    --warn: #D9577F;
    --sel: #D7C7D3;
    --on-sel: #000000;
    --track: #3A2433;
    --flex: #8E6A84;
    --input: #0C0509;
    --today: #2A1622;
    --on-today: #EFE6ED;
    --today-soft: #C9B5C4;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--sans); font-size: 16px; line-height: 1.4; font-variant-numeric: tabular-nums; -webkit-text-size-adjust: 100%; }
a { color: var(--text); text-underline-offset: 3px; text-decoration-color: var(--warn); }
a:hover { color: var(--warn); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0; }
p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.soft { color: var(--soft); }
.small { font-size: 13px; line-height: 19px; }
.tiny { font-size: 12px; line-height: 17px; }
.serif { font-family: var(--serif); }
.strong { font-weight: 700; }
.warn-text { color: var(--warn); font-weight: 700; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--soft); text-transform: none; }
.row { display: flex; align-items: center; gap: 12px; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { display: none; }
.screen { flex: 1; width: 100%; max-width: 560px; margin: 0 auto; padding: 16px 20px 112px; display: flex; flex-direction: column; gap: 12px; }
.screen.full { padding-bottom: 32px; }
.screen-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-height: 44px; }
.screen-head h1 { font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 32px; }
.home-head { display: flex; justify-content: space-between; align-items: center; }
.lockup { height: 40px; width: auto; max-width: 70vw; display: block; }
.logo-dark { display: none; }
:root[data-nv-theme="dark"] .logo-light { display: none; }
:root[data-nv-theme="dark"] .logo-dark { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-nv-theme="auto"] .logo-light { display: none; }
  :root[data-nv-theme="auto"] .logo-dark { display: block; }
}
.avatar { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--control); background: var(--card); color: var(--text); font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; flex: none; }
.map-switch { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; font-weight: 600; font-size: 15px; text-decoration: none; align-self: flex-start; }
.map-switch .soft { font-weight: 400; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--card); border-top: 1px solid var(--line); padding: 6px 8px calc(10px + env(safe-area-inset-bottom)); z-index: 10; }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 48px; font-size: 12px; text-decoration: none; color: var(--soft); }
.tabbar a[aria-current="page"] { color: var(--text); font-weight: 700; }
.fab { position: fixed; right: max(20px, calc(50% - 260px)); bottom: calc(84px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--primary); color: var(--on-primary); display: flex; align-items: center; justify-content: center; z-index: 11; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.sidebar { display: none; }
.banner { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: flex; gap: 10px; align-items: flex-start; font-size: 14px; line-height: 20px; }
.banner button { flex: none; }

/* ---------- surfaces ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.card.alert { border-color: var(--warn); }
.card.selected { border: 2px solid var(--sel); padding: 13px; }
.card.draft { border: 1.5px dashed var(--sel); }
.card h2 { font-size: 16px; font-weight: 700; }
.badge { display: inline-block; font-size: 12px; font-weight: 700; border: 1px solid currentColor; border-radius: 6px; padding: 0 6px; line-height: 18px; vertical-align: 1px; }
.badge.warn { color: var(--warn); }
.answer { font-family: var(--serif); font-weight: 600; font-size: 32px; line-height: 38px; }
.answer-sm { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 34px; }
.lead { font-size: 16px; line-height: 23px; }
.exception { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border: 1px solid var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 20px; text-decoration: none; }
.exception svg { flex: none; margin-top: 1px; color: var(--warn); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--sel); background: transparent; color: var(--text); font-weight: 600; font-size: 14px; text-decoration: none; cursor: pointer; }
.btn:hover { color: var(--text); background: color-mix(in srgb, var(--sel) 8%, transparent); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-size: 15px; }
.btn.primary:hover { filter: brightness(1.1); color: var(--on-primary); }
.btn.big { min-height: 52px; font-size: 16px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn.quiet { border-color: transparent; padding: 0 8px; font-weight: 400; text-decoration: underline; text-decoration-color: var(--warn); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link-btn { background: none; border: 0; padding: 0; min-height: 44px; display: inline-flex; align-items: center; color: var(--text); text-decoration: underline; text-decoration-color: var(--warn); text-underline-offset: 3px; cursor: pointer; font-size: 14px; }
.select-btn { min-height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--control); background: var(--card); color: var(--text); font-weight: 600; font-size: 15px; }
.icon-btn { width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--control); background: var(--card); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); background: var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { min-height: 38px; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 13px; cursor: pointer; padding: 0 6px; }
.seg button[aria-pressed="true"] { background: var(--sel); color: var(--on-sel); font-weight: 600; }
.choice { display: block; width: 100%; text-align: left; min-height: 56px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--control); background: transparent; color: var(--text); font-size: 15px; line-height: 20px; cursor: pointer; }
.choice[aria-pressed="true"] { border: 2px solid var(--sel); padding: 7px 13px; background: var(--card); font-weight: 400; }
.choice .soft { font-size: 13px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--soft); }
.field input, .field select, .field textarea { min-height: 44px; width: 100%; border: 1px solid var(--control); border-radius: 10px; padding: 0 12px; background: var(--input); color: var(--text); font-size: 16px; }
.field input.money { font-weight: 700; font-size: 20px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-error { color: var(--warn); font-weight: 700; font-size: 14px; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.ev { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 4px; min-height: 46px; border-bottom: 1px solid var(--line); font-size: 15px; width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; padding: 6px 0; color: var(--text); cursor: pointer; }
.ev:hover { background: color-mix(in srgb, var(--sel) 5%, transparent); }
.ev.expected { border-bottom: 1px dashed var(--control); }
.ev.estimate { color: var(--soft); }
.ev.promised .amt { background: repeating-linear-gradient(90deg, color-mix(in srgb, var(--primary) 25%, transparent) 0 3px, transparent 3px 6px); padding: 0 4px; border-radius: 4px; }
.ev .day { color: var(--soft); font-size: 13px; }
.ev .sub { display: block; font-size: 12px; color: var(--soft); }
.ev .amt { text-align: right; font-weight: 700; }
.ev .after { display: block; font-size: 12px; color: var(--soft); font-weight: 400; }
.home-rows .ev { grid-template-columns: 40px 1fr auto; min-height: 40px; }
.today-bar { background: var(--today); color: var(--on-today); border-radius: 12px; padding: 10px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.today-bar .tiny { color: var(--today-soft); }
.today-bar .bal { font-size: 20px; font-weight: 700; }
.today-bar .btn { color: var(--on-today); border-color: var(--today-soft); }
.kv { list-style: none; margin: 0; padding: 0; font-size: 14px; line-height: 20px; }
.kv li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.kv li:first-child { border-top: 0; }
.kv li.total { border-top: 2px solid var(--sel); font-weight: 700; }
.kv .sub { display: block; font-size: 12px; color: var(--soft); }
.kv a, .kv button.linkish { color: inherit; }
button.linkish { background: none; border: 0; padding: 0; text-align: left; cursor: pointer; text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px; color: inherit; font: inherit; }
button.linkish:hover { text-decoration-color: var(--warn); }
.month-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 0 4px; border-bottom: 2px solid var(--sel); font-weight: 700; }

/* ---------- bars ---------- */
.bar { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar .over { background: var(--warn); }
.bar .promised { background: repeating-linear-gradient(90deg, var(--primary) 0 3px, var(--track) 3px 6px); }
.split { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.split .c { background: var(--sel); }
.split .f { background: var(--flex); }
.split .g { background: var(--primary); }
.split .u { background: var(--card); border: 1.5px dashed var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--soft); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .ax { fill: var(--soft); font-size: 11px; }
.chart .lbl { fill: var(--text); font-size: 12px; font-weight: 700; }
.chart .warnlbl { fill: var(--warn); font-size: 11px; }

/* ---------- year grid ---------- */
.months { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.months button { width: 100%; min-height: 72px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px; color: var(--text); font-size: 13px; line-height: 17px; cursor: pointer; }
.months button[aria-expanded="true"] { border: 2px solid var(--sel); padding: 7px; }
.months .t { font-size: 15px; font-weight: 700; display: block; }
table.data { width: 100%; border-collapse: collapse; font-size: 15px; text-align: left; }
table.data th { color: var(--soft); font-size: 13px; font-weight: 600; padding: 6px 8px; }
table.data td { padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: top; }
table.data .r { text-align: right; }
table.data tr.total td { border-top: 2px solid var(--sel); font-weight: 700; }
.table-scroll { overflow-x: auto; }

/* ---------- lessons, dialogs, toasts ---------- */
details.lesson { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px; font-size: 14px; line-height: 20px; }
details.lesson summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 600; list-style: none; }
details.lesson summary::-webkit-details-marker { display: none; }
details.lesson summary::before { content: "?"; display: inline-flex; width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid currentColor; align-items: center; justify-content: center; font-size: 12px; flex: none; }
details.lesson[open] { padding-bottom: 12px; }
details.lesson p + p { margin-top: 8px; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--text); padding: 0; width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(20, 4, 15, .45); }
dialog form, dialog .dlg { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 12px; }
dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + env(safe-area-inset-bottom)); background: var(--sel); color: var(--on-sel); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(480px, calc(100vw - 32px)); z-index: 50; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.legal { padding: 8px 0 0; }

/* ---------- desktop ---------- */
@media (min-width: 960px) {
  .tabbar, .fab, .phone-only { display: none !important; }
  .topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; padding: 14px 32px; border-bottom: 1px solid var(--line); }
  .topbar .row { gap: 12px; }
  .body { display: flex; align-items: flex-start; flex: 1; }
  .sidebar { display: flex; flex-direction: column; gap: 4px; padding: 24px 16px; width: 220px; flex: none; position: sticky; top: 0; }
  .sidebar a { min-height: 44px; display: flex; align-items: center; padding: 0 16px; border-radius: 10px; text-decoration: none; font-size: 16px; border: 1px solid transparent; }
  .sidebar a[aria-current="page"] { font-weight: 700; background: var(--card); border-color: var(--line); }
  .sidebar a.minor { font-size: 14px; color: var(--soft); }
  .sidebar .gap { height: 16px; }
  .screen { max-width: 760px; margin: 0; padding: 24px 32px 48px; }
  .screen.wide { max-width: 1240px; }
  .home-head { display: none; }
  .desk-hide { display: none !important; }
  .panes { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  .toast { bottom: 32px; }
}
@media (max-width: 959px) {
  .desk-only { display: none !important; }
  .panes > .pane-side { display: none; }
}
@media (min-width: 960px) and (max-width: 1199px) {
  .panes { grid-template-columns: minmax(0, 1fr); }
  .panes > .pane-side { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
@media print {
  .tabbar, .fab, .sidebar, .topbar, .banner { display: none !important; }
}
.skip { position: absolute; left: 8px; top: -80px; z-index: 100; background: var(--card); }
.skip:focus { top: 8px; }
[tabindex="-1"]:focus:not(:focus-visible), h1[tabindex="-1"]:focus { outline: none; }
.kv.plain li { display: block; }
.card:has(> .chart) { max-width: 560px; }
