/* Аналитика прокатов — светлая премиальная тема
   Layout: боковая навигация по направлениям → шапка с периодом → карточки KPI → графики → таблицы источников */
:root {
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --ink: #0E141B;
  --ink-2: #344054;
  --muted: #667085;
  --faint: #98A2B3;
  --line: #E4E7EC;
  --line-2: #EEF0F3;
  --accent: #2747C4;
  --accent-soft: #EBEFFD;
  --good: #067647;
  --good-soft: #E7F6EE;
  --bad: #C4320A;
  --bad-soft: #FDEEE8;
  --warn: #B54708;
  --warn-soft: #FEF4E6;
  --elite: #2747C4;
  --black: #15181D;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
  --font: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; overflow-y: auto; }
.brandmark { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brandmark .logo { width: 34px; height: 34px; border-radius: 10px; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: -.02em; font-size: 14px; }
.brandmark b { display: block; font-size: 15px; letter-spacing: -.01em; }
.brandmark small { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .lbl { color: var(--faint); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; }
.nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); font-weight: 600; cursor: pointer; }
.nav button:hover { background: var(--surface-2); }
.nav button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav button .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.nav button .soon { margin-left: auto; font-size: 10.5px; font-weight: 700; color: var(--faint); background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 999px; }
.side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 0 8px; display: flex; flex-direction: column; gap: 8px; }
.side .foot form button { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; }

.main { min-width: 0; padding: 22px max(20px, env(safe-area-inset-right, 0px)) 60px max(20px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 18px; max-width: none; width: 100%; }
.top { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.top h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -.025em; }
.top .sub { color: var(--muted); margin-top: 3px; }

/* ---------- Период ---------- */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 11px; border-radius: 7px; font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.seg button:hover { background: var(--surface-2); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.dates { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 4px 8px; }
.dates input { border: 0; background: none; padding: 3px 2px; font-weight: 600; }
.dates span { color: var(--faint); }
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 13px; border-radius: 10px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
.btn:hover { border-color: #CDD2DA; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:focus-visible, .seg button:focus-visible, .nav button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sync { font-size: 12.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sync .led { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.sync.busy .led { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

/* ---------- Карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card h2 { margin: 0; font-size: 16px; font-weight: 800; letter-spacing: -.01em; }
.card .desc { color: var(--muted); margin: 3px 0 0; font-size: 13px; max-width: 80ch; }
.cardhead { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid3 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi .k { color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; gap: 8px; }
.kpi .v { font-size: 27px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
.kpi .v small { font-size: 15px; font-weight: 700; color: var(--muted); margin-left: 2px; }
.kpi .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12.5px; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill.up { background: var(--good-soft); color: var(--good); }
.pill.down { background: var(--bad-soft); color: var(--bad); }
.pill.flat { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line-2); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.brand-elite { background: var(--accent-soft); color: var(--elite); }
.pill.brand-black { background: #ECEDEF; color: var(--black); }
.pill.brand-unknown { background: var(--surface-2); color: var(--muted); }

/* ---------- Таблицы ---------- */
.tbl { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 9px 9px; border-bottom: 1px solid var(--line-2); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; background: var(--surface); position: sticky; top: 0; white-space: normal; vertical-align: bottom; line-height: 1.25; }
td.n, th.n { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tr.group td { background: var(--surface-2); color: var(--muted); font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; padding-top: 12px; }
tr.total td { font-weight: 800; border-top: 2px solid var(--ink); border-bottom: 0; }
td .chname { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
td .chname i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
td.dim, .dim { color: var(--faint); }
td a.lnk, button.lnk { color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; font-weight: 600; }

tr.expandable { cursor: pointer; }
tr.expandable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.caret { display: inline-block; width: 12px; color: var(--faint); font-size: 11px; transition: transform .15s; }
tr[aria-expanded="true"] .caret { transform: rotate(90deg); color: var(--accent); }
tr.subrow td { background: var(--surface-2); font-size: 13px; padding-top: 7px; padding-bottom: 7px; }
tr.subrow .subname { padding-left: 38px; font-weight: 600; color: var(--ink-2); }

/* Матрица по дням */
.matrix td, .matrix th { padding: 7px 8px; font-size: 12.5px; }
.matrix th.sticky, .matrix td.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; box-shadow: 1px 0 0 var(--line); min-width: 190px; }
.matrix td.c { text-align: right; font-variant-numeric: tabular-nums; }
.matrix td.c[data-v="0"] { color: #C9CED6; }
.matrix th.we, .matrix td.we { background-color: rgba(152, 162, 179, .07); }

/* Отклонения */
.devlist { display: flex; flex-direction: column; }
.dev { display: grid; grid-template-columns: 110px minmax(0, 1.4fr) minmax(0, 1fr) 150px 110px; gap: 14px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line-2); }
.dev .what b { display: block; font-weight: 700; }
.dev .what small { color: var(--muted); }
.dev .vals { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.bar { height: 6px; background: var(--line-2); border-radius: 999px; position: relative; overflow: hidden; }
.bar i { position: absolute; top: 0; bottom: 0; border-radius: 999px; }

/* Уведомления */
.notes { display: flex; flex-direction: column; gap: 8px; }
.note { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: #7A2E0E; font-size: 13px; }
.note.info { background: var(--accent-soft); color: #1C2E7A; }
.note b { font-weight: 800; }

/* Формы */
.form { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 700; }
.field input, .field select { border: 1px solid var(--line); background: var(--surface); border-radius: 9px; padding: 8px 10px; min-width: 0; }
.field input[type="number"] { width: 140px; }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-weight: 600; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.18); }

.chart { width: 100%; height: 320px; }
.chart.tall { height: 360px; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }
.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.brandcard { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 10px 14px; }
.brandcard .h { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-weight: 800; }
.brandcard .h i { width: 10px; height: 10px; border-radius: 3px; }
.brandcard .m small { display: block; color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.brandcard .m b { font-size: 17px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.spec-head { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; margin-bottom: 14px; }
.spec-head .m { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.spec-head .m small { color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; display: block; }
.spec-head .m b { font-size: 18px; font-variant-numeric: tabular-nums; }
.loading { opacity: .55; transition: opacity .2s; pointer-events: none; }

@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid3 { grid-template-columns: 1fr; } .spec-head { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 16px; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  .nav .lbl, .side .foot { display: none; }
  .nav button { width: auto; white-space: nowrap; }
  .grid2, .split { grid-template-columns: 1fr; }
  .dev { grid-template-columns: 1fr 1fr; }
  .main { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
}
@media (max-width: 520px) { .kpis { grid-template-columns: 1fr 1fr; } .kpi .v { font-size: 22px; } .brandcard { grid-template-columns: 1fr 1fr; } .spec-head { grid-template-columns: 1fr 1fr; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
