/* ────────────────────────────────────────────────────────────────────────────
   Device board — device.php and compare.php.

   Standalone: this file never loads css/style.css, which is the map's
   stylesheet. It only depends on css/tokens.css.

   The grid replaces Freeboard's gridster: repeat(auto-fit, minmax(...)) walks
   4 → 3 → 2 → 1 columns on its own, so there is no JS resize handler.
   ──────────────────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
}

/* the UA's [hidden] rule is only display:none, which every display below would
   otherwise win against */
[hidden] {
  display: none !important;
}

html {
  background-color: var(--bg);
}
body {
  margin: 0;
  padding: 0 12px 32px;
  min-height: 100%;
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

/* ── top bar ──────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 2px 12px;
}
.topbar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.topbar-sub {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.topbar-spacer {
  flex: 1 1 auto;
}

/* ── tabs ─────────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.tab {
  padding: 6px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.tab:hover {
  color: var(--text);
}
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--teal-600);
  box-shadow: 0 1px 2px var(--chart-shadow);
}

/* ── icon buttons (theme toggle, table toggle) ────────────────────────────── */

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 36px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--text-subtle);
}
.icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}
.icon-btn[aria-pressed="true"] {
  color: var(--teal-600);
  border-color: var(--teal-400);
}

/* only one of the two theme glyphs shows, depending on the resolved theme */
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun  { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root[data-theme-auto]:not([data-theme="light"]) .theme-toggle .icon-sun  { display: none; }
  :root[data-theme-auto]:not([data-theme="light"]) .theme-toggle .icon-moon { display: inline; }
}

/* ── controls row (range picker, compare pickers) ─────────────────────────── */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  max-width: 1320px;
  margin: 0 auto 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
/* lets a nested group's children take part in the .controls flex row */
.controls-inline {
  display: contents;
}
.controls-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  padding: 5px 11px;
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip:hover {
  color: var(--text);
  border-color: var(--text-subtle);
}
.chip[aria-pressed="true"] {
  background: var(--teal-400);
  border-color: var(--teal-400);
  color: #fff;
}
:root[data-theme="dark"] .chip[aria-pressed="true"] { color: #10231d; }
@media (prefers-color-scheme: dark) {
  :root[data-theme-auto]:not([data-theme="light"]) .chip[aria-pressed="true"] { color: #10231d; }
}

.custom-range {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
input[type="date"],
select {
  padding: 5px 8px;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  color-scheme: light;
}
:root[data-theme="dark"] input[type="date"],
:root[data-theme="dark"] select { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root[data-theme-auto]:not([data-theme="light"]) input[type="date"],
  :root[data-theme-auto]:not([data-theme="light"]) select { color-scheme: dark; }
}
select {
  font-family: var(--font-ui);
  font-weight: 600;
}

/* ── the grid ─────────────────────────────────────────────────────────────── */

.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  max-width: 1320px;
  margin: 0 auto;
  align-items: start;
}
.board[hidden] {
  display: none;
}
/* A pane may span several grid columns — see `span` in js/board/layout.js.
   The grid itself is auto-fit, so it drops to 3 / 2 / 1 columns as the board
   narrows; these clamps stop a wide pane from spanning more columns than
   currently exist, which would push it out of the grid.
   Column count follows the track maths: n columns need n*280 + (n-1)*12 px of
   grid, and the grid is the viewport less the 12px body padding either side. */
.pane--span-2 { grid-column: span 2; }
.pane--span-3 { grid-column: span 3; }
.pane--span-4 { grid-column: span 4; }
.pane--full   { grid-column: 1 / -1; }

@media (max-width: 1180px) {          /* room for 3 columns */
  .pane--span-4 { grid-column: span 3; }
}
@media (max-width: 888px) {           /* room for 2 */
  .pane--span-3, .pane--span-4 { grid-column: span 2; }
}
@media (max-width: 596px) {           /* room for 1 */
  .pane--span-2, .pane--span-3, .pane--span-4 { grid-column: span 1; }
}

/* ── panes ────────────────────────────────────────────────────────────────── */

.pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pane-swatch {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--swatch, var(--text-subtle));
}

/* stat pane — the header row of the Nu tab */
.pane-stat {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 62px;
  padding: 12px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 500;
  line-height: 1.1;
  color: var(--text);
  overflow-wrap: anywhere;
}
.stat-value--sm {
  font-size: 15px;
}
.stat-unit {
  font-size: 13px;
  color: var(--text-muted);
}

/* signal pane — a small key/value grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 12px;
  min-height: 62px;
  padding: 10px 12px;
}
.stat-grid div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.stat-grid b {
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
}

/* gauge and chart bodies — echoes Freeboard's fixed block heights */
.pane-gauge {
  height: 200px;
}
.pane-chart {
  height: 200px;
}
/* a pane given more width earns a little more height with it */
.pane--span-2 .pane-chart,
.pane--span-3 .pane-chart,
.pane--span-4 .pane-chart {
  height: 260px;
}
.pane-chart--tall {
  height: 380px;
}

/* ── states ───────────────────────────────────────────────────────────────── */

.note {
  max-width: 1320px;
  margin: 0 auto 12px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--teal-400);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-muted);
}
.note--error {
  border-left-color: var(--status-critical);
}
.note[hidden] {
  display: none;
}

.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-subtle);
  font-size: 13px;
}

.is-loading {
  opacity: 0.55;
  transition: opacity 120ms linear;
}

/* ── table view — the relief channel for the sub-3:1 series colours ───────── */

.table-wrap {
  max-width: 1320px;
  margin: 12px auto 0;
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.table-wrap[hidden] {
  display: none;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.data-table th,
.data-table td {
  padding: 6px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}
.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}
.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.06em;
}
.data-table tbody tr:last-child td {
  border-bottom: 0;
}
/* identifiers and units keep their own case: uppercasing turns µg/m³ into MG/M³ */
.no-caps {
  text-transform: none;
}
.table-key {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 2px;
  vertical-align: baseline;
}

/* ── device picker (compare.php) ──────────────────────────────────────────── */

.device-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 92px;
  overflow-y: auto;
}
.device-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
}
.device-chip:hover {
  color: var(--text);
  border-color: var(--text-subtle);
}
.device-chip[aria-pressed="true"] {
  color: var(--text);
  border-color: currentColor;
}
.device-chip .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border-mid);
}
.device-chip[aria-pressed="true"] .dot {
  background: var(--dot, var(--teal-400));
}
.device-chip[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── footer ───────────────────────────────────────────────────────────────── */

.board-footer {
  max-width: 1320px;
  margin: 20px auto 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
}
.board-footer a {
  color: var(--teal-600);
  text-decoration: none;
}
.board-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 560px) {
  body { padding: 0 8px 24px; }
  .topbar { padding: 10px 2px; }
  .topbar-title { font-size: 17px; }
  .controls { padding: 8px 10px; }
}
