:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e3e6ea;
  --ink: #12191f;
  --ink-2: #4c5560;
  --ink-3: #7b848e;
  --accent: #ff7000;
  --series-revenue: #2a78d6;
  --series-power: #eb6834;
  --series-result: #12191f;
  --good: #137a3a;
  --good-bg: #e3f4e8;
  --warn: #8a5a00;
  --warn-bg: #fff3d6;
  --warn-line: #f0c75e;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --demo-bg: #ede9fe;
  --demo-ink: #4c3aa8;
  --radius: 12px;
  --font: Inter, Manrope, "Segoe UI", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1418;
    --surface: #182027;
    --surface-2: #1f2830;
    --line: #2b353e;
    --ink: #eef1f4;
    --ink-2: #b6bfc8;
    --ink-3: #8a949e;
    --series-revenue: #3987e5;
    --series-power: #d95926;
    --series-result: #eef1f4;
    --good: #6fd697;
    --good-bg: #173523;
    --warn: #f3c969;
    --warn-bg: #3a2f12;
    --warn-line: #7a6223;
    --bad: #ff8a80;
    --bad-bg: #3d1a17;
    --demo-bg: #2b2550;
    --demo-ink: #c9c0ff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1418;
  --surface: #182027;
  --surface-2: #1f2830;
  --line: #2b353e;
  --ink: #eef1f4;
  --ink-2: #b6bfc8;
  --ink-3: #8a949e;
  --series-revenue: #3987e5;
  --series-power: #d95926;
  --series-result: #eef1f4;
  --good: #6fd697;
  --good-bg: #173523;
  --warn: #f3c969;
  --warn-bg: #3a2f12;
  --warn-line: #7a6223;
  --bad: #ff8a80;
  --bad-bg: #3d1a17;
  --demo-bg: #2b2550;
  --demo-ink: #c9c0ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px 48px; }
header.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 18px 0 14px;
}
header.top h1 { font-size: 17px; margin: 0; letter-spacing: .02em; text-transform: uppercase; font-weight: 700; }
header.top h1 span { color: var(--accent); }
header.top .spacer { flex: 1; }
select, input, button {
  font: inherit; color: inherit;
}
select, input[type=text], input[type=number], input[type=month], input[type=date], input[type=email], input[type=password] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
button, .btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--ink-3); }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button:disabled { opacity: .5; cursor: default; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; margin-top: 16px;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); margin: 0 0 14px; font-weight: 600; }
.muted { color: var(--ink-3); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.fact { background: var(--good-bg); color: var(--good); }
.badge.prelim { background: var(--warn-bg); color: var(--warn); }
.badge.nodata { background: var(--surface-2); color: var(--ink-3); }
.badge.small { font-size: 11px; padding: 2px 8px; }

.banner {
  border-radius: var(--radius); padding: 10px 14px; margin-top: 16px; font-size: 14px;
}
.banner.demo { background: var(--demo-bg); color: var(--demo-ink); }
.banner.error { background: var(--bad-bg); color: var(--bad); }

/* --- главный показатель --- */
.hero { text-align: center; padding: 28px 20px 22px; }
.hero .label { font-size: 13px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; }
.hero .meta { margin: 8px 0 4px; display: flex; gap: 10px; justify-content: center; align-items: center; flex-wrap: wrap; }
.hero .big { font-size: clamp(36px, 7vw, 56px); font-weight: 750; letter-spacing: -.02em; margin: 4px 0 18px; }
.trio { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-radius: 10px; overflow: hidden; }
.trio > div { background: var(--surface); padding: 14px 10px; }
.trio .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.trio .v { font-size: 20px; font-weight: 650; margin-top: 2px; }
.trio .s { font-size: 13px; color: var(--ink-3); }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.notes { list-style: none; padding: 0; margin: 16px 0 0; text-align: left; }
.notes li {
  background: var(--warn-bg); color: var(--warn); border-left: 3px solid var(--warn-line);
  padding: 8px 12px; border-radius: 6px; margin-top: 6px; font-size: 14px;
}
.notes li.missing { background: var(--bad-bg); color: var(--bad); border-left-color: var(--bad); }

.months { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.months .card { margin-top: 16px; }
.months .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.months .v { font-size: 26px; font-weight: 700; margin-top: 6px; }

details.costs { margin-top: 12px; text-align: left; font-size: 14px; }
details.costs summary { cursor: pointer; color: var(--ink-3); text-align: center; }
details.costs table { margin-top: 8px; }
details.costs td { padding: 6px 8px; }
details.costs tr.total td { font-weight: 700; border-top: 2px solid var(--line); }

/* --- таблицы --- */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: right; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: none; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; }
tr.expandable { cursor: pointer; }
tr.expandable td:first-child::after { content: " ▸"; color: var(--ink-3); }
tr.expandable.open td:first-child::after { content: " ▾"; }
tr.sub td { background: var(--surface-2); font-size: 14px; color: var(--ink-2); }
tr.sub td:first-child { padding-left: 24px; }

.ops-bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 80px; }
.ops-bar > i { display: block; height: 100%; background: var(--ink-2); border-radius: 3px; }

/* --- график --- */
.chart-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-head h2 { margin: 0; flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 6px 12px; background: var(--surface); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: var(--bg); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin: 4px 0 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--ink-3) 0 4px, transparent 4px 7px) !important; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 280px; overflow: visible; }
.chart .grid line { stroke: var(--line); }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .axis text.val { fill: var(--ink); font-size: 12px; font-weight: 600; }
.chart .tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.12);
  min-width: 190px; display: none; z-index: 2;
}
.chart .tip .r { display: flex; justify-content: space-between; gap: 12px; }
.chart .tip i { display: inline-block; width: 10px; height: 3px; margin-right: 6px; vertical-align: middle; }
details.tableview { margin-top: 10px; font-size: 14px; }
details.tableview summary { cursor: pointer; color: var(--ink-3); }

/* --- курсы --- */
.rates { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.rate { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; min-width: 0; }
.rate .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.rate .row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.rate .v { font-size: 22px; font-weight: 700; }
.rate .chg { font-size: 13px; font-weight: 600; }
.rate .src { font-size: 12px; color: var(--ink-3); }
.rate svg { width: 100%; height: 36px; display: block; }

/* --- свежесть --- */
.fresh { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.fresh > div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.fresh .k { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.fresh .v { margin-top: 2px; font-weight: 600; }
.fresh .v.warn { color: var(--warn); }

/* --- админка --- */
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.result-box { font-size: 14px; margin-top: 10px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); font-size: 12px; margin: 2px 4px 2px 0; }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.issues { max-height: 360px; overflow: auto; margin-top: 10px; }
.issues td, .issues th { font-size: 13px; padding: 6px 8px; }

.login { max-width: 360px; margin: 12vh auto 0; }
.login form { display: grid; gap: 10px; }

/* График: на телефоне долгое нажатие не выделяет страницу, а горизонтальное
   ведение пальцем по графику показывает дни; вертикальная прокрутка работает. */
.chart { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: pan-y; -webkit-tap-highlight-color: transparent; }
.chart svg text { pointer-events: none; }
button, .btn, tr.expandable, .seg button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }

/* Телефон: таблицы с классом stack превращаются в карточки — строка = компания,
   ячейки с подписями из data-label в две колонки. */
@media (max-width: 560px) {
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot { display: block; }
  table.stack tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.stack tr[hidden] { display: none; }
  table.stack tbody tr:last-child { border-bottom: 1px solid var(--line); }
  table.stack td, table.stack .hide-sm { display: block; border: none; padding: 0; text-align: left; font-size: 15px; }
  table.stack td:first-child { grid-column: 1 / -1; font-size: 16px; }
  table.stack td.empty { display: none; }
  table.stack td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; color: var(--ink-3);
    text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; font-weight: 600;
  }
  table.stack td:last-child:not([data-label]):not(:first-child) { grid-column: 1 / -1; }
  table.stack tfoot td { font-weight: 700; }
  table.stack tfoot tr { border-top: 2px solid var(--line); }
  table.stack tr.sub { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin: 6px 0; border-bottom: none; }
  table.stack tr.sub td { background: none; }
  table.stack tr.sub td:first-child { padding-left: 0; }
  .card { padding: 16px; }
  .chart-head h2 { flex-basis: 100%; }
  .seg { width: 100%; }
  .seg button { flex: 1; padding: 8px 4px; }
  header.top select { flex: 1; min-width: 0; }
}

@media (max-width: 720px) {
  .months { grid-template-columns: 1fr; gap: 0; }
  .trio { grid-template-columns: 1fr; }
  .trio .v { font-size: 18px; }
  .hide-sm { display: none; }
  th, td { padding: 9px 5px; font-size: 14px; }
}
