*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface:         #1a1a19;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --gridline:        #2c2c2a;
  --baseline:        #383835;
  --border:          rgba(255,255,255,0.10);
  --series-1:        #3987e5;
  --series-1-track:  rgba(57,135,229,0.18);
  --band:            rgba(255,255,255,0.05);
  --status-critical: #d03b3b;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

html, body { min-height: 100%; }

body {
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}
.app-name { font-weight: 600; letter-spacing: 0.02em; }
.header-right { display: flex; align-items: center; gap: 1rem; }
.last-seen { color: var(--text-muted); font-size: 12px; }
.logout-link { color: var(--text-muted); text-decoration: none; font-size: 13px; }
.logout-link:hover { color: var(--text-primary); }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 0.9rem; font-weight: 500; }
.card h3 { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); margin: 1.5rem 0 0.7rem; font-weight: 500; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.9rem; }
.card-header h2 { margin-bottom: 0; }
.muted { color: var(--text-muted); font-size: 12px; }
.empty { color: var(--text-muted); text-align: center; padding: 1.5rem 0; }

/* offline banner */
.banner {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(208,59,59,0.12);
  border: 1px solid rgba(208,59,59,0.35);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  color: var(--text-primary);
}
.banner-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--status-critical);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.tile-label { color: var(--text-secondary); font-size: 13px; }
.tile-value { font-size: 32px; font-weight: 600; line-height: 1.2; }
.tile-unit { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 0.25rem; }
.tile-note { color: var(--text-muted); font-size: 12px; }
.stale .tile-value { color: var(--text-muted); }

/* equipment */
.badge {
  font-size: 12px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.55rem;
}
.devices { display: flex; flex-direction: column; gap: 0.75rem; }
.device { display: grid; grid-template-columns: 110px 70px 1fr 48px; align-items: center; gap: 0.75rem; }
.device-name { color: var(--text-secondary); }
.device-state { display: flex; align-items: center; gap: 0.45rem; font-weight: 500; }
.device-detail { color: var(--text-secondary); font-variant-numeric: tabular-nums; text-align: right; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--text-muted); flex-shrink: 0; }
.dot.on { background: var(--text-primary); border-color: var(--text-primary); }
.meter { height: 8px; border-radius: 4px; background: var(--series-1-track); overflow: hidden; }
.meter-fill { height: 100%; width: 0; border-radius: 4px; background: var(--series-1); transition: width 0.3s; }
.pending-note { color: var(--text-muted); font-size: 12px; margin-top: 0.75rem; }

/* forms */
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 12px; color: var(--text-muted); }
input, button {
  font-family: inherit;
  font-size: 13px;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  padding: 0.5rem 0.65rem;
}
input:focus { outline: none; border-color: rgba(57,135,229,0.5); }
button {
  background: rgba(57,135,229,0.16);
  border-color: rgba(57,135,229,0.35);
  cursor: pointer;
  font-weight: 500;
}
button:hover { background: rgba(57,135,229,0.28); }

.control-form { display: flex; flex-direction: column; gap: 1rem; }
.segmented { display: inline-flex; align-self: flex-start; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented label { flex-direction: row; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { padding: 0.4rem 0.9rem; color: var(--text-secondary); font-size: 13px; cursor: pointer; }
.segmented input:checked + span { background: rgba(57,135,229,0.18); color: var(--text-primary); }
.segmented input:focus-visible + span { outline: 2px solid rgba(57,135,229,0.6); outline-offset: -2px; }

.control-group { border: 1px solid var(--border); border-radius: 8px; padding: 0.75rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.75rem; }
.control-group legend { padding: 0 0.35rem; font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }
.control-group:disabled { opacity: 0.45; }
.switch { flex-direction: row; align-items: center; gap: 0.5rem; font-size: 13px; color: var(--text-secondary); }
.switch input { width: 16px; height: 16px; accent-color: var(--series-1); }
.slider output { color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.slider input { padding: 0; accent-color: var(--series-1); }
.target-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.form-actions { display: flex; align-items: center; gap: 0.75rem; }
.control-status { color: var(--text-muted); font-size: 12px; }

/* camera */
.snapshot { display: block; width: 100%; max-height: 360px; object-fit: cover; border-radius: 6px; }

/* history */
.filter-row { display: flex; gap: 0.35rem; }
.pill {
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 400;
  padding: 0.3rem 0.65rem;
}
.pill:hover { background: rgba(255,255,255,0.1); color: var(--text-primary); }
.pill.active { background: rgba(57,135,229,0.18); color: var(--text-primary); border-color: rgba(57,135,229,0.4); }

.charts { position: relative; display: flex; flex-direction: column; gap: 1.25rem; transition: opacity 0.2s; }
.charts.loading { opacity: 0.5; }
.chart figcaption { color: var(--text-secondary); font-size: 12px; margin-bottom: 0.35rem; }
.chart-note { color: var(--text-muted); font-size: 11px; margin-left: 0.5rem; }
.chart svg { display: block; width: 100%; height: 160px; overflow: visible; }
.chart svg:focus-visible { outline: 1px solid rgba(57,135,229,0.6); outline-offset: 4px; border-radius: 2px; }
.gridline { stroke: var(--gridline); stroke-width: 1; }
.axis-label { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.target-band { fill: var(--band); }
.target-line { stroke: var(--text-muted); stroke-width: 1; opacity: 0.7; }
.chart-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-end-dot, .chart-hover-dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart-end-label { fill: var(--text-primary); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }
.crosshair { stroke: var(--text-muted); stroke-width: 1; }
.chart-hit-area { fill: transparent; cursor: crosshair; }

.chart-tooltip {
  position: absolute;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 2;
}
.tooltip-row { display: flex; align-items: baseline; gap: 0.4rem; }
.tooltip-value { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.tooltip-label { color: var(--text-muted); font-size: 11px; }
.tooltip-time { color: var(--text-muted); font-size: 11px; margin-top: 0.3rem; border-top: 1px solid var(--border); padding-top: 0.3rem; }

.table-view { margin-top: 1.25rem; }
.table-view summary { color: var(--text-muted); font-size: 12px; cursor: pointer; }
.table-view table { margin-top: 0.75rem; display: block; max-height: 320px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); font-size: 13px; font-variant-numeric: tabular-nums; }
th { color: var(--text-muted); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }

.flash {
  background: rgba(208,59,59,0.12);
  border-bottom: 1px solid rgba(208,59,59,0.3);
  color: var(--text-primary);
  padding: 0.6rem 1.5rem;
  font-size: 13px;
  text-align: center;
}

/* auth */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-box { display: flex; flex-direction: column; gap: 0.75rem; width: 260px; }
.auth-box form { display: flex; flex-direction: column; gap: 0.75rem; }
.auth-appname { text-align: center; font-weight: 600; margin-bottom: 0.5rem; letter-spacing: 0.02em; }

@media (max-width: 640px) {
  main { padding: 1rem; }
  .tiles { gap: 0.5rem; }
  .tile { padding: 0.75rem; }
  .tile-label { font-size: 12px; }
  .tile-value { font-size: 22px; }
  .tile-unit { font-size: 12px; margin-left: 0.15rem; }
  .tile-note { font-size: 11px; }
  .device { grid-template-columns: 90px 60px 1fr 40px; }
  .target-row { grid-template-columns: 1fr; }
}
