/* Reckon — application stylesheet. Hand-written, no framework. */

@import url("https://api.fontshare.com/v2/css?f[]=satoshi@400,500,700&display=swap");
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap");

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: var(--lh-tight); letter-spacing: -0.015em; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); }
h3 { font-size: var(--text-md); }
h4 { font-size: var(--text-base); }
p { margin: 0 0 var(--s3); }
a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.mono, .num, td.num, th.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; white-space: nowrap; }
.pos { color: var(--accent); }
.neg { color: var(--negative); }
.muted { color: var(--ink-3); }
.small { font-size: var(--text-sm); }
.xs { font-size: var(--text-xs); }
.strong { font-weight: 600; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row { display: flex; align-items: center; gap: var(--s2); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 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;
}

/* ------------------------------------------------------------------ shell */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  border-right: 1px solid var(--line);
  background: var(--surface);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s5) var(--s5) var(--s4);
  height: var(--header-h);
}
.brand svg { color: var(--accent); flex: 0 0 auto; }
.brand-name { font-weight: 700; font-size: var(--text-md); letter-spacing: -0.02em; }
.brand-sub { font-size: var(--text-xs); color: var(--ink-3); letter-spacing: 0.08em; text-transform: uppercase; }

.nav { padding: var(--s4) var(--s3); display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--ink-3); padding: var(--s2) var(--s3) var(--s1);
}
.nav a {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--radius);
  color: var(--ink-2); text-decoration: none; font-size: var(--text-base);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"] svg { color: var(--accent); }
.nav svg { width: 17px; height: 17px; flex: 0 0 auto; color: var(--ink-3); }
.nav-foot { margin-top: auto; padding: var(--s4); border-top: 1px solid var(--line); font-size: var(--text-xs); color: var(--ink-3); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s6);
  border-bottom: 1px solid var(--line);
  background: color-mix(in oklab, var(--paper) 88%, transparent);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: var(--text-lg); }
.topbar .spacer { flex: 1 1 auto; }

.view { padding: var(--s6); max-width: 1360px; width: 100%; }
.view-head { margin-bottom: var(--s5); display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }
.view-head .sub { color: var(--ink-3); font-size: var(--text-sm); margin-top: var(--s1); }

/* ------------------------------------------------------------------ banner */
.demo-banner {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-line);
  color: var(--ink);
  font-size: var(--text-sm);
}
.demo-banner strong { font-weight: 700; }
.demo-banner .close { margin-left: auto; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-head {
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
}
.card-head h3 { font-size: var(--text-base); }
.card-body { padding: var(--s5); }
.card-body.tight { padding: var(--s3) 0; }

.grid { display: grid; gap: var(--s4); }
.grid-kpi { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1180px) { .grid-kpi { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px)  { .grid-kpi { grid-template-columns: 1fr; } }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.kpi { padding: var(--s4) var(--s5); }
.kpi .k-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.09em; color: var(--ink-3); }
.kpi .k-value {
  font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.03em;
  margin-top: var(--s2); line-height: 1.1;
}
.kpi .k-foot { font-size: var(--text-xs); color: var(--ink-3); margin-top: var(--s2); }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  font: inherit; font-size: var(--text-sm); font-weight: 500;
  padding: 7px 13px; border-radius: var(--radius);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: color-mix(in oklab, var(--accent) 88%, black); }
.btn-danger { color: var(--negative); border-color: var(--negative-line); }
.btn-danger:hover { background: var(--negative-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { padding: 4px 9px; font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-icon { padding: 6px; }
.btn-icon svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ forms */
label { display: block; font-size: var(--text-sm); font-weight: 500; margin-bottom: var(--s1); color: var(--ink-2); }
.field { margin-bottom: var(--s4); }
.field .hint { font-size: var(--text-xs); color: var(--ink-3); margin-top: var(--s1); }
.field .err { font-size: var(--text-xs); color: var(--negative); margin-top: var(--s1); }
input[type="text"], input[type="email"], input[type="tel"], input[type="date"],
input[type="number"], input[type="password"], input[type="search"], select, textarea {
  width: 100%; font: inherit; font-size: var(--text-base);
  padding: 7px 10px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input.money, input.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 20%, transparent);
}
input[aria-invalid="true"] { border-color: var(--negative); }
textarea { min-height: 74px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: right 14px center, right 9px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 15px; height: 15px; }
.check { display: flex; align-items: center; gap: var(--s2); font-size: var(--text-sm); margin-bottom: var(--s1); }
.check label { margin: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s4); }
.form-grid .full { grid-column: 1 / -1; }

.toolbar { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-bottom: var(--s4); }
.toolbar input[type="search"], .toolbar select { width: auto; min-width: 130px; font-size: var(--text-sm); padding: 6px 10px; }
.toolbar input[type="search"] { min-width: 210px; }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  font: inherit; font-size: var(--text-sm); padding: 6px 12px; border: 0;
  background: var(--surface); color: var(--ink-2); cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Below the breakpoint the table scrolls sideways instead of squashing every
   column into an unreadable stack of two-letter lines. */
@media (max-width: 900px) {
  .table-wrap table.data { min-width: 880px; }
  .table-wrap table.data td, .table-wrap table.data th { white-space: nowrap; }
  .table-wrap table.data td .sub, .table-wrap table.data td .muted { white-space: normal; }
  .table-wrap { border-radius: var(--r2); }
}
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data th {
  text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--ink-3); font-weight: 600; padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface);
}
table.data th.num { text-align: right; }
table.data td { padding: 9px var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tfoot td { padding: var(--s3) var(--s4); font-weight: 600; border-top: 1px solid var(--line-strong); }
table.data .actions { display: flex; gap: var(--s1); justify-content: flex-end; }
.row-click { cursor: pointer; }

/* ------------------------------------------------------------------ chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.03em;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-strong);
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip-paid { background: var(--accent-soft); border-color: var(--accent-line); color: color-mix(in oklab, var(--accent) 80%, var(--ink)); }
.chip-sent { background: var(--surface-3); border-color: var(--line-strong); color: var(--ink-2); }
.chip-overdue { background: var(--negative-soft); border-color: var(--negative-line); color: color-mix(in oklab, var(--negative) 85%, var(--ink)); }
.chip-draft { background: transparent; color: var(--ink-3); }
.chip-void { background: transparent; color: var(--ink-3); text-decoration: line-through; }
.chip-due { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn-ink); }
.chip-plain::before { display: none; }

.badge-box { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--ink-3); }

/* ------------------------------------------------------------------ progress */
.bar { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width var(--dur) var(--ease); }
.bar.warn > span { background: var(--warn); }

/* ------------------------------------------------------------------ drawer + modal */
.scrim {
  position: fixed; inset: 0; background: oklch(0.22 0.015 260 / 0.42);
  z-index: 60; opacity: 0; animation: fade var(--dur) var(--ease) forwards;
}
@keyframes fade { to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw);
  background: var(--paper); border-left: 1px solid var(--line);
  z-index: 61; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%); animation: slidein var(--dur) var(--ease) forwards;
}
@keyframes slidein { to { transform: translateX(0); } }
.drawer-head, .modal-head {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  background: var(--surface);
}
.drawer-body { padding: var(--s5); overflow-y: auto; flex: 1 1 auto; }
.drawer-foot, .modal-foot {
  padding: var(--s4) var(--s5); border-top: 1px solid var(--line);
  display: flex; gap: var(--s2); justify-content: flex-end; background: var(--surface);
  flex-wrap: wrap;
}
.modal {
  position: fixed; z-index: 61; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.modal-body { padding: var(--s5); overflow: auto; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ------------------------------------------------------------------ toasts */
.toasts { position: fixed; bottom: var(--s5); right: var(--s5); z-index: 90; display: flex; flex-direction: column; gap: var(--s2); }
.toast {
  background: var(--surface); border: 1px solid var(--line-strong); border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: var(--s3) var(--s4); box-shadow: var(--shadow);
  font-size: var(--text-sm); max-width: 340px;
  animation: toastin var(--dur) var(--ease);
}
.toast.err { border-left-color: var(--negative); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toastin { from { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------ states */
.empty { text-align: center; padding: var(--s12) var(--s5); color: var(--ink-3); }
.empty svg { width: 34px; height: 34px; color: var(--line-strong); margin-bottom: var(--s3); }
.empty h3 { color: var(--ink); margin-bottom: var(--s2); }
.empty p { max-width: 42ch; margin: 0 auto var(--s4); font-size: var(--text-sm); }

.skeleton { display: block; border-radius: var(--radius-sm); background: var(--surface-3); animation: pulse 1.3s ease-in-out infinite; height: 12px; }
@keyframes pulse { 50% { opacity: 0.45; } }
.skel-row { display: flex; gap: var(--s4); padding: 11px var(--s4); border-bottom: 1px solid var(--line); }

/* ------------------------------------------------------------------ misc */
.chart-box { position: relative; height: 260px; }
/* Pin the canvas so Chart.js can never draw wider than its card. */
.chart-box > canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.chart-box.short { height: 200px; }
.chart-box.tall { height: 320px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4); font-size: var(--text-sm); }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; }
.kv .total { border-top: 1px solid var(--line-strong); padding-top: var(--s2); font-weight: 700; }

.callout {
  border: 1px solid var(--accent-line); background: var(--accent-soft);
  border-radius: var(--radius); padding: var(--s4); font-size: var(--text-sm);
}
.callout.warn { border-color: var(--warn-line); background: var(--warn-soft); }
.callout.neg { border-color: var(--negative-line); background: var(--negative-soft); }
.callout h4 { margin-bottom: var(--s2); }

.disclaimer { font-size: var(--text-xs); color: var(--ink-3); border-top: 1px solid var(--line); padding-top: var(--s3); margin-top: var(--s5); }

.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s5); }
.tabs button {
  font: inherit; font-size: var(--text-sm); font-weight: 500; padding: var(--s3) var(--s4);
  background: transparent; border: 0; border-bottom: 2px solid transparent;
  color: var(--ink-3); cursor: pointer; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }

.dropzone {
  border: 1.5px dashed var(--line-strong); border-radius: var(--radius-lg);
  padding: var(--s8) var(--s5); text-align: center; color: var(--ink-3); font-size: var(--text-sm);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }

.recon-row { border-bottom: 1px solid var(--line); padding: var(--s4); }
.recon-row:last-child { border-bottom: 0; }
.recon-suggest { margin-top: var(--s3); padding: var(--s3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }

.band-bar { display: flex; height: 34px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.band-seg { display: flex; align-items: center; justify-content: center; font-size: var(--text-xs); font-weight: 600; color: white; min-width: 2px; }
.band-legend { display: flex; gap: var(--s4); flex-wrap: wrap; margin-top: var(--s3); font-size: var(--text-xs); color: var(--ink-2); }
.band-legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.band-pa    { background: var(--ink-4, #b9bec7); }
.band-basic { background: var(--accent); }
.band-higher{ background: var(--warn); }
.band-add   { background: var(--negative); }
.band-legend .band-pa, .band-legend .band-basic, .band-legend .band-higher, .band-legend .band-add { color: transparent; }

.link-list { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: 6px; }
.link-list a { font-size: var(--text-sm); color: var(--accent); text-decoration: none; }
.link-list a:hover { text-decoration: underline; }

table.data tr.section-row td { background: var(--surface-2); font-weight: 600; font-size: var(--text-xs);
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }

.thumb {
  width: 34px; height: 34px; min-width: 34px; max-width: 34px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  object-fit: cover; background: var(--surface-2); cursor: pointer;
  /* If an image ever fails, keep the alt text inside the cell instead of
     letting it blow the column out. */
  overflow: hidden; font-size: 0; color: transparent;
}

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--s6); }
.auth-card { width: min(410px, 100%); }

/* ------------------------------------------------------------------ mobile */
.mobile-only { display: none; }
@media (max-width: 767px) {
  .mobile-only { display: block; }
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    width: 100%; flex: none; height: auto;
    border-right: 0; border-top: 1px solid var(--line);
    flex-direction: row; z-index: 50;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .sidebar .brand, .sidebar .nav-label, .sidebar .nav-foot { display: none; }
  .nav { flex-direction: row; width: 100%; padding: var(--s1) var(--s1); justify-content: space-between; gap: 0; }
  .nav a { flex-direction: column; gap: 2px; font-size: 9.5px; padding: 6px 2px; flex: 1 1 0; text-align: center; letter-spacing: -0.01em; }
  .nav svg { width: 18px; height: 18px; }
  .main { padding-bottom: 62px; }
  .view { padding: var(--s4); }
  .topbar { padding: 0 var(--s4); gap: var(--s2); }
  .topbar h1 { font-size: var(--text-base); }
  .topbar .hide-sm { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .drawer { width: 100vw; }
  .toasts { left: var(--s4); right: var(--s4); bottom: 70px; }
  .toast { max-width: none; }
  .kpi .k-value { font-size: var(--text-lg); }
  .chart-box { height: 220px; }
}

@media print {
  .sidebar, .topbar, .toasts, .demo-banner, .no-print { display: none !important; }
  .view { padding: 0; }
  .card { border: 1px solid #ccc; box-shadow: none; break-inside: avoid; }
}
