/* ---- Theme tokens ------------------------------------------------------ */
:root {
  color-scheme: light;
  --page: #f3f3ef;
  --surface: #fcfcfb;
  --surface-2: #efeee9;
  --text: #15171b;
  --text-2: #4b4a46;
  --muted: #6a6862;
  --border: #e1e0d9;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ee;
  --pos: #006300;
  --neg: #b42318;
  --warn: #b25e00;
  --focus: #2a78d6;
  /* charts */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --hover: rgba(11, 11, 11, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #f2f2ef;
    --text-2: #c3c2b7;
    --muted: #9a988f;
    --border: #2e2e2b;
    --accent: #2dd4bf;
    --accent-hover: #5eead4;
    --accent-ink: #06201d;
    --accent-soft: #12302c;
    --pos: #4cc27a;
    --neg: #f07575;
    --warn: #f5b041;
    --focus: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c2a;
    --axis: #383835;
    --hover: rgba(255, 255, 255, 0.05);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242422;
  --text: #f2f2ef;
  --text-2: #c3c2b7;
  --muted: #9a988f;
  --border: #2e2e2b;
  --accent: #2dd4bf;
  --accent-hover: #5eead4;
  --accent-ink: #06201d;
  --accent-soft: #12302c;
  --pos: #4cc27a;
  --neg: #f07575;
  --warn: #f5b041;
  --focus: #6da7ec;
  --series-1: #3987e5;
  --series-2: #d95926;
  --grid: #2c2c2a;
  --axis: #383835;
  --hover: rgba(255, 255, 255, 0.05);
}

/* ---- Base ------------------------------------------------------------- */
* { box-sizing: border-box; }
html { background: var(--page); }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--page); color: var(--text); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { margin: 0 0 10px; font-size: 17px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.hint { color: var(--muted); font-size: 13px; font-weight: normal; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---- Header & navigation ---------------------------------------------- */
header.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { max-width: 1100px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface); }
nav.main { display: flex; gap: 2px; overflow-x: auto; flex: 1 1 auto; min-width: 0; }
nav.main a { padding: 6px 10px; border-radius: 6px; color: var(--text-2); text-decoration: none; white-space: nowrap; font-size: 14px; }
nav.main a:hover { background: var(--hover); color: var(--text); }
nav.main a.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.user { display: flex; gap: 12px; align-items: center; margin-left: auto; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }

/* ---- Cards, tiles, tables --------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; margin-bottom: 16px; min-width: 0; }
.card.attention { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.tile .delta { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: var(--hover); }
tr.transfer td { color: var(--muted); }
tr.muted td { color: var(--muted); }
.desc a { color: var(--text); text-decoration: none; }
.desc a:hover { text-decoration: underline; }

/* ---- Controls ---------------------------------------------------------- */
button, .button { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 6px; padding: 7px 14px; cursor: pointer; font: inherit; font-weight: 600; text-decoration: none; display: inline-block; }
button:hover, .button:hover { background: var(--accent-hover); color: var(--accent-ink); }
button.secondary, .button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); font-weight: 500; }
button.secondary:hover, .button.secondary:hover { background: var(--hover); color: var(--text); }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
button.link:hover { color: var(--accent-hover); background: none; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); max-width: 100%; }
select.compact { padding: 2px 4px; font-size: 13px; max-width: 150px; }
form { display: inline; }
form.block { display: block; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; max-width: 520px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--text-2); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.js .set-btn { display: none; }
details summary { cursor: pointer; color: var(--text-2); }
details[open] summary { margin-bottom: 8px; }

/* ---- Badges, flashes, tabs --------------------------------------------- */
.badge { display: inline-block; font-size: 12px; padding: 0 7px; border-radius: 10px; border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); border-color: transparent; color: var(--text); }
.badge.warn { border-color: var(--warn); color: var(--text); }
.badge.warn::before { content: "!"; display: inline-block; width: 13px; height: 13px; margin-right: 5px; border-radius: 50%; background: var(--warn); color: var(--surface); font-size: 10px; font-weight: 800; line-height: 13px; text-align: center; vertical-align: 0; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid var(--border); background: var(--surface); }
.flash.success { border-color: var(--pos); box-shadow: inset 4px 0 0 var(--pos); }
.flash.error { border-color: var(--neg); box-shadow: inset 4px 0 0 var(--neg); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.tabs a { padding: 6px 12px; border-radius: 6px; text-decoration: none; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); }
.tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.login { max-width: 360px; margin: 40px auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 4px; }

/* ---- Budget meter ------------------------------------------------------ */
progress.meter { appearance: none; -webkit-appearance: none; width: 100%; min-width: 80px; height: 8px; border: 0; border-radius: 4px; background: var(--surface-2); color: var(--series-1); vertical-align: middle; }
progress.meter::-webkit-progress-bar { background: var(--surface-2); border-radius: 4px; }
progress.meter::-webkit-progress-value { background: var(--series-1); border-radius: 4px; }
progress.meter::-moz-progress-bar { background: var(--series-1); border-radius: 4px; }
progress.meter.over { color: var(--neg); }
progress.meter.over::-webkit-progress-value { background: var(--neg); }
progress.meter.over::-moz-progress-bar { background: var(--neg); }

/* ---- Charts ------------------------------------------------------------ */
.viz { width: 100%; height: auto; display: block; }
.viz text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; }
.viz .tick { fill: var(--muted); font-variant-numeric: tabular-nums; }
.viz .label { fill: var(--text-2); font-size: 12px; }
.viz .value { fill: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }
.viz .grid { stroke: var(--grid); stroke-width: 1; }
.viz .axis { stroke: var(--axis); stroke-width: 1; }
.viz .s1 { fill: var(--series-1); }
.viz .s2 { fill: var(--series-2); }
.viz .area { opacity: 0.1; }
.viz .s1-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .end-dot { stroke: var(--surface); stroke-width: 2; }
.viz .hit, .viz .hit-dot { fill: transparent; }
.viz .band:hover .hit { fill: var(--hover); }
.viz .hit-dot:hover { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.viz .budget-mark { fill: var(--text-2); }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.key.s1 { background: var(--series-1); }
.key.s2 { background: var(--series-2); }
.key.mark { width: 2px; height: 12px; border-radius: 0; background: var(--text-2); }

@media (max-width: 640px) {
  .card { padding: 14px; }
  .user .who { display: none; }
}
.mt { margin-top: 16px; }
