/* Lumi Analytics — «ночная книга учёта».
   Тёмная индиговая ночь по умолчанию (Lumi — ночное приложение), светлая «бумага» по переключателю.
   Шрифты: Forum — гравированные римские капители, как подписи карт таро (заголовки и фраза-итог);
   Onest — текст и цифры (табличные). Палитра графиков проверена validate_palette.js на обеих поверхностях. */

:root {
  color-scheme: dark;
  --bg: #13112a;
  --surface: #1b1932;
  --surface-2: #24213f;
  --line: #2e2a4f;
  --grid: #262344;
  --text: #ece8f7;
  --text-2: #bfb9d8;
  --muted: #8f89ad;
  --gold: #e3c27a;
  --gold-wash: rgba(227, 194, 122, .12);
  --focus: #e3c27a;
  --spark: #6f6994;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #0ca30c; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --bad: #d03b3b;
  --good-text: #5fd35f; --bad-text: #f08a8a;
  --seq-0: #1f2a48; --seq-1: #184f95; --seq-2: #1c5cab; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec;
  --shadow: none;
  --display: "Forum", "Times New Roman", serif;
  --sans: "Onest", system-ui, -apple-system, sans-serif;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f3fa;
  --surface: #fdfcff;
  --surface-2: #efecf6;
  --line: #e2deee;
  --grid: #ebe8f3;
  --text: #1b1830;
  --text-2: #4c4766;
  --muted: #7a7594;
  --gold: #9a6d16;
  --gold-wash: rgba(154, 109, 22, .10);
  --focus: #4b3fb0;
  --spark: #aaa5c2;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --good-text: #006300; --bad-text: #b02a2a;
  --seq-0: #cde2fb; --seq-1: #9ec5f4; --seq-2: #6da7ec; --seq-3: #3987e5; --seq-4: #256abf; --seq-5: #184f95;
  --shadow: 0 1px 2px rgba(27, 24, 48, .04), 0 4px 16px rgba(27, 24, 48, .04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--sans);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
button, select, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--surface-2); }
button.ghost { background: transparent; border-color: transparent; }
button.icon { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; }
select, input[type=date], input[type=password], input[type=search] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
}

/* ── шапка ── */
.top {
  display: flex; align-items: flex-end; gap: 28px; padding: 18px 32px 0;
  border-bottom: 1px solid var(--line);
}
.brand {
  font-family: var(--display); font-size: 24px; line-height: 1; white-space: nowrap;
  display: flex; align-items: center; gap: 10px; padding-bottom: 14px; letter-spacing: .01em;
}
.brand svg { width: 22px; height: 22px; color: var(--gold); flex: none; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs button {
  border: none; background: none; border-radius: 0; padding: 10px 12px 13px;
  font-family: var(--display); font-size: 17px; color: var(--muted); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); background: none; }
.tabs button.on { color: var(--text); border-bottom-color: var(--gold); }
.top-right { display: flex; align-items: center; gap: 10px; white-space: nowrap; padding-bottom: 10px; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 16px 32px 0; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: none; border-radius: 0; padding: 6px 12px; background: none; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--gold-wash); color: var(--text); font-weight: 600; }
.range { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }

main { padding: 8px 32px 48px; max-width: 1520px; }
.loading main { opacity: .5; transition: opacity .2s; }
.foot { padding: 0 32px 32px; max-width: 900px; }

/* ── фраза-итог вкладки ── */
.lead { margin: 26px 0 24px; max-width: 980px; }
.lead p {
  font-family: var(--display); font-size: clamp(24px, 2.6vw, 34px); line-height: 1.28;
  margin: 0; font-weight: 400; letter-spacing: .005em; text-wrap: balance;
}
.lead p b { font-family: var(--sans); font-weight: 600; font-size: .86em; letter-spacing: -.01em; white-space: nowrap; }
.lead .when { margin-top: 10px; color: var(--muted); font-size: 13px; }

/* ── строка показателей («гроссбух») ── */
.ledger {
  display: grid; grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr));
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
  margin-bottom: 28px;
}
.ledger .m { padding: 14px 18px 12px; border-left: 1px solid var(--line); min-width: 0; }
.ledger .m.rs { border-left: none; padding-left: 0; }
.ledger .m.r2 { border-top: 1px solid var(--line); }
@media (max-width: 1100px) and (min-width: 761px) {
  .ledger { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ledger .m.rs, .ledger .m.r2 { border-left: 1px solid var(--line); padding-left: 18px; border-top: none; }
  .ledger .m:nth-child(3n+1) { border-left: none; padding-left: 0; }
  .ledger .m:nth-child(n+4) { border-top: 1px solid var(--line); }
}
.ledger .lbl { color: var(--text-2); font-size: 12.5px; }
.ledger .val { font-size: 24px; font-weight: 600; margin-top: 2px; letter-spacing: -.015em; line-height: 1.2; }
.ledger .dl { font-size: 12px; margin-top: 2px; color: var(--muted); white-space: nowrap; }
.ledger .hint { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.ledger svg.spark { display: block; width: 100%; height: 26px; margin-top: 8px; overflow: visible; }
.dl .up { color: var(--good-text); } .dl .down { color: var(--bad-text); }

/* ── сетка и панели ── */
.grid { display: grid; gap: 18px; grid-template-columns: repeat(12, 1fr); margin-bottom: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 18px 20px 16px; box-shadow: var(--shadow); min-width: 0;
}
.c12 { grid-column: span 12; } .c8 { grid-column: span 8; } .c7 { grid-column: span 7; }
.c6 { grid-column: span 6; } .c5 { grid-column: span 5; } .c4 { grid-column: span 4; } .c3 { grid-column: span 3; }
@media (max-width: 1100px) { .c8, .c7, .c6, .c5, .c4 { grid-column: span 12; } .c3 { grid-column: span 6; } }
.card h3 { margin: 0 0 2px; font-size: 15px; font-weight: 600; letter-spacing: -.005em; }
.card .sub { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; max-width: 72ch; }
.section-title {
  font-family: var(--display); font-size: 26px; font-weight: 400; margin: 38px 0 14px;
  display: flex; align-items: center; gap: 14px;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ── графики ── */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--sans); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--line); }
.chart .xhair { stroke: var(--text-2); stroke-width: 1; opacity: .4; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.ln { height: 2px; width: 14px; border-radius: 1px; vertical-align: 3px; }

.tip {
  position: fixed; pointer-events: none; z-index: 50; display: none;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 11px; font-size: 12px; box-shadow: 0 8px 28px rgba(8, 6, 24, .35); min-width: 150px;
}
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.tip .r b { font-weight: 600; color: var(--text); }
.tip .r span { color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.tip .k { display: inline-block; width: 12px; height: 2px; border-radius: 1px; }

/* ── горизонтальные полосы ── */
.hb { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 7px 12px; align-items: center; font-size: 12.5px; }
.hb .l { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb .bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hb .bar i { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--s1); }
.hb .v { text-align: right; white-space: nowrap; font-weight: 500; }
.hb .v small { color: var(--muted); margin-left: 6px; font-weight: 400; }
.group-title { margin: 16px 0 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.group-title:first-child { margin-top: 0; }

/* ── таблицы ── */
.tbl-wrap { overflow-x: auto; }
table.t { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.t th, table.t td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.t th { color: var(--muted); font-weight: 500; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); z-index: 1; }
table.t th:hover { color: var(--text); }
table.t th.sorted { color: var(--text); }
table.t th.sorted::after { content: " ↓"; } table.t th.sorted.asc::after { content: " ↑"; }
table.t td:first-child, table.t th:first-child { text-align: left; }
table.t td.l, table.t th.l { text-align: left; }
table.t tbody tr:hover td { background: var(--surface-2); }
.scroll-y { max-height: 460px; overflow-y: auto; }
td.heat { font-weight: 500; }
table.t td.heat { border-bottom: 2px solid var(--surface); border-left: 2px solid var(--surface); }

.note { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 18px; }
.note b { color: var(--text); }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

.funnel { display: grid; gap: 10px; }
.funnel .st { display: grid; grid-template-columns: 160px 1fr 120px; gap: 12px; align-items: center; font-size: 12.5px; }
.funnel .st > div:first-child { color: var(--text-2); }
.funnel .st .bar { height: 20px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.funnel .st .bar i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.funnel .st .v { text-align: right; font-weight: 600; }
.funnel .st .v small { color: var(--muted); display: block; font-size: 11px; font-weight: 400; }

.inline-seg { display: inline-flex; margin-left: 10px; vertical-align: middle; }
.inline-seg button { padding: 2px 10px; font-size: 12px; }
.ev-search { margin-bottom: 12px; width: 280px; max-width: 100%; }

/* ── вход ── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 30px; width: 340px; max-width: 100%; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card .brand { padding: 0 0 6px; }
.login-card button { background: var(--gold); color: #1b1830; border: none; padding: 10px; font-weight: 600; }
.err { color: var(--bad-text); font-size: 12px; min-height: 16px; }

/* ── телефон ── */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: 14px 16px 0; gap: 8px 12px; align-items: center; }
  .brand { padding-bottom: 6px; font-size: 21px; }
  .top-right { margin-left: auto; padding-bottom: 6px; }
  #sync-state { display: none; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { font-size: 16px; padding: 8px 10px 11px; }
  .filters, main, .foot { padding-left: 16px; padding-right: 16px; }
  .lead { margin: 18px 0 18px; }
  .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ledger .m, .ledger .m.rs, .ledger .m.r2 { padding: 12px 12px 10px; border-left: none; border-top: 1px solid var(--line); }
  .ledger .m:nth-child(odd) { padding-left: 0; }
  .ledger .m:nth-child(even) { border-left: 1px solid var(--line); }
  .ledger .m:nth-child(-n+2) { border-top: none; }
  .ledger .val { font-size: 20px; }
  .card { padding: 16px 14px 14px; }
  .funnel .st { grid-template-columns: 104px 1fr 86px; }
  .section-title { font-size: 22px; margin-top: 30px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.brand-sub { color: var(--muted); }
