:root {
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --status-good: #0ca30c;
  --status-warning: #fab219;

  --seq-100: #cde2fb;
  --seq-150: #b7d3f6;
  --seq-200: #9ec5f4;
  --seq-250: #86b6ef;
  --seq-300: #6da7ec;
  --seq-350: #5598e7;
  --seq-400: #3987e5;
  --seq-450: #2a78d6;
  --seq-500: #256abf;
  --seq-550: #1c5cab;
  --seq-600: #184f95;
  --seq-650: #104281;
  --seq-700: #0d366b;

  --no-data-stripe: #d8d7d0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --status-good: #0ca30c;
    --status-warning: #fab219;
    --no-data-stripe: #333330;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}

header {
  padding: 20px 24px 8px;
}

header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 2px;
}

header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  padding: 16px 24px 32px;
  align-items: start;
}

@media (max-width: 800px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 320px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 4px;
  text-align: center;
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.login-card input {
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-primary);
}

.login-card button {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 10px;
  border-radius: 6px;
  border: none;
  background: var(--seq-450);
  color: #fff;
  cursor: pointer;
  margin-top: 4px;
}

.login-card button:hover {
  background: var(--seq-550);
}

.login-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--status-warning) 15%, transparent);
  color: var(--text-primary);
  font-size: 12px;
}

.device-list {
  padding: 8px;
}

.device-list h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 8px 8px 6px;
  font-weight: 600;
}

.device-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 8px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text-primary);
}

.device-row:hover {
  background: var(--gridline);
}

.device-row.selected {
  background: var(--seq-100);
}

@media (prefers-color-scheme: dark) {
  .device-row.selected {
    background: var(--seq-650);
  }
}

.device-row .name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.device-row .last-seen {
  font-size: 11px;
  color: var(--text-muted);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.active { background: var(--status-good); }
.dot.inactive { background: var(--text-muted); }
.dot.offline { background: var(--status-warning); }

.badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.badge.online {
  color: var(--status-good);
  background: color-mix(in srgb, var(--status-good) 15%, transparent);
}

.badge.offline {
  color: var(--status-warning);
  background: color-mix(in srgb, var(--status-warning) 20%, transparent);
}

.empty-state {
  padding: 20px 12px;
  color: var(--text-muted);
  font-size: 13px;
}

.main-panel {
  padding: 16px 20px 20px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-row label {
  font-size: 12px;
  color: var(--text-secondary);
}

.filter-row select,
.filter-row input[type="datetime-local"] {
  font: inherit;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
}

.spacer { flex: 1; }

/* Elements app.js shows/hides via classList.toggle("hidden", ...) rather
   than el.x.style.display -- keeps the CSP style-src 'self' without
   unsafe-inline, and avoids the bug where el.x.style.display = "" only
   clears an *inline* override and does nothing against a stylesheet rule. */
.hidden {
  display: none !important;
}

#custom-range-fields {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

#table-region {
  margin-top: 16px;
}

.table-toggle {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}

.table-toggle:hover {
  background: var(--gridline);
}

.chart-title {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 2px;
}

.chart-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.chart-row {
  display: flex;
  gap: 8px;
}

.y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 34px;
  padding: 6px 0;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  flex-shrink: 0;
}

.chart-plot {
  position: relative;
  flex: 1;
  height: 200px;
  min-width: 0;
  border-radius: 6px;
  border: 1px solid var(--gridline);
  background: var(--surface-1);
}

.line-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.line-svg .no-data-bg {
  fill: var(--no-data-stripe);
  opacity: 0.35;
}

.line-svg .area-fill {
  fill: var(--seq-450);
  opacity: 0.12;
}

.line-svg .value-line {
  fill: none;
  stroke: var(--seq-450);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-crosshair {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--text-muted);
  opacity: 0;
  pointer-events: none;
}

.x-axis {
  position: relative;
  height: 16px;
  margin: 6px 0 0 42px;
  font-size: 11px;
  color: var(--text-muted);
}

.x-axis span {
  position: absolute;
  top: 0;
  white-space: nowrap;
}

.history-error {
  margin: -6px 0 16px;
  padding: 8px 10px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--status-warning) 15%, transparent);
  color: var(--text-primary);
  font-size: 12px;
}

.tooltip {
  position: fixed;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 20;
  display: none;
  max-width: 220px;
}

.tooltip .value {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
}

.tooltip .range {
  color: var(--text-secondary);
  margin-top: 2px;
}

table.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

table.history-table th,
table.history-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--gridline);
}

table.history-table th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.03em;
}

.table-scroll {
  max-height: 400px;
  overflow-y: auto;
  overflow-x: auto;
}
