/* «План личных финансов» — единственный файл стилей. Без JS, без внешних ресурсов. */

:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #2456c9;
  --accent-text: #ffffff;
  --inc: #17803d;
  --exp: #b8402a;
  --bal: #2456c9;
  --warn-bg: #fff3d6;
  --warn-text: #7a5200;
  --ok-bg: #e2f5e8;
  --err-bg: #fde6e2;
  --gap-bg: #fde0da;
  --cur-bg: #eef3ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-2: #222a35;
    --text: #e6eaf0;
    --muted: #9aa5b4;
    --border: #2f3946;
    --accent: #6e9bff;
    --accent-text: #0d1320;
    --inc: #4cc77a;
    --exp: #ff8a70;
    --bal: #7ea6ff;
    --warn-bg: #3d3115;
    --warn-text: #ffd27a;
    --ok-bg: #173323;
    --err-bg: #3f1d18;
    --gap-bg: #4a1f19;
    --cur-bg: #1f2a40;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
small { font-size: .82em; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.inc { color: var(--inc); }
.exp { color: var(--exp); }
.plain { list-style: none; padding: 0; margin: 0; display: grid; gap: .35rem; }

/* ---------- Шапка ---------- */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
  padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 650; }
.brand svg { width: 32px; height: 32px; flex: none; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .75rem; }
.logo-bg { fill: var(--accent); }
.logo-line { fill: none; stroke: var(--accent-text); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.top nav { display: flex; gap: .15rem; overflow-x: auto; flex: 1 1 auto; scrollbar-width: thin; }
.top nav a { padding: .4rem .7rem; border-radius: 8px; text-decoration: none; color: var(--text); white-space: nowrap; }
.top nav a:hover { background: var(--surface-2); }
.top nav a[aria-current] { background: var(--cur-bg); color: var(--accent); font-weight: 600; }
.who { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .9rem; }
.who form { margin: 0; }

main { width: 100%; max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 2rem; flex: 1; }
main.wide { max-width: 1480px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

/* ---------- Блоки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 0 0 1rem; box-shadow: var(--shadow);
}
.card.narrow { max-width: 440px; margin: 2rem auto; }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: .75rem; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .5rem 1rem; margin-bottom: .5rem; }
.card-head h2, .card-head p { margin: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; margin-right: auto; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.cols { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }

.pager, .seg { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; }
.pager a, .seg a {
  padding: .35rem .7rem; border: 1px solid var(--border); border-radius: 8px;
  text-decoration: none; background: var(--surface); white-space: nowrap;
}
.seg a[aria-current] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; display: grid; gap: .1rem; box-shadow: var(--shadow); }
.tile span { color: var(--muted); font-size: .85rem; }
.tile strong { font-size: 1.35rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile small { color: var(--muted); }
.tile.alarm { background: var(--gap-bg); border-color: var(--exp); }

.flash { padding: .65rem .9rem; border-radius: 8px; margin: 0 0 1rem; background: var(--ok-bg); }
.flash-error { background: var(--err-bg); }
.field-error { color: var(--exp); margin: .2rem 0 0; font-size: .88rem; }
.tag { display: inline-block; font-size: .75rem; padding: .05rem .45rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; vertical-align: middle; }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }
.tag.ok { background: var(--ok-bg); color: var(--inc); }

/* ---------- Формы ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"],
input[type="month"], input[type="search"], input[type="file"], select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); min-height: 2.35rem;
}
input:user-invalid, select:user-invalid { border-color: var(--exp); }
label { display: grid; gap: .25rem; font-size: .92rem; }
label.check, label.radio { display: flex; align-items: center; gap: .4rem; }
input[type="checkbox"], input[type="radio"] { width: 1.05rem; height: 1.05rem; accent-color: var(--accent); margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .8rem .8rem; margin: 0; display: grid; gap: .6rem; }
legend { padding: 0 .3rem; font-size: .92rem; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); cursor: pointer; text-decoration: none; color: var(--text); min-height: 2.35rem; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(.97); }
button.primary, .button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--exp); }
.button.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
button.link.danger { color: var(--exp); }

.stack { display: grid; gap: .75rem; }
.form-grid { display: grid; gap: .9rem 1rem; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.form-grid .span2 { grid-column: 1 / -1; }
.self-end { align-self: end; padding-bottom: .5rem; }
.form-actions { display: flex; gap: 1rem; align-items: center; }
.form-inline { display: flex; flex-wrap: wrap; gap: .6rem .8rem; align-items: end; }
.form-inline label { flex: 0 1 auto; }
.form-inline .grow { flex: 1 1 220px; }
.form-inline .check { padding-bottom: .5rem; }
.form-inline + .form-inline { margin-top: .75rem; }
.filters { padding-block: .75rem; }
.radios { display: flex; flex-wrap: wrap; gap: .5rem 1.1rem; }
.radios.compact { border: 0; padding: 0 0 .5rem; }
.months-grid { display: grid; gap: .4rem .75rem; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
.months-grid.amounts { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
.label { font-size: .92rem; }
details > summary { cursor: pointer; }
details:not(.card) { margin-top: .75rem; }
details:not(.card) > summary { color: var(--accent); }

/* Периодичность: показываем только поля выбранного варианта (CSS :has, без JS) */
@supports selector(:has(*)) {
  .freq-opt { display: none; }
  .freq:has(#freq-quarterly:checked) .f-quarterly,
  .freq:has(#freq-yearly:checked) .f-yearly,
  .freq:has(#freq-months:checked) .f-months,
  .freq:has(#freq-once:checked) .f-once { display: grid; gap: .3rem; }
}
.freq-opt label { max-width: 320px; }

/* Подтверждения в popover */
.danger-zone { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: 1rem; }
.danger-zone form { margin: 0; }
[popover].confirm {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; max-width: min(420px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / 25%);
}
[popover].confirm::backdrop { background: rgb(0 0 0 / 35%); }
[popover].confirm form { display: flex; gap: .75rem; }
[popover].confirm p { margin-top: 0; }

/* ---------- Таблицы ---------- */
.table-scroll { overflow-x: auto; max-width: 100%; }
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; }
.list th, .list td { padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.list thead th { font-size: .82rem; color: var(--muted); font-weight: 500; }
.list td small { display: block; }
.list .num, .num { text-align: right; white-space: nowrap; }
.list .grp-head th { background: var(--surface-2); font-size: .82rem; color: var(--muted); padding-block: .25rem; }
.list tr.inactive td { opacity: .55; }
.list tr.uncat td:first-child { box-shadow: inset 3px 0 var(--warn-text); }
.list.tx select { min-width: 170px; padding-block: .25rem; min-height: 2rem; }
.list.raw td, .list.raw th { font-size: .8rem; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions form { display: inline; margin: 0; }
meter { width: 100%; min-width: 80px; height: 10px; }

/* Годовая таблица */
.year { font-size: .82rem; background: var(--surface); border: 1px solid var(--border); }
.year th, .year td { padding: .3rem .45rem; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.year th.cat {
  text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1;
  min-width: 170px; max-width: 230px; white-space: normal; font-weight: 500; border-right: 1px solid var(--border);
}
.year thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; font-weight: 600; }
.year thead th.cat { z-index: 3; }
.year thead a { color: var(--text); text-decoration: none; text-transform: capitalize; }
.year td small { display: block; color: var(--muted); font-size: .72rem; }
.year .cur { background: var(--cur-bg); }
.year .kind-head th, .year .kind-head td { font-weight: 700; font-size: .88rem; background: var(--surface-2); border-top: 2px solid var(--border); }
.year tbody.income .kind-head td { color: var(--inc); }
.year tbody.expense .kind-head td { color: var(--exp); }
.year .grp-head th { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding-top: .55rem; font-weight: 600; }
.year td.worse { color: var(--exp); font-weight: 600; }
.year td.better { color: var(--inc); }
.year td.total { font-weight: 600; background: var(--surface-2); }
.year tfoot th, .year tfoot td { font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--border); }
.year tfoot .neg { color: var(--exp); }
.year tfoot .pos { color: var(--inc); }
.year tfoot .balance td { font-size: .88rem; }
.year td.gap { background: var(--gap-bg); color: var(--exp); }
.year .vac td, .year .vac th { font-size: .74rem; color: var(--muted); }
.vac-mark { display: inline-block; background: var(--warn-bg); color: var(--warn-text); border-radius: 99px; padding: 0 .4rem; }
span.worse { color: var(--exp); font-weight: 600; }
span.better { color: var(--inc); }

/* SVG-диаграмма */
.chart-card { padding: .75rem; margin-inline: 0; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { stroke: var(--muted); stroke-width: 1.2; }
.chart .tick { fill: var(--muted); font-size: 12px; }
.chart .inc { fill: var(--inc); opacity: .85; }
.chart .exp { fill: var(--exp); opacity: .85; }
.chart .now { fill: var(--cur-bg); }
.chart .bal { fill: none; stroke: var(--bal); stroke-width: 2.5; stroke-linejoin: round; }
.chart .bal-dot { fill: var(--surface); stroke: var(--bal); stroke-width: 2; }
.chart .bal-dot.neg { stroke: var(--exp); fill: var(--exp); }
.legend { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; font-size: .85rem; margin-top: .4rem; }
.lg::before { content: ""; display: inline-block; width: .8em; height: .8em; border-radius: 2px; margin-right: .35em; vertical-align: -.05em; }
.lg.inc::before { background: var(--inc); }
.lg.exp::before { background: var(--exp); }
.lg.bal::before { height: 3px; vertical-align: .2em; background: var(--bal); }
.lg { color: var(--text); }

@media (max-width: 640px) {
  :root { font-size: 14px; }
  h1 { font-size: 1.35rem; }
  .who { width: 100%; justify-content: space-between; }
  .card { padding: .85rem; }
  .tile strong { font-size: 1.15rem; }
}

@media print {
  .top nav, .who, .actions, .pager, .seg, .danger-zone, .foot { display: none; }
  body { background: #fff; }
  .card, .tile { box-shadow: none; }
}
