/* ==========================================================================
   Re-Link design system
   A calm "control surface" for reviving D-Link smart plugs. Dusk by default,
   daybreak under prefers-color-scheme: light. One signature: the current ring.
   ========================================================================== */

/* -- Fonts ----------------------------------------------------------------- */
@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/space-grotesk-500.ab4861869c91.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("/static/fonts/space-grotesk-700.f9e147a59a93.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Space Mono";
  src: url("/static/fonts/space-mono-400.049dfc5919c2.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Space Mono";
  src: url("/static/fonts/space-mono-700.e5e908997a45.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

/* -- Tokens: iOS light (default) ------------------------------------------ */
:root {
  --bg:           #F2F2F7;
  --bg-wash:      none;
  --surface:      #FFFFFF;
  --surface-2:    #F2F2F7;
  --surface-solid:#FFFFFF;

  --stroke:        rgba(60, 60, 67, 0.13);
  --stroke-strong: rgba(60, 60, 67, 0.29);

  --text:   #1C1C1E;
  --text-2: #636366;
  --text-3: #AEAEB2;

  --live-1:    #FF9500;
  --live-2:    #FFB340;
  --live-glow: rgba(255, 149, 0, 0.10);
  --idle:      #C7C7CC;
  --teal:      #007AFF;
  --danger:    #FF3B30;
  --ok:        #34C759;

  --r-tile: 18px;
  --r-card: 12px;
  --r-ctl:  10px;
  --r-pill: 999px;

  --shadow-tile: 0 2px 8px rgba(0, 0, 0, 0.07);
  --shadow-pop:  0 8px 30px rgba(0, 0, 0, 0.12);

  --blur:      blur(20px);
  --blur-card: none;

  --ease:   cubic-bezier(0.22, 0.61, 0.36, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: light;
}

/* -- Tokens: iOS dark override --------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #1C1C1E;
    --bg-wash:      none;
    --surface:      #2C2C2E;
    --surface-2:    #3A3A3C;
    --surface-solid:#2C2C2E;

    --stroke:        rgba(255, 255, 255, 0.08);
    --stroke-strong: rgba(255, 255, 255, 0.16);

    --text:   #FFFFFF;
    --text-2: #8E8E93;
    --text-3: #636366;

    --live-1:    #FF9F0A;
    --live-2:    #FFB340;
    --live-glow: rgba(255, 159, 10, 0.22);
    --idle:      #48484A;
    --teal:      #0A84FF;
    --danger:    #FF453A;
    --ok:        #30D158;

    --shadow-tile: 0 2px 12px rgba(0, 0, 0, 0.35);
    --shadow-pop:  0 8px 30px rgba(0, 0, 0, 0.55);

    --blur:      saturate(160%) blur(22px);
    --blur-card: saturate(160%) blur(22px);

    color-scheme: dark;
  }
}

/* -- Base ------------------------------------------------------------------ */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  background: var(--bg);
  background-image: var(--bg-wash);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, .display { font-family: ui-rounded, "Space Grotesk", -apple-system, "Segoe UI", sans-serif; }
.mono, .readout { font-family: "Space Mono", ui-monospace, "SF Mono", Menlo, monospace; }

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--live-1);
  outline-offset: 2px;
  border-radius: 6px;
}

.wrap { width: min(1120px, 100% - 40px); margin-inline: auto; }
@media (max-width: 560px) { .wrap { width: 100% - 32px; width: calc(100% - 32px); } }

.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.tnum { font-variant-numeric: tabular-nums; }

/* -- Top bar --------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(242, 242, 247, 0.85);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--stroke);
  padding-top: env(safe-area-inset-top);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(28, 28, 30, 0.88); }
}
.topbar__inner {
  display: flex; align-items: center; gap: 18px;
  height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: "Space Grotesk"; font-weight: 700; font-size: 18px; letter-spacing: -0.01em; white-space: nowrap; flex: none; }
.topbar__inner { gap: 12px; }
.nav a, .nav button.linklike { padding: 8px 12px; }
@media (max-width: 480px) { .nav a { padding: 8px 9px; font-size: 13px; } .brand span { font-size: 17px; } }
.brand__mark { width: 26px; height: 26px; flex: none; }
.brand__re { color: var(--live-1); }
.nav { display: flex; flex-wrap: nowrap; gap: 4px; margin-left: auto; align-items: center; }
.nav a, .nav button.linklike {
  padding: 8px 14px; border-radius: var(--r-pill); color: var(--text-2);
  background: none; border: 0; font-size: 14px; font-weight: 500;
  transition: color 0.18s, background 0.18s;
}
.nav a:hover, .nav button.linklike:hover { color: var(--text); background: var(--stroke); }
.nav a.is-active { color: var(--text); background: var(--stroke-strong); }
.iconbtn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: var(--r-pill); border: 1px solid var(--stroke); background: var(--surface);
  color: var(--text-2); transition: color 0.18s, border-color 0.18s;
}
.iconbtn:hover { color: var(--text); border-color: var(--stroke-strong); }

/* -- Page header ----------------------------------------------------------- */
.page { padding: 32px 0 80px; padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
.pagehead { margin: 12px 0 26px; }
.greeting { font-size: clamp(26px, 4vw, 38px); font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.summary {
  margin-top: 8px; color: var(--text-2); font-size: 15px;
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px;
}
.summary .draw { color: var(--text); }
.summary .draw b { font-family: "Space Mono"; font-weight: 700; color: var(--live-1); font-size: 17px; }
.summary .dot { color: var(--text-3); }

/* -- Tile grid ------------------------------------------------------------- */
.grid {
  display: grid; gap: 18px;
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
}

.tile {
  position: relative;
  display: flex; flex-direction: column;
  min-height: 196px; padding: 18px;
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur-card); backdrop-filter: var(--blur-card);
  border: 1px solid var(--stroke);
  border-radius: var(--r-tile);
  box-shadow: var(--shadow-tile);
  overflow: hidden;
  transition: transform 0.4s var(--ease), border-color 0.3s, background 0.4s;
  animation: tile-in 0.5s var(--ease);
}
.tile::before { /* state wash, fades in when energized */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 80% at 18% 0%, var(--live-glow), transparent 60%);
  opacity: 0; transition: opacity 0.5s var(--ease);
}
.tile.is-on::before { opacity: 1; }
.tile.is-on {
  background: rgba(255, 149, 0, 0.08);
  border-color: rgba(255, 149, 0, 0.30);
}
@media (prefers-color-scheme: dark) {
  .tile.is-on { background: var(--surface); }
}
.tile.is-offline { opacity: 0.72; }
.tile:hover { transform: translateY(-2px); }
@keyframes tile-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } }

.tile__top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.tile__link {
  position: absolute; inset: 0; z-index: 1; border-radius: inherit;
}
.tile__name {
  font-family: "Space Grotesk"; font-weight: 500; font-size: 17px; letter-spacing: -0.01em;
  color: var(--text); line-height: 1.25; max-width: 60%;
}

/* current ring (signature) */
.ring { position: relative; width: 62px; height: 62px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); display: block; }
.ring__track { stroke: var(--stroke-strong); fill: none; }
.ring__fill {
  fill: none; stroke: url(#ringgrad); stroke-linecap: round;
  transition: stroke-dashoffset 0.7s var(--ease);
}
.tile.is-off .ring__fill, .tile.is-unknown .ring__fill { stroke: var(--idle); filter: none; }
.tile.is-offline .ring__fill { stroke: var(--idle); filter: none; stroke-dasharray: 4 7 !important; }
.ring.is-breathing .ring__fill { animation: breathe 3.4s var(--ease) infinite; }
@keyframes breathe { 50% { opacity: 0.78; } }

.tile__readout {
  margin-top: auto; display: flex; align-items: baseline; gap: 4px;
  font-family: "Space Mono"; font-variant-numeric: tabular-nums;
}
.tile__watts { font-size: 30px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.tile__watts.is-dim { color: var(--text-2); }
.tile__unit { font-size: 14px; color: var(--text-2); }
.tile__sub { margin-top: 4px; font-size: 12.5px; color: var(--text-2); font-family: "Space Mono"; }
.tile__sub .sep { color: var(--text-3); margin: 0 6px; }

.tile__foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.statepill {
  font-size: 12px; font-weight: 600; letter-spacing: 0.02em; text-transform: lowercase;
  padding: 4px 10px; border-radius: var(--r-pill);
  background: var(--stroke); color: var(--text-2);
}
.tile.is-on .statepill { background: rgba(255, 149, 0, 0.14); color: var(--live-1); }
.tile.is-offline .statepill { background: rgba(232, 117, 95, 0.14); color: var(--danger); }

/* toggle switch */
.switch {
  --w: 52px; --h: 31px;
  position: relative; z-index: 2; width: var(--w); height: var(--h); flex: none;
  border-radius: var(--r-pill); border: 1px solid var(--stroke-strong);
  background: var(--stroke); transition: background 0.3s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: calc(var(--h) - 6px); height: calc(var(--h) - 6px);
  border-radius: 50%; background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,0.35);
  transition: transform 0.32s var(--spring);
}
.tile.is-on .switch { background: linear-gradient(180deg, var(--live-2), var(--live-1)); border-color: transparent; }
.tile.is-on .switch::after { transform: translateX(calc(var(--w) - var(--h))); }
.switch:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
.tile.is-offline .switch { pointer-events: none; cursor: not-allowed; opacity: 0.45; }
.switch.is-busy { opacity: 0.6; }
@media (prefers-color-scheme: light) {
  .switch { background: #E5E5EA; border-color: transparent; }
}

/* -- Empty state ----------------------------------------------------------- */
.empty {
  text-align: center; padding: 72px 24px;
  border: 1px dashed var(--stroke-strong); border-radius: var(--r-card);
  background: var(--surface);
}
.empty h2 { font-size: 22px; margin: 0 0 8px; }
.empty p { color: var(--text-2); margin: 0 auto 22px; max-width: 360px; }

/* -- Buttons --------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 18px; border-radius: var(--r-ctl); border: 1px solid var(--stroke-strong);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px;
  transition: transform 0.15s var(--ease), border-color 0.2s, background 0.2s;
}
.btn:hover { border-color: var(--text-3); }
.btn:active { transform: scale(0.97); }
.btn--primary {
  background: linear-gradient(180deg, var(--live-2), var(--live-1));
  color: #2a1605; border-color: transparent;
}
.btn--primary:hover { filter: brightness(1.04); border-color: transparent; }
.btn--primary:disabled { opacity: 0.45; cursor: not-allowed; filter: none; }
.btn--ghost { background: none; }
.btn--danger { color: var(--danger); border-color: rgba(232,117,95,0.4); background: none; }
.btn--danger:hover { background: rgba(232,117,95,0.1); }
.btn--sm { padding: 7px 12px; font-size: 13px; }

/* -- Cards / panels -------------------------------------------------------- */
.card {
  background: var(--surface);
  -webkit-backdrop-filter: var(--blur-card); backdrop-filter: var(--blur-card);
  border: 1px solid var(--stroke); border-radius: var(--r-card);
  padding: 20px; box-shadow: var(--shadow-tile);
}
.card__title {
  font-family: "Space Grotesk"; font-weight: 500; font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3);
  margin: 0 0 14px;
}
.stack { display: grid; gap: 18px; }
.cols { display: grid; gap: 18px; grid-template-columns: 1.6fr 1fr; align-items: start; }
@media (max-width: 860px) { .cols { grid-template-columns: 1fr; } }

/* -- Detail hero ----------------------------------------------------------- */
.hero {
  display: flex; gap: 26px; align-items: center; flex-wrap: wrap;
}
.hero__ring { width: 156px; height: 156px; position: relative; flex: none; }
.hero__ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.hero__center {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center;
}
.hero__watts { font-family: "Space Mono"; font-weight: 700; font-size: 34px; letter-spacing: -0.02em; line-height: 1; }
.hero__unit { font-family: "Space Mono"; font-size: 13px; color: var(--text-2); margin-top: 3px; }
.hero__meta { flex: 1; min-width: 220px; }
.hero__name { font-size: clamp(24px, 3vw, 32px); font-weight: 700; letter-spacing: -0.02em; margin: 0 0 6px; }
.hero__stats { display: flex; flex-wrap: wrap; gap: 22px; margin-top: 16px; }
.stat .k { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.stat .v { font-family: "Space Mono"; font-size: 19px; font-weight: 700; margin-top: 3px; }
.stat .v small { font-size: 12px; font-weight: 400; color: var(--text-2); }

/* -- Charts ---------------------------------------------------------------- */
.rangetabs { display: inline-flex; gap: 2px; padding: 3px; background: var(--stroke); border-radius: var(--r-pill); }
.rangetabs button {
  padding: 6px 16px; border: 0; background: none; color: var(--text-2);
  border-radius: var(--r-pill); font-size: 13px; font-weight: 600; transition: 0.18s;
}
.rangetabs button.is-active { background: var(--surface-2); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.2); }
@media (prefers-color-scheme: light) {
  .rangetabs { background: rgba(118, 118, 128, 0.12); }
  .rangetabs button.is-active {
    background: #FFFFFF;
    box-shadow: 0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.08);
  }
}
.chartbox { position: relative; height: 260px; margin-top: 8px; }
.chart-empty { display: grid; place-items: center; height: 100%; color: var(--text-3); font-size: 14px; }
.chart-nav { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.chart-nav__arrow {
  background: none; border: 1px solid var(--stroke-strong); border-radius: var(--r-ctl);
  color: var(--text-2); cursor: pointer; font-size: 18px; line-height: 1;
  padding: 2px 10px; transition: background 0.15s;
}
.chart-nav__arrow:hover:not(:disabled) { background: var(--stroke); color: var(--text); }
.chart-nav__arrow:disabled { opacity: 0.3; cursor: default; }
.chart-nav__label { font-size: 13px; color: var(--text-2); min-width: 90px; text-align: center; font-family: 'Space Mono', monospace; }

/* -- Tables / lists -------------------------------------------------------- */
.deflist { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; font-size: 14px; }
.deflist dt { color: var(--text-3); }
.deflist dd { margin: 0; font-family: "Space Mono"; font-size: 13.5px; word-break: break-word; }

.rows { display: grid; gap: 2px; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
}
.rows .row { border-bottom: 1px solid var(--stroke); }
.rows .row:last-child { border-bottom: 0; }
.row__main { flex: 1; min-width: 0; }
.row__title { font-weight: 600; }
.row__sub { font-size: 13px; color: var(--text-2); }
.row__time { font-family: "Space Mono"; font-size: 12.5px; color: var(--text-3); white-space: nowrap; }

.evkind { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-3); }
.evkind--control { background: var(--live-1); }
.evkind--automation { background: var(--teal); }
.evkind--error { background: var(--danger); }
.evkind--info { background: var(--idle); }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.daypill {
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 6px;
  background: var(--stroke); color: var(--text-2); font-family: "Space Mono";
}

/* -- Forms ----------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.field input[type=text], .field input[type=password], .field input[type=number],
.field input[type=time], .field input[type=email], .field select {
  width: 100%; padding: 12px 14px; font-size: 16px; /* >=16px: stops iOS focus-zoom */
  background: var(--surface-solid); color: var(--text);
  border: 1px solid var(--stroke-strong); border-radius: var(--r-ctl);
  transition: border-color 0.18s;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--live-1); }
.field .help { font-size: 12.5px; color: var(--text-3); margin-top: 6px; }
.field .errors { color: var(--danger); font-size: 13px; margin-top: 6px; list-style: none; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 10px; }
.checks label {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px;
  border: 1px solid var(--stroke-strong); border-radius: var(--r-ctl); font-size: 13px;
  font-family: "Space Mono"; cursor: pointer;
}
.checks input { accent-color: var(--live-1); }
.inline-check { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.formactions { display: flex; gap: 10px; align-items: center; margin-top: 22px; }

/* -- Auth ------------------------------------------------------------------ */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.authcard {
  width: min(400px, 100%); padding: 36px 32px;
  background: var(--surface); -webkit-backdrop-filter: var(--blur-card); backdrop-filter: var(--blur-card);
  border: 1px solid var(--stroke); border-radius: var(--r-card); box-shadow: var(--shadow-pop);
}
.authcard .brand { font-size: 24px; justify-content: center; margin-bottom: 6px; }
.auth__tag { text-align: center; color: var(--text-2); font-size: 14px; margin-bottom: 26px; }

/* -- Toasts / messages ----------------------------------------------------- */
.toasts { position: fixed; top: 74px; right: 20px; z-index: 100; display: grid; gap: 10px; width: min(340px, calc(100vw - 40px)); }
.toast {
  padding: 13px 16px; border-radius: var(--r-ctl); font-size: 14px;
  background: var(--surface-2); -webkit-backdrop-filter: var(--blur-card); backdrop-filter: var(--blur-card);
  border: 1px solid var(--stroke-strong); box-shadow: var(--shadow-pop);
  display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in 0.4s var(--spring) both;
}
.toast.is-leaving { animation: toast-out 0.3s var(--ease) forwards; }
.toast__bar { width: 3px; align-self: stretch; border-radius: 3px; background: var(--text-3); flex: none; }
.toast--success .toast__bar { background: var(--ok); }
.toast--warning .toast__bar { background: var(--live-1); }
.toast--error .toast__bar { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }

/* -- Utility --------------------------------------------------------------- */
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sectitle { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.sectitle h2 { font-size: 19px; margin: 0; letter-spacing: -0.01em; }
.backlink { color: var(--text-2); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.backlink:hover { color: var(--text); }
.tag-offline { color: var(--danger); }
hr.div { border: 0; border-top: 1px solid var(--stroke); margin: 18px 0; }

/* -- Collapsible cards ----------------------------------------------------- */
.collapsible__hd {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; padding: 0; cursor: pointer;
  color: inherit; text-align: left; margin-bottom: 14px;
}
.collapsible__hd .card__title { margin-bottom: 0; }
.collapsible.is-collapsed .collapsible__hd { margin-bottom: 0; }
.collapsible.is-collapsed .collapsible__bd { display: none; }
.collapsible__chevron { flex: none; color: var(--text-3); transition: transform 0.18s; }
.collapsible:not(.is-collapsed) .collapsible__chevron { transform: rotate(180deg); }

/* -- Bottom navigation (mobile only) --------------------------------------- */
.bottomnav { display: none; }
.bottomnav__form { display: contents; }

@media (max-width: 600px) {
  .topbar .nav { display: none; }

  .bottomnav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(242, 242, 247, 0.88);
    -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
    border-top: 1px solid var(--stroke);
  }

  .bottomnav__item {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 8px 4px; min-height: 56px;
    color: var(--text-3); font-size: 10px; font-weight: 500; letter-spacing: 0.01em;
    background: none; border: 0; cursor: pointer;
    transition: color 0.18s;
  }
  .bottomnav__item.is-active { color: var(--live-1); }
  .bottomnav__item:active { color: var(--live-1); }
  .bottomnav__item:hover { color: var(--text-2); }
}

@media (max-width: 600px) and (prefers-color-scheme: dark) {
  .bottomnav { background: rgba(28, 28, 30, 0.92); }
}

/* -- Mobile: HomeKit-style two-up grid & touch ergonomics ------------------ */
@media (max-width: 600px) {
  .page { padding: 18px 0; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  .pagehead { margin: 6px 0 18px; }
  .summary { font-size: 14px; }

  /* Two columns of compact tiles, the way the Home app lays out a room. */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .tile { min-height: 150px; padding: 14px; border-radius: var(--r-tile); }
  .tile__top > div:first-child { min-width: 0; }
  .tile__name { font-size: 15px; max-width: none; overflow-wrap: anywhere; }
.tile__watts { font-size: 26px; }
  .tile__sub { font-size: 11.5px; }
  .tile__foot { margin-top: 12px; }
  .ring { width: 44px; height: 44px; }
  .switch { --w: 46px; --h: 28px; }
  .statepill { padding: 3px 9px; font-size: 11px; }

  /* Detail page: ring stacks above meta on narrow screens. */
  .hero { flex-direction: column; align-items: center; gap: 12px; text-align: center; }
  .hero__ring { width: 148px; height: 148px; }
  .hero__meta { min-width: 0; width: 100%; text-align: center; }
  .hero__stats { justify-content: center; gap: 12px 24px; margin-top: 12px; }
  .hero .formactions { justify-content: center; }

  /* Stacked, full-width actions are easier to hit with a thumb. */
  .formactions { flex-wrap: wrap; }
  .formactions .btn { flex: 1 1 auto; justify-content: center; min-height: 44px; }

  .sectitle { flex-wrap: wrap; }
  .chartbox { height: 220px; }
  .empty { padding: 48px 18px; }
  .authcard { padding: 28px 22px; }

  /* Toasts sit above the bottom nav. */
  .toasts {
    top: auto; right: 12px; left: 12px; width: auto;
    bottom: calc(56px + env(safe-area-inset-bottom) + 14px);
  }
}

/* Narrowest phones (iPhone SE etc.): reclaim the brand wordmark for the nav. */
@media (max-width: 380px) {
  .brand span { display: none; }
  .topbar__inner { gap: 8px; }
  .nav a, .nav button.linklike { padding: 8px 8px; font-size: 13px; }
  .grid { gap: 10px; }
  .tile { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
