/* ---------------------------------------------------------------------------
   Базовые токены и общие компоненты дашборда.
   Компоненты, специфичные для этой страницы, — в media.css.

   Светлая тема — база на голом :root, тёмная объявлена дважды:
   через prefers-color-scheme (системная настройка) и через [data-theme]
   (переключатель в шапке), чтобы переключатель выигрывал в обе стороны.
   --------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --surface-sunken: #f2f1ed;

  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;

  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, .10);
  --hover:          rgba(11, 11, 11, .04);

  --series-1:       #2a78d6;  /* аптеки и e-com */
  --series-2:       #eb6834;  /* отзовики и форумы */
  --status-warning: #fab219;

  --radius:   12px;
  --radius-s: 8px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --surface-sunken: #131312;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, .10);
    --hover:          rgba(255, 255, 255, .05);
    --series-1:       #3987e5;
    --series-2:       #d95926;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface:        #1a1a19;
  --surface-sunken: #131312;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --baseline:       #383835;
  --border:         rgba(255, 255, 255, .10);
  --hover:          rgba(255, 255, 255, .05);
  --series-1:       #3987e5;
  --series-2:       #d95926;
}

/* --------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 clamp(12px, 3vw, 32px) 48px;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
p  { margin: 0; }

a { color: inherit; text-decoration-color: var(--baseline); text-underline-offset: 2px; }
a:hover { text-decoration-color: currentColor; }

:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 20;
  padding: 8px 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.skip-link:focus { left: 12px; top: 12px; }

/* --- Шапка --------------------------------------------------------------- */

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px 16px;
  align-items: flex-end; justify-content: space-between;
  padding: 24px 0 16px;
}
.topbar__sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.topbar__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.status { color: var(--text-muted); font-size: 12px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px;
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s); cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn--icon { padding: 0 9px; }
.btn--ghost { background: transparent; }

.banner {
  display: flex; gap: 8px; align-items: flex-start;
  margin-bottom: 16px; padding: 10px 12px;
  font-size: 13px; color: var(--text-secondary);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--status-warning);
  border-radius: var(--radius-s);
}
.banner[hidden] { display: none; }

/* --- Поля ввода ----------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field__label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.field input, .field select {
  min-height: 34px; width: 100%; padding: 0 10px;
  font: inherit; font-size: 13px; color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.field select { padding-right: 6px; }

/* --- Карточки ------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card__head { margin-bottom: 14px; }
.card__head--row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card__sub { margin-top: 3px; font-size: 12px; color: var(--text-muted); }

.kpis {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.kpi__label { font-size: 12px; color: var(--text-secondary); }
.kpi__value { margin-top: 4px; font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.kpi__value--hero { font-size: 48px; line-height: 1.05; }
.kpi__hint { margin-top: 2px; font-size: 12px; color: var(--text-muted); }
.kpi--hero { grid-column: span 2; }
@media (max-width: 520px) { .kpi--hero { grid-column: span 1; } }

.grid {
  display: grid; gap: 12px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
}
.card--wide { grid-column: 1 / -1; }

.empty { padding: 24px 0; text-align: center; color: var(--text-muted); font-size: 13px; }

/* --- Горизонтальные бары ------------------------------------------------- */

.bars { display: flex; flex-direction: column; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(88px, 168px) 1fr minmax(38px, auto);
  align-items: center; gap: 10px;
  min-height: 28px; padding: 0 4px; margin: 0 -4px;
  border-radius: 4px;
}
.bar-row:hover { background: var(--hover); }

.bar-row__label {
  display: flex; align-items: center; gap: 6px; min-width: 0;
  font-size: 13px; color: var(--text-secondary);
}
.bar-row__labeltext { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-row__track {
  position: relative; height: 18px;
  background: var(--surface-sunken); border-radius: 0 4px 4px 0;
}
.bar-row__fill {
  height: 100%; min-width: 2px;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;
}
.bar-row__value {
  font-size: 13px; color: var(--text-primary);
  font-variant-numeric: tabular-nums; text-align: right;
}
.bar-row--muted .bar-row__fill { background: var(--baseline); }
.bar-row--muted .bar-row__value { color: var(--text-muted); }

/* --- Легенда -------------------------------------------------------------- */

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.legend__item { display: flex; align-items: baseline; gap: 7px; font-size: 12px; color: var(--text-secondary); }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; transform: translateY(1px); }
.legend__value { color: var(--text-primary); font-variant-numeric: tabular-nums; font-weight: 600; }

/* --- Таблица ------------------------------------------------------------- */

.table-card { padding-bottom: 8px; }
.table-wrap { max-height: 560px; overflow: auto; border-radius: var(--radius-s); }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  padding: 8px 10px; text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--grid);
}
.data-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface); color: var(--text-secondary);
  font-weight: 500; font-size: 12px; white-space: nowrap;
  cursor: pointer; user-select: none;
  border-bottom: 1px solid var(--baseline);
}
.data-table thead th::after { content: ""; display: inline-block; width: 12px; color: var(--text-muted); }
.data-table thead th[aria-sort="ascending"]::after  { content: " ↑"; }
.data-table thead th[aria-sort="descending"]::after { content: " ↓"; }
.data-table tbody tr:hover { background: var(--hover); }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* --- Подвал и тултип ----------------------------------------------------- */

.pagefoot { margin-top: 24px; font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 2px; }
.pagefoot code { font-size: 11px; background: var(--surface-sunken); padding: 1px 5px; border-radius: 4px; }

.tooltip {
  position: fixed; z-index: 30; max-width: 280px;
  padding: 8px 10px; pointer-events: none; opacity: 0;
  transition: opacity .09s ease-out;
  background: var(--surface); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius-s);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
  font-size: 12px; line-height: 1.4;
}
.tooltip.is-visible { opacity: 1; }
.tooltip__value { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip__label { color: var(--text-secondary); margin-top: 1px; }
.tooltip__meta  { color: var(--text-muted); margin-top: 3px; }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
