/* ═══════════════════════════════════════════════════════════════
   Plant Station Control Room — Dark Dashboard
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Backgrounds */
  --bg:          #0b110e;
  --surface:     #111c16;
  --card:        #152019;
  --card-hover:  #1b2921;

  /* Borders */
  --border:      rgba(34, 197, 94, 0.1);
  --border-mid:  rgba(34, 197, 94, 0.18);
  --border-hi:   rgba(34, 197, 94, 0.3);

  /* Accent green */
  --green:       #22c55e;
  --green-dim:   #16a34a;
  --green-glow:  rgba(34, 197, 94, 0.15);
  --green-muted: rgba(34, 197, 94, 0.08);

  /* Text */
  --ink:         #d4e0d9;
  --muted:       #6b7c74;
  --subtle:      #2e3f36;

  /* Sensor accent colors */
  --warm:        #f97316;
  --warm-bg:     rgba(249, 115, 22, 0.08);
  --cool:        #38bdf8;
  --cool-bg:     rgba(56, 189, 248, 0.08);
  --earth:       #84cc16;
  --earth-bg:    rgba(132, 204, 22, 0.08);
  --light-c:     #facc15;
  --light-bg:    rgba(250, 204, 21, 0.08);

  /* Relay / status colors (kept for JS-generated classes) */
  --forest:        #22c55e;
  --forest-strong: #16a34a;
  --clay:          #f87171;
  --gold:          #fbbf24;

  /* Misc */
  --shadow:      0 4px 32px rgba(0, 0, 0, 0.5);
  --radius-xl:   20px;
  --radius-lg:   16px;
  --radius-md:   12px;
  --radius-sm:   8px;

  /* Topbar height — used for main layout offset */
  --topbar-h:    64px;
  --sensor-h:    84px;
  --bar-h:       44px;
  --tabs-h:      54px;
}

/* ── LIGHT MODE OVERRIDES ──────────────────────────────────── */
body[data-theme="light"] {
  --bg:          #f2f7f4;
  --surface:     #e8f2ec;
  --card:        #ffffff;
  --card-hover:  #f4fbf6;

  --border:      rgba(20, 100, 50, 0.12);
  --border-mid:  rgba(20, 100, 50, 0.2);
  --border-hi:   rgba(20, 100, 50, 0.32);

  --green:       #16a34a;
  --green-dim:   #15803d;
  --green-glow:  rgba(22, 163, 74, 0.12);
  --green-muted: rgba(22, 163, 74, 0.08);

  --ink:         #132118;
  --muted:       #5a7062;
  --subtle:      #b4c9bc;

  --warm:        #d97706;
  --warm-bg:     rgba(217, 119, 6, 0.07);
  --cool:        #0284c7;
  --cool-bg:     rgba(2, 132, 199, 0.07);
  --earth:       #65a30d;
  --earth-bg:    rgba(101, 163, 13, 0.07);
  --light-c:     #ca8a04;
  --light-bg:    rgba(202, 138, 4, 0.07);

  --forest:        #16a34a;
  --forest-strong: #15803d;
  --clay:          #dc2626;
  --gold:          #d97706;

  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

body[data-theme="light"] {
  background: var(--bg);
}

body[data-theme="light"]::before {
  background-image: radial-gradient(circle, rgba(22, 163, 74, 0.05) 1px, transparent 1px);
}

body[data-theme="light"] .topbar,
body[data-theme="light"] .device-bar {
  background: rgba(242, 247, 244, 0.95);
}

body[data-theme="light"] .sensor-strip {
  background: rgba(232, 242, 236, 0.98);
}

body[data-theme="light"] input,
body[data-theme="light"] select,
body[data-theme="light"] textarea {
  background: #ffffff;
}

body[data-theme="light"] .relay-card,
body[data-theme="light"] .detail-card,
body[data-theme="light"] .mode-section,
body[data-theme="light"] .check-line,
body[data-theme="light"] .weekly-row,
body[data-theme="light"] .event-log li {
  background: var(--card);
}

body[data-theme="light"] .primary {
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(22, 163, 74, 0.2);
}

body[data-theme="light"] .badge.online {
  background: rgba(22, 163, 74, 0.1);
  border-color: rgba(22, 163, 74, 0.25);
  color: #15803d;
}

body[data-theme="light"] .badge.offline {
  background: rgba(220, 38, 38, 0.07);
  border-color: rgba(220, 38, 38, 0.18);
  color: #b91c1c;
}

body[data-theme="light"] .badge.pending {
  background: rgba(217, 119, 6, 0.08);
  border-color: rgba(217, 119, 6, 0.2);
  color: #b45309;
}

body[data-theme="light"] .badge.device-summary {
  background: rgba(2, 132, 199, 0.06);
  border-color: rgba(2, 132, 199, 0.15);
  color: #0369a1;
}

body[data-theme="light"] .relay-pill.on {
  background: rgba(22, 163, 74, 0.1);
  color: #15803d;
  border-color: rgba(22, 163, 74, 0.22);
}

body[data-theme="light"] .relay-pill.off {
  background: rgba(220, 38, 38, 0.07);
  color: #b91c1c;
  border-color: rgba(220, 38, 38, 0.15);
}

body[data-theme="light"] .trend-chart-shell {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(246, 251, 248, 0.86)),
    color-mix(in srgb, var(--trend-accent) 4%, transparent);
}

body[data-theme="light"] .trend-canvas-wrap {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(245, 249, 247, 0.94)),
    radial-gradient(circle at top right, color-mix(in srgb, var(--trend-accent) 8%, transparent), transparent 44%);
  border-color: rgba(20, 100, 50, 0.09);
}

body[data-theme="light"] .trend-empty {
  background: linear-gradient(180deg, rgba(244, 249, 246, 0.86), rgba(244, 249, 246, 0.68));
}

body[data-theme="light"] .relay-mode-chip {
  background: rgba(2, 132, 199, 0.07);
  color: #0369a1;
  border-color: rgba(2, 132, 199, 0.14);
}

body[data-theme="light"] .sync-note {
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  border-color: var(--border);
}

body[data-theme="light"] .raw-state,
body[data-theme="light"] .preview-box {
  background: #1a2920;
  color: #4ade80;
}

body[data-theme="light"] .topic-box {
  background: rgba(22, 163, 74, 0.04);
}

body[data-theme="light"] .topic-box code {
  color: #15803d;
}

body[data-theme="light"] .day-tag {
  background: rgba(22, 163, 74, 0.08);
  color: #15803d;
}

body[data-theme="light"] .inline-btn {
  background: rgba(22, 163, 74, 0.08);
  color: #15803d;
  border-color: rgba(22, 163, 74, 0.16);
}

body[data-theme="light"] .inline-btn.power-on {
  background: rgba(22, 163, 74, 0.1);
  color: #15803d;
  border-color: rgba(22, 163, 74, 0.22);
}

body[data-theme="light"] .inline-btn.power-off {
  background: rgba(220, 38, 38, 0.07);
  color: #b91c1c;
  border-color: rgba(220, 38, 38, 0.15);
}

body[data-theme="light"] .ghost {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--border);
  color: var(--ink);
}

body[data-theme="light"] .event-kind { color: var(--green); }

/* ── RESET ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }

body {
  position: relative;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Sora", "Trebuchet MS", sans-serif;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }

/* custom scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--subtle); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* subtle dot-grid background */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    radial-gradient(circle, rgba(34, 197, 94, 0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.4), transparent 70%);
}

/* ── TOP BAR ───────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
  display: grid;
  grid-template-columns: auto 1fr auto;
  justify-items: end;
  align-items: center;
  gap: 20px;
  padding: 0 24px;
  background: rgba(11, 17, 14, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(24px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.brand-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.brand-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--green);
  letter-spacing: 0.02em;
  line-height: 1;
}

.brand-sub {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-facts {
  display: flex;
  align-items: center;
  gap: 0;
  justify-content: center;
  overflow: hidden;
}

.topbar-fact {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 20px;
}

.topbar-fact span {
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.topbar-fact strong {
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
  color: var(--ink);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.topbar-divider {
  width: 1px;
  height: 32px;
  background: var(--border);
  flex-shrink: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-summary {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}

/* ── SENSOR STRIP ──────────────────────────────────────────── */
.sensor-strip {
  position: sticky;
  top: var(--topbar-h);
  z-index: 90;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border);
  background: rgba(17, 28, 22, 0.96);
  backdrop-filter: blur(20px);
}

.sensor-card {
  --accent: var(--green);
  --accent-bg: var(--green-muted);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  border-right: 1px solid var(--border);
  transition: background 200ms ease;
  cursor: default;
}

.sensor-card:last-child { border-right: none; }
.sensor-card:hover { background: rgba(255, 255, 255, 0.02); }

.sensor-card.warm  { --accent: var(--warm);    --accent-bg: var(--warm-bg);  }
.sensor-card.cool  { --accent: var(--cool);    --accent-bg: var(--cool-bg);  }
.sensor-card.earth { --accent: var(--earth);   --accent-bg: var(--earth-bg); }
.sensor-card.light { --accent: var(--light-c); --accent-bg: var(--light-bg); }

.sensor-icon {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background: var(--accent-bg);
  border: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}

.sensor-icon svg {
  width: 22px;
  height: 22px;
}

.sensor-info { flex: 1; min-width: 0; }

.sensor-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.sensor-reading {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 4px;
}

.sensor-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-family: "IBM Plex Mono", monospace;
}

.sensor-unit {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
}

/* ── DEVICE INFO BAR ───────────────────────────────────────── */
.device-bar {
  position: sticky;
  top: calc(var(--topbar-h) + var(--sensor-h));
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 24px;
  height: 44px;
  background: rgba(11, 17, 14, 0.95);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}

.device-bar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 20px;
}

.device-bar-item svg {
  width: 14px;
  height: 14px;
  color: var(--muted);
  flex-shrink: 0;
}

.device-bar-item span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.device-bar-item strong {
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
  font-weight: 500;
  color: var(--ink);
}

.device-bar-divider {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

/* ── MAIN LAYOUT ───────────────────────────────────────────── */
.view-tabs {
  position: sticky;
  top: calc(var(--topbar-h) + var(--sensor-h) + var(--bar-h));
  z-index: 75;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  min-height: var(--tabs-h);
  background: rgba(11, 17, 14, 0.94);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.view-tab {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  padding: 8px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease;
}

.view-tab:hover {
  border-color: var(--border-mid);
  color: var(--ink);
  transform: translateY(-1px);
}

.view-tab.is-active {
  border-color: rgba(34, 197, 94, 0.26);
  background: rgba(34, 197, 94, 0.1);
  color: var(--green);
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.08);
}

.view-panel[hidden] {
  display: none !important;
}

.view-panel {
  position: relative;
  z-index: 1;
}

.main-layout {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 390px;
  min-height: calc(100vh - var(--topbar-h) - var(--sensor-h));
}

.trends-layout {
  padding: 22px 24px 28px;
}

.trends-panel {
  display: grid;
  gap: 18px;
}

.trends-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.trends-tools {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.window-picker {
  display: grid;
  gap: 6px;
  min-width: 132px;
}

.window-picker span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.archive-layout {
  padding: 0 22px 22px;
}

.archive-panel {
  display: grid;
  gap: 16px;
}

.archive-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.archive-tools {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.archive-picker {
  min-width: 190px;
}

.archive-chart-card,
.archive-table-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    var(--card);
}

.archive-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.archive-chart-title {
  margin: 0;
  font-size: 16px;
  color: var(--ink);
}

.archive-chart-wrap {
  position: relative;
  min-height: 340px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    rgba(255, 255, 255, 0.02);
  overflow: hidden;
}

.archive-chart-canvas {
  width: 100%;
  height: 340px;
  display: block;
}

.archive-table-wrap {
  overflow: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.archive-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  font-size: 13px;
}

.archive-table th,
.archive-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.archive-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: color-mix(in srgb, var(--card) 92%, rgba(255, 255, 255, 0.06));
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.archive-table td {
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.archive-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.archive-table-empty {
  text-align: center !important;
  color: var(--muted) !important;
  font-family: "Sora", sans-serif !important;
}

.trend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.trend-card {
  --trend-accent: var(--green);
  --trend-soft: rgba(34, 197, 94, 0.12);
  --trend-glow: rgba(34, 197, 94, 0.22);
  display: grid;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), rgba(255, 255, 255, 0)),
    var(--card);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 12px 34px rgba(6, 15, 11, 0.06);
  overflow: hidden;
}

.trend-card.warm {
  --trend-accent: var(--warm);
  --trend-soft: rgba(249, 115, 22, 0.12);
  --trend-glow: rgba(249, 115, 22, 0.22);
}

.trend-card.cool {
  --trend-accent: var(--cool);
  --trend-soft: rgba(56, 189, 248, 0.12);
  --trend-glow: rgba(56, 189, 248, 0.22);
}

.trend-card.earth {
  --trend-accent: var(--earth);
  --trend-soft: rgba(132, 204, 22, 0.12);
  --trend-glow: rgba(132, 204, 22, 0.22);
}

.trend-card.light {
  --trend-accent: var(--light-c);
  --trend-soft: rgba(250, 204, 21, 0.12);
  --trend-glow: rgba(250, 204, 21, 0.22);
}

.trend-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
}

.trend-heading {
  display: grid;
  gap: 4px;
}

.trend-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.trend-subtitle {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.trend-current {
  text-align: right;
}

.trend-current strong {
  display: block;
  font-size: 28px;
  line-height: 1;
  color: var(--trend-accent);
  font-family: "IBM Plex Mono", monospace;
  font-variant-numeric: tabular-nums;
}

.trend-current span {
  display: block;
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.trend-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.trend-metric {
  padding: 9px 10px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0)),
    color-mix(in srgb, var(--trend-accent) 7%, transparent);
  border: 1px solid color-mix(in srgb, var(--trend-accent) 15%, var(--border));
}

.trend-metric-muted {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)),
    rgba(255, 255, 255, 0.02);
}

.trend-metric span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.trend-metric strong {
  display: block;
  margin-top: 5px;
  font-size: 14px;
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  font-weight: 600;
}

.trend-chart-shell {
  position: relative;
  display: grid;
  gap: 10px;
  border-radius: calc(var(--radius-md) + 2px);
  padding: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)),
    color-mix(in srgb, var(--trend-accent) 5%, rgba(0, 0, 0, 0.14));
  border: 1px solid color-mix(in srgb, var(--trend-accent) 11%, rgba(255, 255, 255, 0.06));
  overflow: hidden;
}

.trend-chart-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.trend-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--trend-accent) 14%, var(--border));
  background: color-mix(in srgb, var(--trend-accent) 8%, transparent);
  color: var(--ink);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.trend-chip-soft {
  background: rgba(255, 255, 255, 0.025);
  border-color: rgba(255, 255, 255, 0.06);
}

.trend-canvas-wrap {
  position: relative;
  min-width: 0;
  min-height: 228px;
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0) 52%),
    radial-gradient(circle at top right, color-mix(in srgb, var(--trend-accent) 10%, transparent), transparent 42%),
    rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
}

.trend-canvas {
  width: 100%;
  height: 228px;
  display: block;
}

.trend-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.08), rgba(0, 0, 0, 0.02));
  backdrop-filter: blur(1px);
}

.trend-empty[hidden] {
  display: none;
}

.trend-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── RELAY PANEL (left) ────────────────────────────────────── */
.relay-panel {
  padding: 22px 24px;
  border-right: 1px solid var(--border);
  overflow: auto;
}

.relay-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

/* ── SETTINGS VIEW ─────────────────────────────────────────── */
.settings-layout {
  padding: 22px 24px 28px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.settings-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
}

.settings-card.dirty {
  border-color: rgba(251, 191, 36, 0.35);
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.08);
}

.settings-card.full-span {
  grid-column: 1 / -1;
}

.settings-card-head,
.pin-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.settings-subgrid {
  display: grid;
  gap: 12px;
}

.settings-subgrid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-block {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.settings-block h3 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
}

.alarm-grid {
  grid-template-columns: minmax(0, 1.15fr) repeat(2, minmax(0, 1fr));
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-button-stack {
  display: grid;
  gap: 8px;
  align-content: end;
}

.settings-button-stack.compact {
  min-height: 100%;
}

.settings-value-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(34, 197, 94, 0.04);
}

.settings-value-card span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-value-card strong {
  font-size: 16px;
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
}

.pin-panel {
  display: grid;
  gap: 10px;
  padding-top: 2px;
  border-top: 1px dashed var(--border);
}

.section-heading {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.mini-note, .summary {
  color: var(--muted);
  font-size: 11px;
}

/* ── RELAY GRID ────────────────────────────────────────────── */
.relay-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.relay-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--card);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.relay-card:hover {
  border-color: var(--border-mid);
  transform: translateY(-1px);
}

.relay-card.dirty {
  border-color: rgba(251, 191, 36, 0.35);
  box-shadow: 0 0 28px rgba(251, 191, 36, 0.08);
}

.relay-heading, .editor-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.relay-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
}

.relay-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.relay-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.relay-actions, .editor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) 1fr;
  gap: 10px;
  align-items: end;
}

.editor-wrap, .builder-wrap, .config-stack {
  display: grid;
  gap: 10px;
}

/* ── RELAY PILLS & CHIPS ───────────────────────────────────── */
.relay-pill, .relay-mode-chip, .sync-note {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.relay-pill.on {
  background: rgba(34, 197, 94, 0.12);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.22);
}

.relay-pill.off {
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
  border: 1px solid rgba(248, 113, 113, 0.18);
}

.relay-mode-chip {
  background: rgba(56, 189, 248, 0.08);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.14);
}

.sync-note {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  border: 1px solid var(--border);
}

.relay-card.dirty .sync-note {
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
  border-color: rgba(251, 191, 36, 0.2);
}

/* ── MODE SECTIONS ─────────────────────────────────────────── */
.mode-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
}

.mode-section.hidden { display: none; }

.section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.section-note {
  margin: -4px 0 0;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
}

.field-grid { display: grid; gap: 8px; }
.field-grid.two   { grid-template-columns: repeat(2, 1fr); }
.field-grid.three { grid-template-columns: repeat(3, 1fr); }

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--border);
  cursor: pointer;
}

.check-line input { width: auto; margin: 0; cursor: pointer; }
.compact-check { min-height: auto; padding: 6px 8px; }

/* ── WEEKLY SCHEDULE ───────────────────────────────────────── */
.weekly-board { display: grid; gap: 6px; }

.weekly-head, .weekly-row {
  display: grid;
  grid-template-columns: 52px 82px 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.weekly-head { padding: 0 2px; }

.weekly-head span {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.weekly-row {
  padding: 8px 10px;
  border-radius: var(--radius-md);
  background: var(--card);
  border: 1px solid var(--border);
}

.day-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: var(--radius-sm);
  background: rgba(34, 197, 94, 0.08);
  color: #4ade80;
  font-size: 10px;
  font-weight: 700;
}

/* ── JSON PREVIEW ──────────────────────────────────────────── */
.json-preview {
  border-top: 1px dashed var(--border);
  padding-top: 10px;
}

.json-preview summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  list-style: none;
  user-select: none;
}

.json-preview summary::-webkit-details-marker { display: none; }

.preview-box {
  margin: 10px 0 0;
  padding: 12px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.35);
  color: #4ade80;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
  max-height: 160px;
  overflow: auto;
  border: 1px solid rgba(34, 197, 94, 0.12);
}

.editor-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

/* ── SIDEBAR (right) ───────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - var(--sensor-h) - var(--bar-h));
  position: sticky;
  top: var(--topbar-h);
}

.panel {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.panel-head, .compact-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-note {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--muted);
}

/* ── DEVICE STATUS ─────────────────────────────────────────── */
.device-panel {}

.transport-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.detail-card {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
}

.detail-card span {
  display: block;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-card strong {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  font-family: "IBM Plex Mono", monospace;
  color: var(--ink);
  word-break: break-word;
  font-weight: 500;
}

/* ── BROKER SETUP ──────────────────────────────────────────── */
.broker-head {
  margin-bottom: 14px;
}

.connect-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.connect-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.connect-grid span,
.topic-box span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.topic-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-mid);
  background: rgba(34, 197, 94, 0.04);
  font-family: "IBM Plex Mono", monospace;
}

.topic-box code {
  font-size: 11px;
  color: #4ade80;
  word-break: break-word;
  line-height: 1.5;
}

/* ── INPUTS ────────────────────────────────────────────────── */
input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  padding: 9px 12px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(34, 197, 94, 0.4);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.07);
}

input::placeholder { color: var(--subtle); }

textarea {
  min-height: 160px;
  resize: vertical;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

/* dark select arrow */
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%236b7c74' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 32px;
}

/* ── ACTIVITY LOG ──────────────────────────────────────────── */
.log-panel {
  flex: 1;
  border-bottom: none;
}

.activity-head {
  border-bottom: 1px dashed var(--border);
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.event-log {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
  max-height: 280px;
  overflow: auto;
}

.event-log li {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  animation: fade-in 250ms ease;
}

.event-kind {
  display: block;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--green);
  font-weight: 700;
}

.event-time {
  display: block;
  font-size: 9px;
  color: var(--muted);
}

.event-log code {
  font-size: 10px;
  font-family: "IBM Plex Mono", monospace;
  line-height: 1.5;
  color: var(--muted);
}

.raw-state {
  margin: 0;
  min-height: 160px;
  max-height: 280px;
  overflow: auto;
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(0, 0, 0, 0.35);
  color: #4ade80;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  line-height: 1.55;
  border: 1px solid rgba(34, 197, 94, 0.12);
}

/* ── BADGES ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge.device-summary {
  background: rgba(100, 180, 255, 0.07);
  border: 1px solid rgba(100, 180, 255, 0.15);
  color: #93c5fd;
  font-size: 10px;
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.device-summary::before { display: none; }

.badge.online {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.22);
  color: #4ade80;
}

.badge.online::before {
  animation: pulse-dot 2s ease-in-out infinite;
}

.badge.offline {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.18);
  color: #fca5a5;
}

.badge.pending {
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.18);
  color: #fde68a;
}

/* ── BUTTONS ───────────────────────────────────────────────── */
.primary, .ghost, .inline-btn {
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  transition: transform 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
  white-space: nowrap;
}

.primary:hover, .ghost:hover, .inline-btn:hover {
  transform: translateY(-1px);
}

.primary:active, .ghost:active, .inline-btn:active {
  transform: translateY(0);
}

.primary {
  padding: 9px 18px;
  background: var(--green);
  color: #0a0f0d;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 4px 18px rgba(34, 197, 94, 0.25);
}

.primary:hover {
  box-shadow: 0 8px 28px rgba(34, 197, 94, 0.35);
}

.ghost {
  padding: 7px 13px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  color: var(--ink);
  font-size: 12px;
}

.ghost:hover {
  background: rgba(255, 255, 255, 0.07);
}

.inline-btn {
  padding: 8px 12px;
  background: var(--green-muted);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.14);
  font-size: 12px;
}

.inline-btn.power-on {
  background: rgba(34, 197, 94, 0.12);
  color: #4ade80;
  border-color: rgba(34, 197, 94, 0.22);
}

.inline-btn.power-off {
  background: rgba(248, 113, 113, 0.08);
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.18);
}

.small {
  padding: 7px 10px;
  font-size: 11px;
}

/* ── THEME TOGGLE BUTTON ───────────────────────────────────── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms, transform 140ms;
  flex-shrink: 0;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  border-color: var(--border-mid);
  transform: rotate(18deg);
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* dark mode → show moon, hide sun */
.icon-sun  { display: none; }
.icon-moon { display: block; }

/* light mode → show sun, hide moon */
body[data-theme="light"] .icon-sun  { display: block; }
body[data-theme="light"] .icon-moon { display: none; }

body[data-theme="light"] .theme-toggle {
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  border-color: var(--border);
}

body[data-theme="light"] .theme-toggle:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--ink);
}

.inline-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.inline-btn:disabled::after {
  content: " …";
}

/* ── ANIMATIONS ────────────────────────────────────────────── */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.3; transform: scale(0.7); }
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes lift-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* kept for compatibility */
.hero-card, .hero-copy, .hero-card-top, .hero-facts, .fact-box,
.lede, .eyebrow, .layout-grid, .side-stack,
.status-log-panel, .broker-panel-old { display: contents; }

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 1200px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .trend-grid {
    grid-template-columns: 1fr;
  }

  .relay-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar {
    max-height: none;
    position: relative;
    top: 0;
  }
}

@media (max-width: 900px) {
  .sensor-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .sensor-card:nth-child(2) { border-right: none; }
  .sensor-card:nth-child(1),
  .sensor-card:nth-child(2) { border-bottom: 1px solid var(--border); }

  .relay-grid,
  .transport-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .topbar {
    grid-template-columns: auto 1fr;
    gap: 12px;
    height: auto;
    padding: 12px 18px;
  }

  .topbar-facts { display: none; }
  .topbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .topbar-summary { display: none; }

  .view-tabs,
  .trends-layout,
  .settings-layout {
    padding-left: 18px;
    padding-right: 18px;
  }
}

@media (max-width: 640px) {
  .sensor-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .relay-grid {
    grid-template-columns: 1fr;
  }

  .transport-grid,
  .control-strip {
    grid-template-columns: 1fr;
  }

  .topbar { padding: 10px 14px; }

  .field-grid.two,
  .field-grid.three,
  .toggle-grid,
  .settings-subgrid.two,
  .weekly-head,
  .weekly-row {
    grid-template-columns: 1fr;
  }

  .relay-heading,
  .editor-head,
  .panel-head,
  .compact-head,
  .trends-head,
  .settings-card-head,
  .pin-panel-head,
  .archive-head,
  .archive-chart-head {
    flex-direction: column;
    align-items: stretch;
  }

  .view-tabs {
    gap: 8px;
    padding: 10px 14px;
  }

  .view-tab {
    flex: 1;
    justify-content: center;
  }

  .trends-layout {
    padding-left: 14px;
    padding-right: 14px;
  }

  .settings-layout {
    padding-left: 14px;
    padding-right: 14px;
  }

  .archive-layout {
    padding-left: 14px;
    padding-right: 14px;
  }

  .trends-tools,
  .trend-footer,
  .settings-actions {
    display: grid;
  }

  .archive-tools {
    display: grid;
    grid-template-columns: 1fr;
  }

  .archive-picker {
    min-width: 0;
  }

  .trend-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .window-picker {
    min-width: 0;
  }

  .alarm-grid {
    grid-template-columns: 1fr;
  }

  .trend-chart-topline {
    flex-direction: column;
    align-items: stretch;
  }

  .trend-canvas-wrap {
    min-height: 212px;
  }

  .trend-canvas {
    height: 212px;
  }

  .archive-chart-canvas {
    height: 280px;
  }
}
