:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #191919;
  --text-2: #5f6670;
  --text-3: #8a9099;
  --accent: #257de0;
  --accent-soft: #e6f0fc;
  --series-1: #257de0;
  --grid: #eceef1;
  --good: #0f7b2e;   --good-bg: #e5f4ea;
  --warn: #9a6400;   --warn-bg: #fdf3dc;
  --bad: #c42b2c;    --bad-bg: #fde8e8;
  --info: #5f6670;   --info-bg: #eef0f3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111214;
    --surface: #191919;
    --surface-2: #222326;
    --border: #2e3034;
    --text: #efefef;
    --text-2: #a8adb5;
    --text-3: #7d828a;
    --accent: #338ced;
    --accent-soft: #1b2a3d;
    --series-1: #338ced;
    --grid: #2a2c30;
    --good: #4cc66a;   --good-bg: #14301c;
    --warn: #e6b23a;   --warn-bg: #3a2e10;
    --bad: #f07071;    --bad-bg: #3d1a1a;
    --info: #a8adb5;   --info-bg: #26282c;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--text-2); }
.sm { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.error { color: var(--bad); min-height: 18px; margin: 0; font-size: 13px; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }
input, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-height: 34px;
}
input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px;
}
.login-card label { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.login-card .btn { justify-content: center; padding: 10px; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100%; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--text-2); font-size: 12px; }
.brand.big b { font-size: 18px; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 21V13M14 21V9M20 21v-6M26 21V11' stroke='white' stroke-width='3' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
}
nav { display: grid; gap: 2px; }
nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; padding: 0 8px; color: var(--text-2); font-size: 12.5px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.menu-btn { display: none; }
.search { position: relative; flex: 1; max-width: 560px; }
.search input { width: 100%; }
.search-results {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); max-height: 420px; overflow: auto; z-index: 30;
}
.search-results a { display: block; padding: 9px 12px; color: var(--text); border-bottom: 1px solid var(--border); }
.search-results a:last-child { border-bottom: 0; }
.search-results a:hover, .search-results a.hl { background: var(--surface-2); text-decoration: none; }
.search-results small { color: var(--text-2); display: block; margin-top: 2px; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.view { padding: 24px; display: grid; gap: 20px; align-content: start; outline: none; max-width: 1500px; width: 100%; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--text-2); }

/* ---------- cards & KPIs ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--text-2); font-size: 12.5px; }
.kpi .value { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi .sub { color: var(--text-2); font-size: 12px; margin-top: 4px; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* ---------- filters ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters label { display: grid; gap: 4px; font-size: 12px; color: var(--text-2); }
.filters input[type=search] { min-width: 240px; }
.filters input[type=number] { width: 120px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  cursor: pointer; font: inherit; font-size: 12.5px; color: var(--text-2); display: inline-flex; gap: 6px; align-items: center;
}
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- table ---------- */
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
th .arrow { opacity: .35; margin-left: 4px; }
th.sorted .arrow { opacity: 1; color: var(--accent); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr.click { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td .main-cell b { display: block; font-weight: 600; max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
td .main-cell small { color: var(--text-2); display: block; max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
.neg { color: var(--bad); } .pos { color: var(--good); }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; gap: 10px; flex-wrap: wrap; color: var(--text-2); font-size: 12.5px; }
.pager { display: flex; gap: 6px; align-items: center; }
.empty { padding: 36px; text-align: center; color: var(--text-2); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge.good { color: var(--good); background: var(--good-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.flag-list { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { filter: brightness(1.15); }
.chart g.col:hover .hl-bg { fill: var(--surface-2); }
.hbar-list { display: grid; gap: 8px; }
.hbar-row { display: grid; grid-template-columns: 130px 1fr 70px; gap: 10px; align-items: center; font-size: 12.5px; }
.hbar-row .track, .hbar-row .fill { display: block; }
.hbar-row .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar-row .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hbar-row .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15);
  line-height: 1.5; max-width: 260px;
}
.tooltip b { font-variant-numeric: tabular-nums; }

/* ---------- store page ---------- */
.store-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.store-head .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tabs button {
  border: 0; background: none; font: inherit; font-weight: 550; color: var(--text-2); padding: 10px 14px;
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; font-size: 13px; }
dl.props dt { color: var(--text-2); }
dl.props dd { margin: 0; word-break: break-word; }

/* ---------- audit ---------- */
.score-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.score-ring { width: 112px; height: 112px; flex: none; }
.score-ring .bg { stroke: var(--surface-2); }
.score-ring text { fill: var(--text); font-weight: 700; font-size: 26px; }
.check-group { margin-top: 6px; }
.check-group h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 16px 0 6px; }
.check { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--border); }
.check:last-child { border-bottom: 0; }
.check .ico { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.ico.pass { background: var(--good-bg); color: var(--good); }
.ico.warn { background: var(--warn-bg); color: var(--warn); }
.ico.fail { background: var(--bad-bg); color: var(--bad); }
.ico.info { background: var(--info-bg); color: var(--info); }
.check .t { font-weight: 550; }
.check .d { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.ext-frame { width: 100%; height: 720px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.setup { background: var(--surface-2); border-radius: 8px; padding: 14px 16px; font-size: 13px; line-height: 1.6; }
.setup code { background: var(--surface); padding: 1px 6px; border-radius: 4px; border: 1px solid var(--border); }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 120; background: var(--text); color: var(--surface);
  padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--border), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite; }
@keyframes sh { to { background-position: -200% 0; } }
.loading { padding: 40px; text-align: center; color: var(--text-2); }

@media (max-width: 1100px) { .cols-2, .cols-3-1 { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .app.menu-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 14px; }
  .view { padding: 14px; }
}
