:root {
  /* Thermly.io brand (brand/Thermly.svg): cyan #01c3d9 + slate #425464 */
  --frost: #f3f7f9;
  --paper: #ffffff;
  --ice: #e0f7fa;
  --cyan: #01c3d9;         /* brand accent: marks and fills only, too light for text on white */
  --cyan-ink: #007c8c;     /* cyan dark enough for text/links on white (4.9:1) */
  --slate: #425464;        /* brand slate: ink + header */
  --slate-2: #5f6f7c;
  --muted: #6b7a86;
  --rule: #dce4e9;
  --ok: #15803d;
  --warn: #e9b308;
  --alert: #f07818;
  --crit: #cf213b;
  --stale: #98a9b4;
  --display: "Outfit", "Avenir Next", system-ui, sans-serif;
  --text: "Outfit", "Avenir Next", system-ui, sans-serif;
  --rail-w: 400px;
  --top-h: 60px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--frost);
  color: var(--slate);
  font: 15px/1.45 var(--text);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

/* ---------- top bar ---------- */
.top {
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 20px 0;
  display: flex; align-items: center; gap: 18px;
  background: var(--header-bg, var(--slate));
  border-bottom: 3px solid var(--cyan);
}
.wordmark { display: flex; align-items: center; }
.wordmark img { height: 32px; width: auto; display: block; }
.wordmark a { display: flex; align-items: center; border-radius: 4px; }
/* white-label: the customer's own (reversed) logo sits where the Thermly wordmark was */
[data-white-label] .wordmark img { height: 34px; max-width: 220px; object-fit: contain; }
.tagline { margin: 0; padding-left: 18px; border-left: 1px solid rgba(255, 255, 255, .3); font-weight: 500; color: #fff; }
.top-tools { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.updated { font-size: 13px; color: #fff; opacity: .8; min-width: 7em; text-align: right; }
.units { display: inline-flex; background: rgba(255, 255, 255, .12); border-radius: 8px; padding: 2px; }
.units button { border: 0; background: none; color: #fff; padding: 4px 10px; border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 14px; }
.units button[aria-pressed="true"] { background: var(--cyan); color: var(--on-accent, var(--slate)); }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  height: calc(100% - var(--top-h) - env(safe-area-inset-top, 0px));
}
.rail { background: var(--paper); border-right: 1px solid var(--rule); overflow-y: auto; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #eceff1; }

/* ---------- sensor list ---------- */
.summary { padding: 22px 22px 16px; border-bottom: 1px solid var(--rule); }
.summary h1 { margin: 0 0 6px; font: 700 26px/1.12 var(--display); letter-spacing: -0.02em; }
.summary p { margin: 0; color: var(--slate-2); }
.filters { display: flex; gap: 6px; padding: 12px 22px; border-bottom: 1px solid var(--rule); }
.chip {
  border: 1px solid var(--rule); background: var(--paper); border-radius: 999px;
  padding: 4px 12px; font-size: 14px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--slate); border-color: var(--slate); color: #fff; }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 14px; align-items: center;
  width: 100%; padding: 14px 22px 14px 0; border: 0; border-bottom: 1px solid var(--rule);
  background: none; text-align: left; cursor: pointer;
}
.row:hover { background: var(--frost); }
.row .bar { align-self: stretch; background: var(--c); border-radius: 0 3px 3px 0; }
.row .name { font-weight: 600; display: block; }
.row .sub { font-size: 13px; color: var(--muted); display: block; }
.row .reading { text-align: right; }
.row .temp { font: 600 24px/1 var(--display); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.row .state { display: block; font-size: 13px; color: var(--slate-2); margin-top: 3px; }
.row.hidden-row .name::after { content: "Hidden"; margin-left: 8px; font-size: 12px; font-weight: 500; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 0 5px; }
.empty { padding: 28px 22px; color: var(--slate-2); }
.empty strong { display: block; color: var(--slate); font-size: 17px; margin-bottom: 4px; }

/* ---------- status badge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--c); color: var(--on, #fff);
}
.badge svg { width: 14px; height: 14px; }

/* ---------- detail ---------- */
.detail { padding: 16px 22px 28px; }
.back { border: 0; background: none; padding: 4px 0; color: var(--cyan-ink); font-weight: 600; cursor: pointer; }
.back:hover { text-decoration: underline; }
.detail h1 { margin: 10px 0 2px; font: 700 28px/1.1 var(--display); letter-spacing: -0.02em; }
.detail .where { margin: 0; color: var(--slate-2); }
.readout { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 20px 0 6px; flex-wrap: wrap; }
.readout .big { font: 600 64px/.9 var(--display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.readout .big small { font-size: 26px; letter-spacing: 0; margin-left: 2px; color: var(--slate-2); }
.target { font-size: 14px; color: var(--slate-2); margin: 0 0 18px; }
.target b { color: var(--slate); font-weight: 600; }

.section-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 22px 0 8px; }
.section-h h2 { margin: 0; font: 600 17px/1.2 var(--text); }
.tabs { display: inline-flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.tabs button { border: 0; background: var(--paper); padding: 4px 10px; font-size: 13px; cursor: pointer; }
.tabs button + button { border-left: 1px solid var(--rule); }
.tabs button[aria-pressed="true"] { background: var(--ice); font-weight: 600; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: #e7eff4; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-family: var(--text); }
.chart .band { fill: var(--ok); opacity: .1; }
.chart .band-edge { stroke: var(--ok); stroke-dasharray: 4 3; opacity: .7; }
.chart .band-label { fill: var(--ok); font-size: 11px; font-weight: 600; }
.chart .env { fill: var(--cyan); opacity: .25; }
.chart .line { fill: none; stroke: var(--slate); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .hover-line { stroke: var(--slate-2); stroke-width: 1; }
.chart .hover-dot { stroke: #fff; stroke-width: 2; }
.chart .nodata { fill: var(--muted); font-size: 13px; }
.tip {
  position: absolute; pointer-events: none; background: var(--slate); color: #fff;
  padding: 6px 9px; border-radius: 6px; font-size: 13px; line-height: 1.35; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}
.tip b { font-size: 15px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; margin-top: 14px; }
.stats div { background: var(--paper); padding: 10px 12px; }
.stats dt { font-size: 12px; color: var(--muted); }
.stats dd { margin: 2px 0 0; font: 700 19px/1.1 var(--display); font-variant-numeric: tabular-nums; }
.note { font-size: 13px; color: var(--muted); margin: 10px 0 0; }

/* ---------- admin form ---------- */
.admin-box { margin-top: 26px; padding-top: 18px; border-top: 2px solid var(--ice); }
.field { display: grid; gap: 4px; margin: 0 0 12px; }
.field label, .field .lbl { font-size: 13px; font-weight: 600; }
.field input, .field select {
  font: inherit; padding: 7px 9px; border: 1px solid #c5d1d9; border-radius: 7px; background: #fff; color: var(--slate);
}
.field .hint { font-size: 12px; color: var(--muted); }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.btn { border: 1px solid #c5d1d9; background: #fff; border-radius: 7px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--slate); border-color: var(--slate); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 18px; height: 18px; accent-color: var(--slate); }
.kv { font-size: 13px; color: var(--slate-2); margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.profiles-edit { margin: 0; padding: 0; list-style: none; }
.profiles-edit li { display: grid; grid-template-columns: 1fr 64px 64px; gap: 6px; align-items: end; margin-bottom: 8px; }
.profiles-edit input { width: 100%; }

/* ---------- map markers ---------- */
.pin-host { background: none; border: 0; }
.pin {
  position: absolute; left: 0; top: 0;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--c); color: var(--on, #fff);
  font: 700 14px/1.2 var(--display); font-variant-numeric: tabular-nums;
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(66, 84, 100, .4);
  cursor: pointer;
}
.pin.fixed { transform: translate(-50%, calc(-100% - 7px)); }
.pin.fixed::after {
  content: ""; position: absolute; left: 50%; bottom: -9px; transform: translateX(-50%);
  border: 6px solid transparent; border-top: 7px solid #fff;
}
.pin.fixed::before {
  content: ""; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 4px solid transparent; border-top: 5px solid var(--c); z-index: 1;
}
.pin.moving { transform: translate(-50%, -50%); }
.pin.moving svg { width: 11px; height: 11px; fill: currentColor; }
.pin.selected { outline: 3px solid var(--slate); outline-offset: 1px; z-index: 5; }
.pin.admin-drag { cursor: grab; }
.ghost { width: 14px; height: 14px; border-radius: 50%; border: 2px dashed var(--slate); background: rgba(255,255,255,.6); transform: translate(-50%, -50%); position: absolute; }

.legend {
  position: absolute; left: 12px; bottom: 22px; z-index: 500;
  background: rgba(255, 255, 255, .94); border: 1px solid var(--rule); border-radius: 10px;
  padding: 8px 12px; font-size: 12.5px; color: var(--slate-2); display: grid; gap: 5px; max-width: calc(100% - 24px);
}
.legend-scale, .legend-kind { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; background: var(--c); margin-left: 6px; }
.legend .sw:first-child { margin-left: 0; }
.legend .k { width: 16px; height: 11px; border-radius: 999px; background: var(--slate); margin-left: 6px; position: relative; }
.legend .k:first-child { margin-left: 0; }
.legend .k-fixed::after { content: ""; position: absolute; left: 50%; bottom: -4px; transform: translateX(-50%); border: 3px solid transparent; border-top: 4px solid var(--slate); }
.legend .k-moving { background: none; border: 2px solid var(--slate); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--slate); color: #fff; padding: 10px 14px; border-radius: 10px; z-index: 1000;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 4px 16px rgba(66, 84, 100, .3); max-width: calc(100% - 32px);
}
.toast button { background: none; border: 0; color: var(--cyan); font-weight: 600; cursor: pointer; padding: 0; }

.leaflet-container { font-family: var(--text); }

/* ---------- small screens ---------- */
@media (max-width: 820px) {
  :root { --top-h: 54px; }
  .tagline { display: none; }
  .top { gap: 10px; }
  .wordmark img { height: 24px; }
  .cobrand { gap: 6px; min-width: 0; }
  .cobrand-x { display: none; }
  .cobrand-logo { height: 30px; padding: 3px 6px; }
  .cobrand-logo img { max-height: 22px; max-width: 88px; }
  .cobrand-for { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
  .units button { padding: 4px 8px; }
  .top { padding-left: 16px; padding-right: 16px; }
  .layout { display: flex; flex-direction: column-reverse; height: auto; }
  .mapwrap { height: 52vh; }
  .rail { border-right: 0; overflow: visible; }
  .summary, .filters, .detail { padding-left: 16px; padding-right: 16px; }
  .row { padding-right: 16px; }
  .legend-kind { display: none; }
  .legend { bottom: 40px; left: 8px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .updated { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- co-branding (demo links) ---------- */
.cobrand { display: flex; align-items: center; gap: 12px; }
.cobrand-x { color: rgba(255, 255, 255, .6); font-size: 18px; }
.cobrand-logo { background: #fff; border-radius: 6px; padding: 4px 8px; display: flex; align-items: center; height: 36px; }
.cobrand-logo img { max-height: 28px; max-width: 140px; display: block; }
.cobrand-for { color: #fff; font-weight: 500; font-size: 16px; }
.top { border-bottom-color: var(--cyan); }
.link-message { margin: 0 0 12px !important; padding: 10px 12px; background: var(--ice); border-radius: 8px; color: var(--slate) !important; }
.summary.message { padding-top: 40px; }

/* ---------- admin chrome ---------- */
.admin-nav { display: flex; gap: 2px; padding: 10px 16px 0; border-bottom: 1px solid var(--rule); position: sticky; top: 0; background: var(--paper); z-index: 2; }
.admin-nav button, .subtabs button {
  border: 0; background: none; padding: 8px 12px; cursor: pointer; font-weight: 600; color: var(--slate-2);
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.admin-nav button[aria-selected="true"], .subtabs button[aria-selected="true"] { color: var(--slate); border-bottom-color: var(--cyan); }
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin: 16px 0 6px; }
.urlbox { background: var(--frost); border: 1px solid var(--rule); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.urlbox code { font: 500 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; color: var(--slate); }
.status-chip { display: inline-block; font-size: 12.5px; font-weight: 600; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
.status-chip.live { background: #dcf3e4; color: #166534; }
.status-chip.paused { background: #eceff1; color: var(--slate-2); }
.btn.danger { color: var(--crit); border-color: #f0c2c9; }
a.btn { text-decoration: none; color: var(--slate); display: inline-block; }
.file-btn { display: inline-block; }
.confirm { margin-top: 10px; padding: 12px; border-radius: 8px; background: #fff7ed; border: 1px solid #fed7aa; }
.confirm p { margin: 0 0 8px; }
.field textarea { font: inherit; padding: 7px 9px; border: 1px solid #c5d1d9; border-radius: 7px; resize: vertical; color: var(--slate); }
.field label { display: grid; gap: 4px; }
.accent-row { display: flex; gap: 8px; align-items: center; }
.accent-row input[type=color] { width: 48px; height: 36px; padding: 2px; border: 1px solid #c5d1d9; border-radius: 7px; background: #fff; }
.brand-preview {
  display: flex; align-items: center; gap: 10px; background: var(--slate); border-bottom: 3px solid var(--pa);
  border-radius: 8px; padding: 10px 12px; margin: 0 0 14px;
}
.brand-preview .cobrand-logo { height: 28px; padding: 3px 6px; }
.brand-preview .cobrand-logo img { max-height: 22px; }
.brand-preview .cobrand-for { font-size: 14px; }
.create-form { border-bottom: 1px solid var(--rule); }
.assign-list .row[aria-expanded="true"], .range-item .row[aria-expanded="true"] { background: var(--frost); }
.assign-form, .range-form { padding: 14px 22px 18px; background: var(--frost); border-bottom: 1px solid var(--rule); }
.detail .range-form { padding: 0 0 18px; background: none; }
.linkish { border: 0; background: none; padding: 2px 0; color: var(--cyan-ink); font-weight: 600; cursor: pointer; text-align: left; }
.linkish:hover { text-decoration: underline; }
ul.plain { margin: 0; padding-left: 18px; }
ul.plain li { margin: 3px 0; }

/* ---------- range editor ---------- */
.thr { margin: 4px 0 12px; }
.thr-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin: 4px 0 10px; }
.thr-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; align-items: end; }
.thr-grid .field { margin: 0; }
.thr-grid .lbl { font-size: 12px; font-weight: 600; }
.thr-grid input { width: 100%; }
.thr-error { color: var(--crit); font-size: 13px; margin: 6px 0 0; }
.thr .hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

/* ---------- analytics ---------- */
.daily svg { display: block; width: 100%; height: auto; }
.axis-t { fill: var(--muted); font-size: 11px; font-family: var(--text); }
.interest { list-style: none; margin: 0; padding: 0; }
.interest li { display: grid; grid-template-columns: minmax(0, 1.2fr) 1fr auto; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }
.interest li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ibar { height: 8px; background: var(--frost); border-radius: 4px; overflow: hidden; }
.ibar span { display: block; height: 100%; background: var(--cyan); border-radius: 4px; }
.table-wrap { overflow-x: auto; }
table.visits { width: 100%; border-collapse: collapse; font-size: 13px; }
table.visits th { text-align: left; font-weight: 600; color: var(--muted); padding: 6px 8px 6px 0; border-bottom: 1px solid var(--rule); }
table.visits td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.muted { color: var(--muted); font-size: 12px; }
.stats:has(> div:nth-child(3):last-child) { grid-template-columns: repeat(3, 1fr); }
