/* OLX UZ KPI dashboard — chrome tokens follow the dataviz reference palette. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --good: #006300;
  --bad: #d03b3b;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --spark: #c3c2b7;
  --diverge-neg: #e34948;
  --fresh-green: #0ca30c;
  --fresh-amber: #fab219;
  --fresh-red: #d03b3b;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --good: #0ca30c;
    --bad: #e66767;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --spark: #52514e;
    --diverge-neg: #e66767;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

/* --- top bar -------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand { font-weight: 650; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--ink-2);
  text-decoration: none;
}
.tab:hover { background: var(--page); }
.tab.active { background: var(--accent); color: #fff; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.fresh {
  font-size: 12px;
  color: var(--ink-2);
  padding: 3px 10px 3px 22px;
  border: 1px solid var(--border);
  border-radius: 999px;
  position: relative;
}
.fresh::before {
  content: "";
  position: absolute;
  left: 9px; top: 50%;
  transform: translateY(-50%);
  width: 8px; height: 8px;
  border-radius: 50%;
}
.fresh-green::before { background: var(--fresh-green); }
.fresh-amber::before { background: var(--fresh-amber); }
.fresh-red::before   { background: var(--fresh-red); }
.logout { color: var(--muted); font-size: 12px; text-decoration: none; }
.logout:hover { color: var(--ink-2); }

main { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* --- stale banner ---------------------------------------------------- */
.stale-banner {
  background: var(--surface);
  border: 1px solid var(--fresh-amber);
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 16px;
  color: var(--ink-2);
  font-size: 13px;
}
.stale-chip {
  display: inline-block;
  margin: 0 4px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--fresh-amber);
  font-size: 12px;
}

/* --- KPI cards -------------------------------------------------------- */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 10px;
}
.card-label { color: var(--ink-2); font-size: 13px; margin-bottom: 6px; }
.card-value { font-size: 28px; font-weight: 600; line-height: 1.1; }
.card-value.none { color: var(--muted); }
.card-unit { font-size: 13px; font-weight: 400; color: var(--muted); margin-left: 6px; }
.card-deltas {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}
.delta { font-variant-numeric: tabular-nums; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.card-period { margin-left: auto; }
.spark-holder { position: relative; height: 36px; margin-top: 8px; }

/* --- charts ----------------------------------------------------------- */
.charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
  gap: 16px;
}
@media (max-width: 560px) { .charts { grid-template-columns: 1fr; } }
.chart-card {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.chart-card figcaption { font-weight: 600; margin-bottom: 10px; }
.chart-card .unit { color: var(--muted); font-weight: 400; font-size: 12px; }
.chart-holder { position: relative; height: 260px; }
.chart-note { color: var(--muted); font-size: 12px; margin-top: 8px; }

/* --- login / nodata ---------------------------------------------------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--page);
}
.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { font-size: 16px; margin: 0 0 8px; }
.login-box input {
  padding: 10px 12px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
}
.login-box button {
  padding: 10px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.login-error { color: var(--bad); font-size: 13px; }
.nodata { text-align: center; padding: 80px 0; color: var(--ink-2); }

/* --- collapsible filter panel -------------------------------------------- */
.filters-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 16px;
}
.filters-panel summary {
  cursor: pointer;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}
.filters-title { font-weight: 600; }
.filters-count {
  font-size: 12px;
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  padding: 1px 10px;
}
.filters-hint { font-size: 12px; color: var(--muted); }
.grain-toggle { margin-left: auto; }
.grain-toggle a {
  display: inline-block;
  padding: 5px 14px;
  font-size: 12.5px;
  color: var(--ink-2);
  background: var(--page);
  text-decoration: none;
}
.grain-toggle a + a { border-left: 1px solid var(--baseline); }
.grain-toggle a.active { background: var(--accent); color: #fff; }
.filters-panel form { padding: 4px 16px 12px; }
.f-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 6px 0;
  border-top: 1px solid var(--grid);
  flex-wrap: wrap;
}
.f-row-label {
  width: 120px;
  flex: 0 0 auto;
  color: var(--ink-2);
  font-size: 13px;
  padding-top: 8px;
}
.f-actions { border-top: 1px solid var(--grid); padding-top: 10px; align-items: center; }
.f-actions button {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.filters-clear { color: var(--muted); font-size: 13px; }
.f-field {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--page);
  flex-wrap: wrap;
  min-width: 160px;
}
.f-lvl { font-size: 11px; color: var(--muted); font-weight: 600; }
.fg-chips { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--ink);
  background: var(--page);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
}
.chip-x {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.chip-x:hover { color: var(--bad); }
.fg-input {
  min-width: 110px;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  padding: 5px 4px;
}
.fg-input:focus { outline: none; }
.filter-note {
  color: var(--muted);
  font-size: 12px;
  margin: -8px 0 14px;
}

/* --- fullscreen charts ------------------------------------------------------ */
.fs-btn {
  float: right;
  border: 1px solid var(--baseline);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
  padding: 3px 7px;
  cursor: pointer;
}
.fs-btn:hover { color: var(--ink); border-color: var(--muted); }
.chart-card.fullscreen {
  position: fixed;
  inset: 14px;
  z-index: 80;
  overflow: auto;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
}
.chart-card.fullscreen .chart-holder { height: calc(100vh - 160px); }
body.has-fullscreen { overflow: hidden; }

/* --- Uzbekistan map ----------------------------------------------------------- */
.uz-map { width: 100%; height: auto; display: block; }
.uz-map path {
  stroke: var(--surface);
  stroke-width: 1.5;
  cursor: pointer;
}
.uz-map path:hover { stroke: var(--ink-2); }
.uz-map .uz-nodata { fill: var(--grid); }
/* --- loading overlay ---------------------------------------------------------- */
.page-loading {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: color-mix(in srgb, var(--page) 72%, transparent);
  backdrop-filter: blur(2px);
}
.page-loading-spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--grid);
  border-top-color: var(--accent);
  animation: pl-spin 0.8s linear infinite;
}
.page-loading-text { color: var(--ink-2); font-size: 13px; }
@keyframes pl-spin { to { transform: rotate(360deg); } }

.viz-tip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--grid);
  border-radius: 8px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  padding: 7px 10px;
  font-size: 12.5px;
  max-width: 320px;
}
.map-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.map-legend-bar {
  flex: 0 0 140px;
  height: 8px;
  border-radius: 4px;
}
.matrix .hm-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.matrix .hm-col { text-align: center; padding: 0 0 4px; }
.matrix .hm-cell { aspect-ratio: auto; height: 22px; }

/* --- timeline player ---------------------------------------------------------- */
.player-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--ink-2);
}
.player-controls label { display: flex; align-items: center; gap: 6px; }
.player-controls select {
  padding: 6px 10px;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
  font-size: 13px;
}
.pl-toggle {
  display: inline-flex;
  border: 1px solid var(--baseline);
  border-radius: 8px;
  overflow: hidden;
}
.pl-toggle button {
  border: none;
  background: var(--page);
  color: var(--ink-2);
  font-size: 12.5px;
  padding: 6px 12px;
  cursor: pointer;
}
.pl-toggle button + button { border-left: 1px solid var(--baseline); }
.pl-toggle button.active { background: var(--accent); color: #fff; }
.pl-toggle button:disabled { opacity: 0.35; cursor: not-allowed; }
.pl-play {
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}
.pl-date {
  margin-left: auto;
  font-weight: 650;
  font-size: 15px;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.player-slider-row { padding: 2px 4px 14px; }
.player-slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.player-holder { height: 460px; transition: opacity 0.15s; }
.player-card { max-width: 1100px; margin: 0 auto; }

/* --- info buttons + popovers -------------------------------------------- */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border: 1px solid var(--baseline);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-style: italic;
  font-family: Georgia, serif;
  cursor: pointer;
  vertical-align: text-bottom;
}
.info-btn:hover { color: var(--ink); border-color: var(--muted); }
.popover {
  position: absolute;
  z-index: 30;
  top: 22px;
  left: 0;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
  padding: 12px 14px;
  font-size: 12.5px;
  font-weight: 400;
  color: var(--ink-2);
}
.popover p { margin: 0 0 6px; }
.popover p:last-child { margin-bottom: 0; }
.fallback {
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--baseline);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

/* --- heatmap -------------------------------------------------------------- */
.heatmap {
  display: grid;
  gap: 2px;                  /* the surface gap between cells */
  align-items: stretch;
}
.hm-label {
  font-size: 10px;
  color: var(--muted);
  padding-right: 6px;
  align-self: center;
}
.hm-cell {
  aspect-ratio: 1 / 1;
  border-radius: 3px;
  min-width: 10px;
}
.hm-cell.hm-empty { background: var(--grid); opacity: 0.35; }

/* --- dictionary ------------------------------------------------------------ */
.dict-title { margin: 4px 0 6px; }
.dict-intro { color: var(--ink-2); max-width: 860px; }
.dict-wrap { overflow-x: auto; }
.dict {
  border-collapse: collapse;
  font-size: 13px;
  min-width: 900px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.dict th, .dict td {
  text-align: left;
  vertical-align: top;
  padding: 9px 12px;
  border-bottom: 1px solid var(--grid);
}
.dict th {
  color: var(--muted);
  font-weight: 600;
  background: var(--surface);
}
.dict-name { font-weight: 600; white-space: nowrap; }
.dict code {
  font-size: 11.5px;
  color: var(--ink-2);
  background: var(--page);
  padding: 1px 4px;
  border-radius: 4px;
}
