/* StreamerFinance -- one stylesheet, light + dark via custom properties. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --ring: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --income: #2a78d6;
  --expense: #eb6834;
  --good: #006300;
  --bad: #b42d2d;
  --bad-wash: #fbeaea;
  --good-wash: #e8f4e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a9890;
    --line: #2c2c2a;
    --axis: #383835;
    --ring: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --income: #3987e5;
    --expense: #d95926;
    --good: #0ca30c;
    --bad: #e66767;
    --bad-wash: #2e1a1a;
    --good-wash: #16271a;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a9890;
  --line: #2c2c2a;
  --axis: #383835;
  --ring: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --income: #3987e5;
  --expense: #d95926;
  --good: #0ca30c;
  --bad: #e66767;
  --bad-wash: #2e1a1a;
  --good-wash: #16271a;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 1rem; margin: 0 0 12px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---------- Layout ---------- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--ink); text-decoration: none; margin-right: 8px; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 8px;
  font-size: 0.93rem;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; padding: 6px 10px; border-radius: 8px; color: var(--ink-2);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.user-menu .menu {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 180px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12); padding: 6px; z-index: 20;
}
.user-menu .menu a, .user-menu .menu button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer;
}
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--surface-2); }

body.wide main, body.wide .topbar-inner { max-width: 1440px; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  flex-wrap: wrap; margin-bottom: 20px;
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stack > * + * { margin-top: 16px; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-income { border-color: var(--income); color: var(--income); }
.btn-expense { border-color: var(--expense); color: var(--expense); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 0.85rem; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 0; font: inherit; cursor: pointer; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=search],
select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--page);
  border: 1px solid var(--axis); border-radius: 8px; padding: 8px 10px; min-height: 40px;
}
input[type=file] { font: inherit; color: var(--ink-2); max-width: 100%; }
textarea { resize: vertical; }
.field { margin-bottom: 16px; }
.field .help { color: var(--muted); font-size: 0.83rem; margin-top: 4px; }
.field .errorlist { color: var(--bad); font-size: 0.85rem; margin: 4px 0 0; padding: 0; list-style: none; }
.field-row { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-card { max-width: 640px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.form-actions .spacer { flex: 1; }
.net-preview {
  background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px;
  display: flex; justify-content: space-between; font-weight: 600;
}
.errorlist.nonfield {
  background: var(--bad-wash); color: var(--bad); padding: 10px 12px; border-radius: 8px; list-style: none;
}

/* ---------- Messages ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li {
  padding: 10px 14px; border-radius: 8px; background: var(--good-wash); color: var(--ink);
  border: 1px solid var(--line);
}
.messages li.error { background: var(--bad-wash); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
.stat .label { color: var(--ink-2); font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 0.83rem; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.swatch.income { background: var(--income); }
.swatch.expense { background: var(--expense); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

/* ---------- Period tabs ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs a {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink-2);
  text-decoration: none; font-size: 0.88rem; background: var(--surface);
}
.tabs a[aria-current="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }

/* ---------- Bar lists (single series, horizontal) ---------- */
.barlist { list-style: none; margin: 0; padding: 0; }
.barlist li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; padding: 6px 0; }
.barlist .name { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barlist .amt { font-size: 0.92rem; font-weight: 600; }
.barlist .amt .muted { font-weight: 400; margin-left: 6px; }
.barlist .track { grid-column: 1 / -1; height: 8px; }
.barlist .bar { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.barlist.income .bar { background: var(--income); }
.barlist.expense .bar { background: var(--expense); }
.empty { color: var(--muted); padding: 12px 0; font-size: 0.92rem; }

/* ---------- Monthly column chart ---------- */
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; font-size: 0.85rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.colchart { position: relative; margin-top: 12px; }
.colchart .plot {
  height: 200px; display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px;
  align-items: end; border-bottom: 1px solid var(--axis);
  background-image: linear-gradient(var(--line) 1px, transparent 1px);
  background-size: 100% 50%;
}
.colchart .month {
  height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 2px;
  cursor: default; border-radius: 4px; padding: 0 2px; outline-offset: 0;
}
.colchart .month:hover, .colchart .month:focus-visible { background: var(--surface-2); }
.colchart .col { flex: 1; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 0; }
.colchart .col.income { background: var(--income); }
.colchart .col.expense { background: var(--expense); }
.colchart .xlabels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; margin-top: 6px; }
.colchart .xlabels span { text-align: center; font-size: 0.75rem; color: var(--muted); }
.colchart { padding-left: 64px; }
.colchart .yticks { position: absolute; left: 0; top: 0; width: 58px; height: 200px; }
.colchart .yticks span {
  position: absolute; right: 0; transform: translateY(50%); font-size: 0.72rem;
  color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tooltip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 170px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15); padding: 8px 10px; font-size: 0.85rem;
}
.tooltip .row { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.tooltip .row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.tooltip strong { display: block; margin-bottom: 4px; }
details.table-view { margin-top: 12px; }
details.table-view summary { cursor: pointer; color: var(--ink-2); font-size: 0.88rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 0.8rem; color: var(--ink-2); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--axis); }
td.desc a { color: var(--ink); text-decoration: none; font-weight: 500; }
td.desc a:hover { text-decoration: underline; }
td.desc .meta { color: var(--muted); font-size: 0.83rem; }
.pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.summary-table th:first-child, .summary-table td:first-child { position: sticky; left: 0; background: var(--surface); min-width: 170px; }
.summary-table td, .summary-table th { font-size: 0.85rem; padding: 6px 8px; }
.summary-table .section td { background: var(--surface-2); font-weight: 700; }
.summary-table .zero { color: var(--muted); }

/* ---------- Filters ---------- */
.filters { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); align-items: end; }
.filters .field { margin: 0; }
.filters label { font-size: 0.8rem; color: var(--ink-2); }
.totals-bar { display: flex; gap: 20px; flex-wrap: wrap; font-size: 0.9rem; margin: 12px 0; color: var(--ink-2); }
.totals-bar strong { color: var(--ink); }
.pagination { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }

/* ---------- Import ---------- */
.howto { margin: 0; }
.howto dt { font-weight: 700; margin-top: 10px; }
.howto dt:first-child { margin-top: 0; }
.howto dd { margin: 2px 0 0; color: var(--ink-2); font-size: 0.92rem; }
span.label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
label.check { font-weight: 400; display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.sample-table td, .sample-table th { font-size: 0.8rem; white-space: nowrap; }
.import-summary { display: grid; gap: 8px; }
.import-table select { min-height: 32px; padding: 4px 8px; min-width: 190px; }
.import-table tr.skipped td:not(:first-child) { opacity: 0.6; }
.import-table input[type=checkbox] { width: 18px; height: 18px; }

/* ---------- Receipt scanning ---------- */
.scan-layout { display: grid; gap: 16px; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
.scan-image { position: sticky; top: 76px; padding: 10px; }
.scan-image img { display: block; width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: 6px; }
.reread { display: flex; gap: 8px; flex-wrap: wrap; }
.scanner-pick { border: 0; padding: 0; margin: 0 0 16px; display: flex; gap: 6px 18px; flex-wrap: wrap; }
.scanner-pick legend { font-weight: 600; font-size: 0.9rem; margin-bottom: 4px; padding: 0; }
.callout { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 10px 12px; background: var(--surface); font-size: 0.92rem; }
.callout-warn { border-left-color: #fab219; }
.callout-bad { border-left-color: var(--bad); background: var(--bad-wash); }
@media (max-width: 800px) {
  .scan-layout { grid-template-columns: 1fr; }
  .scan-image { position: static; }
  .scan-image img { max-height: 45vh; }
}

/* ---------- Backups ---------- */
.small-value { font-size: 1.1rem; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
textarea.mono { font-size: 0.8rem; word-break: break-all; }
code.secret { display: inline-block; margin-top: 6px; padding: 4px 8px; background: var(--surface-2); border-radius: 6px; user-select: all; word-break: break-all; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input { flex: 1; min-width: 160px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.keep-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
pre.mono { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; }

/* ---------- Auth pages ---------- */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth h1 { margin-bottom: 16px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; margin: 14px 0; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.show-sm { display: none; }
@media (max-width: 640px) {
  .hide-sm { display: none; }
  .show-sm { display: inline; }
  .colchart { padding-left: 0; }
  .colchart .yticks { display: none; }
  .stat .value { font-size: 1.4rem; }
  .colchart .plot, .colchart .xlabels { gap: 2px; }
  .colchart .xlabels span { font-size: 0.65rem; }
  .topbar-actions { margin-left: 0; width: 100%; }
  .topbar-actions .btn { flex: 1; }
}
