:root {
  --bg: #f4f3ef;
  --panel: #ffffff;
  --panel-2: #f9f8f5;
  --ink: #1d1c19;
  --ink-2: #57544c;
  --ink-3: #8a867b;
  --line: #e4e1d9;
  --line-2: #efede7;
  --accent: #0d6b57;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ec;
  --google: #2f64d6;
  --yandex: #e0522a;
  --total: #1d1c19;
  --up: #12804f;
  --down: #c2372b;
  --ok: #12804f;
  --partial: #b7791f;
  --stale: #c2372b;
  --na: #8a867b;
  --warn-bg: #fdf4e3;
  --warn-line: #efd7a6;
  --demo-bg: #ecebfb;
  --demo-line: #c9c6f1;
  --radius: 10px;
  --shadow: 0 1px 0 rgba(29, 28, 25, .04), 0 1px 3px rgba(29, 28, 25, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311;
    --panel: #1a1c19;
    --panel-2: #20231f;
    --ink: #ecebe6;
    --ink-2: #b4b1a7;
    --ink-3: #858277;
    --line: #2c2f2a;
    --line-2: #252823;
    --accent: #3fbf9b;
    --accent-ink: #08130f;
    --accent-soft: #17302a;
    --google: #6d97f2;
    --yandex: #f27a52;
    --total: #ecebe6;
    --up: #45c486;
    --down: #f0705f;
    --ok: #45c486;
    --partial: #e0a84a;
    --stale: #f0705f;
    --warn-bg: #2b2414;
    --warn-line: #4d3f1f;
    --demo-bg: #22213a;
    --demo-line: #3b3966;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: 8px; top: -40px; background: var(--panel); padding: 6px 10px; z-index: 10; border-radius: 6px; }
.skip:focus { top: 8px; }

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: -.01em; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { width: 22px; height: 22px; fill: var(--accent); }
.brand-lg { font-size: 16px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); cursor: pointer; font-weight: 550;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { color: var(--ink); background: var(--panel); border-color: var(--line); }
.btn-small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; height: 40px; }

.input, .select {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); min-width: 0;
}
.input:focus, .select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.input-small { height: 30px; font-size: 13px; width: 180px; }
.select { padding-right: 28px; max-width: 240px; }

.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-row { max-width: 1320px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 16px; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex: 1; justify-content: flex-end; }
.control { display: inline-flex; }
.logout { margin: 0; }

.seg { display: inline-flex; margin: 0; padding: 2px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 7px; color: var(--ink-2); font-weight: 550; font-size: 13px; white-space: nowrap; }
.seg input:hover + span { color: var(--ink); }
.seg input:checked + span { background: var(--ink); color: var(--bg); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }
.dot-google { background: var(--google); }
.dot-yandex { background: var(--yandex); }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative; margin: 0; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--panel); transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(12px); }

.main { max-width: 1320px; margin: 0 auto; padding: 18px 20px 48px; display: grid; gap: 14px; }
.scope { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: baseline; gap: 8px; font-size: 20px; font-weight: 650; letter-spacing: -.015em; min-width: 0; }
.crumb { background: none; border: 0; padding: 0; font-weight: inherit; cursor: pointer; color: var(--ink); }
.crumbs.is-site .crumb { color: var(--ink-3); }
.crumbs.is-site .crumb:hover { color: var(--accent); }
.crumb-sep { color: var(--ink-3); font-weight: 400; }
.crumb-current { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.period { margin: 0; color: var(--ink-2); font-size: 13px; }

.notice { display: block; padding: 10px 14px; border-radius: var(--radius); border: 1px solid; font-size: 13px; }
.notice-demo { background: var(--demo-bg); border-color: var(--demo-line); }
.notice-warn { background: var(--warn-bg); border-color: var(--warn-line); }
.notice-error { background: color-mix(in srgb, var(--down) 10%, var(--panel)); border-color: color-mix(in srgb, var(--down) 35%, var(--panel)); }
.notice strong { margin-right: 6px; }
.notice .btn { margin-left: 10px; vertical-align: middle; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.kpi { background: var(--panel); padding: 14px 16px 12px; min-width: 0; }
.kpi:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.kpi-label { margin: 0; font-size: 12px; font-weight: 550; color: var(--ink-2); text-transform: none; }
.kpi-value { margin: 4px 0 2px; font-size: 28px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-delta { margin: 0; font-size: 12px; color: var(--ink-3); min-height: 18px; }
.is-na { color: var(--ink-3); }

.delta { font-weight: 600; white-space: nowrap; }
.delta-up { color: var(--up); }
.delta-down { color: var(--down); }
.delta-flat { color: var(--ink-3); }
.delta-prev { color: var(--ink-3); font-weight: 400; margin-left: 6px; }
body.no-compare .kpi-delta, body.no-compare .col-delta { display: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; min-height: 54px; }
.panel-title { margin: 0; font-size: 14px; font-weight: 650; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }

.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); cursor: pointer; font-size: 13px; color: var(--ink); }
.legend-item[aria-pressed="false"] { color: var(--ink-3); background: var(--panel-2); }
.legend-item[aria-pressed="false"] .legend-swatch { background: transparent !important; }
.legend-swatch { width: 12px; height: 3px; border-radius: 2px; border: 1.5px solid; }
.legend-value { color: var(--ink-2); font-weight: 600; }

.chart { position: relative; height: 300px; padding: 8px 8px 0 0; outline: none; }
.chart:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); border-radius: 0 0 var(--radius) var(--radius); }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .grid line { stroke: var(--line-2); }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; }
.chart .cursor { stroke: var(--ink-3); stroke-dasharray: 3 3; }
.chart .marker { stroke: var(--panel); stroke-width: 2; }
.chart-tip { position: absolute; top: 10px; pointer-events: none; background: var(--ink); color: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: 12px; min-width: 150px; box-shadow: 0 6px 20px rgba(0,0,0,.18); }
.chart-tip-date { font-weight: 650; margin-bottom: 4px; }
.chart-tip-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chart-tip-row span:first-child { display: inline-flex; align-items: center; gap: 6px; opacity: .85; }
.chart-tip-row b { font-weight: 650; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line-2); }
.table th { font-size: 12px; font-weight: 550; color: var(--ink-2); background: var(--panel-2); position: sticky; top: 0; }
.table th:first-child, .table td:first-child { padding-left: 16px; }
.table th:last-child, .table td:last-child { padding-right: 16px; }
.table .col-text { text-align: left; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--panel-2); }
.table th button { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.table th button::after { content: ""; width: 0; height: 0; border: 4px solid transparent; opacity: 0; }
.table th[aria-sort="descending"] button::after { border-top-color: currentColor; border-bottom-width: 0; opacity: 1; }
.table th[aria-sort="ascending"] button::after { border-bottom-color: currentColor; border-top-width: 0; opacity: 1; }
.table th[aria-sort] { color: var(--ink); }
.cell-label { text-align: left !important; max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.site-link { background: none; border: 0; padding: 0; cursor: pointer; font-weight: 550; color: var(--ink); text-align: left; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.site-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
tr.is-current td { background: var(--accent-soft) !important; }
tr.is-current .site-link { color: var(--accent); }

.split { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.split-bar { display: inline-flex; width: 64px; height: 6px; border-radius: 3px; overflow: hidden; background: var(--line-2); }
.split-bar i { display: block; height: 100%; }
.split-bar .g { background: var(--google); }
.split-bar .y { background: var(--yandex); }
.split-nums { color: var(--ink-2); font-size: 12px; min-width: 84px; text-align: right; }

.tabs { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 9px; }
.tabs [role="tab"] { border: 0; background: none; height: 28px; padding: 0 12px; border-radius: 7px; cursor: pointer; font-weight: 550; font-size: 13px; color: var(--ink-2); }
.tabs [role="tab"][aria-selected="true"] { background: var(--ink); color: var(--bg); }

.coverage { list-style: none; margin: 0; padding: 4px 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); column-gap: 1px; }
.coverage-site { display: flex; flex-direction: column; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--line-2); min-width: 0; }
.coverage-domain { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.coverage-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.coverage-src { width: 56px; flex: none; }
.coverage-when { margin-left: auto; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.coverage-summary { margin: 0; font-size: 12px; color: var(--ink-2); display: flex; gap: 12px; flex-wrap: wrap; }
.status { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-ok { color: var(--ok); }
.status-partial { color: var(--partial); }
.status-stale { color: var(--stale); }
.status-unavailable { color: var(--na); }
.status-unavailable::before { background: transparent; border: 1.5px solid currentColor; width: 5px; height: 5px; }

.empty { margin: 0; padding: 28px 16px; text-align: center; color: var(--ink-3); font-size: 13px; }

.main[aria-busy="true"] .kpi-value, .main[aria-busy="true"] .chart svg, .main[aria-busy="true"] tbody { opacity: .45; transition: opacity .2s; }
.main.is-first[aria-busy="true"] .kpi-value { color: transparent; background: var(--line-2); border-radius: 6px; width: 60%; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.login-title { margin: 8px 0 0; font-size: 22px; letter-spacing: -.015em; }
.login-lead { margin: -8px 0 0; color: var(--ink-2); }
.login-error { margin: 0; padding: 9px 12px; border-radius: 8px; background: color-mix(in srgb, var(--down) 10%, var(--panel)); color: var(--down); font-weight: 550; font-size: 13px; }
.login-hint { margin: -4px 0 0; color: var(--ink-3); font-size: 12px; text-align: center; }
.field { display: grid; gap: 6px; }
.field-label { font-size: 13px; font-weight: 550; color: var(--ink-2); }
.field .input { height: 40px; }

@media (max-width: 1080px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .topbar-row { flex-wrap: wrap; }
  .controls { order: 3; flex-basis: 100%; justify-content: flex-start; }
  .logout { margin-left: auto; }
}

@media (max-width: 640px) {
  .topbar { position: static; }
  .topbar-row { padding: 10px 14px; gap: 10px; }
  .main { padding: 14px 12px 40px; }
  .controls .control, .controls .select { flex: 1 1 100%; max-width: none; width: 100%; }
  .seg { flex: 1; }
  .seg label { flex: 1; }
  .seg span { justify-content: center; width: 100%; padding: 0 6px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 22px; }
  .chart { height: 220px; }
  .crumbs { font-size: 17px; }
  .col-hide-sm { display: none; }
  .col-split { display: none; }
  .cell-label { max-width: 170px; }
  .input-small { width: 140px; }
  .table th, .table td { padding: 8px 8px; }
}

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

.detail-coverage { margin: 0; padding: 0 16px 10px; font-size: .75rem; color: var(--ink-2); }
