/* Дизайн-система «Финдиректора».
   1) Токены: цвета, отступы, радиусы. Меняйте их, чтобы перекрасить всю программу.
   2) Каркас: боковое меню, шапка, контент.
   3) Компоненты: плитка показателя, блок, таблица отчёта, фильтры, пустое состояние, графики.
   Описание и примеры — docs/design-system.md. */

:root {
  --ink: #1b2330;          /* основной текст */
  --quiet: #687385;        /* подписи */
  --line: #e4e8ee;         /* линии и рамки */
  --bg: #f4f6f9;           /* фон страницы */
  --card: #ffffff;         /* фон блоков */
  --hover: #f0f4fa;
  --accent: #2563eb;       /* ссылки, кнопки, активный пункт */
  --accent-soft: #e6eefc;

  /* Смысловые цвета: факт насыщенный, план светлый и пунктиром */
  --income: #2f9e6f;       /* доходы, поступления */
  --expense: #e0703c;      /* расходы, выплаты */
  --profit: #2563eb;       /* прибыль, разница */
  --total: #3b82f6;        /* общий остаток */
  --muted: #b7c0cc;        /* «остальные» на графиках */
  --plan: #2563eb;         /* плановые строки и цифры — синие */
  --neg: #d63c3c;          /* минус, разрыв */
  --good: #2f9e6f;
  --warn: #c98a12;
  --warn-soft: #fff4d6;

  /* Палитра долей (кольца, структура) */
  --s0: #2563eb; --s1: #2f9e6f; --s2: #e0703c; --s3: #8b5cf6; --s4: #0ea5b7;
  --s5: #d9a21b; --s6: #db5a8c; --s7: #94a3b8;

  /* Каркас */
  --side: #16213d;         /* боковое меню: тёмно-синий в тон логотипу */
  --side-ink: #c5cede;
  --side-on: #24315a;
  --side-w: 208px;

  --r: 10px;               /* радиус блоков */
  --gap: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #e6e9ef; --quiet: #98a2b3; --line: #2c3442; --bg: #11151c; --card: #181e28; --hover: #1f2733;
    --accent: #6b9bff; --accent-soft: #1d2a44; --income: #45c08b; --expense: #f08a55; --profit: #6b9bff;
    --total: #6b9bff; --muted: #4b5563; --plan: #6b9bff; --neg: #f06666; --warn-soft: #3a2f12;
    --side: #0c1017; --side-on: #1f2733;
  }
}
:root[data-theme="dark"] {
  --ink: #e6e9ef; --quiet: #98a2b3; --line: #2c3442; --bg: #11151c; --card: #181e28; --hover: #1f2733;
  --accent: #6b9bff; --accent-soft: #1d2a44; --income: #45c08b; --expense: #f08a55; --profit: #6b9bff;
  --total: #6b9bff; --muted: #4b5563; --plan: #6b9bff; --neg: #f06666; --warn-soft: #3a2f12;
  --side: #0c1017; --side-on: #1f2733;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; font-weight: 650; }
h2 { font-size: 17px; margin: 20px 0 10px; font-weight: 600; }
code { background: var(--hover); padding: 1px 4px; border-radius: 4px; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }

/* Меню: наш логотип, разделы одной строкой со значком, пункты раздела — всплывающим списком справа.
   Кнопка «‹» сворачивает меню до значков (запоминается в браузере); справочники и настройки — внизу. */
.rail { background: var(--side); color: var(--side-ink); position: sticky; top: 0; height: 100vh; z-index: 30;
  display: flex; flex-direction: column; padding: 14px 10px 12px; gap: 2px; }
.rail .brand-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 0 2px 0 6px; margin-bottom: 16px; min-height: 40px; }
.rail .brand { display: block; line-height: 0; }
.rail .brand .logo { width: 140px; height: auto; }
.rail .brand .mark { display: none; width: 34px; height: 34px; }
.rail .mini-toggle { width: 26px; height: 26px; border: 0; border-radius: 6px; background: none; color: var(--side-ink); opacity: .55; cursor: pointer; display: grid; place-items: center; padding: 0; }
.rail .mini-toggle:hover { opacity: 1; background: var(--side-on); }
.rail .mini-toggle svg { width: 16px; height: 16px; }
.rail .rail-gap { flex: 1; min-height: 16px; }
.rail .ri { position: relative; }
.rail .rl { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: var(--side-ink);
  font-size: 14px; white-space: nowrap; text-decoration: none; }
.rail .rl svg { width: 20px; height: 20px; flex: none; opacity: .8; }
.rail .ri:hover > .rl, .rail .ri.open > .rl, .rail .rl:focus-visible { background: var(--side-on); color: #fff; }
.rail .ri.on > .rl { background: var(--accent); color: #fff; }
.rail .ri.on > .rl svg { opacity: 1; }
.rail .ri.soon .rl { opacity: .45; cursor: default; }
.rail .rx { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; padding: 0; border: 0; border-radius: 5px;
  background: none; color: inherit; opacity: .45; cursor: pointer; display: grid; place-items: center; }
.rail .ri.on .rx { color: #fff; }
.rail .rx svg { width: 13px; height: 13px; }
.rail .rx:hover, .rail .rx:focus-visible { opacity: 1; }
.rail .fly { display: none; position: absolute; left: calc(100% + 10px); top: -6px; width: 236px; padding: 8px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(16, 24, 40, .18); z-index: 40; }
.rail .fly::before { content: ""; position: absolute; left: -12px; top: 0; width: 12px; height: 100%; }   /* мостик: мышь не теряет список */
.rail .ri.has-fly:hover > .fly, .rail .ri.open > .fly { display: block; }
.rail .ri[data-sec="refs"] .fly, .rail .ri[data-sec="settings"] .fly, .rail .ri[data-sec="ext"] .fly { top: auto; bottom: -6px; }
.rail .fly-title { font-size: 12px; font-weight: 650; color: var(--quiet); text-transform: uppercase; letter-spacing: .04em; padding: 4px 10px 6px; }
.rail .fly a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 7px; color: var(--ink); font-size: 14px; white-space: nowrap; text-decoration: none; }
.rail .fly a:hover, .rail .fly a:focus-visible { background: var(--hover); }
.rail .fly a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.rail .fly a small, .subnav a small { margin-left: auto; font-size: 10px; color: var(--quiet); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
/* Свёрнутое меню: только значки и знак «И» из логотипа */
html.nav-mini { --side-w: 64px; }
html.nav-mini .rail { padding-left: 8px; padding-right: 8px; }
html.nav-mini .rail .brand-row { flex-direction: column; padding: 0; gap: 8px; }
html.nav-mini .rail .brand .logo { display: none; }
html.nav-mini .rail .brand .mark { display: block; }
html.nav-mini .rail .mini-toggle svg { transform: rotate(180deg); }
html.nav-mini .rail .rl { justify-content: center; padding: 10px 0; }
html.nav-mini .rail .rl > span, html.nav-mini .rail .rx { display: none; }

/* Второй уровень: вкладки раздела над страницей и свой список слева у «Настроек» */
.sectabs { display: flex; gap: 2px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: -6px 0 18px; }
.sectabs a { padding: 8px 12px; color: var(--quiet); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14px; white-space: nowrap; }
.sectabs a:hover { color: var(--ink); text-decoration: none; }
.sectabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.with-subnav { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.subnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 90px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 8px; }
.subnav a { display: flex; align-items: center; padding: 7px 10px; border-radius: 7px; color: var(--ink); font-size: 14px; }
.subnav a:hover { background: var(--hover); text-decoration: none; }
.subnav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.subnav a[href="/settings/corridors"] { padding-left: 22px; font-size: 13px; }

/* Меню пользователя в шапке */
.usermenu { position: relative; }
.usermenu > summary { list-style: none; cursor: pointer; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--hover); color: var(--ink); }
.usermenu > summary::-webkit-details-marker { display: none; }
.usermenu .pop { position: absolute; right: 0; top: calc(100% + 6px); width: 230px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 30; }
.usermenu .pop > a { padding: 6px 8px; border-radius: 6px; color: var(--ink); }
.usermenu .pop > a:hover { background: var(--hover); text-decoration: none; }
.theme-pick { display: flex; gap: 4px; margin-bottom: 6px; }
.theme-pick button { flex: 1; padding: 5px 4px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 6px; cursor: pointer; font-size: 12px; }
.theme-pick button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* Телефон: нижняя панель и «Ещё» */
.tabbar, .more { display: none; }

.page { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 24px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.cashbox { position: relative; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.cashbox:hover { background: var(--hover); }
.cashbox .label { font-size: 12px; color: var(--quiet); }
.cashbox .sum { font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cashbox .alert { font-size: 12px; color: var(--neg); }
.cashbox .gap { font-size: 12px; color: var(--warn); }
.popover { display: none; position: absolute; right: 0; top: calc(100% + 6px); min-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 12px 14px; cursor: default; }
.cashbox.open .popover { display: block; }
.popover .ent { font-weight: 600; display: flex; justify-content: space-between; margin: 8px 0 4px; }
.popover .acc { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0 2px 10px; font-size: 13px; }
.popover .acc .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); margin-right: 6px; }
.popover .acc.neg .dot { background: var(--neg); }

main { padding: 20px 24px 40px; max-width: 1480px; width: 100%; }

/* ---------- Блоки и плитки ---------- */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.block { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.block.wide { grid-column: 1 / -1; }
.block-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.block-head h2 { margin: 0; font-size: 16px; }
.block-head .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.block-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.block-body.single { grid-template-columns: 1fr; }

.tiles { display: flex; flex-direction: column; gap: 12px; }
.tiles.row { flex-direction: row; flex-wrap: wrap; }
.tile { min-width: 160px; }
.tile .t { font-size: 12px; color: var(--quiet); }
.tile .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.25; }
.tile .v.neg { color: var(--neg); }
.tile .v.good { color: var(--good); }
.tile .p { font-size: 12px; color: var(--plan); }       /* значение «по плану» под цифрой */
.tile .h { font-size: 11px; color: var(--quiet); }

/* Старые карточки страниц отчётов (cards/card) — тот же вид, что у плиток */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; box-shadow: var(--shadow); }
.card b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }

/* Переключатели (вкладки, метод учёта) */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg a, .seg span { padding: 4px 10px; font-size: 12px; color: var(--quiet); border-right: 1px solid var(--line); }
.seg a:last-child, .seg span:last-child { border-right: 0; }
.seg a:hover { background: var(--hover); text-decoration: none; }
.seg .on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg .off { opacity: .5; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--quiet); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend i.c-income { background: var(--income); } .legend i.c-expense { background: var(--expense); }
.legend i.c-profit { background: var(--profit); height: 3px; vertical-align: 3px; }
.legend i.c-owner { background: #8b5cf6; height: 3px; vertical-align: 3px; }
.legend i.plan { background: transparent; border: 1.5px dashed var(--quiet); }

/* Пустое состояние */
.empty { text-align: center; padding: 28px 16px; color: var(--quiet); border: 1px dashed var(--line); border-radius: var(--r); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; font-size: 15px; }
.empty .btn { margin-top: 10px; }

/* Список «требует внимания» */
.todo { list-style: none; margin: 0; padding: 0; }
.todo li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.todo li:last-child { border-bottom: 0; }
.todo .n { font-weight: 650; font-variant-numeric: tabular-nums; }
.ok { color: var(--good); }

/* ---------- Таблицы ---------- */
table { border-collapse: collapse; width: 100%; background: var(--card); }
.block table { background: transparent; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--quiet); font-size: 12px; background: var(--card); position: sticky; top: 0; }
tr:hover > td { background: var(--hover); }
td.n, th.n { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.trend, th.trend { width: 96px; text-align: center; }
tr.section td { font-weight: 600; background: var(--bg); }
tr.total td { font-weight: 650; border-top: 2px solid var(--line); }
td.plan, .plan-val { color: var(--plan); }
.scroll { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.scroll > table { border-radius: var(--r); }
table.first-wide td:first-child { min-width: 260px; }
.scroll td:first-child, .scroll th:first-child { position: sticky; left: 0; background: inherit; }
.scroll tr > td:first-child { background: var(--card); }
.scroll tr.section > td:first-child { background: var(--bg); }

/* Дерево статей: строка раздела сворачивает свои строки (static/findir.js) */
tbody.grp > tr.section td:first-child { cursor: pointer; }
tbody.grp > tr.section td:first-child::before { content: "▾"; display: inline-block; width: 14px; color: var(--quiet); transition: transform .15s; }
tbody.grp.collapsed > tr.section td:first-child::before { transform: rotate(-90deg); }
tbody.grp.collapsed > tr:not(.section) { display: none; }
td.indent { padding-left: 28px; }

.nowrap { white-space: nowrap; }
.neg { color: var(--neg); }
.quiet { color: var(--quiet); font-size: 12px; }
.err { color: var(--neg); margin: 8px 0; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; border: 1px solid var(--line); color: var(--quiet); }
.tag.manual { border-color: var(--good); color: var(--good); }
.tag.review { border-color: var(--warn); color: var(--warn); }

/* Значок риска контрагента (данные даёт расширение) */
.risk { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 6px; vertical-align: 1px; }
.risk.low { background: var(--good); } .risk.mid { background: var(--warn); } .risk.high { background: var(--neg); }

/* ---------- Формы и фильтры ---------- */
form.inline { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.auto-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; padding: 0 !important; border: 0 !important; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: 12px; color: var(--quiet); }
.filters label:has(input[type=checkbox]) { flex-direction: row; align-items: center; gap: 6px; }
.filters .presets { display: flex; gap: 4px; align-self: center; }
.filters .presets a { font-size: 12px; padding: 3px 8px; border-radius: 6px; background: var(--hover); color: var(--ink); }
input, select, button, textarea { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
button, .btn { cursor: pointer; background: var(--accent); color: #fff; border: 1px solid var(--accent); border-radius: 7px; padding: 5px 12px; display: inline-block; }
.btn:hover { text-decoration: none; filter: brightness(1.05); }
button.plain, .btn.plain { background: var(--card); color: var(--ink); border-color: var(--line); }

/* ---------- Графики (findir/charts.py) ---------- */
svg.chart { width: 100%; height: auto; display: block; overflow: visible; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .grid.zero { stroke: var(--quiet); }
svg .axis { fill: var(--quiet); font-size: 11px; }
svg rect.c-income { fill: var(--income); } svg rect.c-expense { fill: var(--expense); }
svg rect.c-muted { fill: var(--muted); }
svg rect.plan { fill-opacity: .35; stroke-dasharray: 3 2; stroke-width: 1; }
svg rect.c-income.plan { stroke: var(--income); } svg rect.c-expense.plan { stroke: var(--expense); }
svg .line { fill: none; stroke-width: 2.2; }
svg .line.c-profit, svg line.c-profit { stroke: var(--profit); } svg .line.c-total { stroke: var(--total); }
svg .line.neg { stroke: var(--neg); }
svg .line.plan { stroke-dasharray: 5 4; }
svg .dot { stroke: var(--card); stroke-width: 1.5; }
svg .line.c-owner { stroke: #8b5cf6; stroke-dasharray: 2 3; } svg .dot.c-owner { fill: #8b5cf6; }
svg .dot.c-profit { fill: var(--profit); } svg .dot.neg { fill: var(--neg); }
svg .fill.c-total { fill: var(--total); fill-opacity: .12; }
svg .thin { fill: none; stroke: var(--quiet); stroke-width: 1; stroke-opacity: .55; }
svg .min { stroke: var(--neg); stroke-dasharray: 4 4; stroke-width: 1; }
svg .today { stroke: var(--quiet); stroke-dasharray: 2 3; }
svg .hover { fill: transparent; }
svg .hover:hover { fill: var(--hover); fill-opacity: .5; }
svg.spark { vertical-align: middle; }
svg.spark polyline { fill: none; stroke: var(--total); stroke-width: 1.6; }
svg.spark circle { fill: var(--total); }
svg.spark.neg polyline { stroke: var(--neg); } svg.spark.neg circle { fill: var(--neg); }
svg.spark .zero { stroke: var(--line); }
svg.donut .seg { fill: none; stroke-width: 22; }
svg.donut .donut-total { fill: var(--ink); font-size: 15px; font-weight: 650; }
.s0 { stroke: var(--s0); --c: var(--s0); } .s1 { stroke: var(--s1); --c: var(--s1); } .s2 { stroke: var(--s2); --c: var(--s2); }
.s3 { stroke: var(--s3); --c: var(--s3); } .s4 { stroke: var(--s4); --c: var(--s4); } .s5 { stroke: var(--s5); --c: var(--s5); }
.s6 { stroke: var(--s6); --c: var(--s6); } .s7 { stroke: var(--s7); --c: var(--s7); }
.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut-legend { flex: 1; min-width: 200px; font-size: 13px; }
.donut-legend div { display: flex; gap: 8px; padding: 3px 0; }
.donut-legend i { width: 10px; height: 10px; border-radius: 2px; background: var(--c); margin-top: 4px; flex: none; }
.donut-legend span:nth-child(2) { flex: 1; }
.donut-legend .n { font-variant-numeric: tabular-nums; }

/* Настройка главной */
.widget-list { list-style: none; padding: 0; margin: 0; max-width: 720px; }
.widget-list li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.widget-list li .d { flex: 1; }
.widget-list li .d small { display: block; color: var(--quiet); }
.widget-list li.off { opacity: .55; }

/* ---------- Узкий экран ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: var(--side); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  .tabbar a, .tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; font-size: 11px; color: var(--side-ink); background: none; border: 0; border-radius: 8px; text-decoration: none; }
  .tabbar svg { width: 22px; height: 22px; }
  .tabbar a.on, .tabbar button[aria-expanded="true"] { color: #fff; background: var(--side-on); }
  .more:not([hidden]) { display: block; position: fixed; inset: 0 0 60px 0; overflow-y: auto; z-index: 39; background: var(--bg); padding: 16px; }
  .more section { margin-bottom: 14px; }
  .more h3 { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--quiet); text-transform: uppercase; letter-spacing: .04em; margin: 0 0 6px; }
  .more a { display: block; padding: 10px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; color: var(--ink); }
  .more a.on { border-color: var(--accent); color: var(--accent); }
  body { padding-bottom: 64px; }
  .with-subnav { grid-template-columns: 1fr; }
  .subnav { position: static; flex-direction: row; flex-wrap: wrap; }
  .sectabs { flex-wrap: nowrap; overflow-x: auto; }
  .topbar { padding: 8px 16px; }
  main { padding: 16px; }
  .grid { grid-template-columns: 1fr; }
  .block-body { grid-template-columns: 1fr; }
  .tiles { flex-direction: row; flex-wrap: wrap; }
  .popover { min-width: 280px; right: -8px; }
  .seg { flex-wrap: wrap; }
  .block { overflow-x: auto; padding: 14px; }
}

/* ---------- Формы ввода (этап 1) ---------- */
.entry .block { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--quiet); }
.form-grid label.wide { grid-column: 1 / -1; }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.form-grid input, .form-grid select { width: 100%; }
.form-grid input[type=checkbox] { width: auto; }
table.parts select { min-width: 260px; }
.summary { border-left: 4px solid var(--accent); }
.summary p { margin: 4px 0; }
.block.err { border-left: 4px solid var(--neg); }
.cashbox .gap { display: block; color: var(--warn); font-weight: 600; }
.cashbox .gap:hover { text-decoration: underline; }
table.calendar th.today { color: var(--accent); }
table.calendar td .plan-val { font-size: 12px; }
.gaps { border-left: 4px solid var(--neg); margin-bottom: 14px; }
.block.wide { margin-bottom: 14px; }
tr.overdue td:first-child { border-left: 3px solid var(--neg); }

/* Этап 3: дерево статей в отчётах, бюджеты */
td.indent.d1 { padding-left: 48px; }
td.indent.d2 { padding-left: 68px; }
td.indent.d3 { padding-left: 88px; }
tr.parent td { font-weight: 550; }
tr.sub td { color: var(--quiet); font-weight: 550; }
.budget input.cell { width: 96px; text-align: right; padding: 4px 6px; font: inherit; font-variant-numeric: tabular-nums; }
.budget td.n.bad, .budget .bad { color: var(--neg); }
.budget td.n.good { color: var(--income); }
.budget .pf { white-space: nowrap; line-height: 1.35; }
.budget .pf small { display: block; color: var(--quiet); font-size: 12px; }
button.danger { color: var(--neg); }
.arts select { max-width: 150px; }
.arts td { vertical-align: middle; padding-left: 6px; padding-right: 6px; }
.arts input[name=name] { width: 210px; }
.arts td.indent.d1 input[name=name] { width: 200px; }
.nowrap { white-space: nowrap; }

/* Юнит-экономика: карточка «цифра → вывод → как считаем». */
.ucards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin-bottom: 10px; }
.ucard { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px; border-top: 3px solid var(--accent); }
.ucard.good { border-top-color: var(--good); }
.ucard.warn { border-top-color: var(--warn); }
.ucard.bad { border-top-color: var(--neg); }
.ucard.missing { border-top-color: var(--line); background: transparent; box-shadow: none; }
.ucard .t { font-size: 13px; color: var(--quiet); }
.ucard .v { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0 4px; }
.ucard .verdict { font-size: 14px; margin-bottom: 6px; }
.ucard .how, .ucard .need { font-size: 12px; color: var(--quiet); }
.ucard .parts { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--quiet); margin-top: 6px; }
.ucard .parts b { font-weight: 600; color: var(--ink); }
.ucard .chg { font-size: 13px; font-weight: 600; margin-left: 6px; }
.ucard .chg.up { color: var(--good); }
.ucard .chg.down { color: var(--neg); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 12px; font-size: 13px; }
.checks label { display: flex; gap: 6px; align-items: center; }

/* Показатели PRO: линии рентабельности и средняя пунктиром. */
svg .line.c-income { stroke: var(--income); } svg .dot.c-income { fill: var(--income); }
svg .line.c-expense { stroke: var(--expense); } svg .dot.c-expense { fill: var(--expense); }
svg .line.avg { stroke-dasharray: 5 4; stroke-width: 1.2; opacity: .7; }
.legend i.avg { background: transparent; border-top: 1.5px dashed var(--quiet); height: 0; vertical-align: 3px; }
.legend i.c-total { background: var(--total); height: 3px; vertical-align: 3px; }
td.n .chg { display: block; font-size: 11px; color: var(--quiet); }
td.n .chg.up { color: var(--good); } td.n .chg.down { color: var(--neg); }
.pro td:first-child { min-width: 200px; } .pro td.n { white-space: nowrap; }

/* ---------- Прогноз по сценариям ---------- */
svg .line.c-s0, svg .line.c-s0.neg { stroke: var(--s0); } svg .dot.c-s0, svg .dot.c-s0.neg { fill: var(--s0); }
svg .line.c-s1, svg .line.c-s1.neg { stroke: var(--s1); } svg .dot.c-s1, svg .dot.c-s1.neg { fill: var(--s1); }
svg .line.c-s2, svg .line.c-s2.neg { stroke: var(--s2); } svg .dot.c-s2, svg .dot.c-s2.neg { fill: var(--s2); }
svg .line.c-s3, svg .line.c-s3.neg { stroke: var(--s3); } svg .dot.c-s3, svg .dot.c-s3.neg { fill: var(--s3); }
svg .line.c-s4, svg .line.c-s4.neg { stroke: var(--s4); } svg .dot.c-s4, svg .dot.c-s4.neg { fill: var(--s4); }
svg .line.c-s5, svg .line.c-s5.neg { stroke: var(--s5); } svg .dot.c-s5, svg .dot.c-s5.neg { fill: var(--s5); }
svg .line.c-s6, svg .line.c-s6.neg { stroke: var(--s6); } svg .dot.c-s6, svg .dot.c-s6.neg { fill: var(--s6); }
svg .line.c-s7, svg .line.c-s7.neg { stroke: var(--s7); } svg .dot.c-s7, svg .dot.c-s7.neg { fill: var(--s7); }
.legend i.c-s0 { background: var(--s0); } .legend i.c-s1 { background: var(--s1); } .legend i.c-s2 { background: var(--s2); }
.legend i.c-s3 { background: var(--s3); } .legend i.c-s4 { background: var(--s4); } .legend i.c-s5 { background: var(--s5); }
.legend i.c-s6 { background: var(--s6); } .legend i.c-s7 { background: var(--s7); }
.drivers { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; margin: 12px 0 var(--gap); align-items: start; }
.drivers details.block { padding: 10px 14px; }
.drivers summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.drivers details[open] { grid-column: 1 / -1; }
.ucard .chg.up { color: var(--good); } .ucard .chg.down { color: var(--neg); }

/* ---------- ИИ-помощник ---------- */
pre.code { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.filters label.check { flex-direction: row; align-items: center; gap: 6px; font-size: 14px; color: var(--ink); flex-basis: 100%; }

/* ---------- Список операций: одна строка на операцию ---------- */
table.ops { table-layout: fixed; }
table.ops th:nth-child(1) { width: 30px; }
table.ops th:nth-child(2) { width: 118px; }
table.ops th:nth-child(4) { width: 130px; }
table.ops th:nth-child(5) { width: 27%; }
table.ops th:nth-child(6) { width: 40px; }
table.ops.pats th:nth-child(2) { width: auto; }
table.ops.pats th:nth-child(3) { width: 80px; }
table.ops.pats th:nth-child(4) { width: 130px; }
table.ops.pats th:nth-child(5) { width: 24%; }
table.ops.pats th:nth-child(6) { width: 150px; }
table.ops.pats td.opx .opx-main { white-space: normal; }
table.ops td { vertical-align: top; padding-top: 7px; padding-bottom: 7px; }
/* Контрагент — строкой, назначение — под ним до двух строк; статья целиком */
td.opx { min-width: 0; }
td.opx .opx-main { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.opx .opx-purpose, td.opx small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  color: var(--quiet); font-size: 13px; line-height: 1.35; }
td.opx .opx-purpose:hover { color: var(--accent); }
.opx-acc { display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.art-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; color: var(--ink); padding: 2px 6px; margin: -2px -6px;
  border-radius: 6px; }
a.art-pick:hover { background: var(--accent-soft); color: var(--ink); }
.ops-view { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 6px 0 10px; }
.bulkbar { position: sticky; bottom: 0; z-index: 7; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .6em .8em; box-shadow: 0 -4px 12px rgba(0,0,0,.1); }
.bulkbar[hidden] { display: none; }
.bulkbar select { max-width: 320px; }
/* «Сменить статью»: панель сбоку и отдельной страницей */
.change-panel { max-width: 760px; }
.change-panel h3 { margin: 16px 0 6px; font-size: 15px; }
.cp-op { display: grid; gap: 4px; padding: 10px 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.cp-op-head { display: flex; justify-content: space-between; gap: 10px; }
.cp-purpose { white-space: pre-wrap; }
.cp-sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 16px; padding: 4px 10px; cursor: pointer; font: inherit; font-size: 13px; }
.chip:hover, .chip.on { border-color: var(--accent); background: var(--accent-soft); }
.cp-search { width: 100%; margin-bottom: 6px; }
.cp-list { width: 100%; }
.cp-list optgroup { font-style: normal; color: var(--quiet); }
.cp-list option { color: var(--ink); padding: 2px 4px; }
.cp-scope { display: grid; gap: 4px; }
.cp-conds { margin: 8px 0 0; padding: 8px 10px; border-left: 3px solid var(--accent-soft); }
.cp-conds[hidden] { display: none; }
.cp-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-check { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 16px; padding: 3px 10px; font-size: 13px; cursor: pointer; }
.chip-check:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.js-result { margin-top: 12px; }
.js-result.loading { opacity: .55; }
.cp-total { font-size: 15px; }
.cp-examples td { vertical-align: top; }
.cp-ex-text span, .cp-ex-text small { display: block; }
.cp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; position: sticky; bottom: 0; background: var(--card); padding: 10px 0 4px; }
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-back { position: absolute; inset: 0; background: rgba(16, 24, 40, .35); }
.drawer-box { position: absolute; top: 0; right: 0; bottom: 0; width: min(720px, 96vw); background: var(--card); overflow-y: auto;
  padding: 16px 22px 0; box-shadow: -8px 0 24px rgba(16, 24, 40, .18); }
.drawer-x { position: absolute; top: 8px; right: 10px; font-size: 22px; line-height: 1; }
body.drawer-open { overflow: hidden; }
/* «Что попало в статью»: образец назначения — главная колонка */
table.review td.tpl { min-width: 22em; max-width: 46em; }
table.review td { vertical-align: top; }
table.review .row-acts { display: flex; flex-direction: column; gap: .3em; align-items: stretch; }
table.review .row-acts button { white-space: nowrap; }
.movebar { position: sticky; bottom: 0; z-index: 5; background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: .6em .8em; box-shadow: 0 -4px 12px rgba(0,0,0,.08); align-items: center; }
td.clip, .clip-in { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.clip a { color: var(--ink); }
td.clip a:hover { color: var(--accent); }
tr.unalloc > td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
td.art { overflow: visible; }
details.pick { position: relative; }
details.pick > summary { list-style: none; display: flex; align-items: center; gap: 6px; cursor: pointer; padding: 2px 6px; margin: -2px -6px; border-radius: 6px; min-width: 0; }
details.pick > summary::-webkit-details-marker { display: none; }
details.pick > summary:hover, details.pick[open] > summary { background: var(--accent-soft); }
details.pick > summary .clip-in { min-width: 0; }
details.pick > summary .tag { flex: none; }
.pick-form { position: absolute; right: 0; top: calc(100% + 6px); z-index: 6; width: 320px; display: flex; flex-direction: column; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 12px; }
.pick-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--quiet); }
.pick-form select { width: 100%; }
.pick-form button { align-self: flex-start; }
@media (min-width: 901px) { .scroll:has(> table.ops) { overflow: visible; } }   /* иначе окно выбора статьи обрезается внизу */

/* ---------- Шапка: где я, поиск, быстрое добавление ---------- */
.topbar .crumbs { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .crumbs .quiet { font-size: 14px; font-weight: 400; }
.topbar .crumbs .sep { color: var(--line); }
.topsearch { position: relative; display: flex; align-items: center; }
.topsearch svg { position: absolute; left: 9px; width: 16px; height: 16px; color: var(--quiet); pointer-events: none; }
.topsearch input { width: 300px; padding-left: 31px; background: var(--bg); border-color: transparent; }
.topsearch input:focus { background: var(--card); }
.btn.addop { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.btn.addop svg { width: 16px; height: 16px; }
/* Окно создания (ui.modal): открывается ссылкой на #new, закрывается ссылкой на # */
.modal { display: none; position: fixed; inset: 0; z-index: 30; align-items: flex-start; justify-content: center; padding: 8vh 16px; }
.modal:target { display: flex; }
.modal .shade { position: absolute; inset: 0; background: rgba(16, 24, 40, .45); }
.modal .box { position: relative; background: var(--card); border-radius: var(--r); box-shadow: 0 12px 32px rgba(16, 24, 40, .2);
  padding: 16px 20px; width: 100%; max-width: 760px; max-height: 84vh; overflow: auto; }
.modal .box .filters { margin-bottom: 0; }
.modal .box > .block-head { justify-content: space-between; }
.cashbox svg.spark { opacity: .9; }
@media (max-width: 1400px) { .topsearch input { width: 220px; } }
@media (max-width: 1100px) { .topsearch input { width: 200px; } }
@media (max-width: 900px) {
  .topbar { gap: 10px; }
  .topbar .crumbs, .topsearch { display: none; }
  .btn.addop span { display: none; }
  .btn.addop { padding: 5px 8px; }
}


/* ---------- Отчёты: красный только у итогов, шапка таблицы не уезжает ---------- */
/* Расходы в строках отчёта — обычным цветом (знак «−» и так виден); минус в итогах и разрывы — красным. */
.scroll:not(.budget) > table:not(.ops) tr:not(.total):not(.sub) > td.n.neg { color: inherit; }
/* Широкие отчёты прокручиваются внутри блока, поэтому шапка с месяцами и первая колонка остаются на месте. */
.scroll:not(:has(> table.ops)) { max-height: calc(100vh - 110px); overflow: auto; }
.scroll th { z-index: 2; box-shadow: inset 0 -1px 0 var(--line); }
.scroll th:first-child { z-index: 3; background: var(--card); }
/* В списке операций шапка прилипает под верхней панелью страницы. */
@media (min-width: 901px) { table.ops th { top: 71px; z-index: 4; } }

/* ---------- Графики: подсказка при наведении, подписи на телефоне ---------- */
.chart-tip { position: fixed; z-index: 50; display: none; pointer-events: none; white-space: pre-line; max-width: 320px;
  background: var(--ink); color: var(--card); font-size: 12px; line-height: 1.5; padding: 6px 9px; border-radius: 6px;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .2); font-variant-numeric: tabular-nums; }
svg .hover:hover { fill: var(--accent); fill-opacity: .06; }
@media (max-width: 900px) {
  /* Графики шириной 1100 сжимаются до экрана телефона: держим минимальную ширину (блок прокручивается вбок) и крупнее подписи. */
  :has(> svg.chart) { overflow-x: auto; min-width: 0; max-width: 100%; }
  svg.chart { min-width: 680px; }
  svg .axis { font-size: 17px; }
}

/* ---------- Телефон: компактные фильтры, отчёты, операции карточками ---------- */
@media (max-width: 900px) {
  h1 { font-size: 20px; }
  .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 10px; }
  .filters label { min-width: 0; }
  .filters input, .filters select { width: 100%; min-width: 0; }
  .filters label:has(input[name=q]), .filters label:has(input[type=checkbox]), .filters .presets { grid-column: 1 / -1; }
  .filters > button, .filters > .btn { grid-column: 1 / -1; justify-self: stretch; }
  /* В отчётах мини-тренд прячем: на узком экране важнее цифры */
  td.trend, th.trend { display: none; }
  .scroll td:first-child, .scroll th:first-child { min-width: 150px; max-width: 190px; }
  table.first-wide td:first-child { min-width: 150px; }
  .scroll:not(:has(> table.ops)) { max-height: calc(100vh - 80px); }

  /* Список операций карточками: дата и сумма сверху, ниже контрагент, назначение и статья */
  .scroll:has(> table.ops) { overflow: visible; background: transparent; border: 0; }
  table.ops, table.ops tbody { display: block; background: transparent; }
  table.ops tr:first-child { display: none; }
  table.ops tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; margin-bottom: 8px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
  table.ops td { display: block; padding: 0; border: 0; position: static; background: transparent !important; }
  table.ops td:nth-child(1) { display: none; }
  table.ops td:nth-child(2) { grid-column: 1; grid-row: 1; color: var(--quiet); font-size: 12px; }
  table.ops td:nth-child(2) .opx-acc { display: none; }
  table.ops td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; }
  table.ops td:nth-child(4) { grid-column: 2; grid-row: 1; font-weight: 650; }
  table.ops td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; margin-top: 4px; }
  table.ops td[colspan] { grid-column: 1 / -1; }
  tr.unalloc { box-shadow: inset 3px 0 0 var(--neg); }
  tr.unalloc > td:first-child { box-shadow: none; }
  .pick-form { left: 0; right: auto; width: min(320px, calc(100vw - 56px)); }
}

/* Карточка выбора (ui.choice) */
.choices { display: grid; gap: 10px; max-width: 640px; }
.choice { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--r); cursor: pointer; }
.choice:hover { border-color: var(--accent); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .ic svg { width: 22px; height: 22px; color: var(--accent); }
.choice .t { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.choice .t small { color: var(--quiet); font-size: 13px; }
.choice .mark { width: 18px; height: 18px; border: 1.5px solid var(--muted); border-radius: 50%; flex: none; }
.choice input[type=checkbox] ~ .mark { border-radius: 5px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice:has(input:checked) .mark { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--card); }
.choice:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.badge { font-style: normal; font-size: 12px; font-weight: 600; color: #fff; background: var(--good); border-radius: 999px; padding: 1px 8px; vertical-align: 1px; }

/* Шаги-таблетки (ui.stepper) и низ шага (ui.step_nav) */
.stepper { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 22px; padding: 4px; background: var(--hover); border-radius: 999px; width: fit-content; max-width: 100%; }
.stepper li { padding: 5px 12px; border-radius: 999px; font-size: 13px; color: var(--quiet); }
.stepper li.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.stepper li.done { color: var(--good); }
.stepper li a { color: inherit; text-decoration: none; }
.stepper li:has(a):hover { background: var(--card); }
.stepper li.skipped { color: var(--quiet); }
.stepper li.ahead { opacity: .7; }
.wizard { max-width: 680px; margin: 24px auto; }
.wizard h1 { font-size: 24px; margin-bottom: 4px; }
.wizard .why { color: var(--quiet); margin: 0 0 18px; }
.modules-pick { max-width: 720px; }
.dims-group { max-width: 720px; margin: 14px 0 0; }
.dims-group .dims-q { margin: 0 0 2px; font-size: 16px; }
.dims-group + .dims-group { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 18px; }
.dims-group .dims-text { margin: 0 0 8px; }
.dims-pick { max-width: 720px; }
.modules-pick .choice { align-items: flex-start; }
.modules-pick .mark { margin-top: 3px; }
.mod-why { display: block; margin-top: 6px; font-size: 13px; color: var(--ink); }
.mod-why b { font-weight: 600; }
.step-nav { display: flex; justify-content: space-between; align-items: center; margin-top: 22px; max-width: 640px; }
.step-later { max-width: 640px; text-align: right; margin: 8px 0 0; }
button.link { background: none; border: 0; color: var(--quiet); padding: 0; text-decoration: underline; cursor: pointer; font: inherit; }
.drop { display: block; border: 2px dashed var(--line); border-radius: var(--r); padding: 18px; text-align: center; background: var(--card); max-width: 640px; margin-top: 12px; }
.drop:hover { border-color: var(--accent); }

/* Плашка-подсказка (ui.hint_card) */
.hint-card { position: relative; background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--r); padding: 12px 34px 12px 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.hint-card p { margin: 4px 0 8px; color: var(--quiet); }
.hint-card form.x { position: absolute; top: 4px; right: 4px; margin: 0; }
.hint-card form.x button { padding: 2px 8px; font-size: 16px; line-height: 1; }

/* Окно, открытое сразу (итог после мастера) */
.modal.open { display: flex; }
.modal .done-ic { font-size: 40px; line-height: 1; color: var(--good); }

/* Счётчик «Первые шаги» в шапке */
.steps-badge { position: relative; }
.steps-badge > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; font-size: 13px; }
.steps-badge > summary::-webkit-details-marker { display: none; }
.steps-badge .pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 340px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 10px 14px; }
.steps-badge .pop ol { margin: 0; padding: 0; list-style: none; }
.steps-badge .pop li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.steps-badge .pop li:last-child { border-bottom: 0; }
.steps-badge .pop li.ok { color: var(--quiet); }

/* Окно проверки разнесения */
.review-groups details { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 8px; }
.review-groups summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 14px; cursor: pointer; }
.review-groups summary .name { font-weight: 600; min-width: 220px; }
.review-groups summary .sum { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.review-groups .chips { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; }
.chip { font-size: 12px; background: var(--hover); border-radius: 999px; padding: 2px 8px; color: var(--quiet); }
.review-groups details.unalloc { border-color: var(--neg); }
.review-groups table { margin: 0 14px 12px; width: calc(100% - 28px); }
@media (max-width: 700px) { .steps-badge .pop { width: 280px; } .review-groups summary .name { min-width: 0; } }

/* Записки ИИ */
.badge.warn { background: var(--neg); }
.hint-card.warn { border-left-color: var(--neg); margin-bottom: 14px; }
.note-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-start; justify-content: space-between; }
.note-head h1 { margin-bottom: 2px; }
.note-head .tools { display: flex; flex-wrap: wrap; gap: 6px; }
.note-checks ul { margin: 6px 0 0; padding-left: 20px; }
.note-checks li { margin: 4px 0; }
.note-wrap { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 14px; }
.note-wrap:not(:has(.note-toc)) { grid-template-columns: minmax(0, 1fr); }
.note-toc { position: sticky; top: 76px; font-size: 13px; }
.note-toc ol { padding-left: 18px; margin: 6px 0 0; }
.note-toc li { margin: 4px 0; }
.note-body { max-width: 900px; line-height: 1.55; }
.note-body h2 { margin-top: 22px; } .note-body h2:first-child { margin-top: 0; }
.note-body .fact { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; border-bottom: 1px dotted var(--line); }
.note-body .fact.neg { color: var(--neg); }
.note-body .btn.small { padding: 2px 8px; font-size: 12px; margin-left: 4px; }
.note-chart { margin: 10px 0 14px; overflow-x: auto; }
.note-chart figcaption { font-size: 12px; margin-top: 2px; }
@media (max-width: 900px) { .note-wrap { grid-template-columns: minmax(0, 1fr); } .note-toc { position: static; } }
@media print {
  .rail, .tabbar, .more, .sectabs, .subnav, .topbar, .noprint, .modal { display: none !important; }
  .app, .with-subnav { display: block; }
  .page { margin: 0 !important; } main { padding: 0 !important; }
  .note-wrap { display: block; } .block { box-shadow: none; border: 0; }
}

/* Операции: шапка с фильтрами-вкладками, группы по дням, итог снизу */
.ops-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 10px; }
.ops-head h1 { margin: 0 6px 0 0; }
.period-arrows { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.period-arrows .btn { padding: 4px 6px; line-height: 0; }
.period-arrows svg { width: 16px; height: 16px; }
.more-filters > summary { cursor: pointer; color: var(--quiet); font-size: 13px; margin-bottom: 8px; }
table.ops tr.day td { background: var(--hover); font-weight: 600; font-size: 12px; color: var(--quiet); padding-top: 6px; padding-bottom: 6px; }
.n.pos, b.pos { color: var(--good); }
.ops-total { position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 6px 24px; padding: 10px 16px; margin-top: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 -4px 12px rgba(16, 24, 40, .06); font-size: 14px; }
/* три кнопки создания (операции): поиск в шапке прячем — на странице есть свой, в «Фильтрах» */
@media (max-width: 1600px) { .topbar:has(.addop ~ .addop ~ .addop) .topsearch { display: none; } }

/* Отчёт ДДС: вкладки разрезов, график с пояснением, подсказки справа */
.report-tabs { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 4px 0 12px; }
.seg a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
button.seg-btn { font-size: 12px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--quiet); }
button.seg-btn.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.report-top { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; margin-bottom: 14px; }
.report-top:not(:has(.hint-card)) { grid-template-columns: minmax(0, 1fr); }
.report-top .hints { display: flex; flex-direction: column; gap: 10px; }
.report-top .hint-card { margin: 0; }
.chart-row { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 16px; align-items: start; }
.chart-row:not(:has(.explain)) { grid-template-columns: minmax(0, 1fr); }
.chart-main { overflow-x: auto; }
.explain { font-size: 13px; color: var(--quiet); border-left: 1px solid var(--line); padding-left: 14px; }
.explain b { color: var(--ink); } .explain p { margin: 4px 0 10px; } .explain ul { margin: 4px 0 0; padding-left: 18px; } .explain li { margin: 4px 0; }
table.cf tr.net td { background: var(--warn-soft); }
table.cf small.share { display: block; font-size: 11px; color: var(--quiet); }
table.cf a.cell { color: inherit; } table.cf a.cell:hover { color: var(--accent); }
@media (max-width: 1100px) { .report-top, .chart-row { grid-template-columns: minmax(0, 1fr); } .explain { border-left: 0; padding-left: 0; } }

/* Коридоры и «Бизнес в цифрах» на главной */
table.corr td.warn { background: var(--warn-soft); color: var(--warn); font-weight: 650; }
.verdict { margin-top: 4px; padding: 12px 14px; border-radius: var(--r); border: 1px solid var(--line); }
.verdict.warn { background: var(--warn-soft); border-color: var(--warn); }
.verdict.neg { border-color: var(--neg); }
.verdict p { margin: 6px 0; }
.form-corr td input { width: 140px; }

/* Статусы и этапы сделок */
.dstatus { --c: var(--quiet); display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  color: var(--c); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); background: color-mix(in srgb, var(--c) 10%, transparent); white-space: nowrap; }
.dstatus.warn { --c: var(--warn); } .dstatus.accent { --c: var(--accent); } .dstatus.good { --c: var(--good); }
.stage-pick { display: block; margin-top: 4px; }
.stage-pick select { font-size: 12px; padding: 2px 4px; }
details.inline-edit > summary { cursor: pointer; color: var(--accent); list-style: none; }
details.inline-edit[open] { min-width: 520px; }
table.catalog tr.off input { color: var(--quiet); }
table.catalog input { width: 100%; min-width: 60px; }

/* Отчёты по месяцам на экране 1366 px: год помещается по ширине без прокрутки */
@media (min-width: 901px) and (max-width: 1500px) {
  main { padding-left: 20px; padding-right: 20px; }
  .scroll > table th.n, .scroll > table td.n { padding-left: 5px; padding-right: 5px; font-size: 13px; }
  .scroll > table td:first-child, .scroll > table th:first-child { padding-right: 6px; }
  td.trend, th.trend { width: 60px; padding-left: 2px; padding-right: 2px; }
  td.trend svg { width: 56px; }
}

/* ---------- Панель показателей: выбор графиков, «?» и «Спросить ИИ», новые блоки ---------- */
.picker { position: relative; }
.picker > summary { list-style: none; }
.picker > summary::-webkit-details-marker { display: none; }
.picker .pop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; width: 300px; max-height: 70vh; overflow: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
  padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.picker label { display: flex; gap: 8px; align-items: center; padding: 5px 6px; border-radius: 6px; cursor: pointer; }
.picker label:hover { background: var(--hover); }
.picker .foot { display: flex; gap: 10px; align-items: center; justify-content: space-between; border-top: 1px solid var(--line); margin-top: 4px; padding: 8px 6px 2px; }
.block { position: relative; }
.bhelp + .block-head { padding-right: 150px; }
.bhelp { position: absolute; top: 12px; right: 14px; display: flex; gap: 6px; z-index: 3; }
.bhelp details { position: relative; }
.bhelp summary { list-style: none; cursor: pointer; font-size: 12px; color: var(--quiet); border: 1px solid var(--line); border-radius: 12px;
  padding: 2px 9px; background: var(--card); user-select: none; }
.bhelp summary::-webkit-details-marker { display: none; }
.bhelp summary:hover, .bhelp details[open] > summary { color: var(--accent); border-color: var(--accent); }
.bhelp .whatis summary { width: 24px; padding: 2px 0; text-align: center; font-weight: 650; }
.bhelp .pop { position: absolute; right: 0; top: calc(100% + 6px); width: 320px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 10px 12px; font-size: 13px; line-height: 1.45; }
.bhelp .pop .q { background: var(--hover); border-radius: 6px; padding: 6px 8px; margin: 6px 0; user-select: all; }
@media (max-width: 700px) { .bhelp + .block-head { padding-right: 0; padding-top: 26px; } .bhelp .pop { width: 260px; } }
.home-head .tools { gap: 8px; }
svg rect.base { fill: var(--total); fill-opacity: .3; }
svg rect.down { fill: url(#hatch-down); stroke: var(--neg); stroke-width: 1; stroke-opacity: .6; }
svg .hatch-bg { fill: var(--neg); fill-opacity: .12; }
svg .hatch { stroke: var(--neg); stroke-width: 2; stroke-opacity: .55; }
svg rect.corridor { fill: var(--good); fill-opacity: .08; }
svg .corridor-edge { stroke: var(--good); stroke-dasharray: 4 3; stroke-opacity: .6; }
svg .bar-label { fill: var(--ink); font-size: 11px; font-weight: 600; }
svg .bar-label.warn { fill: var(--warn); }
svg .bar-label.neg { fill: var(--neg); }
svg .line.dashed { stroke-dasharray: 6 4; }
svg a .dot { cursor: pointer; }
.legend i.c-base { background: var(--total); opacity: .35; }
.legend i.down { background: repeating-linear-gradient(45deg, var(--neg) 0 2px, transparent 2px 4px); opacity: .7; }
.legend i.corridor { background: var(--good); opacity: .25; }
.trend-more { margin-top: 6px; }
.trend-more summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.checks { list-style: none; padding: 0; margin: 8px 0; columns: 2 260px; }
.checks li { break-inside: avoid; padding: 2px 0; }
.ladder { display: flex; align-items: stretch; gap: 10px; flex-wrap: wrap; }
.ladder .step { flex: 1 1 150px; border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.ladder .step .t { font-size: 12px; color: var(--quiet); }
.ladder .step b { font-size: 20px; font-variant-numeric: tabular-nums; }
.ladder .step small { font-size: 12px; color: var(--quiet); }
.ladder .step.result { background: var(--accent-soft); border-color: transparent; }
.ladder .step.result.neg b { color: var(--neg); }
.ladder .op { align-self: center; font-size: 20px; color: var(--quiet); }
.tipq { display: inline-block; position: relative; vertical-align: middle; }
.tipq summary { list-style: none; cursor: pointer; width: 16px; height: 16px; line-height: 15px; text-align: center; border-radius: 50%;
  border: 1px solid var(--line); font-size: 11px; font-weight: 650; color: var(--quiet); user-select: none; }
.tipq summary::-webkit-details-marker { display: none; }
.tipq summary:hover, .tipq[open] > summary { color: var(--accent); border-color: var(--accent); }
.tipq .pop { position: absolute; left: -8px; top: calc(100% + 6px); z-index: 5; width: 300px; background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 10px 12px;
  font-size: 13px; line-height: 1.45; display: flex; flex-direction: column; gap: 2px; }
.tipq .pop b { font-size: 12px; margin-top: 4px; }
.tipq .pop .row { display: flex; justify-content: space-between; gap: 10px; }
.tipq .pop .n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.warn-text { color: var(--warn) !important; }
svg rect.neg-zone { fill: var(--neg); fill-opacity: .06; }
.profit-table tr.section td { font-weight: 400; background: none; }
.profit-table tbody.grp > tr.section > td:first-child { background: var(--card); }
.profit-table tr.loss > td:first-child { box-shadow: inset 3px 0 0 var(--neg); }
.profit-table tr.overspent > td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
.profit-table tr.sub-head td { font-weight: 600; background: var(--bg); }
.badge.neg-badge { background: var(--neg); color: #fff; font-style: normal; }
.badge.warn-badge { background: var(--warn-soft); color: var(--warn); font-style: normal; }
.spent { height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; max-width: 360px; }
.spent i { display: block; height: 100%; background: var(--good); }
.spent.warn i { background: var(--warn); } .spent.over i { background: var(--neg); }
table.pf td.n.dev-bad { color: var(--neg); }
.legend i.neg-zone { background: var(--neg); opacity: .15; }
/* Платёжный календарь: прогноз ниже коридора — жёлтый, ниже нуля — красный */
svg .line.below-low { stroke: var(--warn); stroke-width: 2.6; }
svg .fill.below-low { fill: var(--warn); fill-opacity: .18; }
svg .line.below-zero { stroke: var(--neg); stroke-width: 2.6; }
svg .fill.below-zero { fill: var(--neg); fill-opacity: .2; }
.legend i.below-low { background: var(--warn); } .legend i.below-zero { background: var(--neg); }
/* Меню «⋮» строки */
.kebab { position: relative; display: inline-block; }
.kebab > summary { list-style: none; cursor: pointer; width: 26px; height: 26px; border-radius: 6px; display: grid; place-items: center; color: var(--quiet); font-size: 16px; line-height: 1; }
.kebab > summary::-webkit-details-marker { display: none; }
.kebab > summary:hover, .kebab[open] > summary { background: var(--hover); color: var(--ink); }
.kebab .pop { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 210px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: 0 8px 24px rgba(16, 24, 40, .14); padding: 6px; display: flex; flex-direction: column; text-align: left; }
.kebab .pop a, .kebab .pop button.link { padding: 6px 10px; border-radius: 6px; color: var(--ink); font-size: 13px; white-space: nowrap; text-align: left; }
.kebab .pop a:hover, .kebab .pop button.link:hover { background: var(--hover); text-decoration: none; }
.kebab .pop .sub { padding: 6px 10px 2px; font-size: 11px; color: var(--quiet); text-transform: uppercase; letter-spacing: .03em; }
.kebab .pop form { margin: 0; }
.kebab .pop button.link { width: 100%; background: none; border: 0; cursor: pointer; }
.kebab .pop button.danger { color: var(--neg); }
td.menu { width: 30px; padding-left: 0; padding-right: 4px; text-align: right; }
.kebab .pop button.link { text-decoration: none; }

/* Загрузка пакета 1С в фоне: страница с шкалой и плашка на остальных страницах */
.load-card { max-width: 720px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.load-file { margin: 0 0 12px; overflow-wrap: anywhere; }
.load-bar { height: 14px; border-radius: 7px; background: var(--accent-soft); overflow: hidden; }
.load-fill { height: 100%; background: var(--accent); border-radius: 7px; transition: width .8s ease; min-width: 14px;
  background-image: linear-gradient(45deg, rgba(255,255,255,.22) 25%, transparent 25%, transparent 50%, rgba(255,255,255,.22) 50%,
  rgba(255,255,255,.22) 75%, transparent 75%); background-size: 28px 28px; animation: load-stripes 1s linear infinite; }
@keyframes load-stripes { from { background-position: 0 0; } to { background-position: 28px 0; } }
@media (prefers-reduced-motion: reduce) { .load-fill { animation: none; } }
.load-line { margin: 10px 0 14px; }
.load-note { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; }
.load-note p { margin: 6px 0; }
.load-strip { display: flex; max-width: 1200px; align-items: center; gap: 12px; margin: 0 0 14px; padding: 10px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--ink); border: 1px solid var(--line); }
.load-strip:hover { text-decoration: none; border-color: var(--accent); }
.load-strip-bar { flex: 0 0 120px; height: 8px; border-radius: 4px; background: var(--card); overflow: hidden; }
.load-strip-bar span { display: block; height: 100%; background: var(--accent); }
@media (max-width: 600px) { .load-strip { flex-direction: column; align-items: stretch; } .load-strip-bar { flex-basis: 8px; } }
/* Отчёт «Долги»: вкладки «Вам должны / Вы должны», поиск, группы, возраст, сортировка */
.debt-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 8px; }
.debt-tabs a { flex: 1 1 220px; display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border: 1px solid var(--line);
  border-radius: var(--r); background: var(--card); color: var(--ink); }
.debt-tabs a:hover { text-decoration: none; border-color: var(--accent); }
.debt-tabs a.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 -3px 0 var(--accent); }
.debt-tabs a span { font-size: 13px; color: var(--quiet); }
.debt-tabs a.on span { color: var(--accent); font-weight: 600; }
.debt-tabs a b { font-size: 20px; font-variant-numeric: tabular-nums; }
.debt-tabs a small { font-size: 12px; }
.debt-tools { display: flex; gap: 10px 16px; align-items: center; flex-wrap: wrap; margin: 10px 0 8px; }
.debt-tools input[type=search] { min-width: 260px; }
.debt-tools .btn { margin-left: auto; }
.debt-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 6px 0; }
.debt-chips button { font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; }
.debt-chips button span { color: var(--quiet); font-size: 12px; font-variant-numeric: tabular-nums; }
.debt-chips button:hover { border-color: var(--accent); }
.debt-chips button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.debt-chips.small button { font-size: 12px; padding: 2px 8px; }
table.debts th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.debts th.sortable::after { content: " ↕"; color: var(--quiet); font-weight: 400; }
table.debts th.asc::after { content: " ↑"; color: var(--accent); }
table.debts th.desc::after { content: " ↓"; color: var(--accent); }
details.settings { margin: 16px 0 8px; }
details.settings > summary { cursor: pointer; color: var(--quiet); }
/* Платёжный календарь: линии «только план» и «осторожный прогноз», потребность в деньгах по неделям */
svg .thin.plan-line { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; stroke-opacity: .8; }
svg .thin.careful-line { stroke: var(--neg); stroke-width: 1.5; stroke-dasharray: 3 3; stroke-opacity: .8; }
.legend i.plan-line { background: none; border-top: 2px dashed var(--accent); height: 0; border-radius: 0; vertical-align: 3px; }
.legend i.careful-line { background: none; border-top: 2px dashed var(--neg); height: 0; border-radius: 0; vertical-align: 3px; }
.need-steps { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.need-steps span { display: flex; flex-direction: column; padding: 6px 10px; border: 1px solid var(--line); border-radius: var(--r); }
.need-steps small { color: var(--quiet); font-size: 12px; }
.need-steps b { font-variant-numeric: tabular-nums; color: var(--neg); }
.warn-block { border-color: var(--warn, #d97706); background: var(--warn-soft); }
table.compact td { padding: 3px 8px; }

/* Кнопка «Замечание» на тестовом сервере (feedback.py, FINDIR_FEEDBACK=1) */
.fb-float { position: fixed; right: 18px; bottom: 18px; z-index: 50; }
.fb-float > summary { list-style: none; cursor: pointer; padding: 8px 14px; border-radius: 18px; background: var(--accent);
  color: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.fb-float > summary::-webkit-details-marker { display: none; }
.fb-float[open] > summary { border-radius: 18px 18px 0 0; }
.fb-float form { width: 340px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px 0 10px 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.18); }
.fb-float textarea { width: 100%; box-sizing: border-box; }
@media (max-width: 700px) { .fb-float { bottom: 70px; right: 10px; } .fb-float form { width: 86vw; } }
