:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #eeeeea;
  --line: #e2e1dc;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #75746f;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-fact: #2a78d6;
  --series-plan: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warn: #fab219;
  --warn-text: #8a5a00;
  --crit: #d03b3b;
  --crit-text: #b52f2f;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #262624;
    --line: #33332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9d9c92;
    --accent: #3987e5;
    --series-fact: #3987e5;
    --series-plan: #d95926;
    --series-3: #199e70;
    --good-text: #5fce5f;
    --warn-text: #fab219;
    --crit-text: #e66767;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-variant-numeric: tabular-nums; }
body.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0 0 .5rem; font-weight: 650; }
h3 { font-size: .9rem; margin: 0 0 .4rem; }
a { color: inherit; }
.muted { color: var(--text-3); font-weight: 400; }
.sub { color: var(--text-2); font-size: .875rem; margin: .25rem 0; }
.neg, .crit-text { color: var(--crit-text); }
.pos { color: var(--good-text); }
.error { color: var(--crit-text); margin: .5rem 0; }

/* шапка */
.admin-bar { background: var(--crit); color: #fff; text-align: center; font-size: .8rem; font-weight: 600; padding: .2rem .5rem; }
body.admin .topbar { top: 0; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem; background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 1rem; height: 52px; }
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { position: relative; text-decoration: none; color: var(--text-2); padding: .4rem .7rem; border-radius: 8px; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { color: var(--text); background: var(--surface-2); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; margin-left: .35rem; padding: 0 .35rem; border-radius: 9px; background: var(--crit); color: #fff; font-size: .75rem; line-height: 18px; text-align: center; font-weight: 600; }
.logout { margin: 0; }
.who { color: var(--text-2); text-decoration: none; font-size: .875rem; white-space: nowrap; }
.who:hover { text-decoration: underline; }
.pw-warn { display: block; padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); font-size: .875rem; text-decoration: none; }
.tiles.two { grid-template-columns: 1.3fr 1fr; }
.tiles.three { grid-template-columns: repeat(3, 1fr); }
.small-big { font-size: 1.4rem; white-space: normal; overflow-wrap: anywhere; }
.tiles > *, .card, .page > * { min-width: 0; }
.big.word { font-size: 1.15rem; line-height: 1.25; white-space: normal; }
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .5rem .8rem; text-decoration: none; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); font-weight: 600; border-color: var(--accent); }
.narrow { max-width: 440px; display: grid; gap: .75rem; }
.op-note { margin: -.2rem 0 .5rem; font-size: .8rem; }
.cat-text { font-size: .85rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; justify-self: start; }
.seg label { display: block; cursor: pointer; }
.seg input { position: absolute; opacity: 0; }
.seg span { display: block; padding: .4rem .9rem; color: var(--text-2); }
.seg input:checked + span { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.link { background: none; border: 0; color: var(--text-2); cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.link.danger { color: var(--crit-text); text-decoration: none; }

.page { max-width: 980px; margin: 0 auto; padding: 1rem 1rem 6rem; display: grid; gap: 1rem; }
.page.wide { max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head p { margin: .2rem 0 0; }
.month-nav { justify-content: flex-start; gap: .75rem; }
.month-nav h1, .month-nav h2 { margin: 0; }
.month-nav h1::first-letter, .month-nav h2::first-letter { text-transform: uppercase; }

/* карточки */
.card, .tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .5rem; }
.card-head h2 { margin: 0; }
.tiles { display: grid; gap: 1rem; grid-template-columns: 1.3fr 1fr 1fr; }
.tile h2 { color: var(--text-2); font-weight: 500; font-size: .875rem; margin: 0; }
.big { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; margin: .15rem 0 .25rem; line-height: 1.15; white-space: nowrap; }
.today { margin: .6rem 0 0; font-size: .9rem; }
.status { font-weight: 600; white-space: nowrap; }
.status.good { color: var(--good-text); }
.status.warn { color: var(--warn-text); }
.status.crit { color: var(--crit-text); }
.banner { display: flex; gap: .4rem; flex-wrap: wrap; align-items: baseline; padding: .7rem 1rem; border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 10px; background: var(--surface); text-decoration: none; }
.banner .go { margin-left: auto; font-weight: 600; }
.empty { text-align: center; padding: 2.5rem 1rem; }

/* подсказки */
.hints { display: grid; gap: .4rem; }
.hint { display: flex; gap: .6rem; align-items: baseline; padding: .55rem .8rem; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); border-left-width: 4px; text-decoration: none; font-size: .9rem; }
.hint .mark { font-weight: 700; flex-shrink: 0; width: 1.1em; text-align: center; }
.hint.info .mark { display: inline-block; border: 1.5px solid currentColor; border-radius: 50%; font-size: .7em; line-height: 1.3; width: 1.4em; height: 1.4em; font-style: italic; font-family: Georgia, serif; }
.hint.crit { border-left-color: var(--crit); } .hint.crit .mark { color: var(--crit-text); }
.hint.warn { border-left-color: var(--warn); } .hint.warn .mark { color: var(--warn-text); }
.hint.good { border-left-color: var(--good); } .hint.good .mark { color: var(--good-text); }
.hint.info { border-left-color: var(--accent); } .hint.info .mark { color: var(--accent); }

.carry-link { margin-left: auto; }
.carry-head { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; margin-bottom: .5rem; }
.carry-row { display: grid; grid-template-columns: 140px 1fr auto; gap: .6rem; align-items: end; }
.carry-line { grid-template-columns: 1fr 0 110px 20px; }
.small { font-size: .78rem; font-weight: 400; }
@media (max-width: 760px) { .carry-row { grid-template-columns: 1fr; } }

/* шкала */
.meter { display: block; height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: .4rem 0; }
.meter i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.meter.near i { background: var(--warn); }
.meter.over i { background: var(--crit); }

/* таблица статей */
.sumline { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; padding: .5rem 0 1rem; border-bottom: 1px solid var(--line); }
.sumline div { display: grid; gap: .05rem; }
.sumline strong { font-size: 1.15rem; }
.sumline span { font-size: .8rem; }
.group { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; margin: 1rem 0 .35rem; font-size: .95rem; }
.group .muted { font-size: .8rem; }
.group-total { margin-left: auto; font-weight: 500; color: var(--text-2); font-size: .85rem; }
.rows { display: grid; }
.row { display: grid; grid-template-columns: minmax(120px, 1.6fr) minmax(50px, 1.4fr) 90px 90px; gap: .75rem; align-items: center; text-decoration: none; padding: .35rem .25rem; border-radius: 6px; }
.row:hover { background: var(--surface-2); }
.row .meter { margin: 0; }
.row .val { text-align: right; font-size: .9rem; white-space: nowrap; }

/* таблицы */
.scroll { overflow-x: auto; }
table.num { border-collapse: collapse; width: 100%; font-size: .875rem; }
table.num th, table.num td { padding: .35rem .5rem; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.num th:first-child, table.num td:first-child { text-align: left; }
table.num thead th { color: var(--text-3); font-weight: 500; }
details.mini { margin-top: .5rem; font-size: .875rem; }
details.mini summary { cursor: pointer; color: var(--text-2); }
ul.plain { list-style: none; margin: .25rem 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; gap: 1rem; padding: .15rem 0; }
.ahead { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; font-size: .9rem; }
.ahead h3::first-letter { text-transform: uppercase; }

/* график */
.chart { position: relative; min-height: 260px; }
.chart svg { display: block; width: 100%; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .axis.strong { fill: var(--text-2); font-weight: 600; }
.chart .goal { stroke: var(--text-3); stroke-width: 1; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.fact { stroke: var(--series-fact); }
.chart .line.plan { stroke: var(--series-plan); }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart .dot.fact { fill: var(--series-fact); }
.chart .dot.plan { fill: var(--series-plan); }
.chart .cross { stroke: var(--text-3); stroke-width: 1; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; font-size: .8rem; box-shadow: 0 2px 10px rgb(0 0 0 / .12); white-space: nowrap; }
.legend { display: flex; flex-shrink: 0; white-space: nowrap; gap: .9rem; font-size: .8rem; color: var(--text-2); }
.key { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: .35rem; vertical-align: middle; }
.key.fact { background: var(--series-fact); }
.key.plan { background: var(--series-plan); }
.key.interest, .key.s3 { background: var(--series-3); }
.key.s1 { background: var(--series-fact); }
.key.s2 { background: var(--series-plan); }
.chart .line.interest, .chart .line.s3 { stroke: var(--series-3); }
.chart .dot.interest, .chart .dot.s3 { fill: var(--series-3); }
.chart .line.s1 { stroke: var(--series-fact); } .chart .dot.s1 { fill: var(--series-fact); }
.chart .line.s2 { stroke: var(--series-plan); } .chart .dot.s2 { fill: var(--series-plan); }
.chart .bar.fact { fill: var(--series-fact); }
.chart .bar.plan { fill: var(--series-plan); }
.chart .bar.over, .chart .bar.neg-bar { fill: var(--crit); }
.key.neg-bar, .key.over { background: var(--crit); }
.chart .base { stroke: var(--text-3); stroke-width: 1; }
.chart .label { fill: var(--text-2); font-size: 12px; }
.chart .label.value { fill: var(--text); font-weight: 600; }
.chart .plan-mark { stroke: var(--text); stroke-width: 2; }
.tiles.four { grid-template-columns: repeat(4, 1fr); }
.dep .card-head { align-items: flex-start; }
.danger-text { color: var(--crit-text); }
.dep-form { margin-top: .75rem; display: grid; gap: .75rem; }

/* кнопки и поля */
.btn { display: inline-block; border: 1px solid transparent; border-radius: 10px; padding: .55rem .95rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(.95); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: .25rem .6rem; }
.btn.wide { width: 100%; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; min-width: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .op:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: .2rem; font-size: .875rem; color: var(--text-2); }
label.check { display: flex; align-items: center; gap: .4rem; }
.row-end { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .75rem; }
form.inline { display: flex; flex-wrap: wrap; align-items: end; gap: .5rem; margin-top: .75rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.login { width: min(420px, 100%); display: grid; gap: .75rem; }
.qr { display: grid; place-items: center; padding: .5rem; background: #fff; border-radius: 10px; }
.qr svg { width: 200px; height: 200px; }
.secret { font-size: .85rem; color: var(--text-2); overflow-wrap: anywhere; }
.secret code { font-size: .95rem; }

/* разбор */
#inbox { display: grid; gap: .6rem; }
.op { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; transition: opacity .15s; }
.op.gone { opacity: .3; pointer-events: none; }
.op-main { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-bottom: .5rem; }
.op-title { display: grid; min-width: 0; }
.op-title strong { overflow-wrap: anywhere; }
.op-title .muted { font-size: .8rem; }
.op-amount { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.quiet-row { margin-top: .35rem; }
.quiet-row .chip { font-size: .8rem; padding: .3rem .55rem; }
.chip { font: inherit; font-size: .85rem; line-height: 1.2; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .4rem .65rem; border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--surface-2); }
.chip.hint { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.quiet { color: var(--text-2); background: var(--surface-2); border-color: transparent; }
select.chip.more { width: 5.2rem; padding-right: .3rem; }
.split-row { display: grid; grid-template-columns: 110px 1fr; gap: .4rem; margin-bottom: .4rem; }

/* операции */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters input[type=search] { flex: 1 1 160px; }
.list { padding: 0; }
.line { display: grid; grid-template-columns: 1fr 210px 110px 20px; gap: .75rem; align-items: center; padding: .55rem .9rem; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line-main { display: grid; min-width: 0; }
.line-main strong { font-weight: 500; overflow-wrap: anywhere; }
.line-main .muted { font-size: .8rem; }
.line-amount { text-align: right; font-weight: 600; white-space: nowrap; }
.line select { font-size: .85rem; padding: .3rem .4rem; width: 100%; }

/* загрузка */
.drop { display: grid; justify-items: center; gap: .4rem; padding: 2rem 1rem; border-style: dashed; border-width: 2px; }
.drop.over { border-color: var(--accent); background: var(--surface-2); }
.drop p { margin: 0; }
.how { margin: 0; padding-left: 1.2rem; display: grid; gap: .35rem; color: var(--text-2); font-size: .9rem; }
.result { margin: .25rem 0 .6rem; }

/* план */
.plan-scroll { max-height: 75vh; overflow: auto; }
table.plan { width: max-content; }
table.plan th.sticky { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 500; min-width: 190px; z-index: 1; }
table.plan thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; }
table.plan thead th.sticky { z-index: 3; }
table.plan td { padding: 0 .1rem; }
.group-row th, .group-row td { font-weight: 650; background: var(--surface-2) !important; padding: .35rem .5rem !important; }
.cell { width: 84px; border: 1px solid transparent; background: transparent; text-align: right; padding: .3rem .4rem; border-radius: 6px; font-size: .85rem; }
.cell:hover { border-color: var(--line); }
.over-cell { color: var(--crit-text); font-weight: 700; }
.ok-cell { color: var(--good-text); }
table.plan tfoot .group-row:first-child th, table.plan tfoot .group-row:first-child td { border-top: 2px solid var(--text-3); }

/* нижние элементы */
.fab { position: fixed; right: 1.1rem; bottom: calc(1.1rem + env(safe-area-inset-bottom)); width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 1.8rem; line-height: 1; cursor: pointer; box-shadow: 0 4px 14px rgb(0 0 0 / .25); z-index: 20; }
dialog.sheet { border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; width: min(440px, calc(100vw - 2rem)); background: var(--surface); color: var(--text); }
dialog.sheet::backdrop { background: rgb(0 0 0 / .4); }
dialog.sheet form { display: grid; gap: .6rem; }
dialog.sheet h2 { margin: 0; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1.3rem + env(safe-area-inset-bottom)); background: var(--text); color: var(--surface); padding: .55rem .95rem; border-radius: 10px; z-index: 30; font-size: .9rem; max-width: calc(100vw - 7rem); }
.toast .link { color: inherit; font-weight: 600; margin-left: .5rem; }

@media (max-width: 760px) {
  .topbar { height: auto; flex-wrap: wrap; gap: 0 .75rem; padding: .4rem .75rem 0; }
  .brand { flex: 1; }
  .nav a { flex: 0 0 auto; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; scrollbar-width: none; margin: 0 -.25rem; }
  .nav { justify-content: flex-start; margin: 0 -.3rem; gap: .1rem; overflow-x: auto; }
  .nav a { padding: .4rem .3rem; font-size: .82rem; }
  .badge { margin-left: .2rem; min-width: 16px; line-height: 16px; font-size: .7rem; padding: 0 .25rem; }
  .hide-sm { display: none; }
  .page { padding: .75rem .75rem 6rem; gap: .75rem; }
  .tiles, .tiles.two, .tiles.three { grid-template-columns: 1fr; gap: .75rem; }
  .tiles.four { grid-template-columns: 1fr 1fr; gap: .75rem; }
  .big { font-size: 1.8rem; }
  .sumline { grid-template-columns: 1fr 1fr; }
  .sumline div:last-child { grid-column: span 2; }
  .row { grid-template-columns: 1fr 76px 76px; gap: .15rem .5rem; padding: .4rem .1rem; }
  .row .name { grid-column: 1; }
  .row .meter { grid-column: 1 / -1; grid-row: 2; }
  .row .val { font-size: .85rem; }
  .line { grid-template-columns: 1fr auto 18px; }
  .line select { grid-column: 1 / -1; grid-row: 2; }
  .chip { padding: .5rem .7rem; }
}
