/* Haven app. Limestone and slate, one blue accent for things you can press, heather for the
   first person and moss for the second, red only for SOS. One typeface, Atkinson Hyperlegible
   Next, drawn for readers with low vision. Every value below comes from the tokens in :root. */

@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../assets/fonts/atkinson-hyperlegible-next-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("../assets/fonts/atkinson-hyperlegible-next-latin-ext-wght-normal.woff2") format("woff2");
  font-weight: 200 800; font-style: normal; font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  /* colour: 12 roles, no tints made on the fly */
  --page: #e7e9e4;          /* limestone */
  --surface: #f6f7f4;       /* chalk: plan sheet, dialogs, inputs */
  --well: #dde1dc;          /* quiet fills: secondary buttons, the usual range */
  --line: #bfc7c3;          /* walls on the plan, input edges */
  --ink: #1f2a30;           /* slate */
  --ink-2: #48545a;         /* secondary text, 6.4:1 on the page */
  --accent: #275d8c;        /* things you can press */
  --on-accent: #ffffff;
  --p-a: #7f55b5;           /* heather: first person */
  --p-b: #1f8a6e;           /* moss: second person */
  --alarm: #b42d2d;         /* SOS and emergencies only */
  --alarm-text: #b42d2d;
  --warn: #7a4e00;
  --room: #e7e9e4;          /* a room with nobody in it */
  --room-still: #d8e1e5;    /* someone there, still */
  --room-moving: #c0d1dc;   /* movement now */
  --seq-1: #d3e1ec; --seq-2: #a3c1da; --seq-3: #6694bd; --seq-4: #275d8c;   /* movement, a little to a lot */
  --slate: #1f2a30; --on-slate: #eef1ee; --on-slate-2: #b8c2c5;   /* the utility bar, the same in both themes */
  --live: #6fcf97; --ub-warn: #f2c063; --ub-alarm: #ff8a80;

  /* space, 4 px steps */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --gutter: clamp(16px, 3vw, 40px);
  /* radius: outer = inner + padding wherever one shape sits inside another */
  --r-room: 4px;  --r-ctl: 8px;  --r-sheet: 16px;  /* sheet = room 4 + padding 12 */
  /* type, about 1.25 apart */
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", system-ui, sans-serif;
  --t-xs: 0.8125rem; --t-s: 0.9375rem; --t-m: 1rem; --t-l: 1.1875rem; --t-xl: 1.5rem; --t-2xl: 1.875rem;
  /* motion */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-io: cubic-bezier(0.65, 0, 0.35, 1);
  --t-enter: 200ms; --t-exit: 160ms; --t-move: 650ms;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #12181b; --surface: #1b2226; --well: #27313a; --line: #3d4a52; --ink: #e8ecea; --ink-2: #b4bec2;
    --accent: #8cbbe3; --on-accent: #0f1a22; --p-a: #9479d3; --p-b: #2c9c7d; --alarm: #c93c3c; --alarm-text: #f08080;
    --warn: #e4b04a; --room: #212a2f; --room-still: #24343e; --room-moving: #2c4455;
    --seq-1: #233a4b; --seq-2: #2f5a7c; --seq-3: #4d86b4; --seq-4: #8cbbe3;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #12181b; --surface: #1b2226; --well: #27313a; --line: #3d4a52; --ink: #e8ecea; --ink-2: #b4bec2;
  --accent: #8cbbe3; --on-accent: #0f1a22; --p-a: #9479d3; --p-b: #2c9c7d; --alarm: #c93c3c; --alarm-text: #f08080;
  --warn: #e4b04a; --room: #212a2f; --room-still: #24343e; --room-moving: #2c4455;
  --seq-1: #233a4b; --seq-2: #2f5a7c; --seq-3: #4d86b4; --seq-4: #8cbbe3;
}

/* ---------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; interpolate-size: allow-keywords; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 400 var(--t-m)/1.5 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: var(--t-xl); font-weight: 700; }
h2 { font-size: var(--t-l); font-weight: 700; }
h3 { font-size: var(--t-s); font-weight: 700; color: var(--ink-2); }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: var(--r-room); }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.secondary { color: var(--ink-2); }
.small { font-size: var(--t-s); }
.num, time { font-variant-numeric: tabular-nums; }
svg.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------------------------------------------------------- loading */
.loading { min-height: 100vh; display: grid; place-content: center; gap: var(--s4); justify-items: center; color: var(--ink-2); }
.loading .wordmark { color: var(--ink); }
.loadbar { width: 160px; height: 3px; border-radius: 2px; background: var(--well); overflow: hidden; }
.loadbar i { display: block; width: 40%; height: 100%; background: var(--accent); border-radius: 2px; animation: load 1.1s var(--ease-io) infinite; }
@keyframes load { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* ---------------------------------------------------------------- utility bar and header */
/* A slate strip over every page: is the data live, when, are alerts open, colours, account.
   Everything in it is a word; the only colour is the live dot and an open-alert count. */
.ub {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s1) var(--s5);
  min-height: 40px; padding: var(--s1) var(--gutter); background: var(--slate); color: var(--on-slate);
  font-size: var(--t-xs); font-variant-numeric: tabular-nums;
}
.ub a, .ub-btn { color: var(--on-slate); }
.ub-live { display: inline-flex; align-items: center; gap: var(--s2); font-weight: 700; }
.ub-live i { width: 8px; height: 8px; border-radius: 50%; background: var(--live); }
.ub-live.is-live i { animation: breathe 3s ease-in-out infinite; }
.ub-live.is-stale { color: var(--ub-warn); }
.ub-live.is-stale i { background: var(--ub-warn); }
.ub-live.is-demo i { background: var(--on-slate-2); }
.ub-home, .ub-time { color: var(--on-slate-2); }
.ub-home select { width: auto; min-height: 0; padding: 0 var(--s1); background: transparent; color: var(--on-slate); border: 0; font-size: inherit; }
.ub-time { margin-left: auto; }
.ub-alerts { text-decoration: none; }
.ub-alerts.is-open { font-weight: 700; display: inline-flex; align-items: center; gap: var(--s2); }
.ub-alerts.is-open::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ub-alarm); }
.ub-btn { background: none; border: 0; padding: 2px 0; font: inherit; font-size: var(--t-xs); cursor: pointer; text-decoration: underline; text-decoration-color: var(--on-slate-2); text-underline-offset: 3px; }
.ub-btn:hover, .ub a:hover { text-decoration-color: currentColor; }
.ub-me { display: inline-flex; gap: var(--s3); align-items: center; color: var(--on-slate-2); }
.ub :focus-visible { outline-color: var(--on-slate); }
@keyframes breathe { 50% { opacity: 0.45; } }

.top { display: flex; align-items: center; gap: var(--s6); flex-wrap: wrap; padding: var(--s3) var(--gutter) 0; }
.wordmark { font-weight: 800; font-size: var(--t-xl); text-decoration: none; padding-bottom: var(--s2); }
.tabs { display: flex; gap: var(--s5); flex-wrap: wrap; }
.tabs a { position: relative; text-decoration: none; padding: var(--s2) 0 var(--s3); color: var(--ink-2); font-weight: 700; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); }
.tab-mark {   /* one underline, slides between tabs (view transition) */
  position: absolute; left: 0; right: 0; bottom: 0; height: 3px; border-radius: 2px;
  background: var(--accent); view-transition-name: tab-mark;
}

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: var(--s2) var(--s4); border: 0; border-radius: var(--r-ctl);
  background: var(--well); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform 100ms var(--ease-out), background-color 150ms var(--ease-out), opacity 150ms;
}
.btn:hover { background: var(--line); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.12); }
.btn-wide { width: 100%; }
.btn[aria-busy="true"] { cursor: progress; opacity: 0.75; }
.btn-link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: var(--t-s); font-weight: 700; }
.btn-link:active { transform: scale(0.97); }
.btn-link.danger { color: var(--ink-2); }   /* red stays for SOS; the dialog asks first */
.row-btns { display: flex; gap: var(--s2); flex-wrap: wrap; }

/* ---------------------------------------------------------------- alert band: the one loud thing */
.alertband {
  display: grid; grid-template-columns: auto 1fr auto; column-gap: var(--s4); align-items: start;
  padding: var(--s4) var(--gutter); background: var(--alarm); color: #fff;
  transition: background-color 300ms var(--ease-out);
  animation: reveal-down 260ms var(--ease-out);
}
.alertband--urgent { background: var(--warn); color: #fff; }
.alertband--check, .alertband--info { background: var(--ink); color: var(--page); }   /* low priority: slate, never red */
.alertband.is-acked { background: var(--ink); color: var(--page); }
.ab-icon svg { width: 28px; height: 28px; margin-top: 2px; }
.ab-title { font-size: var(--t-xl); font-weight: 700; line-height: 1.25; }
.ab-sub { font-size: var(--t-m); font-variant-numeric: tabular-nums; }
.ab-ack { font-weight: 700; animation: confirm 700ms var(--ease-out); }
.ab-actions { display: flex; gap: var(--s4); align-items: center; align-self: center; flex-wrap: wrap; justify-content: flex-end; }
.btn-onalarm { background: #fff; color: var(--alarm); }
.btn-onalarm:hover { background: #fff; filter: brightness(0.95); }
.is-acked .btn-onalarm, .alertband--urgent .btn-onalarm, .alertband--check .btn-onalarm { color: var(--ink); }
.btn-link-onalarm { color: inherit; font-size: var(--t-m); }
@keyframes reveal-down { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
@keyframes confirm { 0% { opacity: 0; transform: translateY(4px); } 60% { opacity: 1; transform: none; } 100% { opacity: 1; } }

.demo-note { padding: var(--s2) var(--gutter); font-size: var(--t-s); color: var(--ink-2); }

/* ---------------------------------------------------------------- pages */
.page { padding: var(--s5) var(--gutter) var(--s7); display: grid; gap: var(--s6); align-content: start; }
.page > h1 { font-size: var(--t-2xl); }
.page section > h2 { margin-bottom: var(--s3); }

/* Home: one sentence, then the house; a quiet rail beside it */
.status { display: grid; gap: var(--s1); max-width: 60rem; }
.status h1 { font-size: clamp(1.625rem, 2.4vw, 2.25rem); line-height: 1.15; display: flex; align-items: center; gap: var(--s3); }
.status h1 svg { width: 1em; height: 1em; flex: none; }
.status p { color: var(--ink-2); font-size: var(--t-l); }
.status--alarm h1 { color: var(--alarm-text); }
.status--warn h1 { color: var(--warn); }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(17rem, 21rem); gap: var(--s6) clamp(24px, 3vw, 48px); align-items: start; }
.house { min-width: 0; }
.rail { display: grid; gap: var(--s6); align-content: start; }
.pcard { display: grid; gap: var(--s1); }
.pcard h2 { font-size: var(--t-xl); }
.pcard .where { font-size: var(--t-l); }
.pcard .doing { font-size: var(--t-m); }
.pcard .facts { margin-top: var(--s2); }
.mini { display: block; width: 100%; height: 34px; margin-top: var(--s3); }
.reading { color: var(--ink-2); }
.reading.tone-warn { color: var(--warn); font-weight: 700; }
.reading.lead { font-size: var(--t-l); color: var(--ink); max-width: 46rem; }
.pcard-link { justify-self: start; margin-top: var(--s2); color: var(--accent); font-weight: 700; font-size: var(--t-s); text-underline-offset: 3px; }
.latest { display: grid; gap: var(--s3); }
.latest h2 { font-size: var(--t-l); margin-bottom: 0; }

/* ---------------------------------------------------------------- a person */
.person-head { display: flex; align-items: center; gap: var(--s3); }
.person-head .pebble { margin-top: 3px; }   /* centred on the cap height, not the line box */
.where { margin-top: var(--s1); font-size: var(--t-xl); font-weight: 700; line-height: 1.25; display: flex; align-items: center; gap: var(--s2); }
.where svg { width: 22px; height: 22px; }
.doing { color: var(--ink-2); font-size: var(--t-l); font-variant-numeric: tabular-nums; }
.tone-alarm .where { color: var(--alarm-text); }
.tone-warn .where { color: var(--warn); }
.tone-quiet .where { color: var(--ink-2); }
.partner { margin-top: var(--s2); font-weight: 700; }
.partner.is-alarm { color: var(--alarm-text); }
.facts { list-style: none; padding: 0; margin: var(--s3) 0 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-size: var(--t-s); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.facts li { display: inline-flex; align-items: center; gap: 6px; }
.facts .is-warn { color: var(--warn); font-weight: 700; }

.subtabs { display: flex; gap: var(--s5); flex-wrap: wrap; }
.subtabs a { display: inline-flex; align-items: center; gap: var(--s2); text-decoration: none; font-weight: 700; color: var(--ink-2); padding-bottom: var(--s1); border-bottom: 3px solid transparent; }
.subtabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.person-hero { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s4); align-items: start; }
.person-hero h1 { font-size: var(--t-2xl); }
.pebble--hero { width: 56px; height: 56px; font-size: var(--t-xl); box-shadow: none; margin-top: 2px; }
.person-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s6) clamp(24px, 4vw, 64px); }
.person-grid .chart { margin-top: 0; }
.person-grid .band24 { margin-top: 0; }
.person-today { max-width: 46rem; }

/* Rooms: the room table, then the 24-hour panel */
.now-table { border-collapse: collapse; width: 100%; max-width: 60rem; font-size: var(--t-s); }
.now-table th, .now-table td { text-align: left; padding: var(--s2) var(--s4) var(--s2) 0; vertical-align: middle; }
.now-table thead th { color: var(--ink-2); font-weight: 700; padding-bottom: var(--s3); }
.now-table tbody th { font-weight: 700; }
.now-table tbody tr + tr > * { border-top: 1px solid var(--well); }
.now-table .is-cool { color: var(--warn); font-weight: 700; }
.now-table .is-cold { color: var(--alarm-text); font-weight: 700; }
.act { display: inline-flex; align-items: center; gap: var(--s2); }
.act i { width: 14px; height: 10px; border-radius: 2px; background: var(--well); }
.act--moving i { background: var(--room-moving); box-shadow: inset 0 0 0 1.5px var(--line); }
.act--present i { background: var(--room-still); box-shadow: inset 0 0 0 1.5px var(--line); }
.act--none { color: var(--ink-2); }
.who { display: inline-flex; align-items: center; gap: 6px; margin-right: var(--s3); }

/* Today: events beside alerts, then doors and mats, then the normal-day recording */
.today-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--s6) clamp(24px, 4vw, 64px); align-items: start; }
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s4); }
.al { display: grid; grid-template-columns: 3.25rem 1fr; gap: 10px; font-size: var(--t-s); }
.al time { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.al-msg { font-weight: 700; }
.al--emergency:not(.is-closed) .al-msg { color: var(--alarm-text); }
.al-meta { color: var(--ink-2); }
.al-level { font-weight: 700; margin-right: var(--s1); }
.al-level::after { content: ","; }

/* people on the plan and beside their names */
.pebble {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--p-a); color: #fff; font-weight: 800; font-size: var(--t-m); line-height: 1;
  box-shadow: 0 0 0 2px var(--surface); flex: none;
}
.pebble--b { background: var(--p-b); }
.pebble--static { width: 30px; height: 30px; font-size: var(--t-s); box-shadow: none; }
.pebble--tiny { width: 22px; height: 22px; font-size: 0.6875rem; box-shadow: none; }
.pebble--none { background: var(--line); }
.plan .pebble { position: absolute; translate: calc(-50% + var(--o, 0) * 110%) -50%; z-index: 3; cursor: default;
  width: clamp(22px, 4.4cqw, 36px); height: clamp(22px, 4.4cqw, 36px); font-size: clamp(0.6875rem, 1.9cqw, 1rem); animation: settle var(--t-enter) var(--ease-out) both; animation-delay: calc(240ms + var(--i, 0) * 60ms); }
.pebble.is-alarm { box-shadow: 0 0 0 2px var(--surface), 0 0 0 5px var(--alarm); animation: sos 1.2s ease-in-out infinite; }
@keyframes sos { 50% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 10px transparent; } }
@keyframes settle { from { opacity: 0; scale: 0.95; } to { opacity: 1; scale: 1; } }

/* ---------------------------------------------------------------- charts */
.chart { margin: var(--s4) 0 0; }
.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); font-size: var(--t-s); font-weight: 700; color: var(--ink-2); }
.chart .key { font-weight: 400; display: inline-flex; align-items: center; gap: 6px; }
.key-usual { width: 14px; height: 10px; border-radius: 2px; background: var(--well); display: inline-block; }
.chart svg { display: block; width: 100%; height: auto; margin-top: var(--s1); overflow: visible; }
.c-grid { stroke: var(--well); stroke-width: 1; }
.c-axis { stroke: var(--line); stroke-width: 1; }
.c-tick { fill: var(--ink-2); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.c-usual { fill: var(--well); }
.c-bar--a { fill: var(--p-a); }
.c-bar--b { fill: var(--p-b); }
.c-now { stroke: var(--ink-2); stroke-width: 1; }
.c-usual-line { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; }
.c-bar.is-partial { fill: transparent; stroke-width: 1.5; }
.c-bar--a.is-partial { stroke: var(--p-a); }
.c-bar--b.is-partial { stroke: var(--p-b); }
.c-tick.is-today { font-weight: 700; fill: var(--ink); }
.key-usual-line { width: 14px; height: 2px; border-radius: 1px; background: var(--ink); display: inline-block; }
.mini .c-now { vector-effect: non-scaling-stroke; }
.c-hit { fill: transparent; transition: fill 120ms var(--ease-out); }
.c-hit:hover { fill: var(--well); }
.c-marks { pointer-events: none; }
.numbers { font-size: var(--t-xs); color: var(--ink-2); }
.numbers summary { cursor: pointer; width: max-content; color: var(--accent); font-weight: 700; }
.numbers::details-content { block-size: 0; overflow: clip; transition: block-size var(--t-enter) var(--ease-out), content-visibility var(--t-enter) allow-discrete; }
.numbers[open]::details-content { block-size: auto; }
.numbers table { margin-top: var(--s2); border-collapse: collapse; font-variant-numeric: tabular-nums; }
.numbers th, .numbers td { text-align: left; padding: 2px var(--s4) 2px 0; }

.places { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.places li { display: grid; grid-template-columns: 7rem 1fr auto; gap: var(--s3); align-items: center; font-size: var(--t-s); }
.pl-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-bar { height: 8px; }
.pl-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--p-a); transition: width var(--t-move) var(--ease-io); }
.pl-fill--b { background: var(--p-b); }
.pl-val { color: var(--ink-2); font-variant-numeric: tabular-nums; text-align: right; }

/* ---------------------------------------------------------------- the plan */
.plan-sheet { background: var(--surface); border-radius: var(--r-sheet); padding: var(--s3); view-transition-name: plan; }
.plan-sheet.just-saved { animation: saved 900ms var(--ease-out); }
@keyframes saved { 0% { box-shadow: 0 0 0 0 var(--accent); } 30% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.plan { position: relative; width: 100%; container-type: inline-size; }
.rm {
  position: absolute; border: 2px solid var(--surface); background-clip: padding-box;   /* 4 px between neighbours */
  border-radius: calc(var(--r-room) + 2px); background-color: var(--room); box-shadow: inset 0 0 0 1.5px var(--line);
  container-type: size; overflow: hidden;
  transition: background-color var(--t-move) var(--ease-io);
  animation: settle var(--t-enter) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 30ms);
}
.rm-in { position: absolute; inset: 0; padding: var(--s2) 10px; display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; align-content: flex-start; gap: 0 var(--s2); }
.rm--present { background-color: var(--room-still); }
.rm--moving { background-color: var(--room-moving); }
.rm-name { font-weight: 700; font-size: var(--t-s); line-height: 1.25; overflow-wrap: normal; min-width: 0; }
.rm.no-label .rm-in { visibility: hidden; }   /* set by fitLabels() when the name cannot fit whole */
/* Small rooms: smaller type first, then the label runs along a tall narrow room, then it hides
   (the room's tooltip still names it). No word is ever broken in the middle. */
@container (max-width: 110px) {
  .rm-in { padding: 6px; }
  .rm-name, .rm-temp, .rm-size { font-size: var(--t-xs); }
}
@container (max-height: 52px) { .rm-in { padding-block: 4px; } .rm-temp, .rm-size { display: none; } }
@container (max-width: 72px) and (max-aspect-ratio: 1/2) {
  .rm-in { writing-mode: vertical-rl; padding: 6px 4px; }
  .rm-temp { margin-left: 0; margin-top: auto; }
}
@container (max-width: 72px) and (min-aspect-ratio: 1/2) { .rm-temp, .rm-size { display: none; } }
@container (max-width: 34px), (max-height: 24px) { .rm-in { display: none; } }
.rm-temp { font-size: var(--t-s); color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; margin-left: auto; }
.rm-temp.is-cool { color: var(--warn); font-weight: 700; }
.rm-temp.is-cold { color: var(--alarm-text); font-weight: 700; }
.mk { position: absolute; translate: -50% -50%; z-index: 2; display: block; }
/* Markers shrink a little on a small plan, never below 10 px. */
.plan .mk-door { width: clamp(10px, 1.6cqw, 14px); height: clamp(10px, 1.6cqw, 14px); }
.plan .mk-mat { width: clamp(15px, 2.4cqw, 22px); height: clamp(10px, 1.6cqw, 14px); }
.plan .mk-mon { width: clamp(8px, 1.1cqw, 10px); height: clamp(8px, 1.1cqw, 10px); }
.mk-door { width: 14px; height: 14px; border-radius: 3px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink-2); transition: background-color 300ms var(--ease-out); }
.mk-door.is-on { background: var(--ink); box-shadow: 0 0 0 2px var(--surface); }
.mk-mat { width: 22px; height: 14px; border-radius: 5px; background: var(--surface); box-shadow: inset 0 0 0 2px var(--ink-2); transition: background-color 300ms var(--ease-out); }
.mk-mat.is-on { background: var(--ink-2); box-shadow: 0 0 0 2px var(--surface); }
.mk-mat.is-off { box-shadow: inset 0 0 0 2px var(--line); }
.mk-mon { width: 10px; height: 10px; border-radius: 50%; background: var(--ink-2); box-shadow: 0 0 0 2px var(--surface); }
.plan-foot { display: flex; justify-content: space-between; gap: var(--s4) var(--s6); flex-wrap: wrap; margin-top: var(--s3); align-items: center; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); font-size: var(--t-xs); color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: var(--s2); }
.lg { position: static; translate: none; display: inline-block; flex: none; }
.lg-moving, .lg-present { width: 20px; height: 14px; border-radius: 3px; box-shadow: inset 0 0 0 1.5px var(--line); }
.lg-moving { background: var(--room-moving); }
.lg-present { background: var(--room-still); }
.away { display: inline-flex; gap: var(--s2); align-items: center; font-size: var(--t-s); color: var(--ink-2); }
.cold { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s3); color: var(--alarm-text); font-weight: 700; }
.plan-empty { background: var(--surface); border-radius: var(--r-sheet); padding: clamp(24px, 4vw, 56px); display: grid; gap: var(--s3); justify-items: start; max-width: 40rem; }
.pe-title { font-size: var(--t-xl); font-weight: 700; }

/* ---------------------------------------------------------------- today */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.tl { display: grid; grid-template-columns: 3.25rem auto 1fr; gap: 10px; align-items: center; font-size: var(--t-s); animation: rise var(--t-enter) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 30ms); }
.tl time { color: var(--ink-2); }
.tl.tone-alarm .tl-text { color: var(--alarm-text); font-weight: 700; }
.tl.tone-warn .tl-text { color: var(--warn); }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.fixtures { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.fixtures li { display: grid; grid-template-columns: 28px 1fr; column-gap: var(--s2); font-size: var(--t-s); }
.fx-mark { position: static; translate: none; grid-row: span 2; margin-top: 4px; }
.fx-name { font-weight: 700; }
.fx-val { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.baseline { display: grid; gap: var(--s3); }

/* ---------------------------------------------------------------- the last 24 hours */
/* Small multiples: one shared time axis, one scale per column, lines in ink, people in their own colour,
   movement in one blue from light (a little) to dark (a lot). Charts stretch sideways; strokes do not. */
.d-svg { display: block; width: 100%; height: 40px; overflow: visible; }
.d-line { fill: none; stroke: var(--ink); stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.d-line--a { stroke: var(--p-a); }
.d-line--b { stroke: var(--p-b); }
.d-grid { stroke: var(--well); stroke-width: 1; vector-effect: non-scaling-stroke; }
.d-base { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.d-ref { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.d-ref--cold { stroke: var(--alarm-text); }
.d-hit { fill: transparent; transition: fill 120ms var(--ease-out); }
.d-hit:hover { fill: var(--well); }
.d-marks, .d-tick { pointer-events: none; }
.d-tick { stroke: var(--ink); stroke-width: 2; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.d-span { fill: var(--ink-2); background: var(--ink-2); }
.d-cell--na { fill: transparent; stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.d-cell--0 { fill: var(--well); background: var(--well); }
.d-cell--1 { fill: var(--seq-1); background: var(--seq-1); }
.d-cell--2 { fill: var(--seq-2); background: var(--seq-2); }
.d-cell--3 { fill: var(--seq-3); background: var(--seq-3); }
.d-cell--4 { fill: var(--seq-4); background: var(--seq-4); }
.d-wear--off, .d-wear--asleep { fill: var(--well); background: var(--well); }
.d-wear--charging { fill: var(--ink-2); background: var(--ink-2); }
.d-wear--worn.d-wear--a { fill: var(--p-a); background: var(--p-a); }
.d-wear--worn.d-wear--b { fill: var(--p-b); background: var(--p-b); }
.d-wear--na { fill: transparent; stroke: var(--line); stroke-width: 1; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }
.lg.d-sw { width: 14px; height: 10px; border-radius: 2px; }
.lg.d-sw-tick { width: 2px; height: 12px; border-radius: 1px; background: var(--ink); }
.lg.d-sw-span { width: 18px; height: 10px; border-radius: 2px; background: var(--ink-2); }
.d-now { font-size: var(--t-s); font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.d-now.is-cool { color: var(--warn); }
.d-now.is-cold { color: var(--alarm-text); }
.d-axis { position: relative; height: 1.4em; font-size: var(--t-xs); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.d-axis span { position: absolute; top: 2px; translate: -50% 0; white-space: nowrap; }
.d-axis .d-axis-now { translate: -100% 0; }
.d-foot { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: var(--s3) var(--s6); margin-top: var(--s3); }
.table-scroll { overflow-x: auto; max-width: 100%; }

.r24 h2, .f24 h2 { margin-bottom: var(--s3); }
.r24-grid { display: grid; grid-template-columns: minmax(6.5rem, 9rem) repeat(3, minmax(0, 1fr)); column-gap: clamp(12px, 2vw, 24px); }
.r24-row { display: contents; }
.r24-head > span { font-size: var(--t-s); font-weight: 700; padding-bottom: var(--s2); }
.r24-head .secondary { display: block; font-weight: 400; font-size: var(--t-xs); }
.r24-name { font-weight: 700; font-size: var(--t-s); align-self: center; line-height: 1.25; }
.r24-name .secondary { font-weight: 400; display: block; }
.r24-cell { display: grid; grid-template-columns: minmax(0, 1fr) 3.4rem; align-items: center; gap: var(--s2); min-height: 48px; }
.r24-foot .r24-cell { min-height: 0; }

.f24-grid { display: grid; grid-template-columns: minmax(8rem, 12rem) minmax(0, 1fr) minmax(7rem, 15rem); column-gap: clamp(12px, 2vw, 24px); row-gap: var(--s1); align-items: center; }
.f24-row { display: contents; }
.f24-name { display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: var(--t-s); line-height: 1.25; }
.f24-name .fx-mark { margin-top: 0; flex: none; }
.f24-cell .d-svg { height: 22px; }
.f24-sum { font-size: var(--t-s); color: var(--ink-2); font-variant-numeric: tabular-nums; }

.band24 { margin-top: var(--s5); }
.band24-plot { position: relative; padding-left: 2rem; margin-top: var(--s2); }
.band24 .d-svg { height: 62px; }
.band24-y span { position: absolute; left: 0; translate: 0 -50%; font-size: 11px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.band24 .d-axis { margin-left: 2rem; }
.band24 .legend { margin-top: var(--s2); }
.band24 figcaption .num { font-weight: 700; color: var(--ink); }

@media (max-width: 700px) {   /* each room becomes a block: name, then its three charts, each labelled */
  .r24-grid { grid-template-columns: minmax(0, 1fr); }
  .r24-row { display: grid; gap: var(--s1); margin-bottom: var(--s4); }
  .r24-head, .r24-foot { display: none; }
  .r24-cell { grid-template-columns: 6.5rem minmax(0, 1fr) 3.4rem; min-height: 40px; }
  .r24-cell::before { content: attr(data-label); font-size: var(--t-xs); color: var(--ink-2); }
  .f24-grid { display: block; }
  .f24-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--s3); margin-bottom: var(--s3); }
  .f24-cell { grid-column: 1 / -1; grid-row: 2; }
  .f24-sum { text-align: right; font-size: var(--t-xs); }
  .f24-foot { display: none; }
}

/* ---------------------------------------------------------------- setup */
.setup { display: grid; gap: var(--s6) clamp(24px, 3vw, 48px); grid-template-columns: minmax(0, 1fr) minmax(20rem, 26rem); padding: var(--s2) var(--gutter) var(--s7); align-items: start; }
.setup-plan { display: grid; gap: var(--s3); min-width: 0; position: sticky; top: var(--s3); }
.setup-plan h1 { font-size: var(--t-2xl); }
.setup-side { display: grid; gap: var(--s6); }
.panel { display: grid; gap: var(--s3); align-content: start; }
.plan--edit {   /* one square per metre */
  touch-action: none;
  background-image: linear-gradient(var(--well) 1px, transparent 1px), linear-gradient(90deg, var(--well) 1px, transparent 1px);
  background-size: calc(100% / var(--pw)) calc(100% / var(--ph));
}
.plan--edit .rm { cursor: grab; transition: none; animation: none; }
.plan--edit .rm:active { cursor: grabbing; }
.plan--edit .rm.is-sel { box-shadow: inset 0 0 0 2.5px var(--accent); }
.rm.is-back { transition: left 300ms var(--ease-out), top 300ms var(--ease-out), width 300ms var(--ease-out), height 300ms var(--ease-out); }
.rm-size { font-size: var(--t-xs); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.rm-grip { position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px; cursor: nwse-resize; }
.rm-grip svg { width: 16px; height: 16px; stroke: var(--ink-2); stroke-width: 1.6; stroke-linecap: round; fill: none; }
.drag { cursor: grab; }
.ghost { position: fixed; z-index: 50; pointer-events: none; translate: -50% -50%; scale: 1.4; }
.savebar {
  display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; width: max-content; max-width: 100%;
  background: var(--ink); color: var(--page); padding: 6px 6px 6px var(--s4); border-radius: 14px;   /* 14 = button 8 + padding 6 */
  font-variant-numeric: tabular-nums; animation: rise var(--t-enter) var(--ease-out);
}
.savebar .btn { background: transparent; color: var(--page); }
.savebar .btn:hover { background: var(--ink-2); }
.savebar .btn-primary { background: var(--accent); color: var(--on-accent); }
.tray { display: grid; gap: var(--s2); }
.tray h3 { color: var(--warn); }
.tray ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); }
.tray li { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t-s); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input:not([type]), select {
  width: 100%; min-height: 40px; padding: 6px 10px; border-radius: var(--r-ctl);
  border: 1.5px solid var(--line); background: var(--surface);
  transition: border-color 150ms var(--ease-out);
}
input:focus-visible, select:focus-visible { border-color: var(--accent); outline-offset: 0; }
label > span { display: block; font-size: var(--t-s); font-weight: 700; margin-bottom: var(--s1); color: var(--ink-2); }
.roomlist, .devlist, .members, .pending { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.roomlist li { display: grid; grid-template-columns: 1fr 8.5rem auto; gap: var(--s2); align-items: center; }
.addroom { display: grid; grid-template-columns: 1fr 8.5rem auto; gap: var(--s2); align-items: end; }
.sizes { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }
.devlist li { display: grid; grid-template-columns: 32px 1fr auto; gap: 10px; align-items: center; }
.devlist li.is-unplaced .dev-where { color: var(--warn); font-weight: 700; }
.chip { width: 32px; height: 32px; border-radius: 50%; background: var(--well); display: grid; place-items: center; touch-action: none; }
.chip .mk { position: static; translate: none; }
.dev-main { display: grid; gap: 2px; min-width: 0; }
.dev-where, .dev-hw { font-size: var(--t-xs); color: var(--ink-2); }
.members li { display: grid; grid-template-columns: 1fr auto; gap: 0 var(--s4); }
.mem-name { font-weight: 700; }
.mem-mail { grid-column: 1; font-size: var(--t-xs); color: var(--ink-2); }
.mem-role { grid-column: 2; grid-row: 1 / span 2; font-size: var(--t-s); color: var(--ink-2); align-self: center; }
.invite { display: grid; gap: var(--s2); }
.code { background: var(--surface); border-radius: var(--r-sheet); padding: var(--s3) var(--s4); display: grid; gap: var(--s2); animation: rise var(--t-enter) var(--ease-out); }
.code-value { display: flex; gap: var(--s4); align-items: baseline; }
.code-value { margin: 0; }
.code-value output { font-size: var(--t-2xl); font-weight: 700; letter-spacing: 0.06em; font-variant-numeric: tabular-nums; }
.swap { display: inline-grid; }
.swap > span { grid-area: 1 / 1; transition: opacity 180ms var(--ease-out), filter 180ms var(--ease-out); }
.swap > span:last-child, .swap.is-done > span:first-child { opacity: 0; filter: blur(2px); }
.swap.is-done > span:last-child { opacity: 1; filter: none; }
.pending li { display: flex; justify-content: space-between; gap: var(--s4); font-size: var(--t-s); }

/* switch: the knob stretches while pressed */
.switch { display: flex; gap: var(--s3); align-items: flex-start; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; position: relative; width: 44px; height: 26px; border-radius: 13px; background: var(--line); transition: background-color 200ms var(--ease-out); }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: #fff; transition: transform 200ms var(--ease-io), width 120ms var(--ease-out); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .knob { transform: translateX(18px); }
.switch:active .knob { width: 22.4px; }   /* 12 % longer while pressed, anchored on the side it rests */
.switch:active input:checked + .track .knob { transform: translateX(15.6px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: 0.5; }
.switch-text { font-weight: 400; color: var(--ink); }
.theme { border: 0; padding: 0; margin: 0; display: flex; gap: var(--s5); flex-wrap: wrap; }
.theme legend { font-size: var(--t-s); font-weight: 700; color: var(--ink-2); padding: 0; margin-bottom: var(--s1); }
.theme label { display: inline-flex; gap: 6px; align-items: center; }
.theme label span { display: inline; margin: 0; font-weight: 400; color: var(--ink); font-size: var(--t-m); }
.theme input { accent-color: var(--accent); }
.myname { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: end; }

/* ---------------------------------------------------------------- sign-in */
.gate { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 26rem) minmax(0, 34rem); gap: var(--s7); place-content: center; align-items: center; padding: var(--s6) var(--s4); }
.gate-card { background: var(--surface); border-radius: var(--r-sheet); padding: var(--s6); display: grid; gap: var(--s4); animation: settle var(--t-enter) var(--ease-out); }
.gate .wordmark { font-size: var(--t-2xl); }
.gate-lead { color: var(--ink-2); }
.gate-msg { color: var(--alarm-text); font-weight: 700; display: flex; gap: var(--s2); align-items: flex-start; }
.gate-switch { font-size: var(--t-s); color: var(--ink-2); }
.gate-preview { display: grid; gap: var(--s3); }
.gate-preview { margin: 0; }
.gate-preview figcaption { font-size: var(--t-s); color: var(--ink-2); max-width: 34rem; }
.gate-preview .plan-sheet { view-transition-name: none; }
.stack { display: grid; gap: 14px; }
.captcha { min-height: 0; }
.captcha:empty { display: none; }
.codeinput { font-size: var(--t-xl) !important; letter-spacing: 0.06em; text-transform: uppercase; }

/* ---------------------------------------------------------------- dialog, toast, tooltip */
dialog.ask { border: 0; border-radius: var(--r-sheet); background: var(--surface); color: var(--ink); padding: var(--s5); width: min(28rem, calc(100vw - 32px)); }
dialog.ask::backdrop { background: rgb(18 24 27 / 0.45); animation: fade-in var(--t-enter) var(--ease-out); }
dialog.ask.is-closing::backdrop { animation: fade-out var(--t-exit) var(--ease-in) forwards; }
.ask form { display: grid; gap: 14px; }
.ask-q { font-size: var(--t-l); font-weight: 700; }
.ask-btns { display: flex; gap: var(--s2); justify-content: flex-end; }
#toast { position: fixed; right: var(--s4); bottom: var(--s4); z-index: 60; margin: 0; background: var(--ink); color: var(--page); padding: 10px var(--s4); border-radius: var(--r-ctl); max-width: min(32rem, calc(100vw - 32px)); font-size: var(--t-s);
  opacity: 0; translate: 0 8px; pointer-events: none; transition: opacity var(--t-exit) var(--ease-in), translate var(--t-exit) var(--ease-in); }
#toast.is-on { opacity: 1; translate: 0 0; pointer-events: auto; transition: opacity var(--t-enter) var(--ease-out), translate var(--t-enter) var(--ease-out); }
#toast.is-error { background: var(--alarm); color: #fff; }
#tip { position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none; background: var(--ink); color: var(--page); font-size: var(--t-xs);
  padding: 6px 10px; border-radius: var(--r-ctl); max-width: 18rem; line-height: 1.35; font-variant-numeric: tabular-nums;
  opacity: 0; scale: 0.95; transition: opacity 120ms var(--ease-in), scale 120ms var(--ease-in); transform-origin: var(--tip-origin, 50% 100%); }
#tip.is-on { opacity: 1; scale: 1; transition: opacity 150ms var(--ease-out), scale 150ms var(--ease-out); }

/* ---------------------------------------------------------------- view transitions (Chrome) */
::view-transition-old(root) { animation: 120ms var(--ease-in) both fade-out; }
::view-transition-new(root) { animation: 180ms var(--ease-out) both fade-in; }
::view-transition-group(plan), ::view-transition-group(tab-mark) { animation-duration: 320ms; animation-timing-function: var(--ease-io); }
@keyframes fade-out { to { opacity: 0; } }
@keyframes fade-in { from { opacity: 0; } }

/* ---------------------------------------------------------------- narrower screens */
@media (max-width: 1100px) {   /* the plan takes the full width; the people sit side by side under it */
  .home-grid { grid-template-columns: 1fr; }
  .rail { grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
  .person-grid, .today-grid { grid-template-columns: 1fr; }
  .setup { grid-template-columns: 1fr; }
  .setup-plan { position: static; }
  .gate { grid-template-columns: minmax(0, 26rem); }
  .gate-preview { display: none; }
}
@media (max-height: 760px) { .setup-plan { position: static; } }
@media (max-width: 600px) {   /* phones: the bar keeps live status, time, alerts and the account */
  .ub-home, .ub [data-action="theme"] { display: none; }
}
@media (max-width: 820px) {
  .ub-time { margin-left: 0; }
  .top { gap: var(--s2) var(--s5); }
  .alertband { grid-template-columns: auto 1fr; }
  .ab-actions { grid-column: 1 / -1; justify-content: flex-start; margin-top: var(--s3); }
  .rm-name, .rm-temp { font-size: var(--t-xs); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}
@media (forced-colors: active) {
  .rm--moving, .rm--present { outline: 2px solid CanvasText; }
  .pebble { forced-color-adjust: none; }
}
