:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1d2420;
  --muted: #667069;
  --line: #e2dfd6;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --net: #2f8f77;
  --tax: #9aa39d;
  --extra: #d9822b;
  --other: #b9a24a;
  --bad: #b3372f;
  --ok-bg: #e5f2ec;
  --err-bg: #fbe9e7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06);
}
:root:not([data-theme="light"]) { color-scheme: light dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131815; --surface: #1b221e; --surface-2: #232b26; --text: #e8ece9; --muted: #98a39c;
    --line: #2d3731; --accent: #4fb89d; --accent-ink: #0d1411; --net: #4fb89d; --tax: #6f7a73;
    --extra: #e89a4b; --other: #cdb55a; --bad: #ef7d73; --ok-bg: #1d3029; --err-bg: #3a2220;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-in { max-width: 1080px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 20px; min-height: 54px; flex-wrap: wrap; }
.brand { font-weight: 700; letter-spacing: -.01em; text-decoration: none; color: var(--text); }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { color: var(--accent); background: var(--surface-2); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid > .card { margin-top: 0 !important; }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 860px) { .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.cols-3, .grid.cols-2 { grid-template-columns: 1fr; } }

.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.55rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }

.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; border: 1px solid var(--line); }
.flash.ok { background: var(--ok-bg); }
.flash.error { background: var(--err-bg); border-color: var(--bad); }
.notice { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; font-size: .92rem; }
.warn-text { color: var(--bad); }

table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th.num, td.num { text-align: right; }
tr.forecast td { color: var(--muted); font-style: italic; }
tfoot td { font-weight: 700; border-bottom: none; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

.btn, button {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-weight: 500; text-decoration: none; display: inline-block;
}
.btn:hover, button:hover { background: var(--surface-2); }
.btn.primary, button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
button.link { border: 0; background: none; padding: 0; color: var(--bad); font-size: .85rem; }
button.link:hover { text-decoration: underline; background: none; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=checkbox], input[type=radio] { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: .95rem; margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg label { margin: 0; padding: 8px 14px; cursor: pointer; color: var(--text); font-size: .95rem; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { font-weight: 700; color: var(--accent); }
.seg label:has(input:checked) { background: var(--surface-2); }

.progress { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; }
.progress.passed > div { background: var(--extra); }

/* столбчатая диаграмма по месяцам */
.chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; align-items: end; height: 190px; }
.chart .col { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; }
.chart .bar { display: flex; flex-direction: column-reverse; border-radius: 5px 5px 0 0; overflow: hidden; min-height: 2px; }
.chart .bar.forecast { opacity: .45; }
.chart .bar.empty { background: var(--surface-2); height: 2px !important; }
.chart .seg-net { background: var(--net); }
.chart .seg-tax { background: var(--tax); }
.chart .seg-extra { background: var(--extra); }
.chart .seg-other { background: var(--other); }
.chart-labels { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; margin-top: 6px; text-align: center; font-size: .75rem; color: var(--muted); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; font-size: .85rem; color: var(--muted); }

/* бюджет */
.cat-row { display: grid; grid-template-columns: minmax(0, 160px) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: .92rem; }
.cat-bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.cat-bar > div { height: 100%; background: var(--accent); }
.hist { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; height: 120px; align-items: end; }
.hist .pair { display: flex; gap: 3px; align-items: flex-end; height: 100%; }
.hist .pair div { flex: 1; border-radius: 4px 4px 0 0; min-height: 2px; }
.hist .inc { background: var(--net); }
.hist .exp { background: var(--extra); }
.pos { color: var(--net); }
.neg { color: var(--bad); }
.month-nav { display: flex; align-items: center; gap: 8px; }
.month-nav a { padding: 6px 12px; }
.year-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.year-tabs a { padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.year-tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

details summary { cursor: pointer; color: var(--muted); }
pre.raw { white-space: pre; overflow-x: auto; font-size: .78rem; background: var(--bg); padding: 12px; border-radius: 8px; border: 1px solid var(--line); }
.log td { font-size: .85rem; }
.log .error { color: var(--bad); }
.log .warn { color: var(--other); }
.login-box { max-width: 360px; margin: 12vh auto 0; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .9em; }
ol.steps { padding-left: 1.2rem; margin: .4rem 0; }
ol.steps li { margin: .25rem 0; }

@media (max-width: 640px) {
  .topbar-in { gap: 2px 12px; padding-top: 8px; padding-bottom: 8px; }
  .nav { flex: 1 1 100%; order: 3; gap: 2px; }
  .nav a { padding: 6px 9px; font-size: .92rem; }
  .chart, .chart-labels { gap: 3px; }
  .chart-labels { font-size: .62rem; }
  .stat .value { font-size: 1.3rem; }
}
