/* IoT Cloud design system: tokens, app shell, components. Light and dark themes. No inline styles (strict CSP). */
:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --line: #e2e8f0; --line-strong: #cbd5e1;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-soft: #eaf1ff; --on-accent: #ffffff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fef4e2; --err: #b91c1c; --err-soft: #fdecec;
  --side: #0f172a; --side-text: #cbd5e1; --side-muted: #64748b; --side-hover: #1e293b; --side-active: #1e3a8a;
  --chart-1: #2563eb; --chart-2: #0d9488; --chart-3: #d97706; --chart-4: #9333ea; --chart-5: #e11d48; --chart-6: #0891b2;
  --dial-track: #e2e8f0;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .12);
  --radius: 12px; --radius-sm: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111827; --surface-2: #0f172a; --text: #e5e7eb; --muted: #94a3b8; --faint: #64748b;
    --line: #1f2937; --line-strong: #334155;
    --accent: #60a5fa; --accent-2: #93c5fd; --accent-soft: #172554; --on-accent: #0b1120;
    --ok: #4ade80; --ok-soft: #052e16; --warn: #fbbf24; --warn-soft: #3a2a07; --err: #f87171; --err-soft: #3b0d0d;
    --side: #020617; --side-hover: #0f172a; --side-active: #1e3a8a;
    --chart-1: #60a5fa; --chart-2: #2dd4bf; --chart-3: #fbbf24; --chart-4: #c084fc; --chart-5: #fb7185; --chart-6: #22d3ee;
    --dial-track: #1f2937;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; margin: 0; }
h3 { font-size: .95rem; margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em;
  background: var(--surface-2); border: 1px solid var(--line); padding: .05em .35em; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.num { font-variant-numeric: tabular-nums; }
.icon { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.icon.sm { width: 15px; height: 15px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; padding: 18px 12px; gap: 4px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700;
  font-size: 1.05rem; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: linear-gradient(135deg, #3b82f6, #14b8a6); color: #fff; }
.nav-section { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted);
  padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 8px 12px; border-radius: 8px; color: var(--side-text);
  font-weight: 500; }
.nav a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; }
.nav .ext { margin-left: auto; opacity: .6; }
.nav .count { margin-left: auto; background: #dc2626; color: #fff; border-radius: 99px; font-size: .7rem; padding: 0 7px;
  font-weight: 600; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #1e293b; padding-top: 12px; }
.who { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #06b6d4); color: #fff; font-size: .8rem; flex: none; text-transform: uppercase; }
.who-name { color: #fff; font-weight: 600; line-height: 1.2; }
.who-role { color: var(--side-muted); font-size: .75rem; }
.signout { margin-left: auto; background: none; border: 0; color: var(--side-muted); cursor: pointer; padding: 6px;
  border-radius: 6px; }
.signout:hover { color: #fff; background: var(--side-hover); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); min-height: 60px; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px; color: var(--text);
  cursor: pointer; }
.crumbs { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: 6px; min-width: 0; }
.crumbs strong { color: var(--text); font-weight: 600; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.content { padding: 24px 28px 48px; max-width: 1480px; width: 100%; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px; min-width: 0; }
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head p { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 16px 20px 0; margin-bottom: 0; }
.card.flush .card-body { padding: 14px 20px 18px; }
.section-title { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted);
  font-weight: 600; margin: 26px 0 10px; display: flex; align-items: center; gap: 8px; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.grid.devices { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); align-items: start; }
.grid.dials { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.grid.minis { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stack-gap > * + * { margin-top: 18px; }

/* ---------- KPI / value tiles ---------- */
.kpi { display: flex; gap: 14px; align-items: center; }
.kpi-icon { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft);
  color: var(--accent); flex: none; }
.kpi-icon.ok { background: var(--ok-soft); color: var(--ok); }
.kpi-icon.warn { background: var(--warn-soft); color: var(--warn); }
.kpi-icon.err { background: var(--err-soft); color: var(--err); }
.kpi-label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.kpi-value { font-size: 1.6rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }

.tile { position: relative; display: flex; flex-direction: column; gap: 4px; overflow: hidden; }
.tile-label { color: var(--muted); font-size: .8rem; font-weight: 500; overflow-wrap: anywhere; }
.tile-value { font-size: 1.75rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile-unit { font-size: .85rem; color: var(--muted); font-weight: 500; margin-left: 3px; }
.tile-foot { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .76rem; flex-wrap: wrap; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--err); }
.delta.flat { color: var(--muted); }
.tile .spark-wrap { color: var(--chart-1); line-height: 0; margin-top: 4px; }
.spark { width: 100%; height: 40px; }
.state-pill { display: inline-flex; align-items: center; gap: 8px; font-size: 1.15rem; font-weight: 700; }
.state-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--faint); }
.state-pill.on .state-dot { background: #22c55e; box-shadow: 0 0 0 4px var(--ok-soft); }
.state-pill.off .state-dot { background: var(--faint); box-shadow: 0 0 0 4px var(--surface-2); }
.text-tile .tile-value { font-size: 1.05rem; font-weight: 600; }

/* ---------- dials ---------- */
.dial { display: flex; flex-direction: column; align-items: center; text-align: center; }
.dial svg { width: 100%; max-width: 200px; height: auto; display: block; }
.dial .track { stroke: var(--dial-track); }
.dial .bar { stroke: var(--chart-1); transition: stroke-dashoffset .6s ease; }
.dial.hot .bar { stroke: var(--err); }
.dial .tick { stroke: var(--err); }
.dial-value { font-size: 1.55rem; font-weight: 700; margin-top: -44px; font-variant-numeric: tabular-nums; line-height: 1.2; }
.dial-unit { color: var(--muted); font-size: .8rem; }
.dial-range { display: flex; justify-content: space-between; width: 100%; max-width: 200px; color: var(--faint);
  font-size: .72rem; margin-top: 4px; padding: 0 10px; font-variant-numeric: tabular-nums; }
.dial-label { font-weight: 600; margin-top: 8px; overflow-wrap: anywhere; }

/* ---------- device cards (overview) ---------- */
.device-card { display: flex; flex-direction: column; gap: 12px; transition: box-shadow .15s, border-color .15s; }
.device-card:hover { box-shadow: var(--shadow-lg); border-color: var(--line-strong); }
.device-card-head { display: flex; align-items: center; gap: 10px; }
.device-card-head h3 { font-size: 1rem; overflow-wrap: anywhere; }
.device-card-head h3 a { color: var(--text); }
.device-card-head .badge { margin-left: auto; }
.device-chip { width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; flex: none; }
.device-card .mini-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
.mini-label { font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-value { font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.mini .spark { height: 26px; color: var(--chart-1); }
.device-card-foot { display: flex; gap: 14px; color: var(--muted); font-size: .78rem; flex-wrap: wrap; border-top: 1px solid var(--line);
  padding-top: 10px; }
.device-card-foot span { display: inline-flex; align-items: center; gap: 5px; }
.device-card-foot .open { margin-left: auto; font-weight: 600; }

/* ---------- badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 600; border-radius: 99px;
  padding: 2px 9px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge.on { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.off { background: var(--surface-2); color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.alert { background: var(--err-soft); color: var(--err); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.role { font-size: .7rem; border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; color: var(--muted); }

/* ---------- buttons, segmented control, forms ---------- */
button, .button { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer;
  border-radius: 8px; padding: 7px 13px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
  font-weight: 500; text-decoration: none; white-space: nowrap; }
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover, .button.primary:hover { background: var(--accent-2); }
button.small, .button.small { padding: 4px 10px; font-size: .82rem; }
button.danger, .button.danger { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }
button.ghost, .button.ghost { border-color: transparent; background: transparent; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
.wide { width: 100%; }
.danger-text { color: var(--err); }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px;
  flex-wrap: wrap; }
.segmented a, .segmented button { border: 0; background: transparent; padding: 5px 12px; border-radius: 7px; color: var(--muted);
  font-weight: 600; font-size: .82rem; }
.segmented a:hover, .segmented button:hover { color: var(--text); text-decoration: none; background: transparent; }
.segmented [aria-current="true"], .segmented [aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
label { display: flex; flex-direction: column; gap: 5px; font-size: .8rem; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 400; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
button:focus-visible, .button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.form-row label { flex: 1 1 160px; }
.form-row label.auto { flex: 0 1 auto; }
.hint { font-size: .74rem; color: var(--faint); font-weight: 400; }
form.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
form.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
select[multiple] { min-width: 12rem; }
input.narrow { width: 6.5rem; }

/* ---------- flash messages ---------- */
.flash { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px;
  background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.error { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }
.flash.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: middle; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600;
  background: var(--surface-2); }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; }
.card.flush .table-wrap { border-top: 1px solid var(--line); margin-top: 14px; }
.card.flush table th:first-child, .card.flush table td:first-child { padding-left: 20px; }
.card.flush table th:last-child, .card.flush table td:last-child { padding-right: 20px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
details summary { cursor: pointer; color: var(--accent); font-size: .82rem; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 4px; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.cell-user .avatar { width: 28px; height: 28px; font-size: .72rem; }

/* ---------- toolbar / search ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search input { width: 100%; padding-left: 34px; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }

/* ---------- device switcher ---------- */
.switcher { position: relative; }
.switcher > summary { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 6px 10px 6px 12px; background: var(--surface); color: var(--text); font-weight: 600; font-size: .9rem; }
.switcher[open] > summary { border-color: var(--accent); }
.switcher-panel { position: absolute; right: 0; top: calc(100% + 6px); width: 300px; max-width: 86vw; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 8px; z-index: 30; }
.switcher-panel input { width: 100%; margin-bottom: 6px; }
.switcher-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; }
.switcher-list a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.switcher-list a:hover, .switcher-list a[aria-current="page"] { background: var(--accent-soft); text-decoration: none; }
.icon-btn { padding: 6px; border-radius: 8px; }
.icon-btn[aria-disabled="true"] { opacity: .35; pointer-events: none; }

/* ---------- device dashboard ---------- */
.device-hero { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.device-hero .device-chip { width: 48px; height: 48px; border-radius: 12px; }
.device-hero h1 { overflow-wrap: anywhere; }
.device-meta { display: flex; gap: 16px; color: var(--muted); font-size: .85rem; flex-wrap: wrap; margin-top: 4px; }
.device-meta span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip-toggle { display: inline-flex; align-items: center; gap: 7px; font-size: .78rem; font-weight: 600; padding: 4px 10px;
  border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); cursor: pointer; }
.chip-toggle .swatch { width: 10px; height: 10px; border-radius: 3px; }
.chip-toggle[aria-pressed="false"] { opacity: .45; }
.sw-1 { background: var(--chart-1); } .sw-2 { background: var(--chart-2); } .sw-3 { background: var(--chart-3); }
.sw-4 { background: var(--chart-4); } .sw-5 { background: var(--chart-5); } .sw-6 { background: var(--chart-6); }
.chart-box { width: 100%; min-height: 320px; position: relative; }
.chart-box.mini { min-height: 150px; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; text-align: center; }
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.updated { font-size: .75rem; color: var(--faint); display: inline-flex; align-items: center; gap: 6px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px var(--ok-soft); }
.live-dot.paused { background: var(--faint); box-shadow: none; }

/* uPlot theme */
.uplot { font-family: inherit; }
.u-legend { font-size: .78rem; color: var(--muted); }
.u-select { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .icon { width: 40px; height: 40px; color: var(--faint); margin-bottom: 10px; }
.empty h2 { color: var(--text); margin-bottom: 6px; }

/* ---------- code / raw messages ---------- */
pre.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; overflow: auto;
  font-size: .8rem; line-height: 1.5; margin: 8px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 16rem; }
.raw-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
code.secret { font-size: 1.05rem; user-select: all; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* ---------- login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.auth-brand { background: radial-gradient(1200px 600px at 10% 10%, #1e40af 0%, #0f172a 55%, #020617 100%); color: #e2e8f0;
  padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 24px; }
.auth-brand .brand { padding: 0; }
.auth-brand h2 { font-size: 2rem; line-height: 1.2; color: #fff; max-width: 26rem; margin: 0 0 12px; }
.auth-brand p { color: #94a3b8; max-width: 28rem; margin: 0; }
.auth-points { display: grid; gap: 12px; margin-top: 28px; color: #cbd5e1; }
.auth-points span { display: flex; gap: 10px; align-items: center; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.auth-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 1.6rem; }
.auth-card input { padding: 10px 12px; }
.auth-card button.primary { padding: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .grid.two { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%);
    transition: transform .2s ease; padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 40; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 40px; }
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { padding: 24px 20px; }
  .auth-brand h2 { font-size: 1.35rem; }
  .auth-points { display: none; }
  .grid.devices, .grid.minis { grid-template-columns: minmax(0, 1fr); }
  .grid.dials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile-value { font-size: 1.35rem; }
  .dial-value { font-size: 1.2rem; margin-top: -34px; }
  .switcher-panel { right: auto; left: 0; }
}
@media (max-width: 420px) { .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } .kpi-icon { display: none; } }
.row-forms { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.kpi-value.small { font-size: 1rem; font-weight: 600; }
.card-body { padding: 14px 20px 18px; }

/* ---------- fixes: hidden attribute, grid spacing, chart legend ---------- */
[hidden] { display: none !important; }
.grid > .card + .card, .grid > .card { margin-top: 0; }
.grid + .card, .card + .grid, .grid + .grid { margin-top: 18px; }
.chart-box.compact { min-height: 150px; }
.u-legend th, .u-legend td { background: none; text-transform: none; letter-spacing: 0; font-weight: 500; border: 0;
  padding: 2px 6px; font-size: .78rem; color: var(--muted); }
.u-legend tr:hover { background: none; }
.u-legend .u-marker { border-radius: 3px; }
.hero-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 860px) {
  .crumbs > a, .crumbs > span { display: none; }
  .updated [data-updated] { display: none; }
  .topbar-actions { flex-wrap: nowrap; gap: 6px; }
  .switcher > summary { max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
/* units like µg/m³ must keep their case: no upper-casing in table headers */
th { text-transform: none; letter-spacing: .01em; font-size: .76rem; }
/* forms inside table rows stay on one line */
td form.inline { flex-wrap: nowrap; }
td form.inline input:not(.narrow):not([type=hidden]):not([type=checkbox]) { width: 11rem; }
td form.inline input.narrow { width: 5.5rem; }
.grid + .flash, .grid + form.card, .grid + section.card { margin-top: 18px; }

/* ===================== release 5: gauges, responsive layout, pickers ===================== */

/* ---------- gauges: everything positioned inside the SVG ---------- */
.grid.dials { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); align-items: stretch; }
.dial { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 6px; padding: 16px 16px 14px; }
.dial-label { font-weight: 600; margin: 0; text-align: center; overflow-wrap: anywhere; width: 100%; }
.dial svg.dial-svg { width: 100%; max-width: 220px; height: auto; display: block; overflow: visible; }
.dial-svg .track { stroke: var(--dial-track); }
.dial-svg .bar { stroke: var(--chart-1); transition: stroke-dashoffset .6s ease; }
.dial-svg.hot .bar { stroke: var(--err); }
.dial-svg .tick { stroke: var(--err); }
.dial-svg .dial-num { fill: var(--text); font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dial-svg .dial-unit { fill: var(--muted); font-size: 13px; font-weight: 500; }
.dial-svg .dial-end { fill: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.dial-foot { color: var(--muted); font-size: .76rem; min-height: 1.1em; text-align: center; }

/* ---------- searchable multi-select (Reports sensors) ---------- */
.picker { position: relative; min-width: 0; }
.picker > details > summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px; background: var(--surface); color: var(--text);
  font-size: .9rem; font-weight: 500; min-height: 38px; }
.picker > details[open] > summary { border-color: var(--accent); }
.picker-summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-panel { position: absolute; left: 0; top: calc(100% + 6px); z-index: 25; width: min(360px, 92vw);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 10px; }
.picker-panel .search { max-width: none; }
.picker-tools { display: flex; align-items: center; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.picker-tools .count { margin-left: auto; color: var(--muted); font-size: .78rem; }
.picker-list { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.picker-item { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; color: var(--text);
  font-weight: 400; font-size: .88rem; }
.picker-item:hover { background: var(--surface-2); }
.picker-item input { width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
.picker-item .unit { margin-left: auto; color: var(--faint); font-size: .76rem; }
.picker-empty { color: var(--muted); font-size: .85rem; padding: 8px; }
.picker-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.picker-chips:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 99px;
  padding: 3px 4px 3px 10px; font-size: .78rem; font-weight: 600; }
.chip button { border: 0; background: transparent; color: inherit; padding: 0 6px; border-radius: 99px; font-size: .9rem; line-height: 1; }
.chip button:hover { background: color-mix(in srgb, var(--accent) 15%, transparent); }

/* ---------- report filters: tidy grid at every width ---------- */
.filters-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(0, 1.4fr) auto; gap: 12px 14px; align-items: end; }
.filters-grid .sensors-field { grid-column: span 1; }
.filters-grid .submit { display: flex; }
@media (max-width: 1200px) { .filters-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters-grid .sensors-field { grid-column: span 2; } }
@media (max-width: 640px) { .filters-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filters-grid .sensors-field, .filters-grid .submit { grid-column: 1 / -1; }
  .filters-grid .submit button { width: 100%; } }

/* ---------- tablet: icon rail sidebar ---------- */
@media (min-width: 861px) and (max-width: 1199px) {
  .shell { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding: 16px 10px; align-items: center; }
  .brand { padding: 4px 0 16px; font-size: 0; gap: 0; }
  .nav { width: 100%; }
  .nav a { justify-content: center; padding: 10px; font-size: 0; gap: 0; }
  .nav a .icon { width: 20px; height: 20px; }
  .nav .ext, .nav .count { display: none; }
  .nav-section { font-size: 0; padding: 8px 0 4px; border-top: 1px solid #1e293b; margin-top: 8px; }
  .who { flex-direction: column; padding: 4px 0; gap: 6px; }
  .who > span:not(.avatar) { display: none; }
  .signout { margin: 0; }
  .content { padding: 22px 22px 44px; }
  .grid.devices { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
}

/* ---------- tables become labelled cards on small screens ---------- */
@media (max-width: 768px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--line); border-radius: 10px; margin: 10px 12px; padding: 6px 4px;
    width: auto; background: var(--surface); }
  table.responsive tbody tr:hover { background: var(--surface); }
  table.responsive td { display: flex; gap: 12px; justify-content: space-between; align-items: center; border: 0;
    white-space: normal; padding: 6px 10px; text-align: right; overflow-wrap: anywhere; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: .74rem; font-weight: 600;
    text-align: left; flex: none; max-width: 40%; }
  table.responsive td[data-label=""]::before { display: none; }
  table.responsive td.actions { justify-content: flex-start; flex-wrap: wrap; text-align: left; }
  table.responsive td.actions::before { width: 100%; max-width: none; }
  table.responsive td form.inline { flex-wrap: wrap; justify-content: flex-end; }
  table.responsive td form.inline input:not(.narrow):not([type=hidden]):not([type=checkbox]) { width: 100%; min-width: 0; }
  .card.flush table.responsive td:first-child, .card.flush table.responsive td:last-child { padding-left: 10px; padding-right: 10px; }
  .card.flush .table-wrap { border-top: 0; }
  .card-head .search { max-width: none; width: 100%; }
  .page-head { align-items: flex-start; }
  .page-head .actions, .page-head > nav { width: 100%; }
  .form-row label { flex-basis: 100%; }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .kpi { gap: 10px; }
  .kpi-icon { width: 34px; height: 34px; }
  .kpi-value { font-size: 1.3rem; }
  .card { padding: 14px 14px; }
  .card.flush .card-head { padding: 14px 14px 0; }
  .device-hero { gap: 12px; }
  .hero-actions { margin-left: 0; width: 100%; }
  .hero-actions .button { flex: 1 1 auto; }
  .segmented { width: 100%; }
  .segmented a, .segmented button { flex: 1 1 auto; text-align: center; }
  h1 { font-size: 1.25rem; }
}
@media (max-width: 420px) {
  .grid.dials, .grid.tiles { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .dial { padding: 12px 10px; }
  .tile-value { font-size: 1.2rem; }
  .content { padding: 14px 12px 36px; }
  .topbar { padding: 8px 12px; }
}

/* ===================== visual QA fixes (all widths) ===================== */
/* picker */
.picker-item { flex-direction: row; justify-content: flex-start; text-align: left; }
.picker-item > span:first-of-type { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker > details { position: relative; }
.picker-panel { width: max(100%, 300px); max-width: calc(100vw - 32px); }
@media (max-width: 640px) { .picker-panel { left: 0; right: 0; width: auto; } }

/* report filters: top-aligned, equal control heights, sensors row */
.filters-grid { align-items: start; }
.filters-grid .submit { padding-top: 23px; }
@media (max-width: 1200px) {
  .filters-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters-grid .sensors-field { grid-column: 1 / span 3; }
}
@media (max-width: 640px) {
  .filters-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .filters-grid .sensors-field, .filters-grid .submit { grid-column: 1 / -1; }
  .filters-grid .submit { padding-top: 0; }
}

/* table action cells keep table layout; summaries look like buttons */
td.actions { display: table-cell; }
td.actions > * { display: inline-flex; vertical-align: middle; margin: 2px 6px 2px 0; }
td details > summary { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 4px 10px; font-size: .82rem; color: var(--text); background: var(--surface); font-weight: 500; }
td details > summary.danger-text { color: var(--err); border-color: color-mix(in srgb, var(--err) 45%, transparent); }
td details[open] { display: flex; flex-direction: column; align-items: flex-start; }

/* grids fill their row; equal-height cards */
.grid.dials { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: stretch; }
.grid.minis { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.dial svg.dial-svg { max-width: 240px; }
.grid.devices { align-items: stretch; }
.device-card-foot { margin-top: auto; }
.tile { justify-content: space-between; }
.tile-foot { flex-direction: column; gap: 2px; }
.mini .spark-wrap svg, .mini .spark { width: 100%; height: 30px; display: block; }

/* gauges: readable labels at small sizes */
.dial-svg .dial-unit { font-size: 16px; fill: var(--muted); }
.dial-svg .dial-end { font-size: 14px; fill: var(--muted); }

/* page header: title takes the space, action stays top-right */
.page-head > div:first-child { flex: 1 1 380px; min-width: 0; }
.page-head > .actions, .page-head > nav { margin-left: auto; align-self: flex-start; }
.section-title .muted { text-transform: none; letter-spacing: 0; font-weight: 500; }
p code, .muted code { white-space: nowrap; }

/* device hero: icon stays beside the name */
.hero-main { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 320px; }
.hero-main > div { min-width: 0; }

/* alerts form */
.form-row label .hint { display: inline; margin-left: 4px; }
.cond { display: grid; grid-template-columns: 5rem minmax(0, 1fr); gap: 6px; }
.form-row label.short { flex: 0 1 150px; }

/* tall tables scroll inside their card with a sticky header */
.table-scroll { max-height: 560px; overflow: auto; }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; }
td .none { color: var(--faint); }
.downloads { display: flex; gap: 8px; flex-wrap: wrap; }

/* charts */
.u-legend { text-align: left; }
.chart-box.compact { min-height: 170px; }

/* tablet rail: drop the low-value sensor column */
@media (min-width: 769px) and (max-width: 1199px) { .sensors-table .col-seen { display: none; } }

@media (max-width: 860px) {
  .topbar:has(.switcher) .crumbs { display: none; }
}
@media (max-width: 768px) {
  .grid.kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .hero-actions .button { flex: 1 1 0; }
  .device-hero .device-chip { width: 40px; height: 40px; }
  .chart-box { min-height: 0; }
  .downloads { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); width: 100%; }
  /* cells holding forms: caption above, form below */
  table.responsive td.stack { flex-direction: column; align-items: stretch; text-align: left; }
  table.responsive td.stack::before { max-width: none; }
  table.responsive td.stack form.inline { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 6px; }
  table.responsive td.stack form.inline input, table.responsive td.stack form.inline select { width: 100% !important; }
  table.responsive td.block { flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; }
  table.responsive td.block::before { max-width: none; }
}
/* short tables (report summary, readings) only turn into cards on phones */
@media (max-width: 640px) {
  table.responsive-sm thead { display: none; }
  table.responsive-sm, table.responsive-sm tbody, table.responsive-sm tr, table.responsive-sm td { display: block; width: 100%; }
  table.responsive-sm tr { border: 1px solid var(--line); border-radius: 10px; margin: 10px 12px; padding: 6px 4px; width: auto; }
  table.responsive-sm td { display: flex; justify-content: space-between; gap: 12px; border: 0; white-space: normal; padding: 5px 10px; text-align: right; }
  table.responsive-sm td::before { content: attr(data-label); color: var(--muted); font-size: .74rem; font-weight: 600; text-align: left; }
  .table-scroll { max-height: none; }
}
.picker-item input[type=checkbox] { padding: 0; margin: 0; border-radius: 4px; }
.picker-item { padding: 6px 8px; }

/* ===================== visual QA, second pass ===================== */
.filters-grid > label > input, .filters-grid > label > select, .picker > details > summary { height: 40px; }
.form-row input:not([type=checkbox]):not([type=hidden]), .form-row select { height: 40px; }
.picker-item input[type=checkbox] { height: 16px; width: 16px; padding: 0; }
.picker-item .unit { color: var(--muted); font-size: .8rem; }
.picker-panel .search input { height: 36px; }

/* gauges never stretch alone; trends 2 x 2 */
.grid.dials { grid-template-columns: repeat(auto-fill, minmax(220px, 300px)); justify-content: start; }
.grid.minis { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.grid.two.equal { align-items: stretch; }
.delta.flat { color: var(--muted); }
.badge { vertical-align: middle; }

/* captions: text and hint on one line */
.label-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* code sample keeps its layout */
pre.code.json { white-space: pre; overflow-wrap: normal; overflow-x: auto; }

/* tall readings table: whole rows, fade cue */
.table-scroll { max-height: 528px; }
.kpi > div { min-width: 0; }
.kpi-value.small { white-space: nowrap; font-size: 1rem; }

@media (min-width: 861px) and (max-width: 1199px) {
  .col-desc { display: none; }
  .kpi-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kpi { gap: 10px; }
  .kpi-icon { width: 36px; height: 36px; }
}
@media (max-width: 768px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.kpis:has(> :nth-child(3):last-child) { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.kpis:has(> :nth-child(5):last-child) { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .grid.kpis:has(> :nth-child(5):last-child) > :nth-child(-n+3) { grid-column: span 2; }
  .grid.kpis:has(> :nth-child(5):last-child) > :nth-child(n+4) { grid-column: span 3; }
  .grid.tiles { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
  table.responsive td.stack form.widget-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; }
  table.responsive td.stack form.widget-form select { grid-column: 1 / -1; }
  table.responsive td .ghost.danger { padding-left: 10px; border-color: color-mix(in srgb, var(--err) 45%, transparent); }
  .u-legend { display: flex; flex-wrap: wrap; justify-content: flex-start; gap: 2px 12px; }
  .u-legend tr { display: inline-flex; align-items: center; }
  .u-legend .u-series:first-child { display: none; }
}
@media (max-width: 640px) {
  .downloads { grid-template-columns: 1fr; }
  .card.flush table.responsive-sm td:first-child, .card.flush table.responsive-sm td:last-child { padding-left: 10px; padding-right: 10px; }
  .table-scroll { max-height: 70vh; }
}
@media (max-width: 420px) {
  .grid.dials { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.tiles > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .grid.kpis:has(> :nth-child(3):last-child) { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.kpis:has(> :nth-child(3):last-child) > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 420px) {
  .grid.dials { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
  .grid.dials > .dial:only-child svg { max-width: 260px; margin-inline: auto; display: block; }
  .kpi-value.small { white-space: normal; font-size: .95rem; }
}
