/* Emporia Notifications — no inline styles anywhere (the CSP forbids them). */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202a;
  --muted: #5b6573;
  --border: #dde1e6;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d9f2ef;
  --high: #b42318;
  --high-soft: #fde7e5;
  --ok: #18794e;
  --ok-soft: #dcf3e7;
  --warn: #8a5300;
  --warn-soft: #fff1d6;
  --focus: #2563eb;
  --chart-line: #0f766e;
  --chart-fill: rgba(15, 118, 110, 0.12);
  --chart-high: #b42318;
  --chart-low: #8a5300;
  --chart-grid: rgba(23, 32, 42, 0.08);
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1d232c;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --border: #2b323c;
    --accent: #2dd4bf;
    --accent-text: #04201d;
    --accent-soft: #0f2f2c;
    --high: #ff7b72;
    --high-soft: #3a1714;
    --ok: #56d364;
    --ok-soft: #12301b;
    --warn: #e3b341;
    --warn-soft: #33270b;
    --focus: #60a5fa;
    --chart-line: #2dd4bf;
    --chart-fill: rgba(45, 212, 191, 0.14);
    --chart-high: #ff7b72;
    --chart-low: #e3b341;
    --chart-grid: rgba(230, 233, 238, 0.08);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

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

[hidden] { display: none !important; }

/* ---------- layout ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 650;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand-mark { width: 22px; height: 22px; fill: var(--accent); }

.nav { display: flex; gap: 4px; flex: 1; }

.nav a {
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }

.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }

.view {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
  outline: none;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 16px;
}

h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.mono { font-family: var(--mono); }

/* ---------- surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }

.stack > * + * { margin-top: 16px; }

.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}

/* ---------- dashboard cards ---------- */

.channel-card { display: flex; flex-direction: column; gap: 12px; text-decoration: none; color: inherit; }

.channel-card:hover { border-color: var(--accent); }

.channel-card .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }

.big { font-size: 2.25rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }

.big .unit { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 4px; }

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

.stat { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; }

.stat .label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.stat .value { font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
}

.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.badge.high { background: var(--high-soft); color: var(--high); }
.badge.normal { background: var(--ok-soft); color: var(--ok); }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.config { background: var(--accent-soft); color: var(--accent); }

/* ---------- devices ---------- */

.device + .device { margin-top: 16px; }

.device-head { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; margin-bottom: 8px; }

.rows { list-style: none; margin: 0; padding: 0; }

.rows li + li { border-top: 1px solid var(--border); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  color: inherit;
  text-decoration: none;
}

a.row:hover { background: var(--surface-2); }

.row .grow { flex: 1; min-width: 0; }

.row .chan { font-family: var(--mono); font-size: 0.85rem; color: var(--muted); min-width: 64px; }

/* ---------- chart ---------- */

.ranges { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }

.ranges button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.ranges button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chart-box { position: relative; height: 320px; margin-top: 12px; }

.chart-note { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* ---------- forms ---------- */

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

.form .full { grid-column: 1 / -1; }

.field label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; }

.field .hint { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }

.field .error { font-size: 0.8rem; color: var(--high); margin-top: 2px; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"] {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input[aria-invalid="true"] { border-color: var(--high); }

.check { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.check input { width: 18px; height: 18px; accent-color: var(--accent); }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.actions .spacer { flex: 1; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  font: inherit;
  font-weight: 650;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  text-decoration: none;
}

.button:disabled { opacity: 0.6; cursor: progress; }

.button.quiet { background: transparent; color: var(--muted); border-color: var(--border); }

.button.quiet:hover { color: var(--text); }

.button.danger { background: transparent; color: var(--high); border-color: var(--high); }

.notice { padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; }

.notice.error { background: var(--high-soft); color: var(--high); }

.notice.warn { background: var(--warn-soft); color: var(--warn); }

.notice.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- sign-in ---------- */

.auth { max-width: 420px; margin: 8vh auto 0; }

.auth .brand { justify-content: center; font-size: 1.2rem; margin-bottom: 20px; }

.auth form { display: grid; gap: 14px; }

.auth .button { width: 100%; }

.auth .actions .button { width: auto; flex: 1 1 0; white-space: nowrap; }

.code-input { font-family: var(--mono); font-size: 1.5rem !important; letter-spacing: 0.3em; text-align: center; }

.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 8px; width: max-content; margin: 0 auto; }

.qr img { display: block; width: 200px; height: 200px; image-rendering: pixelated; }

.secret {
  font-family: var(--mono);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: center;
}

.steps { margin: 0; padding-left: 20px; color: var(--muted); }

/* ---------- alerts ---------- */

.event { display: grid; grid-template-columns: 150px auto 1fr; gap: 4px 12px; align-items: baseline; padding: 12px 4px; }

.event + .event { border-top: 1px solid var(--border); }

.event time { color: var(--muted); font-size: 0.875rem; font-variant-numeric: tabular-nums; }

.event .changes { grid-column: 3; font-size: 0.85rem; color: var(--muted); }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 20;
}

/* ---------- small screens ---------- */

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  #sign-out { margin-left: auto; }
  .view { padding: 16px; }
  .form { grid-template-columns: 1fr; }
  .event { grid-template-columns: 1fr auto; }
  .event .what, .event .changes { grid-column: 1 / -1; }
  .chart-box { height: 260px; }
  .big { font-size: 1.9rem; }
}
