:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface-1: #ffffff;
  --surface-2: #f1f1ef;
  --border: #e4e4e0;
  --text-primary: #191919;
  --text-secondary: #666666;
  --text-muted: #8a8a86;
  --accent: #1b64be;
  --accent-contrast: #ffffff;
  --series-1: #257de0;
  --grid: #ececea;
  --good: #0a7a1e;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --bad: #c42f30;
  --bad-bg: #fde8e8;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111111;
    --surface-1: #191919;
    --surface-2: #222222;
    --border: #2e2e2e;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --text-muted: #7c7c7c;
    --accent: #4b97f0;
    --accent-contrast: #0b0b0b;
    --series-1: #338ced;
    --grid: #2a2a2a;
    --good: #3ccf55;
    --warn-bg: #3a2d0a;
    --warn-text: #f2c25a;
    --bad: #ff7b7c;
    --bad-bg: #3a1515;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 14px/1.45 var(--font); background: var(--bg); color: var(--text-primary); }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 12px; font-weight: 650; }
h2 { font-size: 17px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; }
p { margin: 0 0 10px; }
.muted { color: var(--text-secondary); }
.hint { color: var(--text-muted); font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* Простые страницы (подключение, ошибки) */
body.simple-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 24px; }
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.card.narrow { max-width: 560px; width: 100%; }
.steps { padding-left: 20px; margin: 0 0 16px; }
.steps li { margin-bottom: 6px; }

/* Кнопки и поля */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); color: var(--text-primary);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-fb { background: #1877f2; border-color: #1877f2; color: #fff; height: 42px; padding: 0 20px; font-size: 15px; }
.btn-fb:hover { background: #1877f2; filter: brightness(1.08); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-danger { color: var(--bad); }
.btn-link { border: 0; background: none; color: var(--accent); padding: 0; height: auto; font-weight: 500; }
.btn-link:hover { background: none; text-decoration: underline; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=search], select, textarea {
  height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-1); color: var(--text-primary); font: inherit; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-weight: 550; font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* Каркас админки */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 0 20px; height: 54px; background: var(--surface-1); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 15px; }
.tabs { display: flex; gap: 2px; height: 100%; }
.tabs button {
  border: 0; background: none; color: var(--text-secondary); font: inherit; font-weight: 550; padding: 0 12px; cursor: pointer;
  border-bottom: 2px solid transparent; height: 100%;
}
.tabs button.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tabs .badge { margin-left: 4px; }
.content { max-width: 1400px; margin: 0 auto; padding: 20px; }
.section { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }

/* Таблицы */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: var(--surface-1); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover td { background: var(--surface-2); }
tfoot td { font-weight: 650; border-top: 1px solid var(--border); border-bottom: 0; background: var(--surface-2); }
.cell-title { font-weight: 550; }
.cell-sub { color: var(--text-muted); font-size: 12px; }
.empty { padding: 28px; text-align: center; color: var(--text-secondary); }

/* Бейджи статусов: всегда текст + цвет */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--text-secondary); white-space: nowrap; }
.badge.ok { color: var(--good); }
.badge.ok::before { content: "●"; font-size: 9px; }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.warn::before { content: "▲"; font-size: 9px; }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.bad::before { content: "■"; font-size: 9px; }

/* Плитки показателей */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.tile-label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 4px; }
.tile-value { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }

/* График */
.chart-box { position: relative; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 6px; margin-bottom: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.chart-svg { display: block; width: 100%; }
.chart-svg text { fill: var(--text-secondary); font: 11px var(--font); font-variant-numeric: tabular-nums; }
.chart-svg .grid { stroke: var(--grid); stroke-width: 1; }
.chart-svg .bar { fill: var(--series-1); transition: opacity .12s; }
.chart-svg.hovering .bar { opacity: .35; }
.chart-svg.hovering .bar.on { opacity: 1; }
.chart-svg .hit { fill: transparent; }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; z-index: 3;
}
.chart-tip b { display: block; font-weight: 650; font-size: 13.5px; }

/* Модалка / панель */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: min(720px, 100%); height: 100%; overflow-y: auto; background: var(--bg); padding: 20px; border-left: 1px solid var(--border); }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.picker { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); padding: 6px 10px; }
.picker .group { font-size: 12px; font-weight: 650; color: var(--text-secondary); margin: 8px 0 4px; }
.picker label.check { display: flex; padding: 3px 0; }
.picker label.check.disabled { opacity: .45; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 12px; }
.script-box { width: 100%; min-height: 240px; margin-top: 10px; font-size: 12px; white-space: pre; overflow: auto; }
.copybox { display: flex; gap: 8px; align-items: center; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; word-break: break-all; }
.copybox .mono { flex: 1; }
.notice { padding: 10px 12px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); margin-bottom: 14px; }
.notice.error { background: var(--bad-bg); color: var(--bad); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 100; font-weight: 550; }
.login-box { max-width: 360px; margin: 12vh auto; }
/* color-scheme: light — иначе в тёмной теме iframe кнопки Google рисуется на белой подложке */
.gsi-host { min-height: 44px; display: flex; justify-content: center; margin-top: 8px; color-scheme: light; }
.lock-box { margin: 10vh auto; }
.mt { margin-top: 16px; }

/* Клиентский отчёт */
.report { max-width: 1100px; margin: 0 auto; padding: 24px 20px 40px; }
.report-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.report-head h1 { margin-bottom: 4px; }
.period-ctl { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
details.daily summary { cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.footer-note { margin-top: 20px; color: var(--text-muted); font-size: 12.5px; }

@media (max-width: 720px) {
  .topbar { gap: 8px; padding: 0 10px; overflow-x: auto; }
  .content, .report { padding: 12px; }
  .tile-value { font-size: 19px; }
}
