/* ==========================================================================
   Statistics deck shell (RFC #80 §3, issue #133)
   Zero-scroll frame from the Laptop minimum (760 CSS px) up; stacks and scrolls below.
   Tokens: docs/standards/ui-design-guidelines.md §2.1.
   ========================================================================== */

/* While the deck is shown it replaces the app header, HUD ribbon and deck selector. */
body.statistics-deck-active #main-header,
body.statistics-deck-active #master-hud-ribbon,
body.statistics-deck-active #operational-deck-selector,
body.statistics-deck-active #system-status-strip {
  display: none !important;
}

#content-statistics.sd-root {
  position: fixed;
  inset: 0;
  z-index: 30;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  display: grid;
  grid-template-rows: 38px minmax(0, 1fr);
  gap: 1px;
  margin: 0;
  padding: 0;
  background: var(--color-border-grid, #222832);
  color: var(--color-text-primary, #eaeaea);
  font-family: "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

#content-statistics.sd-root.hidden {
  display: none;
}

.sd-root *,
.sd-root *::before,
.sd-root *::after {
  border-radius: 0 !important;
  box-sizing: border-box;
}

/* ---------------------------------------------------------------- top bar */

.sd-topbar {
  height: 38px;
  min-width: 0;
  display: flex;
  align-items: stretch;
  gap: 1px;
  background: var(--color-border-grid, #222832);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sd-topbar > * {
  background: var(--color-bg-surface, #111418);
}

.sd-spacer {
  flex: 1 1 0;
  min-width: 0;
}

.sd-root button {
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--color-text-muted, #7c8797);
  background: var(--color-bg-surface, #111418);
  border: 0;
  cursor: pointer;
  transition: none;
}

.sd-root button:hover {
  color: var(--color-text-primary, #eaeaea);
  background: var(--color-bg-elevated, #181c22);
}

.sd-root button:active {
  transform: translate(1px, 1px);
}

.sd-root button:focus-visible {
  outline: 1px solid var(--color-telemetry-cyan, #00e5ff);
  outline-offset: -1px;
}

.sd-period-btn {
  flex: 0 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 0.75em;
  padding: 0 0.9em;
  white-space: nowrap;
  overflow: hidden;
}

.sd-period-kind {
  color: var(--color-telemetry-cyan, #00e5ff);
  font-weight: 700;
}

.sd-period-range {
  color: var(--color-text-primary, #eaeaea);
  overflow: hidden;
  text-overflow: ellipsis;
}

.sd-period-week {
  color: var(--color-text-muted, #7c8797);
  font-size: 10px;
}

.sd-period-caret {
  color: var(--color-text-dim, #454f5e);
}

.sd-seg {
  display: flex;
  gap: 1px;
  background: var(--color-border-grid, #222832);
}

.sd-seg-btn {
  padding: 0 0.8em;
  white-space: nowrap;
}

.sd-seg-btn.active {
  color: var(--color-text-primary, #eaeaea);
  background: var(--color-bg-elevated, #181c22);
  box-shadow: inset 0 -2px 0 var(--color-telemetry-cyan, #00e5ff);
}

.sd-short {
  display: none;
}

.sd-icon-btn {
  min-width: 38px;
  padding: 0 0.7em;
  white-space: nowrap;
}

.sd-ops-btn {
  color: var(--color-text-dim, #454f5e);
}

/* Data-quality badge: amber only, never hazard red (RFC §4.1). It never shrinks: the period
   range gives way (ellipsis) first, so the full Room/Desk text always shows. */
.sd-root .sd-badge {
  flex: 0 0 auto;
  padding: 0 0.9em;
  color: var(--color-warning-amber, #ffb000);
  background: var(--color-bg-surface, #111418);
  box-shadow: inset 0 0 0 1px rgba(255, 176, 0, 0.45);
  white-space: nowrap;
  font-weight: 700;
}

.sd-root .sd-badge:hover {
  color: var(--color-warning-amber, #ffb000);
}

.sd-root .sd-badge.hidden {
  display: none;
}

/* Narrow top bar: short tab and profile labels keep the 38 px bar on one line. */
@media (max-width: 1279.98px) {
  .sd-long {
    display: none;
  }

  .sd-short {
    display: inline;
  }
}

/* ---------------------------------------------------------------- view grid */

.sd-view {
  position: relative;
  min-height: 0;
  display: grid;
  gap: 1px;
  background: var(--color-border-grid, #222832);
  overflow: hidden;
}

.sd-view[data-profile="room"] {
  grid-template-rows: minmax(0, 12fr) minmax(0, 55fr) minmax(0, 33fr);
  --sd-kpi-size: clamp(1.5rem, 2.6vw, 3rem);
}

.sd-view[data-profile="desk"] {
  grid-template-rows: minmax(0, 17fr) minmax(0, 50fr) minmax(0, 33fr);
  --sd-kpi-size: clamp(1.5rem, 3vw, 3.25rem);
}

.sd-view[data-profile="laptop"] {
  grid-template-rows: minmax(0, 26fr) minmax(0, 74fr);
  --sd-kpi-size: clamp(1.75rem, 4.5vw, 4rem);
}

.sd-row {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--sd-cols, 1), minmax(0, 1fr));
  gap: 1px;
  background: var(--color-border-grid, #222832);
}

.sd-cell {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  padding: 0.6rem 0.75rem;
  background: var(--color-bg-surface, #111418);
  display: flex;
  flex-direction: column;
}

.sd-cell-kpi,
.sd-cell-graph {
  justify-content: center;
  align-items: center;
}

/* A graph fills whatever box its cell gets; Chart.js redraws to it. */
.sd-graph-box {
  position: relative;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  width: 100%;
}

.sd-graph-box > canvas {
  position: absolute;
  inset: 0;
}

.sd-muted {
  color: var(--color-text-dim, #454f5e);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sd-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  color: var(--color-text-muted, #7c8797);
  text-transform: uppercase;
  pointer-events: none;
}

/* ---------------------------------------------------------------- panels */

.sd-panel {
  position: absolute;
  top: 39px;
  z-index: 5;
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 0 0 0.75rem;
  background: var(--color-bg-surface, #111418);
  border: 1px solid var(--color-border-active, #3a4454);
  font-size: 12px;
}

.sd-panel.hidden {
  display: none;
}

.sd-panel-picker {
  left: 0;
  width: min(460px, 100vw);
}

.sd-panel-quality {
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, 100vw);
}

.sd-panel-help {
  right: 0;
  width: min(520px, 100vw);
}

.sd-panel-head {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 0.75rem;
  background: var(--color-bg-elevated, #181c22);
  border-bottom: 1px solid var(--color-border-grid, #222832);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 32px;
}

.sd-panel p,
.sd-panel ul,
.sd-panel ol,
.sd-panel dl {
  margin: 0.75rem;
  padding: 0;
  list-style: none;
}

.sd-picker-list {
  display: grid;
  gap: 1px;
  background: var(--color-border-grid, #222832);
}

.sd-picker-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 0.75em;
  align-items: baseline;
  padding: 0.5rem 0.6rem;
  text-align: left;
}

.sd-picker-item.active,
.sd-calendar-day.active {
  color: var(--color-text-primary, #eaeaea);
  background: var(--color-bg-elevated, #181c22);
  box-shadow: inset 2px 0 0 var(--color-telemetry-cyan, #00e5ff);
}

.sd-picker-coverage {
  color: var(--color-text-muted, #7c8797);
  font-size: 11px;
}

.sd-picker-marks,
.sd-calendar-day i,
.sd-glyph {
  color: var(--color-warning-amber, #ffb000);
  font-style: normal;
}

.sd-calendar {
  display: grid;
  gap: 0.75rem;
  margin: 0.75rem;
}

.sd-calendar-month > header {
  margin-bottom: 0.35rem;
  color: var(--color-text-muted, #7c8797);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sd-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 1px;
  background: var(--color-border-grid, #222832);
}

.sd-calendar-grid > * {
  background: var(--color-bg-surface, #111418);
}

.sd-calendar-wd {
  padding: 0.25rem 0;
  text-align: center;
  color: var(--color-text-dim, #454f5e);
  font-size: 10px;
}

.sd-calendar-day {
  position: relative;
  padding: 0.4rem 0;
  text-align: center;
}

.sd-calendar-day.disabled {
  color: var(--color-text-dim, #454f5e);
}

.sd-calendar-day.closed {
  color: var(--color-text-dim, #454f5e);
  text-decoration: line-through;
}

.sd-root .sd-picker-older {
  display: block;
  width: calc(100% - 1.5rem);
  margin: 0.75rem;
  padding: 0.45rem;
  border: 1px solid var(--color-border-grid, #222832);
  text-align: center;
}

.sd-root data {
  font-variant-numeric: tabular-nums;
}

.sd-calendar-day i {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 9px;
}

.sd-quality-lines {
  display: grid;
  gap: 0.35rem;
}

.sd-quality-line {
  display: flex;
  gap: 0.6em;
}

.sd-legend {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 0.75rem;
  align-items: center;
  padding-top: 0.6rem;
  border-top: 1px solid var(--color-border-grid, #222832);
}

.sd-legend dt {
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.sd-legend dd {
  margin: 0;
  color: var(--color-text-muted, #7c8797);
}

/* Shared data-quality styles (RFC §4.1); graphs draw the same marks on canvas (charts.js). */
.sd-swatch {
  display: inline-block;
  width: 22px;
  height: 12px;
}

.sd-swatch-estimate {
  border: 1.5px dashed var(--color-warning-amber, #ffb000);
}

.sd-swatch-unreliable {
  background: repeating-linear-gradient(
    -45deg,
    rgba(124, 135, 151, 0.55) 0 2px,
    transparent 2px 6px
  );
}

/* Numpad diagram in the "/" help. */
.sd-numpad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 52px;
  gap: 1px;
  margin: 0.75rem;
  background: var(--color-border-grid, #222832);
}

.sd-key {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
  background: var(--color-bg-elevated, #181c22);
  font-family: inherit;
  font-size: 10px;
  color: var(--color-text-muted, #7c8797);
  text-transform: uppercase;
}

.sd-key b {
  color: var(--color-text-primary, #eaeaea);
  font-size: 15px;
}

.sd-key-dim b {
  color: var(--color-text-dim, #454f5e);
}

.sd-key-tall {
  grid-row: span 2;
}

.sd-key-wide {
  grid-column: span 2;
}

/* ---------------------------------------------------------------- small screens */

/* Below the Laptop minimum the deck stacks into one column and scrolls (RFC §3.1). */
@media (max-width: 759.98px) {
  #content-statistics.sd-root {
    overflow-y: auto;
    grid-template-rows: auto auto;
  }

  .sd-topbar {
    height: auto;
    flex-wrap: wrap;
  }

  .sd-topbar > * {
    min-height: 38px;
  }

  .sd-view,
  .sd-view[data-profile] {
    grid-template-rows: none;
    grid-auto-rows: auto;
    overflow: visible;
  }

  .sd-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .sd-row-kpi {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sd-cell-kpi {
    min-height: 96px;
  }

  .sd-cell-graph {
    min-height: 240px;
  }

  .sd-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    transform: none;
    width: auto;
    max-height: 100dvh;
  }
}
