/* Оформление дашборда. Все цвета — токены: светлая и тёмная тема меняются в одном месте. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --wash: rgba(11, 11, 11, .045);
  --wash-2: rgba(11, 11, 11, .08);
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --border-2: rgba(11, 11, 11, .18);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, .11);
  --good: #006300;
  --bad: #d03b3b;
  --warn-wash: rgba(250, 178, 25, .18);
  /* ряды графика: порядок закреплён, он же обеспечивает различимость соседей */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --s0: #898781;                 /* «Остальное» */
  --pos: #2a78d6; --neg: #e34948; /* доходы и расходы в режиме «Всё» */
  --heat: 42, 120, 214;
  --heat-neg: 227, 73, 72;
  --heat-ink: 11, 11, 11;        /* фон клетки дня в календаре: чем больше потрачено, тем плотнее */
  --shadow: 0 10px 30px rgba(0, 0, 0, .13), 0 1px 3px rgba(0, 0, 0, .08);
  --radius: 12px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --wash: rgba(255, 255, 255, .06);
  --wash-2: rgba(255, 255, 255, .11);
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --border-2: rgba(255, 255, 255, .20);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: rgba(57, 135, 229, .18);
  --good: #0ca30c;
  --bad: #e66767;
  --warn-wash: rgba(250, 178, 25, .16);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --s0: #898781;
  --pos: #3987e5; --neg: #e66767;
  --heat: 57, 135, 229;
  --heat-neg: 230, 103, 103;
  --heat-ink: 255, 255, 255;
  --shadow: 0 10px 30px rgba(0, 0, 0, .6), 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--ink-2); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.wrap { max-width: 1360px; margin: 0 auto; padding: 0 24px; }
.main { display: grid; gap: 16px; padding-top: 16px; padding-bottom: 56px; }

/* ------------------------------------------------------------- шапка */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 20px 0 12px; }
.top h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.sub { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

/* ------------------------------------------------------- кнопки и поля */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 8px;
  white-space: nowrap; transition: background .12s;
}
.btn:hover:not(:disabled) { background: var(--wash); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.icon { width: 34px; padding: 0; justify-content: center; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.small { height: 28px; padding: 0 9px; font-size: 13px; }
.btn.on { border-color: var(--accent); background: var(--accent-wash); color: var(--accent-ink); }
.btn .count {
  min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; font-variant-numeric: tabular-nums;
}
.btn .ico:last-child:not(:first-child) { color: var(--muted); margin-right: -3px; }

.seg { display: inline-flex; padding: 2px; gap: 2px; background: var(--wash-2); border-radius: 9px; }
.seg button {
  height: 30px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--ink-2); white-space: nowrap;
}
.seg button:hover:not(:disabled):not([aria-pressed="true"]) { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border), 0 1px 2px rgba(0, 0, 0, .08); }
.seg button:disabled { opacity: .35; cursor: default; }
.seg.small button { height: 26px; padding: 0 9px; font-size: 13px; }

.select {
  height: 30px; padding: 0 26px 0 9px; border: 1px solid var(--border-2); border-radius: 7px; background-color: var(--surface);
  appearance: none; -webkit-appearance: none; font-size: 13px; cursor: pointer; max-width: 170px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 13px, calc(100% - 8px) 13px; background-size: 5px 5px; background-repeat: no-repeat;
}
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.check input, .opt input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); flex: none; }
.field {
  height: 34px; padding: 0 10px; border: 1px solid var(--border-2); border-radius: 8px; background: var(--surface); min-width: 0;
}
.field::placeholder, .search input::placeholder { color: var(--muted); }

/* ---------------------------------------------------- панель фильтров */
.bar-wrap { position: sticky; top: 0; z-index: 20; background: var(--page); border-bottom: 1px solid var(--border); padding: 10px 0; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.anchor { position: relative; display: inline-flex; }
.period-group { gap: 4px; }
.period-group .btn.period { font-weight: 600; min-width: 150px; justify-content: space-between; }
.search { position: relative; flex: 1 1 220px; min-width: 180px; max-width: 420px; }
.search .ico { position: absolute; left: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.search input {
  width: 100%; height: 34px; padding: 0 10px 0 32px; border: 1px solid var(--border-2); border-radius: 8px; background: var(--surface);
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips:not(:empty) { margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; max-width: 100%; border-radius: 16px; background: var(--accent-wash); font-size: 13px;
}
.chip.out { background: var(--wash-2); }
.chip button { border: 0; background: transparent; height: 28px; }
.chip .chip-body { padding: 0 2px 0 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46ch; border-radius: 16px 0 0 16px; }
.chip .chip-x { display: inline-flex; align-items: center; padding: 0 8px 0 4px; color: var(--ink-2); border-radius: 0 16px 16px 0; }
.chip .chip-x:hover { color: var(--ink); }
.chip b { font-weight: 600; }

/* ------------------------------------------------------ всплывающие окна */
.pop {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 40; width: max-content; min-width: 250px;
  max-width: min(380px, calc(100vw - 16px)); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 8px; font-size: 13px; white-space: normal; font-weight: 400;
  color: var(--ink); text-align: left;
}
.pop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 4px 6px 8px; }
.pop-title { font-weight: 600; font-size: 14px; }
.pop-search { width: 100%; margin: 0 0 6px; height: 32px; padding: 0 10px; border: 1px solid var(--border-2); border-radius: 8px; background: var(--surface); }
.pop-list { max-height: min(360px, 52vh); overflow-y: auto; overscroll-behavior: contain; margin: 0 -2px; padding: 0 2px; }
.opt { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.opt:hover { background: var(--wash); }
.opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt-sum { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.opt.ghost .opt-label { color: var(--ink-2); }
.pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 6px 2px; margin-top: 6px; border-top: 1px solid var(--border); color: var(--ink-2); }
.pop-sep { height: 1px; background: var(--border); margin: 6px 0; }
.pop-note { padding: 6px 8px; color: var(--ink-2); }
.pop-label { padding: 8px 8px 4px; color: var(--ink-2); font-size: 12px; }
.menu-row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 7px;
  background: transparent; text-align: left;
}
.menu-row:hover { background: var(--wash); }
.menu-row .ico { color: var(--ink); }
.menu-row .mark { width: 16px; height: 16px; flex: none; display: inline-flex; }
.menu-row .name { flex: 1; min-width: 0; }
.menu-row .hint { color: var(--ink-2); white-space: nowrap; }
.menu-row .hint.wrap-ok { white-space: normal; display: block; font-size: 12px; }
.menu-row[aria-checked="true"] .name { font-weight: 600; }
.row-x { border: 0; background: transparent; color: var(--ink-2); padding: 4px; border-radius: 6px; display: inline-flex; }
.row-x:hover { background: var(--wash-2); color: var(--ink); }
.pop-form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 4px 8px 6px; }
.pop-form .field { height: 32px; flex: 1 1 110px; }
.pop-form .btn { height: 32px; }
.pop-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 8px 6px; }
.files { margin: 0; padding: 0 8px; list-style: none; }
.files li { padding: 6px 0; border-top: 1px solid var(--border); overflow-wrap: anywhere; }
.files li:first-child { border-top: 0; }
.warn { display: flex; gap: 8px; margin: 6px 0; padding: 8px 10px; border-radius: 8px; background: var(--warn-wash); overflow-wrap: anywhere; }
.warn .ico { margin-top: 2px; }
.steps { margin: 4px 0 4px; padding: 0 8px 0 28px; }
.steps li { padding: 2px 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; padding: 1px 5px; border-radius: 5px; background: var(--wash-2); }

/* ------------------------------------------------------- главные цифры */
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.tile {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 18px 15px; min-width: 0; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
button.tile:hover { background: color-mix(in srgb, var(--surface) 92%, var(--ink)); }
.tile.hero { grid-column: span 2; }
.tile-label { color: var(--ink-2); font-size: 13px; }
.tile-value { font-size: 24px; font-weight: 650; letter-spacing: -.015em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile.hero .tile-value { font-size: 48px; line-height: 1.1; letter-spacing: -.03em; }
.tile-note {
  margin-top: 4px; color: var(--ink-2); font-size: 13px; overflow: hidden;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
}
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; white-space: nowrap; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.meter { height: 6px; margin-top: 8px; border-radius: 3px; background: var(--accent-wash); overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* ------------------------------------------------------------ карточки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px 18px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin-bottom: 12px; }
.card-title { margin: 0; font-size: 16px; font-weight: 650; }
.card-sub { color: var(--ink-2); font-size: 13px; }
.card-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.tool-label { color: var(--ink-2); font-size: 13px; }
.levels { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.level { display: inline-flex; align-items: center; }
.level .select { border-radius: 7px 0 0 7px; }
.level .select:only-child { border-radius: 7px; }
.level .row-x { height: 30px; border: 1px solid var(--border-2); border-left: 0; border-radius: 0 7px 7px 0; padding: 0 5px; align-items: center; }
.levels .sep { color: var(--muted); }
.empty { text-align: center; padding: 48px 20px; color: var(--ink-2); }
.empty p { margin: 0 0 14px; font-size: 15px; }

/* -------------------------------------------------------------- график */
.chart-box { position: relative; width: 100%; }
.chart { display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .ctx { fill: var(--ink-2); }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .zero { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart .marks { pointer-events: none; }
.chart .partial { opacity: .5; }
.chart .hit { fill: transparent; cursor: pointer; outline-offset: -2px; }
.chart .hit:hover, .chart .hit:focus-visible { fill: var(--wash); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 10px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; padding: 4px 9px; border: 0; border-radius: 7px; background: transparent;
  font-size: 13px; color: var(--ink-2);
}
button.legend-item:hover { background: var(--wash); color: var(--ink); }
.legend-item b { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.chart-note { margin-top: 8px; color: var(--muted); font-size: 12px; }

.tip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 300px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); font-size: 13px;
}
.tip-title { color: var(--ink-2); margin-bottom: 2px; }
.tip-total { font-size: 17px; font-weight: 650; }
.tip-rows { margin-top: 6px; display: grid; grid-template-columns: auto auto 1fr; gap: 3px 8px; align-items: center; }
.tip-key { width: 12px; height: 3px; border-radius: 2px; }
.tip-val { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tip-name { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip-foot { margin-top: 6px; color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------- таблицы */
.tbl-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.tbl-wrap.plain { overflow: visible; } /* таблица помещается сама; прокрутка обрезала бы всплывающие окна */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  padding: 7px 10px; text-align: left; font-weight: 500; color: var(--ink-2); font-size: 12px; white-space: nowrap;
  border-bottom: 1px solid var(--border-2);
}
.tbl td { padding: 0 10px; height: 34px; border-bottom: 1px solid var(--border); }
.tbl tr:last-child > td { border-bottom: 0; }
.tbl th.num { text-align: right; }
.tbl tbody tr.row:hover > td { background: var(--wash); }
.th-btn { display: inline-flex; align-items: center; gap: 3px; border: 0; background: transparent; padding: 2px 0; color: inherit; font-size: inherit; }
.th-btn:hover { color: var(--ink); }
.th-btn[aria-pressed="true"] { color: var(--ink); font-weight: 650; }
.th-btn .ico { width: 12px; height: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }

.g-name { max-width: 0; width: 34%; }
.g-row { display: flex; align-items: center; gap: 7px; min-width: 0; }
.g-toggle { display: inline-flex; align-items: center; gap: 7px; min-width: 0; border: 0; background: transparent; padding: 4px 0; text-align: left; }
.g-toggle .ico { color: var(--muted); }
.g-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.depth-0 .g-label { font-weight: 600; }
.g-actions { display: inline-flex; gap: 2px; margin-left: auto; opacity: 0; }
tr:hover .g-actions, .g-actions:focus-within { opacity: 1; }
.g-actions button { display: inline-flex; border: 0; background: transparent; color: var(--ink-2); padding: 4px; border-radius: 6px; }
.g-actions button:hover { background: var(--wash-2); color: var(--ink); }
.bar-cell { width: 24%; min-width: 90px; }
.hbar { height: 8px; }
.hbar i { display: block; height: 100%; min-width: 1px; border-radius: 0 4px 4px 0; background: var(--muted); }
.more-row td { color: var(--ink-2); }
.link { border: 0; background: transparent; padding: 0; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; }
.total-row td { font-weight: 650; border-top: 1px solid var(--border-2); }
.leaf-cell { padding: 4px 0 10px !important; height: auto !important; background: var(--wash); }
.leaf-cell .tbl td { height: 30px; border-bottom-color: transparent; }

.pivot th:first-child, .pivot td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.pivot .g-name { width: auto; max-width: none; min-width: 220px; }
.pivot .g-label { max-width: 240px; }
.pivot tbody tr.row:hover > td:first-child { background: color-mix(in srgb, var(--surface) 95.5%, var(--ink)); }
.pivot td.cell { padding: 0 2px; }
.cell-btn {
  display: block; width: 100%; min-width: 62px; height: 28px; padding: 0 8px; border: 0; border-radius: 5px; background: transparent;
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 12.5px;
}
.cell-btn:hover { box-shadow: inset 0 0 0 1px var(--border-2); }
.cell-btn.zero { color: var(--muted); cursor: default; }
.pivot .tot { font-weight: 600; border-right: 1px solid var(--border); }
.scale { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.scale i { width: 64px; height: 8px; border-radius: 2px; background: linear-gradient(90deg, rgba(var(--heat), .04), rgba(var(--heat), .55)); }

/* ------------------------------------------------------------ операции */
.tx { table-layout: fixed; } /* ширины столбцов — из первой строки, содержимое их не распирает */
.tx td { height: 38px; }
.tx tr.row { cursor: pointer; }
.tx-date { white-space: nowrap; color: var(--ink-2); font-variant-numeric: tabular-nums; width: 108px; }
.tx-m { font-weight: 500; }
.tx-m > .g-label { display: block; }
.tx-sub { display: none; margin-top: 1px; font-weight: 400; }
.cat-anchor { position: relative; min-width: 0; }
.tx-cat { width: 30%; }
.cat-cell { overflow: hidden; }
.tx-sum { width: 128px; }
.col-bon { width: 84px; }
.tx-sum { font-weight: 600; }
.tx-sum.pos { color: var(--good); }
.tx tr.off td { opacity: .55; }
.badge { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 9px; background: var(--wash-2); color: var(--ink-2); font-size: 11px; font-weight: 500; vertical-align: 1px; }
.tx-detail > td { height: auto !important; padding: 12px 14px 14px !important; background: var(--wash); }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px 24px; margin: 0 0 12px; }
.kv div { min-width: 0; }
.kv dt { color: var(--ink-2); font-size: 12px; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 12px; color: var(--ink-2); font-size: 13px; }

.missing { max-width: 620px; margin: 12vh auto; padding: 28px; }
.missing h1 { font-size: 20px; margin: 0 0 8px; }

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  .bar-wrap { position: static; }
  .tile.hero { grid-column: 1 / -1; }
  .tile.hero .tile-value { font-size: 40px; }
  .kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card { padding: 14px 14px 16px; }
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
  .bar-cell, .col-avg, .col-share, .col-n, .col-bon, .tx-cat { display: none; }
  .tx-sub { display: block; }
  .tx td { height: 48px; }
  .tx-date { width: 84px; }
  .tx-sum { width: 96px; }
  .g-name { width: 68%; }
  .g-actions { opacity: 1; }
  .period-group .btn.period { min-width: 0; }
  .search { max-width: none; flex-basis: 100%; }
}
@media (prefers-reduced-motion: no-preference) {
  .hbar i, .meter i { transition: width .25s ease; }
}

/* ------------------------------------------------- категории и правила */
.cat-btn {
  display: inline-flex; align-items: center; gap: 6px; max-width: 280px; padding: 3px 6px 3px 4px; margin-left: -4px;
  border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--ink-2); font-size: 13px; text-align: left;
}
.cat-btn .g-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-btn .ico { color: var(--muted); opacity: 0; }
.cat-btn:hover, .cat-btn:focus-visible { border-color: var(--border-2); background: var(--surface); color: var(--ink); }
.cat-btn:hover .ico, .cat-btn:focus-visible .ico { opacity: 1; }
tr:hover .cat-btn .ico { opacity: .7; }
.g-cat { margin-left: 6px; white-space: nowrap; }
.small { font-size: 12px; }
.link.plain { text-decoration: none; color: inherit; font-weight: 500; }
.link.plain:hover { text-decoration: underline; }
.pick-scope { margin: 0 0 8px; flex-wrap: wrap; }
.pick-scope button { white-space: normal; text-align: left; }
.pick-new { padding: 2px 0 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.pick-new .menu-row { font-weight: 600; }
.pick-new .menu-row .ico { color: var(--accent); }
.pick-grp { display: inline-flex; align-items: center; gap: 6px; padding: 0 8px 4px 30px; color: var(--ink-2); font-size: 12px; }
.pop-foot-actions { display: inline-flex; gap: 12px; }
.dot-badge { width: 8px; height: 8px; border-radius: 50%; background: #fab219; margin-left: 2px; }
.select.tiny { height: 26px; font-size: 12px; padding-right: 22px; max-width: 150px; }
.field.inline { height: 30px; min-width: 180px; }
.inline-edit { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; max-width: min(560px, calc(100vw - 32px));
  display: flex; align-items: flex-start; gap: 8px; padding: 10px 14px; border-radius: 10px; white-space: pre-line;
  background: var(--ink); color: var(--page); font-size: 13px; box-shadow: var(--shadow);
}
.toast .ico { color: #5bd36b; margin-top: 1px; }
.toast.warn .ico { color: #fab219; }

.modal-back { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .42); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; overflow-y: auto; }
.modal {
  width: min(900px, 100%); max-height: 92vh; display: flex; flex-direction: column; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 10px; }
.explain { padding: 0 20px; color: var(--ink-2); font-size: 13px; }
.explain p { margin: 0 0 6px; }
.modal-tools { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 8px 12px 10px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.modal-tools .pop-form { padding: 2px 0; }
.modal-tools .field { flex: 1 1 200px; }
.cat-list { overflow-y: auto; overscroll-behavior: contain; padding: 6px 12px 12px; }
.cat-group { margin-top: 10px; }
.cat-group-head, .cat-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 4px 14px; align-items: center; padding: 6px 8px; border-radius: 8px; }
.cat-group-head { grid-template-columns: auto minmax(0, 1fr) auto auto; background: var(--wash); font-size: 14px; }
.cat-row { padding-left: 22px; }
.cat-row:hover { background: var(--wash); }
.cat-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; overflow-wrap: anywhere; }
.cat-sum { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; }
.cat-ctl { display: inline-flex; gap: 4px; align-items: center; justify-content: flex-end; }
.cat-empty { padding: 4px 30px 6px; }
.modal-foot { padding: 10px 20px 14px; border-top: 1px solid var(--border); }
body.has-modal { overflow: hidden; }

.drop { position: fixed; inset: 0; z-index: 90; background: rgba(42, 120, 214, .18); display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-box { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 40px; border: 2px dashed var(--accent); border-radius: 16px; background: var(--surface); color: var(--ink); }
.drop-box .ico { color: var(--accent); }

@media (max-width: 720px) {
  .modal-back { padding: 0; }
  .modal { max-height: 100vh; border-radius: 0; border: 0; }
  .cat-group-head, .cat-row { grid-template-columns: minmax(0, 1fr) auto; }
  .cat-group-head { grid-template-columns: auto minmax(0, 1fr) auto; }
  .cat-ctl { grid-column: 1 / -1; justify-content: flex-start; flex-wrap: wrap; }
  .cat-row { padding-left: 14px; }
  .g-cat { display: none; }
}

/* ------------------------------------------- выделение операций и поиск */
.tx-check { width: 34px; padding: 0 4px 0 10px !important; cursor: pointer; }
.tx-check input { width: 15px; height: 15px; margin: 0; accent-color: var(--accent); vertical-align: middle; cursor: pointer; }
.tx tr.selected > td { background: var(--accent-wash); }
.selbar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; max-width: calc(100vw - 24px);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border-2); border-radius: 12px; box-shadow: var(--shadow); font-size: 13px;
}
.selbar-text { white-space: nowrap; margin-right: 4px; }
.selbar .pop { bottom: calc(100% + 8px); top: auto; left: 0; min-width: 420px; }
.pick-scope button { flex: 1 1 auto; }
body.has-sel .toast { bottom: 84px; }
body.has-sel .main { padding-bottom: 96px; }
.chip-q { background: var(--wash-2); }
.chip-q .chip-body { cursor: default; }
.chip-link { border: 0; background: transparent; height: 28px; padding: 0 4px 0 2px; color: var(--accent-ink); text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.btn.period:disabled, .seg button:disabled { opacity: .5; cursor: default; }
@media (max-width: 720px) {
  .tx-check { width: 30px; padding-left: 6px !important; }
  .selbar { bottom: 8px; }
}

/* ------------------------------------------------------------ календарь */
.view-seg button { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; font-weight: 500; }
.cal { display: grid; gap: 14px; min-width: 0; }
.cal-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; }
.cal-title { margin: 0; font-size: 14px; font-weight: 500; color: var(--ink-2); }
.cal-total { font-size: 36px; font-weight: 650; letter-spacing: -.025em; line-height: 1.15; }
.cal-note { margin-top: 2px; color: var(--ink-2); font-size: 13px; }
.cal-note .delta { font-size: 13px; }
.cal-back { display: inline-block; margin-bottom: 6px; font-size: 13px; }
.cal-legend { margin-top: -4px; align-items: center; }
.legend-share { color: var(--muted); font-size: 12px; }
.cal-year { display: flex; align-items: baseline; gap: 10px; margin: 8px 0 -4px; font-size: 18px; font-weight: 650; }
.cal-year .muted { font-size: 13px; font-weight: 400; }
.cal-months { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }

.mcard {
  display: flex; flex-direction: column; gap: 3px; min-width: 0; padding: 14px 16px 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color .12s, box-shadow .12s;
}
.mcard:hover:not(:disabled) { border-color: var(--border-2); box-shadow: 0 2px 12px rgba(0, 0, 0, .07); }
.mcard:disabled { opacity: .5; cursor: default; }
.mcard-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mcard-name { font-size: 14px; font-weight: 600; }
.mcard .delta { font-size: 12.5px; }
.mcard-sum { font-size: 22px; font-weight: 650; letter-spacing: -.015em; white-space: nowrap; }
.mcard-bar { display: block; min-width: 4px; margin: 5px 0 7px; }
.mcard.partial .mcard-bar { opacity: .55; }
.strip { display: flex; gap: 2px; width: 100%; height: 8px; }
.strip i { flex: 1 1 0; min-width: 2px; }
.strip i:last-child { border-radius: 0 4px 4px 0; }
.mcard-items { display: grid; gap: 3px; }
.mcard-item { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 13px; color: var(--ink-2); }
.mcard-item .g-label { flex: 1; min-width: 0; }
.mcard-val { color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.mcard-foot { margin-top: 4px; color: var(--muted); font-size: 12px; }

.cal-body { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 14px; align-items: start; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-wd { padding-bottom: 2px; text-align: center; color: var(--muted); font-size: 12px; }
.cal-wd.weekend, .dcell.weekend .dcell-num { color: var(--bad); }
.dcell {
  position: relative; display: flex; flex-direction: column; justify-content: space-between; gap: 2px; min-width: 0; height: 84px;
  padding: 7px 8px 8px; text-align: left; background: transparent; border: 1px solid var(--border); border-radius: 10px;
}
.dcell.blank { border-color: transparent; }
.dcell:disabled { cursor: default; }
.dcell:disabled .dcell-num { color: var(--muted); }
.dcell.off { opacity: .4; }
.dcell:hover:not(:disabled) { border-color: var(--border-2); }
.dcell.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.dcell-num { font-size: 12px; color: var(--ink-2); }
.dcell-sum { overflow: hidden; font-size: 14px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.dcell-sum .short { display: none; }
.dcell-side { position: absolute; top: 7px; right: 8px; color: var(--good); font-size: 11px; font-variant-numeric: tabular-nums; }
.dcell .strip { height: 5px; }
.dcell .strip i:last-child { border-radius: 0 3px 3px 0; }

.cal-side h3, .cal-ops h3 { margin: 0; font-size: 15px; font-weight: 650; }
.cal-side h3 { margin-bottom: 8px; }
.rank { display: grid; gap: 1px; margin: 0 -8px; }
.rank-row {
  display: grid; grid-template-columns: 22px minmax(0, 1.5fr) minmax(32px, 1fr) auto 38px; gap: 8px; align-items: center;
  width: 100%; padding: 5px 8px; border: 0; border-radius: 7px; background: transparent; text-align: left; font-size: 13px;
}
button.rank-row:hover { background: var(--wash); }
.rank-bar { height: 8px; }
.rank-bar i { display: block; height: 100%; min-width: 2px; border-radius: 0 4px 4px 0; }
.rank-val { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-share { color: var(--ink-2); font-size: 12px; text-align: right; }
.rank-more { display: inline-block; margin-top: 8px; font-size: 13px; }
.cal-ops .card-head { margin-bottom: 6px; }

@media (max-width: 1040px) {
  .cal-months { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cal-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 720px) {
  .cal-months { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .mcard { padding: 12px 12px 10px; }
  .mcard-sum { font-size: 18px; }
  .cal-total { font-size: 30px; }
  .cal-grid { gap: 3px; }
  .cal-grid-card { padding-left: 8px; padding-right: 8px; }
  .dcell { height: 60px; padding: 5px 4px 5px; border-radius: 7px; }
  .dcell-sum { font-size: 11.5px; }
  .dcell-sum .full { display: none; }
  .dcell-sum .short { display: inline; }
  .dcell-side { display: none; }
  .view-seg { order: 3; width: 100%; }
  .top-actions { flex-wrap: wrap; }
  .view-seg button { flex: 1; justify-content: center; }
}

/* --------------------------------------------------------------- значки */
.emo {
  display: inline-flex; align-items: center; justify-content: center; flex: none; width: 26px; height: 26px; padding: 0;
  border: 0; border-radius: 50%; background: color-mix(in srgb, var(--c, var(--s0)) 22%, transparent);
  font: 15px/1 "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-variant-emoji: emoji;
}
.emo.sm { width: 22px; height: 22px; font-size: 13px; }
:root[data-theme="dark"] .emo { background: color-mix(in srgb, var(--c, var(--s0)) 34%, transparent); }
button.emo { cursor: pointer; }
button.emo:hover, button.emo:focus-visible { box-shadow: 0 0 0 2px var(--border-2); }
.rank-row > .dot { justify-self: center; }
.pop.fixed { position: fixed; z-index: 85; }
.emoji-grid { display: grid; grid-template-columns: repeat(10, 30px); gap: 2px; max-height: 232px; padding: 0 4px 6px; overflow-y: auto; overscroll-behavior: contain; }
.emoji-opt {
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; background: transparent;
  font: 17px/1 "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; font-variant-emoji: emoji;
}
.emoji-opt:hover { background: var(--wash-2); }
.emoji-opt[aria-pressed="true"] { background: var(--accent-wash); box-shadow: inset 0 0 0 1px var(--accent); }
@media (max-width: 720px) {
  .emoji-grid { grid-template-columns: repeat(8, 30px); }
}

/* ------------------------------------------------- вкладка «Категории» */
.browse { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; min-width: 0; }
/* высоту списка уточняет fitBrowseNav() в app.js: от верха списка до низа окна */
.b-nav { position: sticky; top: 12px; display: flex; flex-direction: column; max-height: calc(100vh - 24px); padding: 12px 8px 10px; }
.b-nav .search { flex: none; min-width: 0; max-width: none; margin: 0 4px 8px; }
.b-tree { position: relative; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.b-group { padding: 1px 0 5px; border-radius: 10px; }
.b-item {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 8px; min-height: 32px;
  padding: 3px 8px; border-radius: 8px; font-size: 13px; cursor: pointer; user-select: none;
}
.b-item.grp { font-size: 14px; font-weight: 600; }
.b-item.cat { padding-left: 22px; }
.b-item:hover { background: var(--wash); }
.b-item[aria-selected="true"] { background: var(--accent-wash); box-shadow: inset 2px 0 0 var(--accent); }
.b-item.dim { opacity: .45; }
.b-n { min-width: 26px; text-align: right; color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.b-sum { min-width: 76px; text-align: right; white-space: nowrap; font-weight: 500; font-variant-numeric: tabular-nums; }
.b-sum.pos { color: var(--good); }
.b-new { display: flex; gap: 6px; margin-top: 6px; padding: 8px 4px 0; border-top: 1px solid var(--border); }
.b-new .field { flex: 1 1 auto; height: 32px; font-size: 13px; }
.b-new .btn { height: 32px; flex: none; }
.b-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.b-ctl { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 12px; }
.b-hint, .b-found { margin: -4px 0 10px; color: var(--ink-2); font-size: 13px; }
.b-found { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 0; padding: 8px 12px; border-radius: 8px; background: var(--wash); color: var(--ink); }
.b-none { margin: 28px 0 22px; text-align: center; color: var(--ink-2); }
.b-main .tx tr.row { cursor: grab; }
.b-main .col-bon { display: none; }      /* кэшбэк здесь не нужен — место отдано мерчанту */
.b-main .tx-cat { width: 27%; }
/* перенос: цель под курсором закрашена, не-цели приглушены */
body.drag-ops .b-item.grp, body.drag-cat .b-item.cat { opacity: .5; }
.b-item.drop-on { background: var(--accent); color: #fff; opacity: 1; }
.b-item.drop-on .b-n, .b-item.drop-on .b-sum { color: inherit; }
.b-group.drop-on { background: var(--accent-wash); box-shadow: inset 0 0 0 2px var(--accent); }
.b-group.drop-on .b-item.grp { opacity: 1; }
.drag-ghost {
  position: fixed; left: 0; top: -200px; z-index: 0; max-width: 320px; padding: 6px 12px; border-radius: 8px; overflow: hidden;
  background: var(--ink); color: var(--page); font-size: 13px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; pointer-events: none;
}
/* уведомление с кнопками: текст — первой строкой, кнопки — второй, чтобы длинное название не сжимало текст */
.toast.has-acts { flex-wrap: wrap; max-width: min(640px, calc(100vw - 32px)); }
.toast.has-acts > span { flex: 1 1 0; min-width: 0; }
.toast-acts { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 4px 18px; padding-left: 24px; }
.toast-act {
  padding: 0; border: 0; background: transparent; color: inherit; font-weight: 650; text-align: left;
  text-decoration: underline; text-underline-offset: 2px;
}
@keyframes b-flash { from { background: color-mix(in srgb, var(--accent) 45%, transparent); } }
@media (prefers-reduced-motion: no-preference) {
  .b-item.flash { animation: b-flash 1.4s ease-out; }
}
@media (max-width: 1140px) {
  .browse { grid-template-columns: 300px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .browse { grid-template-columns: minmax(0, 1fr); }
  .b-nav { position: static; max-height: none; }
  .b-tree { max-height: 42vh; }
  .b-hint { display: none; } /* на телефоне перетаскивания нет — работают галочки и «Категория…» */
}

/* ---------------------------------------- опубликованная версия страницы */
.welcome { max-width: 640px; margin: 9vh auto 40px; padding: 28px 30px 26px; }
.welcome h1 { margin: 0 0 10px; font-size: 26px; font-weight: 650; letter-spacing: -.015em; }
.welcome .lead { margin: 0 0 18px; font-size: 16px; }
.welcome .pop-form { padding: 0; gap: 8px; margin-bottom: 14px; }
.welcome .pop-form .btn { height: 38px; padding: 0 16px; font-size: 14px; }
.btn.primary { border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent-ink); }
.welcome .private { display: flex; gap: 10px; margin: 18px 0 0; padding: 12px 14px; border-radius: 10px; background: var(--wash); font-size: 13px; }
.welcome .private .ico { color: var(--good); margin-top: 2px; }
.demo-bar { background: var(--warn-wash); border-bottom: 1px solid var(--border); font-size: 13px; }
.demo-bar .wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding-top: 8px; padding-bottom: 8px; }
.demo-bar .wrap > span { flex: 1 1 220px; min-width: 0; }
.files li > div:first-child { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
@media (max-width: 720px) {
  .welcome { margin: 16px; padding: 22px 18px; }
}
