/* ---------- Design tokens (светлая/тёмная тема) ---------- */
:root {
  color-scheme: light;
  --surface-0: #f9f9f7;
  --surface-1: #fcfcfb;
  --surface-2: #f1f0ec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --baseline: #c3c2b7;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --success-text: #006300;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06), 0 1px 8px rgba(11, 11, 11, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #0d0d0d;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --baseline: #383835;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --status-good: #0ca30c;
    --status-warning: #fab219;
    --status-serious: #ec835a;
    --status-critical: #e66767;
    --success-text: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #0d0d0d;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --baseline: #383835;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --status-good: #0ca30c; --status-warning: #fab219; --status-serious: #ec835a; --status-critical: #e66767;
  --success-text: #0ca30c;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--surface-0);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px 60px; }

/* ---------- Navigation ---------- */
.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 56px;
}
.brand { font-weight: 700; margin-right: 16px; white-space: nowrap; }
.brand span { color: var(--series-1); }
.nav-link {
  color: var(--text-secondary); padding: 8px 10px; border-radius: 8px; font-size: 14px;
  white-space: nowrap;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }

/* ---------- Layout helpers ---------- */
.page-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 28px 0 18px; flex-wrap: wrap;
}
.page-header h1 { margin: 0; font-size: 22px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }
.stat-tile .stat-label { color: var(--text-muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.stat-tile .stat-value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-tile .stat-sub { color: var(--text-secondary); font-size: 13px; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); padding: 8px 14px; font-size: 14px;
  cursor: pointer; font-family: inherit;
}
.btn:hover { filter: brightness(0.97); text-decoration: none; }
.btn-primary { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: transparent; border-color: var(--status-critical); color: var(--status-critical); }
.btn-danger:hover { background: var(--status-critical); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); font-family: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }
.field { margin-bottom: 14px; }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.help { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--gridline); }
th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges / tags ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border);
}
.amount-income { color: var(--success-text); font-weight: 600; }
.amount-expense { color: var(--text-primary); font-weight: 600; }
.amount-transfer { color: var(--text-secondary); font-weight: 600; }

/* ---------- Flash messages ---------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; font-size: 14px; border: 1px solid transparent; }
.flash-success { background: rgba(12, 163, 12, 0.10); color: var(--success-text); border-color: rgba(12,163,12,.25); }
.flash-error { background: rgba(208, 59, 59, 0.10); color: var(--status-critical); border-color: rgba(208,59,59,.25); }

/* ---------- Progress bars (бюджеты) ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--series-1); border-radius: 999px; }
.progress.over > span { background: var(--status-critical); }

/* ---------- Charts (SVG) ---------- */
.chart { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: var(--gridline); stroke-width: 1; }
.chart-axis-label { fill: var(--text-muted); font-size: 11px; }
.donut-hole { fill: var(--surface-1); }
.bar, .donut-seg { transition: opacity .15s; }
.bar:hover, .donut-seg:hover { opacity: .85; }
.line { stroke: var(--series-1); stroke-width: 2; }
.dot { fill: var(--surface-1); stroke: var(--series-1); stroke-width: 2; }
.series-1 { stroke: var(--series-1); fill: var(--series-1); }
.series-2 { stroke: var(--series-2); fill: var(--series-2); }
.series-3 { stroke: var(--series-3); fill: var(--series-3); }
.series-4 { stroke: var(--series-4); fill: var(--series-4); }
.series-5 { stroke: var(--series-5); fill: var(--series-5); }
.series-6 { stroke: var(--series-6); fill: var(--series-6); }
.series-7 { stroke: var(--series-7); fill: var(--series-7); }
.series-8 { stroke: var(--series-8); fill: var(--series-8); }

.legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; font-size: 13px; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* ---------- Misc ---------- */
.muted { color: var(--text-muted); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.icon-swatch {
  width: 34px; height: 34px; border-radius: 9px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 17px; background: var(--surface-2);
}
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; }
.kv .k { color: var(--text-secondary); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 24px 0 10px; }
.pill-tabs { display: flex; gap: 6px; }
.pill-tabs a { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); font-size: 13px; color: var(--text-secondary); }
.pill-tabs a.active { background: var(--series-1); border-color: var(--series-1); color: #fff; }

/* ---------- Сканирование чека ---------- */
/* Кнопка в шапке выделена цветом: с телефона в магазине это самый частый
   вход в приложение, искать её среди прочих ссылок неудобно. */
.nav-scan {
  padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
  white-space: nowrap; background: var(--series-3); color: #fff; margin-right: 8px;
}
.nav-scan:hover { filter: brightness(1.08); text-decoration: none; }
.nav-scan.active { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55); }

/* Кнопка-камера: палец попадает без прицеливания, поэтому во всю ширину
   и высотой заметно больше обычной кнопки. Сам input скрыт — клик по нему
   передаёт label. */
.scan-shot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; width: 100%; min-height: 170px; padding: 24px;
  border: 2px dashed var(--series-3); border-radius: var(--radius);
  background: color-mix(in srgb, var(--series-3) 8%, transparent);
  color: var(--series-3); font-size: 18px; font-weight: 600; cursor: pointer;
  text-align: center;
}
.scan-shot:hover { filter: brightness(1.03); }
.scan-shot .scan-shot-icon { font-size: 44px; line-height: 1; }
.scan-shot .scan-shot-hint { font-size: 13px; font-weight: 400; color: var(--text-secondary); }
.scan-shot input[type="file"] { display: none; }

.scan-amount { font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums; }
.scan-items { border-top: 1px solid var(--border); margin-top: 12px; }
.scan-items .scan-item {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.scan-items .scan-item .qty { color: var(--text-muted); font-size: 12px; }
.scan-items .scan-item .sum { font-variant-numeric: tabular-nums; white-space: nowrap; }

@media (max-width: 640px) {
  .topbar-inner { padding: 8px 16px; }
  table { font-size: 13px; }
  /* На телефоне кнопка сканера должна оставаться на виду рядом с логотипом,
     даже когда остальные ссылки переносятся на вторую строку. */
  .nav-scan { order: -1; margin-left: auto; }
}
