/* FinancePilot — оформление по общему шаблону внутренних приложений «Вкусные бочки».
   Сначала телефон (от 360 px), потом планшет (от 720 px) и компьютер (от 1000 px).
   Тёмная тема включается сама по настройке устройства. */

:root {
  --bg: #e9edf1; --surface: #ffffff; --ink: #17212b; --muted: #5a6775; --line: #cdd5dd;
  --accent: #2c43c4; --on-accent: #ffffff; --accent-soft: #e3e7fb;
  --warn: #a45a00; --warn-bg: #ffeccc; --err: #b3261e; --err-bg: #fde4e1; --ok: #1b6b3a; --ok-bg: #dff3e6;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --r: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161b; --surface: #1b222a; --ink: #e8edf2; --muted: #9aa7b5; --line: #323d49;
    --accent: #95a3ff; --on-accent: #0d1330; --accent-soft: #252c57;
    --warn: #ffb95c; --warn-bg: #463211; --err: #ff8e85; --err-bg: #4a1f1c; --ok: #7fd6a0; --ok-bg: #173a26;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; line-height: 1.25; margin: 0; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
p { margin: 0 0 12px; }
small, .muted { color: var(--muted); font-size: 13px; }
.num, td.n, th.n { font-family: var(--mono); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ───── каркас ───── */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  height: 48px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--ink); }
.who { font-size: 13px; color: var(--muted); }
.side { display: none; }
.main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); max-width: 1120px; margin: 0 auto; }
.main.solo { max-width: 420px; padding-top: 12vh; }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: flex; align-items: center; justify-content: center; height: 56px;
  font-size: 13px; color: var(--muted); border-top: 2px solid transparent;
}
.tabs a:hover { text-decoration: none; }
.tabs a.on { color: var(--accent); border-top-color: var(--accent); font-weight: 600; }
.tabs a.plus {
  margin: 6px auto; width: 56px; height: 44px; border: 0; border-radius: var(--r);
  background: var(--accent); color: var(--on-accent); font-size: 26px; font-weight: 400; line-height: 1;
}

.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.page-head > div:first-child { flex: 1 1 260px; min-width: 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page-actions:empty { display: none; }
.back { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.help { color: var(--muted); font-size: 13px; margin: 6px 0 0; max-width: 760px; }

.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.sheet > :last-child { margin-bottom: 0; }

.banner { border-radius: var(--r); padding: 12px 14px; margin-bottom: 16px; border: 1px solid transparent; }
.banner.info { background: var(--accent-soft); color: var(--ink); border-color: var(--accent); }
.banner.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.banner.err { background: var(--err-bg); color: var(--err); border-color: var(--err); }

/* ───── плитки с цифрами ───── */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; min-width: 0; }
.tile span { display: block; font-size: 13px; color: var(--muted); }
.tile b { display: block; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile small { display: block; }
.tile.accent { background: var(--accent-soft); border-color: var(--accent); }
.tile.warn b { color: var(--warn); }
.tile.err b { color: var(--err); }
.tile.ok b { color: var(--ok); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--accent-soft); color: var(--ink); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.off { background: var(--bg); color: var(--muted); text-decoration: line-through; }

/* ───── кнопки ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 6px 16px;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; text-align: center; line-height: 1.25;
}
.btn.small { white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.big { min-height: 52px; width: 100%; font-size: 16px; }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn.small { min-height: 36px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: default; }
form.inline { display: inline; }
form.inline:has(select) { display: flex; gap: 8px; align-items: center; min-width: 0; flex: 1 1 auto; }
form.inline select { min-width: 0; flex: 1 1 160px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions .btn.primary { flex: 1 1 200px; min-height: 52px; font-size: 16px; }

/* ───── формы ───── */
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.form.one { max-width: 420px; }
.f { display: block; min-width: 0; }
.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.f > small { display: block; margin-top: 4px; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 16px;
}
input.num { font-family: var(--mono); }
textarea { min-height: 72px; resize: vertical; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--accent); flex: none; }
input:required:placeholder-shown, select:required:invalid { border-left: 3px solid var(--accent); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg label { flex: 1 1 0; min-width: 0; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 2px; font-size: 13px; border-left: 1px solid var(--line); text-align: center; }
.seg label:first-child span { border-left: 0; }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -4px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }

details.more { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 4px; }
details.more > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--accent); font-weight: 500; }
details.more[open] > summary { margin-bottom: 8px; }

/* Строки «магазин — сумма» в сплитах и строки зарплаты */
.lines { display: grid; gap: 8px; }
.line { display: grid; grid-template-columns: minmax(0, 1fr) 132px; gap: 8px; align-items: center; }
.line .check { min-width: 0; }
.line .check span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.pay:first-child { border-top: 0; padding-top: 0; }
.pay .who-cell { grid-column: 1 / -1; font-weight: 600; }
.counter { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: var(--r); background: var(--bg); margin-top: 12px; }
.counter.bad { background: var(--warn-bg); color: var(--warn); }
.counter.good { background: var(--ok-bg); color: var(--ok); }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.filters .wide-f { grid-column: 1 / -1; }
.filters .btn { align-self: end; }

.kv { display: grid; grid-template-columns: minmax(110px, 38%) minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.menu-list a { display: block; padding: 12px 0; border-top: 1px solid var(--line); color: var(--ink); }
.menu-list a:first-of-type { border-top: 0; }
.menu-list a b { display: block; color: var(--accent); }
.menu-list a small { display: block; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-top: 12px; }
.empty { padding: 20px 0; color: var(--muted); text-align: center; }

/* ───── таблицы: на телефоне каждая строка — карточка ───── */
.tbl { width: 100%; border-collapse: collapse; }
.tbl thead { display: none; }
.tbl tr { display: flex; flex-wrap: wrap; align-content: flex-start; gap: 2px 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.tbl tbody tr:first-child { border-top: 0; padding-top: 0; }
.tbl td { display: flex; flex: 1 1 100%; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 0; min-width: 0; overflow-wrap: anywhere; }
.tbl td::before { content: attr(data-l); color: var(--muted); font-size: 13px; flex: none; }
.tbl td.h { flex: 0 1 auto; font-weight: 600; }
.tbl td.h::before, .tbl td[data-l=""]::before { content: none; }
.tbl td:has(> span.muted:only-child), .tbl td:empty { display: none; }
.tbl td.n { white-space: nowrap; }
.tbl td > div { text-align: right; min-width: 0; }
.tbl tfoot tr { border-top: 2px solid var(--line); font-weight: 600; }
.tbl td.pick { flex: 0 0 auto; }
.tbl .sub { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.tbl tr.off td { color: var(--muted); }
.row-form { display: contents; }

/* ───── планшет ───── */
@media (min-width: 720px) {
  .tiles { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .tile b { font-size: 20px; }
  .form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form.one { grid-template-columns: minmax(0, 1fr); }
  .form .full { grid-column: 1 / -1; }
  .filters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters .wide-f { grid-column: span 2; }
  .lines { grid-template-columns: 1fr 1fr; gap: 8px 24px; }
  .pay { grid-template-columns: minmax(140px, 1.4fr) minmax(120px, 1fr) 130px 170px auto; align-items: center; }
  .pay .who-cell { grid-column: auto; }
  .kv { grid-template-columns: 180px minmax(0, 1fr); }
  .menu-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
  .menu-list a:nth-of-type(2) { border-top: 0; }

  .scroll { overflow-x: auto; }
  .tbl:not(.big) thead { display: table-header-group; }
  .tbl:not(.big) tr, .tbl:not(.big) tbody tr:first-child { display: table-row; padding: 0; }
  .tbl:not(.big) td, .tbl:not(.big) td.h, .tbl:not(.big) td.pick { display: table-cell; padding: 8px 8px; border-top: 1px solid var(--line); vertical-align: top; font-weight: inherit; }
  .tbl:not(.big) td:has(> span.muted:only-child), .tbl:not(.big) td:empty { display: table-cell; }
  .tbl:not(.big) td::before { content: none; }
  .tbl:not(.big) td > div { text-align: left; }
  .tbl:not(.big) { font-size: 14px; }
  .tbl:not(.big) td { overflow-wrap: break-word; }
  .tbl:not(.big) td .check { display: inline-flex; min-height: 32px; margin-right: 12px; white-space: nowrap; }
  .tbl:not(.big) td.h, .tbl:not(.big) td.n { white-space: nowrap; }
  .tbl:not(.big) td:last-child { white-space: nowrap; }
  .tbl:not(.big) td input:not([type=checkbox]), .tbl:not(.big) td select { min-width: 120px; }
  .tbl:not(.big) th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 8px; white-space: nowrap; border-bottom: 1px solid var(--line); }
  .tbl:not(.big) th.n, .tbl:not(.big) td.n { text-align: right; }
  .tbl:not(.big) tbody tr:hover td { background: var(--bg); }
  .tbl:not(.big) tfoot td { border-top: 2px solid var(--line); font-weight: 600; }
  .tbl:not(.big) td.h a { font-weight: 600; }
  .tbl.big tbody { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; }
  .tbl.big tbody tr:nth-child(2) { border-top: 0; padding-top: 0; }
}

/* ───── компьютер: меню слева, таблицы на всю ширину ───── */
@media (min-width: 1000px) {
  body { display: grid; grid-template-columns: 228px minmax(0, 1fr); grid-template-rows: 48px 1fr; min-height: 100vh; }
  .top { grid-column: 1 / -1; }
  .side { display: block; position: sticky; top: 48px; align-self: start; height: calc(100vh - 48px); overflow-y: auto;
          padding: 12px 8px 24px; background: var(--surface); border-right: 1px solid var(--line); }
  .side-group { margin-bottom: 14px; }
  .side-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 10px; }
  .side a { display: block; padding: 7px 10px; border-radius: var(--r); color: var(--ink); }
  .side a:hover { background: var(--bg); text-decoration: none; }
  .side a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .tabs { display: none; }
  .main { width: 100%; margin: 0; padding: 24px 28px 48px; }
  .main.wide { max-width: none; }
  body:has(.main.solo) { display: block; }
  .main.solo { margin: 0 auto; }
  .form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form.cols4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .lines { grid-template-columns: repeat(3, 1fr); }
  .actions .btn.primary { flex: 0 0 auto; min-width: 220px; }
  .tbl.big tbody { display: table-row-group; }
  .tbl.big thead { display: table-header-group; }
  .tbl.big tr, .tbl.big tbody tr:first-child { display: table-row; padding: 0; }
  .tbl.big td, .tbl.big td.h, .tbl.big td.pick { display: table-cell; padding: 8px 8px; border-top: 1px solid var(--line); vertical-align: top; font-weight: inherit; }
  .tbl.big td:has(> span.muted:only-child), .tbl.big td:empty { display: table-cell; }
  .tbl.big td::before { content: none; }
  .tbl.big td > div { text-align: left; }
  .tbl.big { font-size: 14px; }
  .tbl.big td { overflow-wrap: break-word; }
  .tbl.big td .check { display: inline-flex; min-height: 32px; margin-right: 12px; white-space: nowrap; }
  .tbl.big td.h, .tbl.big td.n { white-space: nowrap; }
  .tbl.big td input:not([type=checkbox]), .tbl.big td select { min-width: 120px; }
  .tbl.big th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 8px; white-space: nowrap; border-bottom: 1px solid var(--line); }
  .tbl.big th.n, .tbl.big td.n { text-align: right; }
  .tbl.big th.n { white-space: normal; }
  .tbl.big td:nth-child(3) { white-space: normal; }
  .tbl.big tbody tr:hover td { background: var(--bg); }
  .tbl.big tfoot td { border-top: 2px solid var(--line); font-weight: 600; }
  .tbl.big td.h a { font-weight: 600; }
  .cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .cols > .sheet { margin-bottom: 0; }
  .cols { margin-bottom: 16px; }
}
@media print { .top, .side, .tabs, .page-actions, .btn { display: none !important; } body { background: #fff; } }
