/* Glass theme: frosted panels over a soft gradient backdrop. Dark by default look, light follows the OS. */
:root {
  color-scheme: light dark; /* native date pickers, menus and scrollbars follow the theme */
  --bg: #eef2f8; --panel: #ffffff; --text: #111827; --muted: #64748b; --line: rgba(15, 23, 42, .08);
  --accent: #4f6ef7; --accent2: #06b6d4; --green: #16a34a; --amber: #d97706; --red: #dc2626; --flat: #64748b;
  --glass: rgba(255, 255, 255, .55); --glass2: rgba(255, 255, 255, .45); --glass-border: rgba(255, 255, 255, .85);
  --hi: rgba(255, 255, 255, .9); --shadow: 0 10px 30px -12px rgba(30, 41, 80, .25);
  --blob1: rgba(52, 211, 153, .30); --blob2: rgba(99, 102, 241, .28); --blob3: rgba(236, 72, 153, .16);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #070a12; --panel: #121826; --text: #e8ecf3; --muted: #8b95a8; --line: rgba(255, 255, 255, .07);
    --accent: #6d8bff; --accent2: #22d3ee; --green: #4ade80; --amber: #fbbf24; --red: #f87171; --flat: #94a3b8;
    --glass: rgba(255, 255, 255, .045); --glass2: rgba(255, 255, 255, .035); --glass-border: rgba(255, 255, 255, .09);
    --hi: rgba(255, 255, 255, .10); --shadow: 0 18px 40px -18px rgba(0, 0, 0, .7);
    --blob1: rgba(16, 185, 129, .22); --blob2: rgba(79, 70, 229, .26); --blob3: rgba(168, 85, 247, .14);
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0; min-height: 100vh; color: var(--text); background: transparent;
  font: 14px/1.45 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
/* The backdrop is its own fixed layer: background-attachment: fixed doesn't work properly on iOS */
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 600px at 8% -10%, var(--blob1), transparent 60%),
    radial-gradient(800px 600px at 100% 0%, var(--blob2), transparent 60%),
    radial-gradient(900px 700px at 50% 110%, var(--blob3), transparent 60%),
    var(--bg);
}
button, a, select, input { touch-action: manipulation; } /* no double-tap zoom on controls */

/* Frosted surface shared by the header, panels and cards */
header, .panel, .card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--hi), var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%);
}

/* The header: no border, shadow or blur, so no light line along its bottom edge */
header {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center;
  padding: 12px 24px; border: 0; border-radius: 0; box-shadow: none;
  background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none;
}
h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: -.01em;
  background: linear-gradient(90deg, var(--green), var(--accent2) 55%, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
h2 { font-size: 12px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; }
h3 { font-size: 13px; margin: 0 0 6px; }

nav { display: flex; gap: 2px; flex-wrap: wrap; padding: 3px; border-radius: 999px; background: var(--glass2); border: 1px solid var(--line); }
nav button { border: 0; background: transparent; color: var(--muted); padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 500; transition: color .15s, background .15s; }
nav button svg { display: none; }
nav button:hover { color: var(--text); }
nav button.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 4px 14px -4px var(--accent); }
.btn, .controls button { border: 1px solid var(--glass-border); background: var(--glass2); color: var(--text); padding: 6px 14px; border-radius: 10px; cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover, .controls button:hover { border-color: var(--accent); }

.stamp { margin-left: auto; color: var(--muted); font-size: 12px; padding: 5px 12px; border-radius: 999px; background: var(--glass2); border: 1px solid var(--line); }
.stamp::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 8px var(--green); margin-right: 8px; vertical-align: 1px; }
.stamp.stale::before { background: var(--red); box-shadow: 0 0 8px var(--red); }

main { padding: 20px 24px 40px; max-width: 1240px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; animation: rise .25s ease-out; }
@keyframes rise { from { transform: translateY(4px); } to { transform: none; } }
.panel { border-radius: 18px; padding: 18px 20px; margin-bottom: 18px; overflow-x: auto; }

/* Summary cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 18px; }
.card { border-radius: 18px; padding: 16px 18px; position: relative; }
.card .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.card .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
@media (min-width: 1000px) { .cards { grid-template-columns: 1fr 1.4fr 1fr; } }
/* Total / predicted cost: the middle card, with a gradient edge and a soft green glow */
.card.feature { text-align: center; padding: 18px 20px; border-color: transparent;
  box-shadow: inset 0 1px 0 var(--hi), 0 20px 50px -20px rgba(34, 197, 94, .45); }
.card.feature::before { content: ""; position: absolute; inset: 0; border-radius: inherit; padding: 1.5px; pointer-events: none;
  background: linear-gradient(135deg, #86efac, #22c55e 40%, #14b8a6 70%, #0e7490);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0); }
.card.feature .label { text-transform: uppercase; letter-spacing: .1em; font-weight: 600; font-size: 11px; }
.card.feature .value { font-size: 38px; line-height: 1.1;
  background: linear-gradient(135deg, var(--green), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.card.feature .predicted { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); }
.card.feature .predicted b { font-size: 20px; color: var(--text); margin-left: 6px; }

/* Top 5 */
.top5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.top-item { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-width: 0; background: var(--glass2); position: relative; overflow: hidden; }
.top-item::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2)); opacity: .7; }
.top-item:first-child::after { background: linear-gradient(90deg, var(--green), var(--accent2)); opacity: 1; }
.top-item .rank { color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .05em; }
.top-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.top-item .cost { font-size: 22px; font-weight: 700; margin: 4px 0 2px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
@media (max-width: 700px) { .top5 { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); } }

/* Right now: one card per room */
.status { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: 12px; }
.room { border: 1px solid var(--line); border-radius: 14px; padding: 4px 0 8px; background: var(--glass2); }
.room.aside-room { opacity: .7; }
.room-head { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 16px;
  font-weight: 600; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.room-head .muted { font-weight: 400; font-size: 12px; } .room-head b { color: var(--text); }
.dev.on { color: var(--text); }
.dev { display: grid; grid-template-columns: 10px 1fr auto 64px; gap: 10px; align-items: center; padding: 6px 16px; }
.dev .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); opacity: .4; }
.dev.on .dot { background: var(--green); opacity: 1; box-shadow: 0 0 10px var(--green); }
.dev.offline .dot { background: var(--red); opacity: 1; }
.dev .dname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .state { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.dev.on .state { color: var(--green); } .dev.offline .state { color: var(--red); }
.dev .power { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.dev.off .dname, .dev.off .power { color: var(--muted); }

/* Tables and other tabs */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; } .grid2.tight { gap: 8px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; } td.num, th.num { text-align: right; }
tbody tr:hover td { background: var(--glass2); }
tr.room td { background: var(--glass2); font-weight: 600; }
.muted { color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); background: var(--glass2); }
.on { color: var(--green); } .off { color: var(--muted); } .bad { color: var(--red); }
.bar { display: flex; height: 22px; border-radius: 8px; overflow: hidden; margin: 6px 0 4px; background: var(--line); }
.bar span { display: block; height: 100%; }
.legend span { margin-right: 12px; font-size: 12px; } .legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
input, select { font: inherit; padding: 5px 8px; border-radius: 10px; border: 1px solid var(--glass-border); background: var(--glass2); color: var(--text); }
select option { background: var(--panel); }

/* Main chart */
.hero-head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.hero-head h2 { margin: 0; }
.hero-summary { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 12px 0 8px; }
.hero-summary .k { color: var(--muted); font-size: 12px; } .hero-summary .v { font-size: 18px; font-weight: 650; }
.hero-chart { position: relative; height: 360px; margin-top: 12px; }
.seg { position: relative; display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--glass2); }
.seg button { border: 0; background: transparent; color: var(--text); padding: 5px 12px; font: inherit; cursor: pointer; }
.seg button.active { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; }
.small { font-size: 12px; margin: 8px 0 0; }
@media (max-width: 600px) { .hero-chart { height: 260px; } }
.logs { font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 70vh; overflow: auto; white-space: pre-wrap; }

/* Links into a device's page */
a.top-item, a.dev { color: inherit; text-decoration: none; transition: background .15s, border-color .15s, transform .15s; }
@media (hover: hover) { a.top-item:hover { border-color: var(--accent); transform: translateY(-2px); } }
a.dev:hover { background: var(--glass2); }
a.dlink { color: var(--text); font-weight: 600; text-decoration: none; border-bottom: 1px dashed var(--muted); }
a.dlink:hover { color: var(--accent); border-color: var(--accent); }

/* One device */
.dev-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; overflow: visible; }
.dev-head .back { color: var(--muted); text-decoration: none; font-weight: 500; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--glass2); }
.dev-head .back:hover { color: var(--text); border-color: var(--accent); }
.dev-title { flex: 1; min-width: 200px; }
.dev-name { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.dev-head .seg { margin-left: auto; }
.state-pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 14px; border-radius: 999px; font-weight: 600;
  border: 1px solid var(--line); background: var(--glass2); color: var(--muted); }
.state-pill .dot, .run-now .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.state-pill.on { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.state-pill.on .dot, .run-now .dot { background: var(--green); box-shadow: 0 0 10px var(--green); }
.state-pill.offline { color: var(--red); } .state-pill.offline .dot { background: var(--red); }
@media (min-width: 1000px) { .cards.six { grid-template-columns: repeat(6, 1fr); } }
.cards.six .card .value { font-size: 22px; }
.chart-box { position: relative; height: 300px; } .chart-box.sm { height: 220px; }
.run-now { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--green); margin: 0 0 10px; }
#devRuns table { max-width: 560px; }

/* Devices: quick ranges and the usage list */
.seg button:hover:not(.active) { color: var(--text); background: var(--glass); }
#devRanges { margin-right: 6px; }
@media (min-width: 700px) { .cards.three { grid-template-columns: repeat(3, 1fr); } }
.dtable { overflow: visible; }
.dtable-head, .drow { display: grid; grid-template-columns: minmax(160px, 1.3fr) minmax(140px, 2fr) 100px 90px; gap: 16px; align-items: center; }
.dtable-head { padding: 0 14px 10px; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.droom { border: 1px solid var(--line); border-radius: 14px; background: var(--glass2); margin-bottom: 12px; overflow: hidden; }
.droom-head { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; border-bottom: 1px solid var(--line); }
.drow { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.drow:last-child { border-bottom: 0; }
.drow:hover { background: var(--glass); }
.drow .small { margin: 2px 0 0; }
.drow.none { grid-template-columns: minmax(160px, 1.3fr) 1fr; }
.drow .why { font-size: 13px; }
.drow .num { text-align: right; font-variant-numeric: tabular-nums; }
.drow .cost { font-weight: 700; }
.usage { display: flex; align-items: center; gap: 10px; }
.ubar { flex: 1; display: flex; gap: 2px; height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.ubar span { display: block; height: 100%; border-radius: 999px; }
.ubar .fill { background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.usage .small { width: 34px; text-align: right; margin: 0; }
.dtable .legend { margin-top: 4px; }
@media (max-width: 700px) {
  .dtable-head { display: none; }
  .drow { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .drow .usage { grid-column: 1 / -1; order: 3; } .drow .num:not(.cost) { display: none; }
}

/* Temperature */
.sensors { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; margin-bottom: 18px; }
.card.sensor { padding: 18px 20px; }
.sensor-head { display: flex; align-items: center; gap: 8px; }
.sensor-head .muted { margin-left: auto; font-size: 12px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--c); }
.sensor-now { display: flex; align-items: baseline; gap: 16px; margin: 10px 0 2px; }
.sensor-now .t { font-size: 40px; font-weight: 700; letter-spacing: -.03em; line-height: 1;
  background: linear-gradient(135deg, var(--text), var(--c)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sensor-now .h { font-size: 18px; font-weight: 600; } .sensor-now small { color: var(--muted); font-weight: 400; font-size: 12px; }
.trend { font-size: 12px; color: var(--muted); } .trend.up { color: var(--amber); } .trend.down { color: var(--accent2); }
.sensor-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 10px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.sensor-stats div { display: flex; flex-direction: column; gap: 2px; } .sensor-stats .muted { font-size: 11px; }
#tempNote { margin: 0; }

/* Chart tooltip */
.tip { position: fixed; z-index: 40; left: 0; top: 0; min-width: 190px; max-width: min(300px, calc(100vw - 16px)); padding: 12px 14px; border-radius: 14px;
  pointer-events: none; visibility: hidden; font-size: 12.5px; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--hi), 0 20px 50px -16px rgba(0, 0, 0, .55);
  -webkit-backdrop-filter: blur(16px) saturate(150%); backdrop-filter: blur(16px) saturate(150%); }
.tip.show { visibility: visible; }
.tip-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; } .tip-head b { font-size: 14px; letter-spacing: -.01em; }
.tip-head small { flex-basis: 100%; color: var(--muted); font-size: 11px; }
.tip-sec { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--line); }
.tip-row { display: grid; grid-template-columns: 14px 1fr auto; gap: 8px; align-items: center; padding: 2px 0; }
.tip-row span { color: var(--muted); } .tip-row b { font-weight: 600; } .tip-row.strong span, .tip-row.strong b { color: var(--text); font-weight: 700; }
.tip-row small { display: block; font-size: 11px; opacity: .85; }
.tip-sec.plain .tip-row { grid-template-columns: 1fr auto; } .tip-sec.plain .sw { display: none; }
.sw { display: block; width: 12px; } .sw.fill { height: 12px; border-radius: 4px; }
.sw.line { width: 14px; height: 0; border-top: 2.5px solid; border-radius: 2px; } .sw.line.dashed { border-top-style: dashed; border-top-width: 2px; border-radius: 0; }

/* Gear menu */
.gear { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; margin-left: -12px; cursor: pointer;
  border-radius: 50%; border: 1px solid var(--line); background: var(--glass2); color: var(--muted); }
.gear svg { width: 19px; height: 19px; transition: transform .25s; }
.gear:hover, .gear.active, .menu-open .gear { color: var(--text); border-color: var(--accent); } .menu-open .gear svg { transform: rotate(60deg); }
.menu-back { position: fixed; inset: 0; z-index: 25; visibility: hidden; opacity: 0; transition: opacity .2s, visibility .2s; }
.menu { position: absolute; z-index: 30; top: calc(100% - 4px); right: 24px; width: 270px; padding: 8px; border-radius: 16px;
  background: var(--panel); border: 1px solid var(--glass-border); box-shadow: 0 24px 60px -16px rgba(0, 0, 0, .6);
  visibility: hidden; opacity: 0; transform: translateY(-6px); transition: transform .22s ease-out, opacity .15s, visibility .22s; }
.menu-open .menu, .menu-open .menu-back { visibility: visible; opacity: 1; } .menu-open .menu { transform: none; }
.menu button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 12px; border: 0; border-radius: 11px; background: none;
  color: var(--text); font: inherit; font-weight: 600; text-align: left; cursor: pointer; }
.menu button:hover, .menu button.active { background: var(--line); } .menu button.active svg { color: var(--accent); }
.menu svg { flex: none; width: 21px; height: 21px; color: var(--muted); }
.menu small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

/* Settings */
.tariffs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tariff { border: 1px solid var(--line); border-radius: 14px; background: var(--glass2); padding: 12px 16px; }
.tariff-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.tariffs .wide { grid-column: 1 / -1; margin: 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.kv i { display: inline-block; width: 8px; height: 8px; border-radius: 3px; margin-right: 8px; }
.grid2 > .panel > div > .kv:first-child { border-top: 0; }
.tariff .pill { white-space: nowrap; } @media (max-width: 700px) { .tariffs { grid-template-columns: 1fr; } }
.pill.live { color: var(--green); border-color: var(--green); }

/* ---- Phones (and the notch, in landscape) -------------------------------------------------- */
header { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
main { padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }

@media (max-width: 700px) {
  header { flex-wrap: nowrap; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; }
  .stamp { white-space: nowrap; } .stamp .long { display: none; }
  main { padding: 10px 14px calc(88px + env(safe-area-inset-bottom)); }
  .panel, .card { -webkit-backdrop-filter: none; backdrop-filter: none; }  /* many blurred layers make scrolling stutter */
  .panel { padding: 14px; border-radius: 16px; margin-bottom: 14px; }

  /* tabs: a full-width bar along the bottom, in thumb reach; the current one gets a tinted pill behind its icon */
  nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; flex-wrap: nowrap; gap: 0; border: 0; border-radius: 0;
    padding: 8px max(10px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    border-top: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 86%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(160%); backdrop-filter: blur(20px) saturate(160%); }
  nav button, nav button.active { flex: 1 1 0; min-width: 0; min-height: 52px; padding: 0; font-size: 11px; background: none; box-shadow: none;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
  nav button svg { display: block; width: 60px; height: 30px; padding: 4px 0; border-radius: 999px; transition: background .2s; }
  nav button.active { color: var(--text); font-weight: 600; }
  nav button.active svg { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent2)); box-shadow: 0 4px 14px -5px var(--accent); }

  .gear { width: 42px; height: 42px; }
  .menu { position: fixed; top: auto; right: 0; left: 0; bottom: 0; width: auto; border-radius: 22px 22px 0 0; border-width: 1px 0 0;
    padding: 22px 14px calc(18px + env(safe-area-inset-bottom)); transform: translateY(100%); opacity: 1; }
  .menu::before { content: ""; position: absolute; top: 9px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 2px; background: var(--muted); opacity: .4; }
  .menu button { padding: 14px; min-height: 60px; font-size: 16px; }
  .menu-back { background: rgba(0, 0, 0, .5); }

  /* cards: the bill first and full width, the rest in pairs */
  .cards, .cards.three, .cards.six { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .card { padding: 13px 14px; border-radius: 16px; }
  .card .value { font-size: 22px; }
  .card.feature { grid-column: 1 / -1; order: -1; } .card.feature .value { font-size: 36px; }
  .cards.three .card:last-child { grid-column: 1 / -1; }

  .hero-chart { height: 280px; } .chart-box { height: 250px; } .chart-box.sm { height: 200px; }
  .grid2 { gap: 0; }

  .top5 { grid-template-columns: 1fr; gap: 8px; }
  .top-item { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; column-gap: 8px; align-items: center; padding: 10px 14px; }
  .top-item .rank { grid-row: 1 / 3; } .top-item .name { grid-column: 2; margin: 0; }
  .top-item .small { grid-column: 2; grid-row: 2; margin: 0; } .top-item .cost { grid-column: 3; grid-row: 1 / 3; margin: 0; }
  .dev { padding-top: 10px; padding-bottom: 10px; }

  /* controls: finger-sized; 16px text, or iOS zooms in when a field is tapped */
  input, select { font-size: 16px; min-height: 42px; }
  .btn, .controls button { min-height: 42px; }
  .controls > label { flex: 1 1 130px; min-width: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
  .controls input[type="date"] { width: 100%; min-width: 0; -webkit-appearance: none; appearance: none; }
  .controls > button, .controls > .btn { flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center; }
  .seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; } .seg::-webkit-scrollbar { display: none; }
  .seg button, .controls .seg button { flex: 1 0 auto; min-height: 40px; padding: 5px 12px; white-space: nowrap; border: 0; border-radius: 0; }
  .controls .seg button:not(.active) { background: transparent; }
  #devRanges, #tempRange, .dev-head .seg { width: 100%; margin: 0; }

  .dev-head { gap: 10px 12px; } .dev-title { order: 1; flex: 1 1 100%; min-width: 0; } .dev-head .seg { order: 2; }
  .dev-head .state-pill { margin-left: auto; } .dev-head .back { padding: 9px 14px; }
  .sensors { gap: 10px; margin-bottom: 14px; }

  th, td { padding: 8px 6px; font-size: 13px; } th { font-size: 10px; letter-spacing: .02em; }
  #devTable th:last-child, #devTable td:last-child { display: none; }  /* Source */
  #devTable th { white-space: normal; }
  .panel > div { -webkit-overflow-scrolling: touch; }
  .logs { font-size: 11px; overflow-wrap: anywhere; }
}
/* phone on its side: keep the header from taking much of the short screen */
@media (max-height: 480px) and (min-width: 701px) { header { position: static; } .hero-chart, .chart-box { height: 240px; } }
@media (max-width: 350px) { .seg button, .controls .seg button { padding: 5px 9px; } }
