/* Family Finance — layout and components. Colours come only from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 15px/1.5 var(--font-body); }
h1, h2, h3 { font-family: var(--font-head); color: var(--heading); font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: 2rem; } h2 { font-size: 1.45rem; } h3 { font-size: 1.15rem; font-family: var(--font-body); font-weight: 600; color: var(--text); }
a { color: var(--accent); }
.num, td.num, .amount { font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }
.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; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[tabindex="-1"]:focus { outline: none; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--surface); padding: 8px 12px; z-index: 100; border-radius: 8px; }
.skip:focus { top: 8px; }
[hidden] { display: none !important; }

/* ---------- Sign-in (immersive, distinct from the app) ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 32px 16px; background-color: #071A2B; color: #F3EBD8;
  background-image: url('/brand/signin-art.svg'), radial-gradient(ellipse at 50% 18%, rgba(198,161,91,.16), transparent 60%), linear-gradient(180deg, #071A2B 0%, #06111D 100%);
  background-repeat: no-repeat; background-position: center bottom, center, center; background-size: min(1400px, 180%) auto, cover, cover; }
.auth-inner { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.auth-brand { text-align: center; }
.auth-brand img { width: 260px; max-width: 80vw; height: auto; }
.auth-brand .descriptor { font: italic 500 1.1rem var(--font-head); color: #E7CB87; margin-top: 2px; }
.auth-card { width: 100%; background: rgba(16, 33, 49, .92); border: 1px solid rgba(198,161,91,.45); border-radius: 16px; padding: 28px 24px; box-shadow: 0 12px 40px rgba(0,0,0,.35); }
.auth-card h1 { color: #E7CB87; font-size: 1.6rem; margin-bottom: 4px; }
.auth-card p { color: #D7CFBD; margin: 0 0 16px; }
.auth-card label { color: #F3EBD8; }
.auth-card input { background: #0B1A28; color: #F3EBD8; border-color: #3A4D61; }
.auth-card .btn-primary { background: #C6A15B; color: #071A2B; border-color: #C6A15B; width: 100%; }
.auth-card .btn-primary:hover { background: #E7CB87; }
.auth-card .error { color: #F0A39A; }
.auth-card a { color: #E7CB87; }
.auth-foot { color: #9FA8AE; font-size: .8rem; text-align: center; letter-spacing: .08em; }
.qr { background: #fff; padding: 8px; border-radius: 8px; display: block; margin: 8px auto; }
.secret { font-family: ui-monospace, Menlo, monospace; word-break: break-all; background: #0B1A28; padding: 8px; border-radius: 6px; }

/* ---------- App shell ---------- */
.shell { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar { background: var(--midnight); color: #E9E1CF; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; border-bottom: 1px solid rgba(198,161,91,.35); margin-bottom: 8px; }
.sidebar .brand img { width: 196px; height: auto; }
.nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; flex-direction: column; padding: 8px 12px; border-radius: 8px; color: #E9E1CF; text-decoration: none; line-height: 1.2; }
.nav a .t { font-family: var(--font-head); font-size: 1.12rem; font-weight: 600; }
.nav a .s { font-size: .75rem; color: #AFB7BC; }
.nav a:hover { background: rgba(198,161,91,.12); }
.nav a[aria-current="page"] { background: rgba(198,161,91,.18); box-shadow: inset 3px 0 0 #C6A15B; }
.nav a[aria-current="page"] .t { color: #E7CB87; }
.sidebar .who { margin-top: auto; border-top: 1px solid rgba(198,161,91,.35); padding: 12px 8px 0; font-size: .85rem; color: #C9C2B1; }
.sidebar .who button { color: #E7CB87; background: none; border: 0; padding: 4px 0; cursor: pointer; font: inherit; text-decoration: underline; }
.topbar { display: none; }
main { padding: 28px clamp(16px, 3vw, 40px) 96px; max-width: 1280px; width: 100%; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head .sub { color: var(--text-muted); margin-top: 4px; }
.ornament { display: flex; align-items: center; gap: 10px; color: var(--ornament); margin: 26px 0 12px; }
.ornament::before, .ornament::after { content: ''; height: 1px; background: var(--rule); flex: 1; }
.ornament h2 { text-align: center; min-width: 0; overflow-wrap: anywhere; }
.ornament svg { width: 14px; height: 14px; flex: none; }
.fab { display: none; }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-top: 2px solid var(--ornament); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card.plain { border-top-width: 1px; border-top-color: var(--border); }
.card .label { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.card .value { font-size: 1.6rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; color: var(--text); overflow-wrap: anywhere; }
.card .value.big { font-size: 2.2rem; }
.card .meta { color: var(--text-muted); font-size: .82rem; margin-top: 4px; }
.card h3 { margin-bottom: 8px; }
.hero { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px; display: grid; gap: 16px; grid-template-columns: 1.4fr 1fr 1fr; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.hero .label { color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.hero .value { font-size: 1.6rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero .value.big { font-size: 2.4rem; color: var(--heading); font-family: var(--font-body); }
.hero .meta { color: var(--text-muted); font-size: .82rem; margin-top: 4px; }
.hero > div { position: relative; z-index: 1; min-width: 0; }
.hero::after { content: ''; position: absolute; right: -40px; top: -40px; width: 220px; height: 220px; background: url('/brand/constellation.svg') no-repeat center / contain; opacity: .5; pointer-events: none; }
.pos { color: var(--success); } .neg { color: var(--error); }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 8px; border: 1px solid var(--border); }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; width: 0; }
.progress.over > span { background: var(--error); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); white-space: nowrap; }
.badge.warn { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.badge.err { background: var(--error-bg); color: var(--error); border-color: transparent; }
.badge.ok { background: var(--success-bg); color: var(--success); border-color: transparent; }
.notice { padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); margin: 8px 0; }
.notice.warn { background: var(--warning-bg); color: var(--warning); border-color: transparent; }
.notice.err { background: var(--error-bg); color: var(--error); border-color: transparent; }
.notice.ok { background: var(--success-bg); color: var(--success); border-color: transparent; }
.empty { text-align: center; padding: 36px 16px; color: var(--text-muted); }
.empty .em-title { font-family: var(--font-head); font-size: 1.35rem; color: var(--heading); margin-bottom: 6px; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list li > span:first-child { min-width: 0; overflow-wrap: anywhere; }

/* ---------- Tables (conventional, legible) ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
th.num, td.num { text-align: right; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--text-muted); font-size: .8rem; }
th button.sort { background: none; border: 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; cursor: pointer; padding: 0; }

/* ---------- Forms & buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 .92rem var(--font-body); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-danger { color: var(--error); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.filters { flex-basis: 100%; }
.filters summary { cursor: pointer; color: var(--accent); font-weight: 600; padding: 6px 0; }
.filters .row { margin-top: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 14px; }
form .row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 12px; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; }
.field { min-width: 0; }
.field .hint { color: var(--text-muted); font-size: .8rem; margin-top: 3px; }
.field .error { color: var(--error); font-size: .82rem; margin-top: 3px; }
input, select, textarea { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: 400 1rem var(--font-body); }
input[type="checkbox"] { width: auto; min-height: 0; }
textarea { min-height: 72px; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--error); }
.fx-preview { padding: 8px 12px; background: var(--surface-2); border-radius: 8px; font-size: .9rem; border: 1px dashed var(--border); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--surface); color: var(--text); padding: 8px 12px; font: 600 .85rem var(--font-body); cursor: pointer; min-height: 40px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-contrast); }

dialog { border: 1px solid var(--border); border-top: 3px solid var(--ornament); border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(6, 17, 29, .55); }
dialog .dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 0; }
dialog .dlg-body { padding: 16px 20px 20px; overflow-y: auto; max-height: calc(100dvh - 120px); }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.x { background: none; border: 0; font-size: 1.5rem; line-height: 1; cursor: pointer; color: var(--text-muted); min-width: 40px; min-height: 40px; }
.toast { position: fixed; inset: auto auto 20px 50%; margin: 0; transform: translateX(-50%); background: var(--midnight); color: #F3EBD8; padding: 10px 18px; border-radius: 10px; border: 1px solid var(--gold); z-index: 200; max-width: calc(100vw - 32px); }
.toast.err { border-color: #F0A39A; }

/* ---------- Charts ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); }
.chart text { fill: var(--text-muted); font: 11px var(--font-body); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .82rem; color: var(--text-muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.c1 { background: var(--chart-1); } .c2 { background: var(--chart-2); } .c3 { background: var(--chart-3); } .c4 { background: var(--chart-4); } .c5 { background: var(--chart-5); } .c6 { background: var(--chart-6); }
.bar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.bar span { display: block; height: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 60; transform: translateX(-102%); transition: transform .15s ease; }
  .shell.nav-open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(6,17,29,.5); z-index: 50; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: sticky; top: 0; z-index: 40; background: var(--midnight); padding: 8px 12px; }
  .topbar img { height: 34px; width: auto; }
  .topbar button { background: none; border: 1px solid rgba(198,161,91,.5); color: #E7CB87; border-radius: 8px; min-height: 40px; min-width: 44px; font: 600 .9rem var(--font-body); }
  main { padding: 18px 16px 110px; }
  .hero { grid-template-columns: 1fr; }
  .fab { display: inline-flex; position: fixed; right: 16px; bottom: 16px; z-index: 45; min-height: 52px; padding: 0 20px; border-radius: 26px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
  .add-desktop { display: none; }
}
@media (max-width: 640px) {
  h1 { font-size: 1.65rem; }
  .grid, .grid.two { grid-template-columns: 1fr; }
  /* Tables become stacked rows on phones: no horizontal scrolling */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { border-bottom: 1px solid var(--border); padding: 8px 4px; }
  table.stack td { border: 0; padding: 3px 10px; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--text-muted); font-size: .78rem; text-align: left; font-weight: 600; flex: none; max-width: 45%; }
  table.stack td.num { text-align: right; }
  table.stack td > * { min-width: 0; overflow-wrap: anywhere; }
  .table-wrap { overflow-x: visible; }
  .card .value.big { font-size: 1.8rem; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
@media print { .sidebar, .topbar, .fab, .toolbar, .btn { display: none !important; } .shell { display: block; } body { background: #fff; } }
