/* Dashboard theme over Pico.css 2 (forced dark). No inline styles (CSP).
 * 1. palette tokens  2. Pico variable map  3. app classes.
 * data-tone=success/warning/danger/info/purple/muted sets --tone (.badge .dot .alert .stats). */
:root {
  --bg: #0a0e17; --surface: #111827; --raised: #172036; --border: #223050; --border-hi: #2f4270;
  --text: #e6eaf2; --muted: #8a94a8; --primary: #2d8cff; --primary-hover: #5aa6ff; --primary-active: #1877f2;
  --focus: rgba(45,140,255,.45); --tint: rgba(45,140,255,.12); --success: #22c55e; --warning: #f5a623;
  --danger: #ff4d4f; --purple: #b26bff; --radius: 12px; --sunken: #0d1322;
  --mono: ui-monospace, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --pico-font-family-monospace: var(--mono); --pico-font-size: 93.75%; --pico-border-radius: 8px;
  --pico-block-spacing-vertical: 1.25rem; --pico-block-spacing-horizontal: 1.25rem;
  --pico-form-element-spacing-vertical: .55rem; --pico-form-element-spacing-horizontal: .8rem;
  --pico-background-color: var(--bg); --pico-color: var(--text);
  --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--border); --pico-primary: var(--primary);
  --pico-primary-background: var(--primary); --pico-primary-hover: var(--primary-hover);
  --pico-primary-hover-background: var(--primary-hover); --pico-primary-focus: var(--focus);
  --pico-primary-inverse: #06101f; --pico-secondary: var(--muted); --pico-secondary-background: var(--raised);
  --pico-secondary-border: var(--border); --pico-secondary-hover: var(--text);
  --pico-secondary-hover-background: #1d2843; --pico-secondary-hover-border: var(--border-hi);
  --pico-secondary-focus: var(--focus);
  --pico-code-background-color: var(--raised); --pico-code-color: #b8c6e0;
  --pico-form-element-background-color: #0d1322;
  --pico-form-element-selected-background-color: var(--raised); --pico-form-element-border-color: var(--border);
  --pico-form-element-placeholder-color: #66718a;
  --pico-form-element-focus-color: var(--focus);
  --pico-card-border-color: var(--border); --pico-card-box-shadow: none;
  --pico-card-sectioning-background-color: var(--raised);
}

h1, h2, h3 { letter-spacing: -.01em; }
h1 { font-size: 1.65rem; margin-bottom: 1rem; }
h2 { font-size: 1.1rem; margin-bottom: .75rem; }
h3 { font-size: .95rem; margin: 1.25rem 0 .5rem; }
a { text-underline-offset: .2em; }
:where(a:not([role="button"])) { text-decoration: none; }
:where(a:not([role="button"])):hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .86em; }
code { padding: .1em .4em; border-radius: 5px; }
.muted, dt, label > small, label + small, article.confirm .cancel { color: var(--muted); }
.num { text-align: right; }
.nowrap { white-space: nowrap; }
.warn-text { color: var(--warning); }
article, .table-wrap, form.filters, .inline-filters { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.25rem; margin: 0; }
dd { margin: 0; }

/* ── Shell ── */
.container { max-width: calc(1120px + 2rem); padding-inline: 1rem; }
header.site {
  position: sticky; top: 0; z-index: 10; padding-block: 0; background: rgba(10,14,23,.86);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
header.site nav { padding-block: .15rem; }
header.site nav ul { align-items: center; gap: .15rem; margin-inline: 0; }
header.site nav li { padding: .45rem .1rem; }
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; }
nav li a.brand { padding: .25rem 0; margin: 0; }
.brand { color: var(--text); text-decoration: none; }
/* QR Intercom mark on its tile (logo guide: Signal gradient, 22% corners, white mark at 62.5%). */
.qri-tile {
  flex: none; display: grid; place-items: center; width: 1.75rem; aspect-ratio: 1; border-radius: 22%;
  color: #fff; background: linear-gradient(45deg, #38BDF8, #1D4ED8);
}
.qri-tile svg { width: 62.5%; height: 62.5%; }
nav li a.pill { margin: 0; padding: .3rem .8rem; border-radius: 999px; color: var(--muted); font-size: .9rem; }
nav li a.pill:hover { background: var(--raised); }
form.inline { display: inline; margin: 0; }
form.inline button { margin: 0; padding: .3rem .8rem; font-size: .875rem; width: auto; }
header.site form.inline button { border-radius: 999px; }

nav.tabs { display: block; border-bottom: 1px solid var(--border); }
nav.tabs ul {
  display: flex; flex-wrap: nowrap; gap: .25rem; width: 100%; margin: 0 auto; padding-inline: 1rem;
  overflow-x: auto; scrollbar-width: none;
}
nav.tabs ul::-webkit-scrollbar { display: none; }
nav.tabs li { padding: 0; }
nav.tabs a {
  display: block; margin: 0; padding: .7rem .7rem .6rem; border-radius: 0; color: var(--muted);
  font-size: .9rem; white-space: nowrap; border-bottom: 2px solid transparent;
}
nav :is(a.pill, .tabs a):hover, nav.tabs a[aria-current="page"] { color: var(--text); text-decoration: none; }
nav.tabs a[aria-current="page"] { font-weight: 600; border-bottom-color: var(--primary); }

body > main.container { padding-block: 1.75rem 3rem; }
main > h1 + p { color: var(--muted); font-size: .9rem; margin: -.6rem 0 1.5rem; }
main section { margin-block: 2rem 0; }
main > section:first-of-type, .stats + section { margin-top: 1.5rem; }

/* Bare (auth) pages */
body.bare > main.container { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding-block: 2rem; }
.bare-brand { display: flex; justify-content: center; margin-bottom: 1.25rem; font-size: 1.15rem; }
.narrow { width: 100%; max-width: 26rem; margin-inline: auto; padding: 1.75rem; }
.narrow h1 { font-size: 1.35rem; margin-bottom: 1.25rem; }
.narrow form:not(.inline) button[type="submit"] { width: 100%; }
.narrow > p:last-child { margin-bottom: 0; font-size: .9rem; text-align: center; color: var(--muted); }

/* ── Buttons ── */
button, [role="button"], [type="submit"] { font-weight: 600; }
button:not(.secondary, .outline, .danger):active { background: var(--primary-active); border-color: var(--primary-active); }
:is(button, [role="button"]).secondary.outline { color: var(--text); border-color: var(--border); background: transparent; }
button.secondary.outline:hover { background: var(--raised); border-color: var(--border-hi); }
:is(button, [role="button"]).danger { background: transparent; border-color: rgba(255,77,79,.55); color: var(--danger); }
:is(button, [role="button"]).danger:hover { background: rgba(255,77,79,.12); border-color: var(--danger); color: #ff7072; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-block: .5rem 1rem; }
.pager { display: flex; gap: 1rem; justify-content: flex-end; margin-block: 1rem; font-size: .9rem; }
form.filters > a, article.confirm .cancel { margin-left: .75rem; }

article.confirm { border-color: rgba(255,77,79,.45); background: color-mix(in srgb, var(--danger) 6%, var(--surface)); }
article.confirm h2 { color: var(--danger); }

/* ── Tones ── */
.alert, .badge, .dot { --tone: var(--muted); }
.alert:not([data-tone]) { --tone: var(--primary); }
[data-tone="success"] { --tone: var(--success); }
[data-tone="warning"] { --tone: var(--warning); }
[data-tone="danger"] { --tone: var(--danger); }
[data-tone="info"] { --tone: var(--primary-hover); }
[data-tone="purple"] { --tone: var(--purple); }
[data-tone="muted"] { --tone: var(--muted); }
.alert {
  padding: .75rem 1rem; margin-bottom: 1rem;
  border: 1px solid color-mix(in srgb, var(--tone) 40%, transparent); border-left: 3px solid var(--tone);
  background: color-mix(in srgb, var(--tone) 10%, var(--surface));
}
.badge {
  display: inline-flex; align-items: center; gap: .4em; padding: .1em .6em; border-radius: 999px;
  vertical-align: middle; font-size: .78rem; font-weight: 500; line-height: 1.6; white-space: nowrap;
  color: var(--tone); background: color-mix(in srgb, var(--tone) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--tone) 28%, transparent);
}
.badge::before { content: ""; width: .45em; height: .45em; border-radius: 50%; background: currentColor; }
.badge + .badge { margin-left: .25rem; }
.dot {
  display: inline-block; width: .5rem; height: .5rem; margin-right: .55rem; border-radius: 50%;
  vertical-align: .05em; background: var(--tone);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tone) 18%, transparent);
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); gap: .75rem; margin-block: 0 1.5rem; }
.stats article { --tone: var(--text); margin: 0; padding: .9rem 1.1rem; }
.stats strong { display: block; font-size: 1.85rem; font-weight: 700; line-height: 1.15; color: var(--tone); }
.stats small { display: block; margin-top: .2rem; color: var(--muted); font-size: .8rem; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.table-wrap > table, .grid > .table-wrap { margin: 0; }
table, .stats strong { font-variant-numeric: tabular-nums; }
th, td { background: transparent; border-bottom: 1px solid var(--border); padding: .6rem .85rem; vertical-align: middle; }
thead th, .stats span { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
thead th { font-weight: 600; white-space: nowrap; }
tbody tr:last-child > *, tr.ev:has(+ .ev-more[hidden]:last-child) > * { border-bottom: 0; }
tbody tr:hover > * { background: var(--tint); }
table.compact :is(th, td) { padding: .45rem .75rem; }
table.compact td { font-size: .9rem; }
td.empty { text-align: center; padding-block: 1.25rem; }
td small.mono { display: block; margin-top: .1rem; }
td :is(input, select) { margin: 0; --pico-form-element-spacing-vertical: .3rem; }
td form.inline select { width: auto; display: inline-block; }
main form:not(.inline) button[type="submit"] { width: auto; min-width: 8rem; }

/* Events: ⋯ unfolds tr.ev-more (app.js) */
table.events { width: 100%; table-layout: auto; }
table.events td:is(.time, .detail) { white-space: nowrap; }
table.events td.time { color: var(--muted); font-size: .82rem; }
table.events :is(thead th:last-child, td.detail) { width: 2.5rem; padding-inline: .25rem; text-align: center; }
table.events td.detail { padding-block: 0; }
table.events td.detail { position: relative; }
.ev-toggle {
  width: 2rem; height: 1.5rem; margin: 0; padding: 0; vertical-align: middle;
  line-height: 1; font-weight: 400; color: var(--muted); background: transparent; border: 0; border-radius: 6px;
}
/* Hit area = the whole cell, never past it: no row overhang, no overlap with the next row. */
.ev-toggle::before { content: ""; position: absolute; inset: 0; }
.ev-toggle:is(:hover, [aria-expanded="true"]) { background: var(--raised); color: var(--text); }
tr.ev:has(+ .ev-more:not([hidden])) > * { border-bottom: 0; background: var(--raised); }
tr.ev:has(+ .ev-more:not([hidden])) > :first-child, tr.ev-more > td { box-shadow: inset 2px 0 var(--primary); }
tr.ev-more > td { padding: 0 .75rem .6rem; background: var(--raised); }
.ev-detail-body {
  display: flex; flex-wrap: wrap; gap: .2rem 1.25rem; padding-left: .5rem; font-family: var(--mono);
  font-size: .75rem; color: var(--muted); overflow-wrap: anywhere;
}
code.ev-type { padding: 0; background: none; color: var(--text); font-family: inherit; font-size: inherit; font-weight: 500; }
code.ev-type::after { content: " ·"; color: var(--muted); font-weight: 400; }

/* ── Forms ── */
label, fieldset legend { font-size: .9rem; }
fieldset legend { font-weight: 600; }
fieldset.types { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
fieldset.types label { margin: 0; }
fieldset.types legend { width: 100%; }
form.filters { padding: 1rem 1.1rem .25rem; margin-bottom: 1.25rem; }
.inline-filters { display: flex; gap: .5rem; align-items: center; max-width: 28rem; padding: .6rem; margin-bottom: 1.25rem; }
.inline-filters :is(select, button) { margin: 0; }
input.copy { font-family: var(--mono); font-size: .85rem; }
.qr svg { width: min(320px, 100%); height: auto; background: #fff; padding: .75rem; border-radius: var(--radius); }
.logo-preview img { max-height: 120px; max-width: 100%; background: #fff; padding: .5rem; border-radius: 8px; }

@media (max-width: 640px) {
  .ev-date { display: none; }
  .ev-detail-body { position: sticky; left: .75rem; max-width: calc(100vw - 4rem); }
  h1 { font-size: 1.4rem; }
  header.site nav { flex-wrap: wrap; }
  nav li a.pill { padding-inline: .55rem; }
  .narrow { padding: 1.25rem; }
}

/* ── Staff shell: header building selector, role chip, section tabs ── */
header.site .bsel { display: inline-flex; align-items: center; gap: .5rem; margin: 0 0 0 .75rem; font-size: .82rem; color: var(--muted); }
header.site .bsel label { display: inline-flex; align-items: center; gap: .5rem; margin: 0; font-size: inherit; color: inherit; }
header.site .bsel select {
  width: auto; min-width: 13rem; margin: 0; padding: .3rem 2rem .3rem .65rem; font-size: .9rem;
  background-position: center right .55rem; --pico-form-element-spacing-vertical: .3rem;
}
header.site .bsel button { width: auto; margin: 0; padding: .3rem .75rem; font-size: .82rem; border-radius: 8px; }
header.site .bsel strong { color: var(--text); font-size: .9rem; font-weight: 600; }
.role-chip {
  display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 500;
  color: var(--primary-hover); background: var(--tint); border: 1px solid var(--border-hi);
}
/* Admin-only marker on a tab or heading */
.adm {
  display: inline-block; margin-left: .4rem; padding: .05rem .3rem; border: 1px solid var(--border-hi); border-radius: 4px;
  font-size: .62rem; font-weight: 700; letter-spacing: .06em; line-height: 1.3; color: var(--muted); vertical-align: .1em;
}
/* A section that needs a building while "All buildings" is selected */
nav.tabs span[aria-disabled="true"] {
  display: block; padding: .7rem .7rem .6rem; color: color-mix(in srgb, var(--muted) 55%, transparent);
  font-size: .9rem; white-space: nowrap; border-bottom: 2px solid transparent; cursor: not-allowed;
}
nav.tabs span[aria-disabled="true"][aria-current="page"] { border-bottom-color: var(--border-hi); }

/* ── Page head: h1 + lead on the left, actions (Show deleted, buttons) on the right ── */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1.5rem; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; }
.page-head :is(.lead, h1 + p) { margin: .35rem 0 0; color: var(--muted); font-size: .9rem; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding-bottom: .2rem; }
.page-actions :is(button, [role="button"]) { width: auto; margin: 0; padding: .4rem .9rem; font-size: .875rem; }
/* Section heading with a link or action on the right */
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1rem; margin-bottom: .75rem; }
.section-head > h2 { margin: 0; }
.section-head > a { font-size: .875rem; }
small.block { display: block; }

/* Switch: <a class="switch" role="switch" aria-checked> (a link toggling ?deleted=1, works without JS) */
.switch { position: relative; display: inline-flex; align-items: center; gap: .55rem; font-size: .85rem; color: var(--muted); white-space: nowrap; cursor: pointer; }
.switch::before { content: ""; flex: none; width: 2.25rem; height: 1.25rem; border-radius: 999px; background: var(--border); transition: background .15s; }
.switch::after {
  content: ""; position: absolute; left: .19rem; top: 50%; width: .875rem; height: .875rem; margin-top: -.4375rem;
  border-radius: 50%; background: var(--muted); transition: left .15s, background .15s;
}
.switch[aria-checked="true"]::before { background: var(--primary); }
.switch[aria-checked="true"]::after { left: 1.19rem; background: var(--pico-primary-inverse); }
:where(a.switch):hover { color: var(--text); text-decoration: none; }
.switch:focus-visible { outline: none; }
.switch:focus-visible::before { box-shadow: 0 0 0 3px var(--focus); }

/* Soft-deleted rows / items: dimmed, name struck through; the Restore action stays legible */
tr.deleted > td, .deleted:not(tr) { opacity: .55; }
tr.deleted > td:has(form, button) { opacity: 1; }
.deleted :is(.name, td:first-child > a) { text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 70%, transparent); }
tr.deleted:hover > * { background: transparent; }

/* ── I/O strip: <div class="io"> of .pin cells (OUT1–4, a .sep, IN1–8). Each cell: label, door line
   (blank when unmapped), then the state pushed to the bottom with mV or relay buttons under it. ── */
.io { display: flex; flex-wrap: wrap; align-items: stretch; gap: .5rem .6rem; }
.io .pin:not([data-tone]) { --tone: var(--muted); }
.io .pin {
  flex: 1 0 3.5rem; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: .2rem;
  padding: .45rem .35rem; border: 1px solid var(--border); border-radius: 8px; background: var(--sunken);
}
.io .pin small { font-family: var(--mono); font-size: .7rem; color: var(--muted); }
.io .pin > span { margin-top: auto; font-size: .78rem; font-weight: 600; color: var(--tone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.io .pin[data-tone] { border-color: color-mix(in srgb, var(--tone) 55%, var(--border)); }
.io .pin[data-tone]:not([data-tone="muted"]) { background: color-mix(in srgb, var(--tone) 9%, var(--sunken)); }
.io .pin[data-tone="muted"] { border-color: var(--border); }
.io .pin[data-tone="muted"] > span { color: var(--muted); }
.io .pin.out[data-tone="muted"] { border-color: var(--border-hi); }
.io .sep { flex: 0 0 2px; align-self: stretch; border-radius: 1px; background: var(--border-hi); }
.io .pin small.mv { font-size: .66rem; }
.io .pin.out { flex: 2 0 7.25rem; }
.io .relay-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .25rem; padding-top: .15rem; }
.io .relay-actions form.inline button { padding: .15rem .5rem; font-size: .72rem; }
.section-head .io-legend { margin: 0 auto 0 1rem; }
.io-legend { display: inline-flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .75rem; }
.io-legend .dot { margin-right: .35rem; }

/* ── Settings: side nav (.side) + a column of .card sections ── */
.settings { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.5rem; }
.settings > .side { position: sticky; top: 7.5rem; flex: 1 1 11rem; max-width: 14rem; display: flex; flex-direction: column; gap: 2px; }
.settings > :not(.side) { flex: 999 1 35rem; min-width: 0; display: flex; flex-direction: column; gap: 1.25rem; }
.side a { display: block; padding: .45rem .75rem; border-radius: 8px; color: var(--muted); font-size: .9rem; }
.side a:hover { background: var(--raised); color: var(--text); text-decoration: none; }
.side a[aria-current="true"] { background: var(--raised); color: var(--text); font-weight: 600; }

/* ── Card: a bordered section with an h2, an optional .lead and its content ── */
.card {
  display: flex; flex-direction: column; gap: 1rem; margin: 0; padding: 1.25rem 1.4rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
main section.card { margin-block: 0; }
main section.card + section.card { margin-top: 1.25rem; }
.settings section.card + section.card { margin-top: 0; }
.card[id] { scroll-margin-top: 7.5rem; }
.card > h2 { margin: 0; font-size: 1.05rem; }
.card :is(.lead, h2 + p) { margin: 0; color: var(--muted); font-size: .9rem; }
.card > :last-child, .card form:last-child { margin-bottom: 0; }
.card .table-wrap { margin: 0; }
/* Card whose table runs edge to edge: <section class="card flush"><div class="card-head">h2 + actions</div>table</section> */
.card.flush { gap: 0; padding: 0; overflow: hidden; }
.card.flush .table-wrap { border: 0; border-radius: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding: .85rem 1rem; border-bottom: 1px solid var(--border); }
.card-head > h2 { margin: 0; font-size: 1rem; }
.card-head :is(button, [role="button"]) { width: auto; margin: 0; padding: .35rem .8rem; font-size: .85rem; }

/* ── Filter bar: one row of compact controls (GET form) ── */
form.filterbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.25rem; padding: .75rem 1rem; margin-bottom: 1.25rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.filterbar :is(input:not([type="checkbox"], [type="radio"]), select) { width: auto; margin: 0; padding: .35rem .65rem; font-size: .875rem; --pico-form-element-spacing-vertical: .35rem; }
.filterbar select { padding-right: 2rem; }
.filterbar input[type="search"] { flex: 1 1 14rem; min-width: 10rem; }
.filterbar > label, .filterbar fieldset:not([role]) > label { display: inline-flex; align-items: center; gap: .45rem; margin: 0; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.filterbar fieldset:not([role]) { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .9rem; width: auto; margin: 0; padding: 0; border: 0; }
.filterbar legend { float: left; margin-right: .25rem; padding: 0; font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.filterbar :is(input[type="checkbox"], input[type="radio"]) { margin: 0; }
.filterbar fieldset:not([role]) > label:has(input:checked) { color: var(--text); }
.filterbar :is(button, [role="button"]) { width: auto; margin: 0; padding: .35rem .9rem; font-size: .875rem; }
main form.filterbar button[type="submit"] { min-width: 0; }
.filterbar .grow { flex: 1 1 auto; }

/* ── Segmented control: <div class="seg"> of buttons/links, or labels wrapping radios (no JS) ── */
.seg { display: inline-flex; flex-wrap: nowrap; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg > :is(a, button, label) {
  width: auto; margin: 0; padding: .35rem .8rem; border: 0; border-right: 1px solid var(--border); border-radius: 0;
  background: transparent; color: var(--muted); font-size: .85rem; font-weight: 400; white-space: nowrap; cursor: pointer;
}
.seg > :last-child { border-right: 0; }
.seg > :is(a, button, label):hover { color: var(--text); background: var(--raised); text-decoration: none; }
.seg > :is([aria-pressed="true"], [aria-current]:not([aria-current="false"]), label:has(input:checked)) { background: var(--raised); color: var(--text); font-weight: 600; }
.seg input[type="radio"] { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.seg label:has(input:focus-visible) { box-shadow: inset 0 0 0 2px var(--focus); }

/* Search-term highlight */
mark { padding: 0 1px; border-radius: 3px; color: #ffd27a; background: color-mix(in srgb, var(--warning) 28%, transparent); }

/* ── Phone preview: <figure class="phone"><div class="screen">…</div></figure>; add .peek to show only the top ── */
.phone {
  flex: none; width: 16.5rem; height: 34rem; margin: 0; padding: .55rem; border-radius: 2.75rem;
  background: #1c1f26; border: 1px solid #3a3f4b; box-shadow: 0 0 0 2px var(--bg), 0 18px 40px rgba(0,0,0,.5);
}
.phone .screen {
  position: relative; display: flex; flex-direction: column; gap: .75rem; height: 100%; overflow: hidden;
  padding: 3.5rem 1rem 1rem; border-radius: 2.25rem; background: var(--bg); font-size: .85rem;
}
.phone .screen::before {
  content: ""; position: absolute; top: .75rem; left: 50%; width: 5.1rem; height: 1.5rem; margin-left: -2.55rem;
  border-radius: 999px; background: #000;
}
.phone.peek { height: 16.5rem; padding-bottom: 0; border-bottom: 0; border-radius: 2.75rem 2.75rem 0 0; overflow: hidden; }
.phone.peek .screen { height: 33rem; }

/* ── QR actions: download links (PDF, SVG) and the rotate button ── */
.qr-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-block: .25rem; }
.qr-actions :is(a[role="button"], button) { display: inline-flex; align-items: center; gap: .45rem; width: auto; margin: 0; padding: .45rem .9rem; font-size: .875rem; }
.qr-actions svg { width: 1em; height: 1em; flex: none; }

@media (max-width: 640px) {
  header.site .bsel { margin-left: 0; }
  header.site .bsel select { min-width: 0; max-width: 11rem; }
  header.site .bsel label > span, header.site span.bsel > span:first-child { display: none; }
  .settings > .side { position: static; flex: 1 1 100%; max-width: none; flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .settings > .side a { white-space: nowrap; }
  .page-head { align-items: flex-start; }
  .card { padding: 1rem; }
}

/* ── activity ── */
.activity-pair { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr)); gap: 1.25rem; margin-bottom: 1.25rem; }
main .activity-pair section.card + section.card { margin-top: 0; }
.activity-pair + section.card { margin-bottom: 1.25rem; }
.card.flush > p.muted { margin: 0; padding: 1rem; }
.card.flush > .pager { margin: 0; padding: .75rem 1rem; border-top: 1px solid var(--border); }
.card.flush > .pager:empty { display: none; }
.card-head > span.muted { font-size: .85rem; }
.page-actions details.dropdown { margin: 0; }
.page-actions details.dropdown > summary { padding: .4rem 2.2rem .4rem .9rem; font-size: .875rem; height: auto; }

/* ── doors & devices ── */
section.devices > .card + .card { margin-top: .9rem; }
.card.device { gap: .6rem; padding: 1rem 1.2rem; }
.dev-head { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem .75rem; }
.dev-head .dev-name { font-weight: 600; }
.dev-head .dev-doors { margin-left: auto; }
.dev-head form.inline { margin-left: auto; }
.card.device .reading { margin: 0; font-size: .8rem; }
.io .pin small.map { font-family: inherit; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card.device.deleted { opacity: 1; }
.card.device.deleted .dev-head > :not(form) { opacity: .55; }

/* ── admin extras: collapsible panels (device Manage, firmware release, tenant import) ── */
details.dev-manage { margin: .25rem 0 0; border-top: 1px solid var(--border); padding-top: .6rem; }
details.dev-manage > summary { font-size: .875rem; color: var(--muted); }
details.dev-manage[open] > summary { margin-bottom: .75rem; }
details.dev-manage h3 { margin: 1rem 0 .5rem; font-size: .9rem; }
details.dev-manage form button[type="submit"] { width: auto; }
details.card { display: block; }
details.card + details.card, section.card + details.card, details.card + section.card { margin-top: 1rem; }
details.card > summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; margin: 0; }
details.card > summary::after { margin-left: auto; }
details.card[open] > summary { margin-bottom: 1rem; }
details.card h3 { margin: 1rem 0 .5rem; font-size: .95rem; }
details.card form button[type="submit"] { width: auto; }
.token-notice p { margin: .35rem 0 .6rem; }
.token-notice input.copy { margin: 0; font-family: var(--pico-font-family-monospace); }
@media (min-width: 768px) { .grid.building-fields { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) 13rem; } }

/* ── tenancy / account edit: cards, PIN beside Password (.grid.cards) ── */
.grid.cards { margin-block: 1.25rem; align-items: stretch; }
@media (min-width: 768px) { .grid.cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid.cards > .card { margin: 0; }
@media (min-width: 768px) { .grid.tenancy-fields { grid-template-columns: 8rem minmax(0, 1fr) minmax(0, 1fr) 11rem; } }

/* ── accounts ── */
/* Search: Pico input group (<fieldset role="group">), the search icon is Pico's own */
.filterbar fieldset.search { flex: 1 1 20rem; width: auto; min-width: 0; margin: 0; }
.filterbar fieldset.search input[type="search"] { flex: 1 1 auto; min-width: 0; padding-inline-start: 2.2rem; background-position: center left .75rem; }
.filterbar fieldset.search button { flex: none; padding-inline: 1rem; }
td small.sub { display: block; font-size: .75rem; }
td a.name { font-weight: 600; }
form.role-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
form.role-form select { width: auto; margin: 0; }
form.role-form button { width: auto; margin: 0; }

/* ── settings ── */
.card.flush .card-body { margin: 0; padding: .85rem 1rem; }
.card.flush .card-body .alert { margin: 0; }
.card.flush > p.card-body.muted { padding: 1rem; }
.card.flush .table-wrap + form.card-body, .card.flush p.card-body + form.card-body { border-top: 1px solid var(--border); }
.card.flush td.num form.inline { display: inline-block; }
.card.flush td.num button { width: auto; margin: 0; padding: .3rem .75rem; font-size: .85rem; }
form.window-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .75rem; }
form.window-form label { flex: 1 1 8rem; margin: 0; }
form.window-form :is(select, input) { margin: 0; }
form.window-form button { width: auto; margin: 0; }
.settings .card form button[type="submit"] { width: auto; }
.settings .card fieldset { margin-bottom: 1rem; }
.branding { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.5rem; }
.branding-controls { flex: 1 1 16rem; min-width: 0; display: flex; flex-direction: column; gap: 1rem; }
.branding-controls form { margin: 0; }
.branding-controls form.inline button { width: auto; margin: 0; }
.logo-current { display: flex; align-items: center; gap: 1rem; }
.logo-current > div { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.logo-current .logo-preview { margin: 0; flex: none; }
.logo-current .logo-preview img { max-height: 4.5rem; max-width: 9rem; }
.logo-empty { flex: none; display: grid; place-items: center; width: 4.5rem; height: 4.5rem; border: 1px dashed var(--border-hi); border-radius: 8px; color: var(--muted); font-size: .75rem; }
/* Visitor page look-alike inside .phone (mirrors public/visitor/index.html) */
.visitor-preview .screen { gap: .6rem; }
.vp-brand { display: flex; align-items: center; gap: .6rem; }
.vp-brand > div { display: flex; flex-direction: column; min-width: 0; }
.vp-logo { flex: none; width: 2.4rem; height: 2.4rem; object-fit: contain; padding: .2rem; border-radius: 9px; background: #fff; border: 1px solid var(--border); }
.vp-logo-empty { background: var(--raised); }
.vp-name { font-size: 1rem; line-height: 1.2; overflow-wrap: anywhere; }
.vp-sub { display: flex; align-items: center; gap: .35rem; font-size: .62rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.vp-sub svg { width: .8rem; height: .8rem; flex: none; }
.vp-lead { color: var(--muted); }
.vp-contact { display: flex; flex-direction: column; padding: .55rem .8rem; border-radius: 10px; background: var(--primary); color: #06101f; }
.vp-contact small { font-size: .72rem; opacity: .8; }
.vp-contact.off { background: var(--raised); color: var(--muted); }
.vp-search { padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: #66718a; }
.vp-dir { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.vp-dir li { display: flex; align-items: center; gap: .6rem; margin: 0; padding: .45rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); list-style: none; }
.vp-unit { flex: none; min-width: 2.2rem; padding: .1rem .4rem; border-radius: 6px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--tint); color: var(--primary-hover); border: 1px solid rgba(45,140,255,.35); }
.qr-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 1.5rem; }
.qr-row figure.qr { flex: none; margin: 0; }
.qr-row figure.qr svg { width: 12.5rem; }
.qr-info { flex: 1 1 16rem; min-width: 0; display: flex; flex-direction: column; gap: .9rem; }
.qr-info > div:first-child { display: flex; flex-direction: column; gap: .25rem; }
.qr-info .visitor-url { font-family: var(--mono); font-size: .875rem; overflow-wrap: anywhere; }

/* Tenant import review (views/manager/TenantImport.tsx) */
.import-row .section-head > h2 { font-size: 1rem; }
.import-row .seg { flex-wrap: wrap; }
td .seg { white-space: nowrap; }
