/* Layout / padding / spacing inherited from `.app-content > .screen` and
   its `> * + *` rule in app-shell.css. Per-screen `display: flex; gap: 18px`
   would compound with the shared margin rule and produce uneven spacing.
   Explicit width + box-sizing keeps toolbar from collapsing to intrinsic
   content width on browsers that ignore parent's stretch. */
.admin-dashboard-toolbar,
.admin-dashboard-screen > .ad-section,
.admin-dashboard-screen > .ad-kpi-grid,
.admin-dashboard-screen > .ad-analytics-grid {
  width: 100%;
  box-sizing: border-box;
}

.admin-dashboard-toolbar {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  min-width: 0;
}
.ad-generated {
  color: var(--text-muted); font-size: 0.82rem;
  flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.admin-dashboard-toolbar-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  flex: 0 0 auto;
  margin-left: auto;
}

.admin-dashboard-loading, .admin-dashboard-error {
  padding: 28px 20px; text-align: center;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 10px;
}
.admin-dashboard-error { color: var(--accent-red); }

.ad-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 12px;
  min-width: 0; /* let flex/grid children shrink */
}
.ad-section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.ad-section-title {
  font-size: 0.78rem;
  color: var(--accent-gold);
  letter-spacing: 0.8px; text-transform: uppercase;
  font-weight: 700;
  margin: 0;
}
.ad-section-sub { color: var(--text-primary); font-size: 0.78rem; }

/* Tiles: Activity + Games each render as a row of 4 (stacked 2 rows).
   ≥720px: 4-per-row; <720px: 2-per-row. */
.ad-tiles-grid {
  display: grid;
  gap: 1rem;
  /* Centre tile content so DAU/MAU read like HQ tiles. */
  justify-items: center;
  text-align: center;
}
/* 4 tiles in the half-width KPI card: 2x2 desktop, 2-up tablet, 1-up narrow. */
.ad-tiles-row2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.ad-tile {
  /* Match .ad-match-stats-card chrome so Activity / Games + Match-stats
     sub-cards read as one family. */
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  gap: 4px;
  min-width: 0; width: 100%;
  /* Fixed height so every tile shares the same footprint regardless of content. */
  min-height: 116px;
  transition: border-color 0.15s ease, background-color 0.15s ease, transform 0.15s ease;
}
.ad-tile:hover {
  border-color: color-mix(in srgb, var(--accent-gold) 50%, transparent);
  background: var(--bg-hover);
  transform: translateY(-1px);
}
.ad-tile-label {
  /* Aligned with .ad-card-title (match-stats inner card title style). */
  font-size: 0.78rem; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.ad-tile-value {
  font-size: 1.7rem; /* matches .home-tile-value */
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}
.ad-tile-sub {
  font-size: 0.7rem; color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Fixed height so tiles stay uniform when one has a sparkline and
   another has the no-history placeholder. */
.ad-tile-spark {
  width: 100%;
  height: 22px;
  display: flex; align-items: center; justify-content: center;
}
.ad-sparkline {
  width: 100%; height: 100%;
  display: block;
}
.ad-tile-spark-empty {
  font-size: 0.78rem; color: var(--text-muted);
  letter-spacing: 0.4px;
  cursor: help; /* hover surfaces tooltip via title="" */
  opacity: 0.5;
}

.ad-range-select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 6px 28px 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  /* Inline SVG chevron — %23 escapes the # so the data-uri stays valid. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none' stroke='%23888' stroke-width='1.5'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px 8px;
  transition: border-color 0.12s ease, background-color 0.12s ease;
}
.ad-range-select:hover {
  border-color: color-mix(in srgb, var(--accent-gold) 50%, var(--border-color));
  background-color: var(--bg-hover);
}
.ad-range-select:focus-visible {
  outline: 2px solid var(--accent-gold);
  outline-offset: 2px;
}

/* Chart.js 4.x reads parent width at construction. If flex column hasn't
   laid out yet, wrap reads 0 → Chart.js falls back to 300px default →
   section card locks to ~336px wide. Combat with: explicit align-self +
   width on card, explicit width on wrap + canvas, JS rAF resize() after
   construction. */
.ad-chart-card {
  align-self: stretch;
  width: 100%;
  box-sizing: border-box;
}
.ad-chart-card .ad-chart-wrap {
  position: relative;
  height: 320px;
  width: 100%;
  min-width: 0;
}
.ad-chart-card .ad-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.ad-device-card { align-self: stretch; width: 100%; box-sizing: border-box; }
.ad-device-row {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.ad-device-chart-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  flex: 0 0 auto;
}
.ad-device-chart-wrap canvas { display: block; width: 100% !important; height: 100% !important; }
.ad-device-legend { flex: 1 1 240px; min-width: 200px; display: flex; flex-direction: column; gap: 8px; }
.ad-device-legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--bg-card);
  font-size: 0.92rem;
}
.ad-device-swatch {
  width: 14px; height: 14px; border-radius: 3px; flex: 0 0 auto;
}
.ad-device-label  { color: var(--text-primary); }
.ad-device-count  { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.ad-device-pct    { color: var(--text-primary); font-weight: 700; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
@media (max-width: 600px) {
  .ad-device-row { gap: 16px; }
  .ad-device-chart-wrap { width: 200px; height: 200px; }
}

/* 1:1 layout on desktop so every section is the same width; 1-col <1000px.
   align-self:stretch + width:100% required to fill the flex-column parent. */
.ad-kpi-grid,
.ad-analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-self: stretch;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Chrome inherited from data-table block above. Funnel-only: th left
   (label), td right (value), gold tabular numerals. Layout: label / count
   / percent — percent reads as secondary so count stays the headline. */
.ad-funnel-table th { width: 50%; text-transform: none; letter-spacing: 0; font-size: 0.9rem; color: var(--text-secondary); font-weight: 500; border-bottom: 1px solid var(--border-color); background: transparent; }
.ad-funnel-table td { text-align: right; color: var(--text-primary); font-weight: 700; font-variant-numeric: tabular-nums; }
/* Last-row th too — shared rule only targets td and would leave a
   partial-width line under the label cell. */
.ad-funnel-table tr:last-child th { border-bottom: 0; }
.ad-funnel-table .ad-funnel-pct {
  color: var(--text-primary);
  font-weight: 500;
  width: 64px;
}
/* Forfeited + Drawn nest under Finished — left padding + ↳ arrow on label;
   count + percent columns stay aligned with parent rows. */
.ad-funnel-table .ad-funnel-row-sub th {
  padding-left: 28px;
  color: var(--text-muted);
  font-weight: 400;
  position: relative;
}
.ad-funnel-table .ad-funnel-row-sub th::before {
  content: '↳';
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  opacity: 0.6;
}
.ad-funnel-table .ad-funnel-row-sub td {
  color: var(--text-primary);
}

.ad-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Chrome inherited from data-table block above; ad-map-only below. */
.ad-map-table { min-width: 540px; }
.ad-map-table thead th { white-space: nowrap; }
.ad-map-table thead th.ad-num,
.ad-map-table tbody td.ad-num { text-align: right; font-variant-numeric: tabular-nums; }
.ad-map-table tbody td { vertical-align: middle; }
.ad-map-table .ad-map { max-width: 220px; }
.ad-map-friendly {
  color: var(--text-primary); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ad-map-raw {
  color: var(--text-muted); font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.ad-pct {
  display: flex; align-items: center; gap: 8px;
  white-space: nowrap; font-variant-numeric: tabular-nums;
  min-width: 140px;
}
/* Track = P2 portion (unfilled remainder behind P1 fill). Palette matches
   .ad-gametype-bar: blue=first/bot/P1, green=second/human/P2. */
.ad-pct-bar {
  flex: 1 1 80px; height: 8px;
  background: var(--accent-green);
  border-radius: 4px; overflow: hidden;
  min-width: 50px; max-width: 140px;
  position: relative;
}
.ad-pct-p1 {
  display: block; height: 100%;
  background: var(--accent-info);
  transition: width 0.25s ease;
}
.ad-pct-label { font-size: 0.78rem; color: var(--text-secondary); }

.ad-empty {
  text-align: center; color: var(--text-muted); font-style: italic;
  padding: 28px 12px;
}

/* Four cards (specs / end-reasons / decapitation / map-picker); auto-fit
   gives 4 across on wide, 2x2 then 1-up as it narrows. */
.ad-match-stats-section { padding: 16px 18px; }
.ad-match-stats-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  align-items: stretch;
}
.ad-match-stats-card {
  background: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: 8px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
  min-width: 0;
  /* Container-query anchor: spec table inside tightens on card width, not
     viewport. auto-fit minmax(260px,1fr) can produce narrow cards on a
     wide viewport (3 cards × ~320px on 1024px) where @media rules don't fire. */
  container-type: inline-size;
}

/* Inline horizontal bar inside a numeric cell — fills behind the number so
   the eye can compare share without scanning a separate column. */
.ad-cell-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  white-space: nowrap;
}
.ad-cell-bar > span { min-width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.ad-bar-track {
  flex: 1 1 auto; min-width: 32px; max-width: 90px;
  height: 6px; border-radius: 3px;
  background: color-mix(in srgb, var(--accent-gold) 14%, transparent);
  overflow: hidden;
}
.ad-bar-track-warn { background: color-mix(in srgb, var(--accent-red) 14%, transparent); }
.ad-bar-track-neutral { background: color-mix(in srgb, var(--text-secondary) 14%, transparent); }
.ad-bar-fill {
  height: 100%;
  background: var(--accent-gold);
  border-radius: 3px;
  transition: width 240ms ease;
}
.ad-bar-track-warn    .ad-bar-fill { background: var(--accent-red); }
.ad-bar-track-neutral .ad-bar-fill { background: var(--text-secondary); }

.ad-spec-name { font-weight: 600; color: var(--text-primary); }
.ad-winrate {
  display: inline-block;
  font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 1px 8px; border-radius: 999px;
  border: 1px solid currentColor;
  background: color-mix(in srgb, currentColor 12%, transparent);
  /* Don't widen past the cell — would clip on narrow viewports. */
  max-width: 100%;
  white-space: nowrap;
}
.ad-winrate-win-high    { color: var(--accent-green); }
.ad-winrate-win-low     { color: var(--accent-red); }
.ad-winrate-win-neutral { color: var(--text-secondary); }

/* Mini-table needs ~330px; auto-fit minmax(260px,1fr) on the parent grid
   can produce 260-320px cards on a wide viewport, so use a CONTAINER
   query — viewport @media wouldn't fire. */
@container (max-width: 360px) {
  .ad-mini-table              { font-size: 0.82rem; }
  .ad-mini-table th, .ad-mini-table td { padding: 4px 6px; }
  .ad-cell-bar                { gap: 4px; }
  .ad-cell-bar > span         { min-width: 2.6em; }
  .ad-bar-track               { display: none; }
  .ad-winrate                 { padding: 1px 5px; font-size: 0.78rem; }
}

.ad-gametype-card { gap: 14px; }
.ad-gametype-bar {
  display: flex; height: 12px; border-radius: 6px; overflow: hidden;
  background: color-mix(in srgb, var(--text-secondary) 14%, transparent);
}
.ad-gametype-bar-bot   { background: var(--accent-info);  height: 100%; }
.ad-gametype-bar-human { background: var(--accent-green); height: 100%; }

.ad-gametype-legend {
  margin: 0; display: flex; flex-direction: column; gap: 6px;
  font-size: 0.88rem;
}
.ad-gametype-row {
  display: flex; justify-content: space-between; gap: 8px; align-items: baseline;
}
.ad-gametype-row dt {
  display: flex; align-items: center; gap: 8px;
  margin: 0; color: var(--text-muted);
  /* Truncate before label pushes count off-card in narrow containers. */
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.ad-gametype-row dd {
  margin: 0; color: var(--text-primary); font-weight: 700;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ad-gametype-swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  flex: 0 0 auto;
}
.ad-gametype-swatch-bot   { background: var(--accent-info); }
.ad-gametype-swatch-human { background: var(--accent-green); }

.ad-decap-card { gap: 14px; }
.ad-decap-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-style: italic; padding: 24px 0;
}
.ad-decap-hero {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px;
  padding: 18px 0; border-radius: 12px;
  background: color-mix(in srgb, var(--text-secondary) 6%, transparent);
  border: 2px solid color-mix(in srgb, var(--text-secondary) 20%, transparent);
}
/* Alarm ring + number — applied when metric is far enough off-balance to warrant attention. */
.ad-decap-ring-alarm { border-color: color-mix(in srgb, var(--accent-red) 55%, transparent); background: color-mix(in srgb, var(--accent-red) 10%, transparent); }
.ad-decap-rate {
  font-size: 2.2rem; font-weight: 800; line-height: 1;
  color: var(--text-primary); font-variant-numeric: tabular-nums;
}
.ad-decap-ring-alarm .ad-decap-rate { color: var(--accent-red); }
.ad-decap-rate-label {
  font-size: 0.72rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.ad-decap-meta {
  margin: 0; display: flex; flex-direction: column; gap: 6px;
}
.ad-decap-row {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.88rem;
}
.ad-decap-row dt { color: var(--text-muted); margin: 0; }
.ad-decap-row dd { color: var(--text-primary); font-weight: 700; margin: 0; font-variant-numeric: tabular-nums; }
.ad-card-title {
  font-size: 0.85rem; color: var(--text-secondary); margin: 0;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.ad-mini-table {
  width: 100%; border-collapse: collapse; font-size: 0.88rem;
}
.ad-mini-table th, .ad-mini-table td {
  padding: 5px 8px; text-align: left;
}
.ad-mini-table th {
  color: var(--text-muted); font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border-color);
}
.ad-mini-table td {
  color: var(--text-primary); font-variant-numeric: tabular-nums;
}
.ad-mini-table .ad-num { text-align: right; }

/* Breakpoints:
   ≥1000px    4-per-row tiles, analytics side-by-side
   720-1000px 4-per-row tiles, analytics stacked
   480-720px  2-per-row tiles, header stacked, shorter chart
   <480px     2-per-row compact, no sub-labels */
@media (max-width: 1000px) {
  .ad-kpi-grid,
  .ad-analytics-grid { grid-template-columns: 1fr; }
  /* Full-width KPI cards get 4 tiles in one row. */
  .ad-tiles-row2 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .admin-dashboard-toolbar { flex-direction: column; align-items: stretch; }
  .admin-dashboard-toolbar-actions { justify-content: flex-end; }
  .ad-chart-card .ad-chart-wrap { height: 240px; }
  .ad-tiles-row2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ad-tile-value { font-size: 1.4rem; }
  .ad-tile { padding: 12px 12px; }
}
@media (max-width: 480px) {
  .ad-tiles-grid { gap: 8px; }
  .ad-tile { padding: 10px 11px; }
  .ad-tile-value { font-size: 1.3rem; }
  .ad-tile-sub { display: none; }
  .ad-section { padding: 14px; }
  .ad-chart-card .ad-chart-wrap { height: 200px; }
  .admin-dashboard-screen { padding: 14px 12px; gap: 14px; }
}
