/*
 * Zani Budget. One stylesheet, no framework. No inline styles anywhere (the
 * CSP forbids them), so everything a template needs is a class here. Bars
 * are SVG whose widths are attributes.
 *
 * Colours are tokens, redefined for dark mode, so a phone at night gets a
 * dark page without a second stylesheet.
 */

:root {
  --page: #F4F5F2;
  --card: #FFFFFF;
  --ink: #18201D;
  --muted: #5E6763;
  --faint: #8A928E;
  --border: #E1E4DF;
  --rule: #ECEEEA;
  --row-hover: #F8F9F6;
  --accent: #2E6B57;
  --accent-ink: #FFFFFF;
  --accent-soft: #E3EFEA;
  --track: #E9ECE7;
  --ok: #3F8F6E;
  --near: #C98A1B;
  --over: #B4432F;
  --in: #2E7D55;
  --out: #18201D;
  --notice: #FFF4DB;
  --notice-ink: #6B4A00;
  --info: #E3EFEA;
  --info-ink: #1F4D3E;
  --error: #FBE7E3;
  --error-ink: #8A2E1E;
  --sidebar: #18201D;
  --sidebar-ink: #EEF2EF;
  --sidebar-muted: rgba(238, 242, 239, .55);
  --radius: 10px;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #111614;
    --card: #1A201D;
    --ink: #E8ECE9;
    --muted: #A3ACA7;
    --faint: #7C8580;
    --border: #2C3430;
    --rule: #242B28;
    --row-hover: #202723;
    --accent: #5FB394;
    --accent-ink: #0E1311;
    --accent-soft: #1E3029;
    --track: #2A322E;
    --ok: #5FB394;
    --near: #E0A63C;
    --over: #E2715B;
    --in: #6CC596;
    --out: #E8ECE9;
    --notice: #3A2F12;
    --notice-ink: #F3D58A;
    --info: #1E3029;
    --info-ink: #BFE3D3;
    --error: #3B1E18;
    --error-ink: #F2B4A6;
    --sidebar: #0C100E;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink); font-family: var(--sans);
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, table, .figure { font-variant-numeric: tabular-nums; }
h1 { font-size: 26px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.in { color: var(--in); }
.out { color: var(--out); }
.over-text { color: var(--over); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* --- Shell --------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: none; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; gap: 22px; padding: 24px 16px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.01em; padding: 0 10px; color: var(--sidebar-ink); }
.brand span { color: #7FCBAE; }
.auth-card .brand span { color: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sidebar-muted); padding: 8px 10px 4px;
}
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border-radius: 8px; color: var(--sidebar-ink); font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .07); text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .12); }
.badge {
  min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--near); color: #1A1300;
  font-size: 12px; font-weight: 700; text-align: center;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 0 10px; font-size: 13px; color: var(--sidebar-muted); }
.sidebar-foot a, .sidebar-foot .link-button { color: var(--sidebar-ink); }
.topbar { display: none; }
.main { flex: 1; min-width: 0; padding: 28px 32px 64px; max-width: 1180px; }
.hidden-note { padding: 10px 20px 14px; font-size: 13px; color: var(--faint); }

@media (max-width: 860px) {
  .shell { display: block; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10;
    background: var(--sidebar); color: var(--sidebar-ink); padding: 10px 16px;
  }
  .topbar button {
    background: transparent; border: 1px solid rgba(255, 255, 255, .25); color: var(--sidebar-ink);
    border-radius: 8px; padding: 6px 12px;
  }
  .sidebar { display: none; width: auto; height: auto; position: static; }
  .sidebar.open { display: flex; }
  .sidebar .brand { display: none; }
  .main { padding: 20px 16px 56px; }
  h1 { font-size: 22px; }
}

/* --- Page parts ---------------------------------------------------------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.month-nav { display: flex; gap: 6px; align-items: center; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  margin-bottom: 16px;
}
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h2, .card.flush > .card-head { padding: 16px 20px 0; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); margin-bottom: 16px; }
@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .grid .card { padding: 12px 14px; }
  .stat .figure { font-size: 19px; }
  th, td { padding: 8px 8px; }
  .card.flush > h2, .card.flush > .card-head { padding: 14px 14px 0; }
  .card { padding: 14px; }
}
.grid .card { margin-bottom: 0; }
.two-up { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .two-up { grid-template-columns: 1fr; } }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .figure { font-size: 24px; font-weight: 650; letter-spacing: -.01em; margin: 2px 0; }
.stat .sub { font-size: 13px; color: var(--muted); }
.callouts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split-right { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

/* --- Messages and notices ------------------------------------------------ */
.messages { list-style: none; padding: 0; margin: 0 0 16px; display: flex; flex-direction: column; gap: 8px; }
.notice { padding: 10px 14px; border-radius: 8px; background: var(--notice); color: var(--notice-ink); }
.notice.info { background: var(--info); color: var(--info-ink); }
.notice.error { background: var(--error); color: var(--error-ink); }
.notice a { color: inherit; text-decoration: underline; }

/* --- Buttons and forms --------------------------------------------------- */
.button, button.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 8px; padding: 8px 14px; font-weight: 600; text-decoration: none; line-height: 1.2;
}
.button:hover { text-decoration: none; filter: brightness(1.05); }
.button.secondary { background: transparent; color: var(--ink); border-color: var(--border); }
.button.secondary:hover { background: var(--row-hover); }
.button.danger { background: var(--over); border-color: var(--over); color: #fff; }
.button.small { padding: 5px 10px; font-size: 13px; }
.link-button { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; }
.link-button:hover { text-decoration: underline; }
form.inline { display: inline; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label, .label { font-weight: 600; font-size: 14px; }
.field .help { font-size: 13px; color: var(--muted); }
.field .errorlist, .errorlist {
  list-style: none; margin: 0; padding: 0; color: var(--over); font-size: 13px; font-weight: 500;
}
.errorlist.nonfield, .nonfield .errorlist { padding: 10px 14px; background: var(--error); color: var(--error-ink); border-radius: 8px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month],
input[type=search], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card);
  min-height: 38px;
}
input[type=file] { font-size: 14px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
.choices ul, .field ul.choices, .field > div > div { list-style: none; margin: 0; padding: 0; }
.field ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.field ul label, .check label { font-weight: 400; display: inline-flex; gap: 8px; align-items: center; }
.check { display: flex; gap: 8px; align-items: center; }
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.filters { display: grid; gap: 10px; grid-template-columns: 1.2fr 1.4fr 1fr 1.6fr auto; align-items: end; }
@media (max-width: 860px) { .filters { grid-template-columns: 1fr 1fr; } }

/* --- Tables -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--rule); }
th { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--row-hover); }
tr.group-row td { font-weight: 650; background: var(--page); border-bottom-color: var(--border); }
tr.total-row td { font-weight: 650; border-top: 2px solid var(--border); }
td .sub { display: block; font-size: 12.5px; color: var(--faint); }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--track); color: var(--muted);
}
.tag.transfer { background: var(--accent-soft); color: var(--accent); }
.tag.none { background: var(--notice); color: var(--notice-ink); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 14px; }

/* --- Plan vs. actual ----------------------------------------------------- */
.plan-table td.cat { width: 34%; }
.plan-table td.bar { width: 26%; min-width: 120px; }
.meter { display: block; width: 100%; height: 8px; }
.meter .track { fill: var(--track); }
.meter .fill { fill: var(--ok); }
.meter .fill.near { fill: var(--near); }
.meter .fill.over { fill: var(--over); }
.meter .fill.done { fill: var(--in); }
.state-over { color: var(--over); font-weight: 600; }
.state-near { color: var(--near); font-weight: 600; }
.carry { font-size: 12px; color: var(--faint); }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .plan-table td.cat { width: auto; }
  .plan-table td.bar { min-width: 70px; }
}

/* Plan editing */
.plan-input { max-width: 130px; text-align: right; }
.hint { font-size: 12.5px; color: var(--faint); white-space: nowrap; }

/* Reports */
.report-table th, .report-table td { padding: 7px 9px; font-size: 13px; }
.report-table td.label-col { white-space: nowrap; }
.chart { width: 100%; height: 180px; display: block; }
.chart .income { fill: var(--in); }
.chart .spending { fill: var(--over); opacity: .85; }
.chart .axis { stroke: var(--border); stroke-width: .5; }
.chart-labels { display: grid; grid-template-columns: repeat(12, 1fr); font-size: 11.5px; color: var(--muted); text-align: center; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend span::before { content: ''; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend .l-income::before { background: var(--in); }
.legend .l-spending::before { background: var(--over); }

/* Review queue */
.review-item { padding: 14px 20px; border-bottom: 1px solid var(--rule); display: grid; gap: 10px; grid-template-columns: 1fr minmax(min(260px, 100%), 420px); align-items: start; }
.review-item:last-child { border-bottom: 0; }
.review-item .what { display: flex; justify-content: space-between; gap: 12px; }
.review-item .payee { font-weight: 600; }
.review-item .bank { font-size: 12.5px; color: var(--faint); word-break: break-word; }
.review-item form.categorize { display: grid; gap: 8px; grid-template-columns: 1fr auto; }
.review-item .rule-line { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.review-item .rule-line input[type=text] { min-height: 30px; padding: 4px 8px; font-size: 13px; }
.review-item .pair { grid-column: 1 / -1; font-size: 13px; }
@media (max-width: 860px) { .review-item { grid-template-columns: 1fr; } }

/* CSV preview */
.preview td { font-size: 13px; }

/* --- Sign-in ------------------------------------------------------------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card .brand { color: var(--ink); padding: 0; margin-bottom: 18px; }
.auth-card .foot { margin-top: 16px; font-size: 13px; color: var(--muted); }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr svg { width: 240px; max-width: 100%; height: auto; display: block; background: #fff; border-radius: 8px; }
.secret { font-family: ui-monospace, Menlo, monospace; text-align: center; font-size: 13px; color: var(--muted); word-break: break-all; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: ui-monospace, Menlo, monospace; font-size: 16px; margin: 14px 0 18px; }

/* Passkeys */
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 13px; }
.divider::before, .divider::after { content: ''; flex: 1; border-top: 1px solid var(--border); }
.passkey-first { margin-bottom: 14px; }
.passkey-add { align-items: end; }
.auth-card h1 { margin-bottom: 16px; }
