/* Stats domain: /stats tabs, /map, /heatmap. Uses the tokens of app.css only. */

/* ------------------------------------------------------------- shared bits */
.st-counts { margin-bottom: 14px; }
.st-tabs { margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.st-tabs .tabs { border-bottom: 0; }
.st-body > .card + .card, .st-body > .grid-2 + .card, .st-body > .card + .grid-2,
.st-body > .grid-3 + .card, .st-body > .card + .grid-3, .st-body > .grid-2 + .grid-2,
.st-body .pn-dim > .card + .card, .st-body .pn-dim > .grid-2 + .card, .st-body .pn-dim > .card + .grid-2,
.st-body .pn-dim > .grid-3 + .card, .st-body .pn-dim > .card + .grid-3, .st-body .pn-dim > .grid-2 + .grid-2,
.st-body p + .grid-2, .st-body p + .card, .st-body .country-grid { margin-top: 14px; }
.st-body > .card:first-child, .st-body .pn-dim > .card:first-of-type { margin-top: 0; }
.st-body .state.error { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.st-h2 { font-size: 16px; font-weight: 700; margin: 22px 0 4px; }
.st-subhead { font-weight: 650; font-size: 13.5px; margin: 14px 0 6px; }
.st-subhead:first-child { margin-top: 0; }
.st-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin: 2px 0 6px; }
.st-foot { margin: 10px 0 0; }
.st-gap { height: 12px; }
.st-loading { display: flex; align-items: center; gap: 8px; color: var(--text-2); }
.card-note { color: var(--text-2); font-size: 13px; margin: 0 0 12px; }
.strong { color: var(--text); }
.big-figure { font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.25; }
.big-figure .muted { font-size: 14px; font-weight: 500; }
.star { color: #f59f00; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.pad { padding: 12px 16px; margin: 0; }
.trunc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-active td { background: var(--accent-soft); }
.card-head .card-title .muted { font-weight: 500; }
.card-actions .input-sm { max-width: 52vw; }

/* Reloading: the previous result stays, dimmed and inert, under a spinner. */
.pn-dim { position: relative; }
.pn-dim > :not(.pn-dim-spin) { opacity: .45; pointer-events: none; transition: opacity .15s; }
.pn-dim-spin { position: absolute; z-index: 5; left: 50%; top: 40px; transform: translateX(-50%); padding: 8px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-lg); line-height: 0; }

/* Two-column stat lists. */
.grid-3 { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2.st-5-7 { grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
  .grid-2.st-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }
  .grid-2.st-4-8 { grid-template-columns: minmax(0, 4fr) minmax(0, 8fr); }
}
.kvlist { list-style: none; margin: 0 0 6px; padding: 0; }
.kvlist li { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kvlist li:last-child { border-bottom: 0; }
.kvlist.narrow { max-width: 460px; }
.mini-stats { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-bottom: 4px; }
@media (min-width: 900px) { .mini-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mini-stat { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; background: var(--surface-2); }
.mini-stat span { font-size: 12px; color: var(--text-2); font-weight: 600; }
.mini-stat strong { font-size: 19px; font-variant-numeric: tabular-nums; }
.mini-stat em { font-style: normal; font-size: 13px; color: var(--text-2); font-weight: 600; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th { text-align: left; font-size: 11.5px; color: var(--text-3); font-weight: 650; padding: 4px 6px 4px 0; border-bottom: 1px solid var(--border); }
.mini-table td { padding: 4px 6px 4px 0; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.mini-table .num { text-align: right; }
.delist-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); margin-top: 12px; }
@media (min-width: 900px) { .delist-grid { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); } }
.recent-grid { display: grid; gap: 2px 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .recent-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .recent-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.recent-item { font-size: 13px; padding: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Ranked lists: thumb · name + sub · value. */
.rank { list-style: none; margin: 0; padding: 0; counter-reset: rank; }
.rank li { counter-increment: rank; display: flex; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--border); min-height: 44px; }
.rank li:last-child { border-bottom: 0; }
.rank li::before { content: counter(rank); flex: none; width: 18px; text-align: right; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.rank.plain li { min-height: 32px; }
.rank-main { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.rank-name { font-size: 13px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.rank-name { color: var(--text); }
.rank-sub { font-size: 11.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-val { flex: none; font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cthumb { flex: none; display: block; width: 28px; height: 36px; border-radius: 5px; overflow: hidden; background: var(--surface-3); }
.cthumb img { width: 100%; height: 100%; object-fit: cover; }
.cthumb.lg { width: 36px; height: 46px; }
.rank-groups { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .rank-groups { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1900px) { .rank-groups { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.rank-group-title { font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.rank-pair { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.rank-cols { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }
.rank-wide .rank { columns: 1; }
@media (min-width: 900px) { .rank-wide .rank { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; } }
.hbars-2col .hbars { display: grid; gap: 9px 28px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .hbars-2col .hbars { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Age distribution (vertical CSS bars). */
.vbars { display: flex; align-items: flex-end; gap: 2px; height: 150px; }
.vbar { flex: 1 1 0; min-height: 2px; background: var(--c-blue); border-radius: 2px 2px 0 0; }
.vbar-labels { display: flex; gap: 2px; margin-top: 3px; }
.vbar-labels span { flex: 1 1 0; text-align: center; font-size: 9.5px; color: var(--text-3); overflow: visible; white-space: nowrap; }

/* Overlap card. */
.ov-head { max-width: 560px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; }
.ov-title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ov-legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; font-size: 13px; }
.ov-legend a { color: var(--text); min-height: 32px; display: inline-flex; align-items: center; }
.ov-legend strong { margin-left: 4px; }
td.ov-mix { min-width: 140px; vertical-align: middle; }
.ov-sides { margin-bottom: 4px; }
@media (max-width: 719.98px) { td.ov-mix { grid-column: 1 / -1; } }

/* Working-schedule heatmap. */
.sched-wrap { overflow-x: auto; margin: 0 calc(-1 * 4px); padding: 0 4px; }
.sched { border-collapse: separate; border-spacing: 2px; font-size: 11px; }
.sched th { font-weight: 500; color: var(--text-3); text-align: center; min-width: 22px; }
.sched th[scope="row"] { text-align: left; padding-right: 6px; white-space: nowrap; }
.sched td { width: 22px; height: 22px; border-radius: 3px; }
.sched td.zero { outline: 1px solid var(--border); outline-offset: -1px; }
.sched .sched-total { color: var(--text-2); padding-left: 8px; white-space: nowrap; width: auto; text-align: left; }
.sched-foot td { height: auto; font-size: 9px; color: var(--text-3); text-align: center; }
.sched-sw { display: inline-block; width: 16px; height: 12px; border-radius: 2px; }

/* Countries. */
.flag { font-size: 18px; margin-right: 6px; vertical-align: -2px; }
.flag.lg { font-size: 22px; }
.country-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 720px) { .country-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1200px) { .country-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.country-card { margin: 0 !important; scroll-margin-top: 80px; }
.country-head { display: flex; align-items: center; gap: 6px; padding: 10px 16px 0; min-width: 0; }
.country-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.country-head .push { margin-left: auto; flex: none; }

/* Options tab. */
.opt-filters { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); margin-bottom: 12px; }
@media (min-width: 720px) { .opt-filters { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
td.q-few { font-size: 12px; }
@media (max-width: 719.98px) { td.q-few { grid-column: 1 / -1; } }

/* AI tab. */
.ai-chip { display: inline-block; padding: 1px 6px; border-radius: 5px; font-size: 11px; font-weight: 700; line-height: 1.4; color: #fff; background: rgba(111, 66, 193, .94); vertical-align: 1px; cursor: help; }
.ai-chip.edit { background: rgba(52, 58, 64, .9); }
.ai-chip.copy { outline: 1px dashed rgba(255, 255, 255, .9); outline-offset: -2px; }
.ai-chip.sm { font-size: 10px; padding: 0 4px; }
.ai-chip.over { position: absolute; top: 6px; left: 6px; }
.stat-share { font-size: 14px; font-weight: 600; color: var(--text-2); }
.stat-hint.wrap { white-space: normal; }
.st-ai-kpis { margin-top: 14px; }

/* ------------------------------------------------------------------ /map */
.map-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.map-toolbar:empty { display: none; }
.map-switch { margin-left: auto; }
.map-page { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
.map-pane { position: relative; }
.map-canvas, .hm-map { width: 100%; height: 62vh; min-height: 360px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-2); z-index: 0; }
.map-gate {
  position: absolute; inset: 0; z-index: 500; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 16px; text-align: center; color: var(--text-2); font-weight: 600;
  background: color-mix(in srgb, var(--surface) 72%, transparent); border-radius: var(--radius); backdrop-filter: blur(2px);
}
.map-list { min-width: 0; }
.map-list > .alert { margin-bottom: 10px; }
.map-coverage { margin: 0 0 8px; }
.map-hint { margin: 0 0 8px; }
.map-cards { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) and (max-width: 1199.98px) { .map-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.map-card { display: flex; gap: 10px; padding: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); scroll-margin: 12px; }
.map-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.map-banner { position: relative; flex: none; width: 112px; }
.map-banner img, .map-banner-empty { width: 112px; height: 84px; object-fit: cover; border-radius: var(--radius-sm); background: var(--surface-3); }
.map-card-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.map-card-body .badge { align-self: flex-start; margin-bottom: 2px; }
.map-name { font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-locate { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; min-height: 32px; }
.map-addr { margin-top: 10px; }
.map-addr summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.map-addr ul { list-style: none; padding: 0; margin: 6px 0 0; font-size: 13px; }
.map-addr li { padding: 3px 0; }
.map-dir { margin-top: 12px; }
@media (min-width: 1200px) {
  .map-page { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
  .map-pane { position: sticky; top: 16px; }
  .map-canvas { height: calc(100dvh - 190px); }
  .map-list { max-height: calc(100dvh - 190px); overflow-y: auto; padding-right: 2px; }
}
@media (min-width: 720px) { .map-switch { display: none; } .map-toolbar:has(.filter-toggle) { display: none; } }
/* Phones: one of map or list at a time; in map mode only the selected card shows. */
@media (max-width: 719.98px) {
  .map-canvas { height: 58vh; min-height: 300px; }
  .map-page.show-list .map-pane { display: none; }
  .map-page:not(.show-list) .map-card:not(.selected), .map-page:not(.show-list) .map-addr,
  .map-page:not(.show-list) .map-dir { display: none; }
}
/* Leaflet surfaces follow the theme; the tiles are inverted in dark mode. */
html[data-theme="dark"] .map-shell .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9); }
html[data-theme="dark"] .map-shell.leaflet-container { background: #1f2937; }
.map-shell .leaflet-popup-content-wrapper, .map-shell .leaflet-popup-tip,
.map-shell .leaflet-bar a, .map-shell .leaflet-tooltip { background: var(--surface); color: var(--text); border-color: var(--border); }
.map-shell .leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 80%, transparent); color: var(--text-2); }
.map-shell .leaflet-control-attribution a { color: var(--text-2); }

/* -------------------------------------------------------------- /heatmap */
.hm-status { margin: 0 0 10px; }
.hm-wrap { position: relative; }
.hm-map { height: 72vh; min-height: 420px; background: #dfe7ee; }
html[data-theme="dark"] .hm-map { background: #1f2937; }
.hm-desc { margin: 6px 0 0; }
.hm-legend {
  position: absolute; right: 10px; bottom: 22px; z-index: 800; pointer-events: none;
  background: var(--surface); color: var(--text); padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.35;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25); max-width: 240px;
}
.hm-legend .hm-title { font-weight: 650; margin-bottom: 4px; }
.hm-legend .hm-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.hm-legend .hm-swatch { width: 16px; height: 12px; border-radius: 2px; flex: none; border: 1px solid rgba(0, 0, 0, .15); }
.hm-legend .hm-dot { border-radius: 50%; flex: none; background: rgba(235, 104, 52, .55); border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .25); }
.hm-legend .hm-hatch { background: repeating-linear-gradient(45deg, #e1e0d9 0 3px, #fcfcfb 3px 6px); }
.hm-legend .hm-bubbles .hm-title { margin-top: 6px; }
.hm-muted { color: var(--text-2); }
@media (max-width: 600px) {
  .hm-map { height: 64vh; min-height: 340px; }
  .hm-legend { font-size: 11px; padding: 5px 7px; max-width: 150px; right: 6px; bottom: 18px; }
  .hm-legend .hm-bubbles { display: none; }
}
.hm-tip { font-size: 12px; line-height: 1.4; }
.hm-tip b { font-weight: 650; }
.hm-tip-title { font-weight: 650; }
.hm-details { margin-top: 14px; }
.hm-details > summary { justify-content: flex-start; align-items: center; cursor: pointer; list-style: none; padding: 13px 16px; min-height: 44px; }
.hm-details > summary::-webkit-details-marker { display: none; }
.hm-details > summary::before { content: "▸"; color: var(--text-3); margin-right: 8px; }
.hm-details[open] > summary::before { content: "▾"; }
.hm-method { margin: 0 0 8px; padding-left: 18px; }
.hm-method li { margin-bottom: 4px; }

/* ------------------------------------------------- layout fixes / phones */
.st-body .grid-2, .st-body .grid-3 { align-items: start; }
.st-body .grid-2 > .card, .st-body .grid-3 > .card, .st-body .grid-2 > div > .card,
.st-body .pn-dim .grid-2 > .card, .st-body .pn-dim .grid-3 > .card { margin-top: 0; }
.st-stack > div + div { margin-top: 6px; }
a.opt-link { color: var(--text); }
/* Phones: stats tables are compact rows (name on top, figures inline with small
   labels) instead of one tall label/value grid per row. */
@media (max-width: 719.98px) {
  .st-body .dt tr, .hm-details .dt tr {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 3px 14px; padding: 9px 16px;
  }
  .st-body .dt td, .hm-details .dt td { width: auto; font-size: 13px; }
  .st-body .dt td.dt-primary, .hm-details .dt td.dt-primary { flex: 1 1 100%; font-size: 14px; margin: 0; }
  .st-body .dt td::before, .hm-details .dt td::before {
    display: inline; margin: 0 4px 0 0; font-size: 10px; letter-spacing: .03em;
  }
  .st-body .dt td.ov-mix { flex: 1 1 100%; }
  .st-body .dt td.ov-mix::before { display: none; }
  .st-body .dt td[data-label=""]::before { display: none; }
}
@media (max-width: 719.98px) {
  .st-body .dt td.dt-primary::before, .hm-details .dt td.dt-primary::before { display: none; }
}
.opt-sort { display: none; }
@media (max-width: 719.98px) { .opt-sort { display: block; padding: 12px 16px 4px; } }
