/* Спокойный деловой стиль. Светлая тема — базовая, тёмная переопределяет
   переменные: явным выбором через [data-theme="dark"] и системным
   предпочтением, когда выбрана тема "system". */

:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2563eb;
  --income: #059669;
  --expense: #dc2626;
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262a33;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #5b8cff;
  --income: #34d399;
  --expense: #f87171;
}

@media (prefers-color-scheme: dark) {
  [data-theme="system"] {
    --bg: #0f1115;
    --panel: #171a21;
    --border: #262a33;
    --text: #e6e8ec;
    --muted: #9aa1ad;
    --accent: #5b8cff;
    --income: #34d399;
    --expense: #f87171;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Раскладка */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex: 0 0 220px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar .brand {
  font-weight: 600;
  padding: 0 10px 16px;
  letter-spacing: 0.01em;
}

.sidebar .brand span { color: var(--accent); }

.sidebar a {
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius);
}

.sidebar a:hover { background: var(--bg); text-decoration: none; }
.sidebar a.on { background: var(--bg); color: var(--accent); font-weight: 500; }

.content { flex: 1; padding: 24px 28px; max-width: 1200px; }

.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

/* Панели и формы */

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  min-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card h1 { margin: 0; font-size: 20px; font-weight: 600; }

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input, select, textarea, button {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
}

button.secondary {
  background: var(--panel);
  color: var(--text);
  border-color: var(--border);
}

.hint { color: var(--muted); font-size: 13px; margin: 0; }
.error { color: var(--expense); font-size: 13px; margin: 0; }

.banner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 20px;
}

/* Таблицы и суммы */

table { width: 100%; border-collapse: collapse; background: var(--panel); }

th, td {
  text-align: left;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-weight: 500;
}

tbody tr:last-child td { border-bottom: none; }

.money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.income { color: var(--income); }
.expense { color: var(--expense); }
.muted { color: var(--muted); }

/* Страницы */

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
}

.panel h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.panel table { border: none; }

.columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }

/* auto-fit, а не фиксированные 4 колонки: плиток может быть 4 или 5,
   и пятая не должна уезжать одна на новую строку. */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.tile-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.tile-value { font-size: 22px; font-weight: 600; margin-top: 6px; text-align: left; }
.tile-note { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Формы фильтров и разметки */

.filters, .inline { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters label, .inline label { flex: 0 1 auto; }

.stack { display: flex; flex-direction: column; gap: 14px; }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

legend { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: auto; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 13px; }
.facts dd { margin: 0; }

.purpose { max-width: 380px; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .columns { grid-template-columns: 1fr; }
}

.row-actions { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.banner.error { border-left-color: var(--expense); color: var(--expense); }
tr.muted td { color: var(--muted); }

.qr { background: #fff; padding: 12px; border-radius: var(--radius); width: max-content; margin: 14px 0; }
.qr svg { display: block; width: 220px; height: 220px; }
.codes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
  list-style: none;
  padding: 0;
  font-variant-numeric: tabular-nums;
}
.break { word-break: break-all; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

/* Обёртка графика. Высота обязана быть явной: Chart.js работает с
   maintainAspectRatio=false и тянется по высоте родителя. Если родитель
   меряется по содержимому, канвас и родитель начинают тянуть друг друга,
   и страница растёт вниз без конца. */
.chart {
  position: relative;
  height: 260px;
  margin-top: 8px;
}

.chart canvas {
  display: block;
}

/* Панель массовой разметки под списком операций. */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.secondary-link { margin-left: 12px; color: var(--muted); }
