/* Statistics in the cabinet and on the operator page. Loaded after
   bearmark.css and the page's own sheet; kit roles only (design/core:
   BmChart, BmCard tiles, BmBadge, BmTable, BmSegmented). Series are marks
   on the surface, so they use the -ink tones (3:1 and more in both themes);
   raw brass is never a mark or text. */

.stats-view {
  display: grid;
  gap: 18px;
  min-width: 0;
}
.stats-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px 16px;
}
.stats-controls .field {
  display: grid;
  gap: 6px;
  min-width: min(100%, 220px);
}
.stats-period {
  display: grid;
  gap: 6px;
}
/* The overline over the period switch, like a field label. */
.stats-overline {
  color: var(--bm-text-soft);
  font: 600 11px/1.35 var(--bm-font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.segmented.is-three,
.admin-segmented.is-three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.stats-note {
  margin: 0;
  color: var(--bm-text-soft);
  font-size: 13px;
}
.stats-body {
  display: grid;
  gap: 18px;
  min-width: 0;
}
.stats-body[aria-busy='true'] {
  opacity: 0.6;
}
.skeleton.chart-shape {
  min-height: 268px;
  border-radius: var(--bm-radius-lg);
}
.stats-section {
  display: grid;
  gap: 12px;
  min-width: 0;
}
.stats-section > h3 {
  margin: 6px 0 0;
  font-size: 18px;
}
.stats-section > .muted {
  margin: -6px 0 0;
  font-size: 14px;
}

/* ---- tiles (BmCard, overline label, display figure) ------------------------- */
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr));

  gap: 12px;
  margin: 0;
}
.stat-tile {
  display: grid;
  align-content: start;
  gap: 4px;
  min-width: 0;
  margin: 0;
  padding: 14px 16px 15px;
  border: 1px solid var(--bm-border-strong);
  border-radius: var(--bm-radius-lg);
  background: var(--bm-surface);
  box-shadow: var(--bm-shadow-xs);
}
.stat-tile dt {
  color: var(--bm-text-soft);
  font: 700 11px/1.35 var(--bm-font-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.stat-tile dd {
  margin: 0;
  min-width: 0;
}
/* A tile's figure: the H2 role. */
.stat-value {
  font: 600 var(--tb-type-h2-size) / var(--tb-type-h2-line)
    var(--bm-font-display);
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-value small {
  margin-left: 4px;
  color: var(--bm-text-soft);
  font: 600 14px/1 var(--bm-font-body);
  letter-spacing: 0;
}
.stat-delta {
  color: var(--bm-text-soft);
  font: 600 12px/1.35 var(--bm-font-mono);
  font-variant-numeric: tabular-nums;
}
.stat-delta[data-tone='good'] {
  color: var(--bm-good-ink);
}
.stat-delta[data-tone='warn'] {
  color: var(--bm-warn-ink);
}
.stat-detail {
  color: var(--bm-text-soft);
  font-size: 13px;
}
.stat-tile[data-tone='warn'] {
  border-color: color-mix(in srgb, var(--bm-warn-ink) 60%, transparent);
}
.stat-tile[data-tone='warn'] .stat-value {
  color: var(--bm-warn-ink);
}

/* Six or seven tiles: rows of three on a wide screen, never an orphan. */
@media (min-width: 900px) {
  .stat-tiles {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (min-width: 1300px) {
  .admin-panel .stat-tiles {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

/* ---- charts (BmChart) ---------------------------------------------------- */
.stats-charts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr));
  gap: 12px;
}
.chart {
  display: grid;
  gap: 10px;
  align-content: start;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--bm-border-strong);
  border-radius: var(--bm-radius-lg);
  background: var(--bm-surface);
  box-shadow: var(--bm-shadow-xs);
}
.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chart-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.chart-toggle {
  flex: none;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--bm-border-strong);
  border-radius: var(--bm-radius-md);
  background: transparent;
  color: var(--bm-text);
  font: 700 11px/1 var(--bm-font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
}
.chart-toggle:hover {
  background: color-mix(in srgb, var(--bm-text) 6%, transparent);
}
.chart-canvas {
  min-width: 0;
  height: 180px;
}
.chart-svg {
  display: block;
  overflow: visible;
}
.chart-grid {
  stroke: var(--bm-border);
  stroke-width: 1;
}
.chart-base {
  stroke: var(--bm-border-strong);
  stroke-width: 1;
}
.chart-tick {
  fill: var(--bm-text-soft);
  font: 500 11px var(--bm-font-mono);
  font-variant-numeric: tabular-nums;
}
.chart-line {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chart-limit {
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
}
.chart-summary {
  margin: 0;
  color: var(--bm-text-soft);
  font-size: 13px;
}
.chart-empty {
  margin: 0;
  font-size: 14px;
}
.chart-legend,
.share-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}
.chart-legend li,
.share-list li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.chart-legend strong,
.share-list strong {
  font: 700 13px/1 var(--bm-font-mono);
  font-variant-numeric: tabular-nums;
}
.chart-legend-name {
  color: var(--bm-text-soft);
}
.chart-swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: currentColor;
}
.chart-swatch.is-line {
  height: 0;
  border-top: 2px dashed currentColor;
  background: transparent;
}
.share-percent {
  color: var(--bm-text-soft);
  font: 500 12px/1 var(--bm-font-mono);
}
.share-track {
  display: flex;
  gap: 2px;
  height: 14px;
  overflow: hidden;
  border-radius: var(--bm-radius-pill);
  background: var(--bm-track);
}
.share-part {
  flex: var(--share) 1 0;
  min-width: 3px;
  background: currentColor;
}
.chart-table-wrap {
  max-height: 320px;
  overflow: auto;
  border: 1px solid var(--bm-border);
  border-radius: var(--bm-radius-md);
}

/* Tones: text colour for swatches and parts, fill or stroke for marks. */
.tone-accent {
  color: var(--bm-accent-ink);
}
.tone-info {
  color: var(--bm-info-ink);
}
.tone-good {
  color: var(--bm-good-ink);
}
.tone-warn {
  color: var(--bm-warn-ink);
}
.tone-caution {
  color: var(--bm-caution-ink);
}
.tone-muted {
  color: var(--bm-pending-ink);
}
.chart-bar,
.chart-point {
  fill: currentColor;
}
.chart-line,
.chart-limit {
  stroke: currentColor;
}

/* ---- tables (BmTable) -------------------------------------------------------- */
.stats-table-wrap {
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--bm-border-strong);
  border-radius: var(--bm-radius-lg);
  background: var(--bm-surface);
}
.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.stats-table th,
.stats-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--bm-border);
  text-align: left;
  vertical-align: middle;
}
.stats-table thead th {
  color: var(--bm-text-soft);
  font: 700 11px/1.3 var(--bm-font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom-color: var(--bm-border-strong);
}
.stats-table tbody tr:last-child > * {
  border-bottom: 0;
}
.stats-table tbody th {
  font-weight: 600;
}
.stats-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cell-sub {
  display: block;
  color: var(--bm-text-soft);
  font-size: 13px;
  font-weight: 400;
}
.stats-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
}
.stats-sort::after {
  content: '↕';
  color: var(--bm-text-faint);
}
th[aria-sort='descending'] .stats-sort::after {
  content: '↓';
  color: var(--bm-text);
}
th[aria-sort='ascending'] .stats-sort::after {
  content: '↑';
  color: var(--bm-text);
}
.stats-badge {
  display: inline-flex;
  margin-left: 6px;
  padding: 1px 7px;
  border: 1px solid color-mix(in srgb, currentColor 32%, transparent);
  border-radius: var(--bm-radius-pill);
  background: color-mix(in srgb, currentColor 15%, transparent);
  color: var(--bm-pending-ink);
  font: 700 10px/1.5 var(--bm-font-mono);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  vertical-align: 1px;
  white-space: nowrap;
}
.stats-badge[data-tone='warn'] {
  color: var(--bm-warn-ink);
}
.stats-badge[data-tone='caution'] {
  color: var(--bm-caution-ink);
}
.stats-empty {
  padding: 18px 16px;
  border: 1px dashed var(--bm-border-strong);
  border-radius: var(--bm-radius-lg);
}
.stats-empty p {
  margin: 0;
}
.stats-empty p + p {
  margin-top: 6px;
}
.stats-reasons {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}
.stats-reasons li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--bm-border);
  border-radius: var(--bm-radius-md);
  background: var(--bm-surface);
}
.stats-reasons strong {
  font: 700 13px/1.4 var(--bm-font-mono);
  font-variant-numeric: tabular-nums;
}
.stats-help {
  border: 1px solid var(--bm-border);
  border-radius: var(--bm-radius-lg);
  background: var(--bm-surface);
}
.stats-help > summary {
  min-height: 48px;
  padding: 0 14px 0 16px;
  border-radius: var(--bm-radius-lg);
  font-weight: 600;
}
.stats-help dl {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 16px 16px;
  font-size: 14px;
}
.stats-help dt {
  font-weight: 600;
}
.stats-help dd {
  margin: 2px 0 0;
  color: var(--bm-text-soft);
}

/* ---- phone ---------------------------------------------------------------------- */
@media (max-width: 620px) {
  .stat-tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .stat-tile {
    padding: 11px 12px 12px;
  }
  .stat-tile dt {
    font-size: 10px;
    letter-spacing: 0.06em;
  }
  .stat-value {
    font-size: 22px;
  }
  .stat-detail {
    font-size: 13px;
  }
  .stats-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }
  .chart {
    padding: 12px;
  }
  /* Tables turn into one card per row: label and value side by side. */
  .stats-table-wrap {
    overflow: visible;
    border: 0;
    background: transparent;
  }
  .stats-table.is-cards thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }
  .stats-table.is-cards,
  .stats-table.is-cards tbody,
  .stats-table.is-cards tr,
  .stats-table.is-cards th,
  .stats-table.is-cards td {
    display: block;
  }
  .stats-table.is-cards tr {
    margin-bottom: 8px;
    padding: 6px 12px;
    border: 1px solid var(--bm-border-strong);
    border-radius: var(--bm-radius-lg);
    background: var(--bm-surface);
  }
  .stats-table.is-cards tbody th {
    padding: 6px 0;
    border-bottom: 1px solid var(--bm-border);
  }
  .stats-table.is-cards td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 5px 0;
    border: 0;
    text-align: right;
  }
  .stats-table.is-cards td::before {
    content: attr(data-label);
    color: var(--bm-text-soft);
    font: 600 11px/1.6 var(--bm-font-mono);
    letter-spacing: 0.06em;
    text-align: left;
    text-transform: uppercase;
  }
  .stats-table.is-cards tbody tr:last-child > * {
    border-bottom: 0;
  }
  .stats-table.is-cards tbody tr > th {
    border-bottom: 1px solid var(--bm-border);
  }
}
@media (max-width: 360px) {
  .stat-value {
    font-size: 20px;
  }
}
