/* Status-bar fills. tokens.css keeps primitives theme-independent, so the
   dark variants are mapped here with the same selectors it uses. */
:root {
  --state-idle: var(--color-green-700);
  --state-finished: var(--color-orange-500);
  --state-running: var(--color-blue-600);
  --state-fault: var(--color-red-700);
  --state-muted: var(--color-gray-400);
}

:root[data-theme="dark"] {
  --state-idle: var(--color-green-500);
  --state-running: var(--color-blue-400);
  --state-fault: #FFB5BA;
  --state-muted: #606060;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --state-idle: var(--color-green-500);
    --state-running: var(--color-blue-400);
    --state-fault: #FFB5BA;
    --state-muted: #606060;
  }
}

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

body {
  margin: 0;
  background: var(--color-canvas);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-body);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1,
h2,
p,
ul {
  margin: 0;
}

button {
  font: inherit;
}

:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.container {
  width: 100%;
  max-width: var(--layout-content);
  margin: 0 auto;
  padding-inline: var(--space-4);
}

@media (min-width: 768px) {
  .container {
    padding-inline: var(--space-6);
  }
}

.muted {
  color: var(--color-text-muted);
  font-size: var(--text-small);
}

.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: 10;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--color-action-primary);
  color: var(--color-action-on-primary);
  font-weight: 700;
}

.skip-link:focus {
  top: var(--space-2);
}

/* Header */

.site-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border-subtle);
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3) var(--space-4);
  padding-block: var(--space-3);
}

.brand {
  display: inline-flex;
  min-height: var(--layout-tap-target);
  align-items: center;
}

.brand img {
  display: block;
  height: 36px;
  width: auto;
}

.header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  background: var(--color-info-surface);
  color: var(--color-info-text);
}

.live-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--state-running);
}

.live-badge[data-state="live"] {
  background: var(--color-success-surface);
  color: var(--color-success-text);
}

.live-badge[data-state="live"] .dot {
  background: var(--state-idle);
}

.live-badge[data-state="stale"] {
  background: var(--color-warning-surface);
  color: var(--color-warning-text);
}

.live-badge[data-state="stale"] .dot {
  background: var(--state-finished);
}

.updated {
  color: var(--color-text-muted);
  font-size: var(--text-small);
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--layout-tap-target);
  padding: 0 var(--space-4);
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text-primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--motion-ease), border-color var(--motion-fast) var(--motion-ease);
}

.btn:hover {
  border-color: var(--color-action-primary);
}

.btn:disabled {
  cursor: progress;
  opacity: 0.7;
}

/* Hero and notices */

.main {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding-block: var(--space-8) var(--space-12);
}

.hero {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.eyebrow {
  color: var(--color-text-brand);
  font-size: var(--text-small);
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hero h1 {
  font-size: clamp(2rem, 5vw, 2.75rem);
  line-height: 1.15;
  font-weight: 800;
}

.lede {
  color: var(--color-text-secondary);
}

.lede strong {
  color: var(--color-text-primary);
}

.refresh-msg {
  min-height: 1.5em;
  color: var(--color-text-muted);
  font-size: var(--text-small);
}

.notices {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.notices:empty {
  display: none;
}

.notice {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-4) 20px;
  border-radius: var(--radius-lg);
  background: var(--color-info-surface);
  color: var(--color-info-text);
}

.notice[data-tone="warning"] {
  background: var(--color-warning-surface);
  color: var(--color-warning-text);
}

.notice-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.notice-body,
.notice > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.notice-text,
.notice span {
  font-size: var(--text-small);
}

/* Summary */

.summary {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.summary:empty {
  display: none;
}

.card {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
}

.summary-card {
  flex: 1 1 300px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px var(--space-6);
}

.summary-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.kind-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  color: var(--color-text-brand);
}

.summary-title {
  flex-grow: 1;
  font-size: 18px;
  font-weight: 700;
}

.summary-figure {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.summary-idle {
  font-size: 52px;
  line-height: 1;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.summary-idle-label {
  color: var(--color-success-text);
  font-weight: 700;
}

.bar {
  display: flex;
  gap: 3px;
  height: 10px;
}

.bar span {
  flex-basis: 0;
  border-radius: var(--radius-pill);
  background: var(--state-muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px var(--space-4);
  padding: 0;
  list-style: none;
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: var(--text-small);
}

.legend li::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--state-muted);
}

.legend strong {
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
}

/* State colors, shared by bar segments, legend swatches, dots, and badges. */

[data-state="idle"] { --fill: var(--state-idle); }
[data-state="finished"] { --fill: var(--state-finished); }
[data-state="running"] { --fill: var(--state-running); }
[data-state="fault"] { --fill: var(--state-fault); }

.bar span[data-state],
.state-dot {
  background: var(--fill, var(--state-muted));
}

.legend li[data-state]::before {
  background: var(--fill, var(--state-muted));
}

/* Filters */

.filters {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  padding: var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--color-surface-soft);
}

.segment {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--layout-tap-target);
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}

.segment[aria-pressed="true"] {
  background: var(--color-action-primary);
  color: var(--color-action-on-primary);
}

.segment .count {
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.toggle .icon-on,
.toggle[aria-pressed="true"] .icon-off {
  display: none;
}

.toggle[aria-pressed="true"] .icon-on {
  display: block;
}

.toggle[aria-pressed="true"] {
  background: var(--color-success-surface);
  color: var(--color-success-text);
  border-color: var(--state-idle);
}

/* Machines */

#sections {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.machine-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.section-title {
  font-size: 22px;
  font-weight: 800;
}

.empty {
  padding: var(--space-6);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  color: var(--color-text-secondary);
}

.machine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: var(--space-3);
  padding: 0;
  list-style: none;
}

.machine {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px var(--space-4);
  border-radius: var(--radius-md);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-subtle);
}

.machine[data-state="idle"] {
  border-color: var(--state-idle);
}

.machine-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.machine-id {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.machine[data-state="offline"] .machine-id,
.machine[data-state="unknown"] .machine-id {
  color: var(--color-text-muted);
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
}

.badge {
  align-self: flex-start;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 700;
  background: var(--color-action-disabled-surface);
  color: var(--color-action-disabled-text);
}

.machine[data-state="idle"] .badge {
  background: var(--color-success-surface);
  color: var(--color-success-text);
}

.machine[data-state="finished"] .badge {
  background: var(--color-warning-surface);
  color: var(--color-warning-text);
}

.machine[data-state="running"] .badge {
  background: var(--color-info-surface);
  color: var(--color-info-text);
}

.machine[data-state="fault"] .badge {
  background: var(--color-danger-surface);
  color: var(--color-danger-text);
}

.machine[data-state="door_open"] .badge {
  background: var(--color-surface-soft);
  color: var(--color-text-secondary);
}

.machine-detail {
  color: var(--color-text-muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Footer */

.site-footer {
  border-top: 1px solid var(--color-border-subtle);
}

.footer-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-2) var(--space-6);
  padding-block: 20px var(--space-8);
  color: var(--color-text-muted);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
