:root {
  color-scheme: light dark;
  --bg: #fff; --fg: #14171f; --muted: #596073; --line: #d3d8e2; --line-strong: #7d849a; --panel: #eef0f5;
  --accent: #2f55d4; --accent-fg: #fff; --danger: #b3261e;
  --radius: 12px; --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(20, 23, 31, 0.08), 0 1px 3px rgba(20, 23, 31, 0.1);
  --shadow-2: 0 10px 28px rgba(20, 23, 31, 0.2), 0 2px 6px rgba(20, 23, 31, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --fg: #eceef3; --muted: #a6adbd; --line: #2e3340; --line-strong: #6f778a; --panel: #20242e;
    --accent: #93aaff; --accent-fg: #10131a; --danger: #f2b8b5;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-2: 0 10px 28px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
  }
}

/* Web Awesome reads its own tokens; point them at ours so it follows the same colours, both schemes and the radius.
   Ours are not in a layer, so they win over its theme. Only wa-details and wa-callout are used (src/wa.js). */
:root {
  --wa-color-surface-default: var(--bg); --wa-color-surface-raised: var(--panel); --wa-color-surface-lowered: var(--panel);
  --wa-color-surface-border: var(--line-strong); --wa-color-text-normal: var(--fg); --wa-color-text-quiet: var(--muted);
  --wa-color-focus: var(--accent); --wa-border-radius-m: var(--radius); --wa-border-radius-l: var(--radius);
  --wa-color-brand-fill-quiet: var(--panel); --wa-color-brand-border-quiet: var(--line); --wa-color-brand-on-quiet: var(--fg);
  --wa-color-brand-fill-normal: var(--panel); --wa-color-brand-border-normal: var(--accent); --wa-color-brand-on-normal: var(--fg);
  --wa-font-family-body: inherit; --wa-font-size-m: 1em;
  color-scheme: light dark; color: var(--fg);
}
wa-details { margin: 8px 0; font-size: 18px; }
wa-details::part(summary) { min-height: 44px; font-weight: 600; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  font: 18px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg); color: var(--fg);
}

/* Phone order: header, banner, screen, mode bar, tabs. Wide order: header, banner, tabs, mode bar, screen. */
#header { order: 1; display: flex; align-items: center; gap: 12px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--bg); box-shadow: var(--shadow-1); position: relative; z-index: 2; }
#header h1 { flex: 1; margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#top-banner { order: 2; padding: 10px 16px; background: var(--danger); color: var(--bg); font-weight: 600; }
#screen { order: 3; flex: 1; min-height: 0; overflow: auto; }
#mode-bar { order: 4; display: flex; align-items: center; gap: 12px; padding: 8px 16px; border-top: 1px solid var(--line); background: var(--panel); }
#mode-banner { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#tabs { order: 5; display: flex; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs button { flex: 1; min-height: 56px; border: 0; border-radius: 0; background: none; box-shadow: none; color: var(--muted); font-weight: 500; }
#tabs button[aria-current="page"] { color: var(--fg); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }
@media (min-width: 700px) {
  #tabs { order: 2; border-top: 0; border-bottom: 1px solid var(--line); padding-bottom: 0; }
  #tabs button { flex: none; padding: 8px 24px; }
  #tabs button[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--accent); }
  #mode-bar { order: 3; border-top: 0; border-bottom: 1px solid var(--line); }
  #screen { order: 4; }
}
body.no-project #header, body.no-project #tabs, body.no-project #mode-bar { display: none; }

button, input { font: inherit; color: inherit; }
button { min-width: 44px; min-height: 44px; padding: 8px 16px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--panel); font-weight: 500; cursor: pointer; transition: background-color 0.12s, box-shadow 0.12s, transform 0.06s; }
button.main { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 650; box-shadow: var(--shadow-1); }
@media (hover: hover) { button:not(:disabled):hover { background-image: linear-gradient(rgba(127, 127, 127, 0.14), rgba(127, 127, 127, 0.14)); } }
button:not(:disabled):active { transform: translateY(1px); }
@media (prefers-reduced-motion: reduce) { button { transition: none; } button:not(:disabled):active { transform: none; } }
button.plain { background: none; border: 0; text-decoration: underline; align-self: flex-start; }
p button.plain { display: inline; min-width: 0; min-height: 0; padding: 6px 2px; }
button.danger { color: var(--danger); }
button.row { display: flex; flex-direction: column; align-items: flex-start; width: 100%; text-align: left; }
button:disabled { opacity: 0.5; }
button[aria-pressed="true"] { border-width: 2px; border-color: var(--accent); font-weight: 700; }
button[aria-pressed="true"]::before { content: "\2713\00a0"; }
input[type="text"], input[type="number"] { display: block; width: 100%; min-height: 44px; margin-top: 4px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); }
label { display: block; font-weight: 600; font-size: 16px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.page { display: flex; flex-direction: column; gap: 16px; max-width: 640px; margin: 0 auto; padding: 16px; }
.page h1, .page h2, .page p { margin: 0; }
.page h2 { font-size: 20px; }
.page > button { align-self: flex-start; }
.small { font-size: 16px; font-weight: 400; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.buttons { display: flex; flex-wrap: wrap; gap: 12px; }
.buttons.equal { flex-direction: column; }
.buttons.equal button { width: 100%; min-height: 64px; }
.rows { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 0; list-style: none; }
.rows li { display: flex; flex-direction: column; gap: 8px; }
.checklist { margin: 0; padding: 12px 12px 12px 40px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.checklist .done { color: var(--muted); }
.wide-only { display: none; }
@media (min-width: 700px) { .wide-only { display: inline; } }

.plan-screen { display: flex; flex-direction: column; height: 100%; }
.plan-screen > .page { width: 100%; box-sizing: border-box; }
.floor-switch { display: flex; gap: 8px; padding: 8px 16px; overflow-x: auto; }
.plan { position: relative; flex: 1; min-height: 50vh; overflow: hidden; background: var(--panel); }
.floor-page .plan { flex: none; height: 60vh; }
.plan-svg { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; }
.plan-message { position: absolute; top: 40%; left: 16px; right: 16px; margin: 0; text-align: center; pointer-events: none; }
.zoom-buttons { position: absolute; right: 12px; top: 12px; display: flex; gap: 8px; }
.zoom-buttons button { padding: 8px 6px; background: var(--bg); }
.zoom-buttons button:last-child { padding-inline: 12px; }

dialog.sheet { width: 100%; max-width: 640px; max-height: 90vh; margin: auto auto 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); border: 0; border-radius: 20px 20px 0 0; background: var(--bg); color: var(--fg); box-shadow: var(--shadow-2); }
dialog.sheet:focus { outline: none; }
dialog.sheet[open] { animation: sheet-in 0.2s ease-out; }
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.sheet[open] { animation: none; } }
dialog.sheet > * { margin: 0; }
dialog.sheet > * + * { margin-top: 12px; }
dialog.sheet h2 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
dialog.sheet::backdrop { background: rgba(10, 12, 18, 0.5); backdrop-filter: blur(2px); }
@media (min-width: 700px) { dialog.sheet { margin: auto; border-radius: 20px; } }
.preview { display: block; max-width: 100%; max-height: 45vh; margin: 0 auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }

#toast { position: fixed; left: 0; right: 0; top: calc(72px + env(safe-area-inset-top)); z-index: 5; display: flex; justify-content: center; padding: 0 16px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 16px; min-height: 60px; border-radius: 14px; background: var(--fg); color: var(--bg); box-shadow: var(--shadow-2); pointer-events: auto; }
.toast button { background: var(--bg); color: var(--fg); }

/* On the plan. Colours here are fixed, not themed: the picture under them is never inverted for dark mode. */
.fixed { transform: scale(calc(1 / var(--k, 1))); }
.room { fill: rgba(11, 87, 208, 0.12); stroke: #0b57d0; stroke-width: 2px; vector-effect: non-scaling-stroke; }
.room.editing { fill: rgba(11, 87, 208, 0.2); stroke-dasharray: 8 5; }
.room-name { font: 600 16px system-ui, -apple-system, "Segoe UI", sans-serif; fill: #111; stroke: #fff; stroke-width: 4px; paint-order: stroke; pointer-events: none; }
.trace-line { fill: none; stroke: #0b57d0; stroke-width: 3px; vector-effect: non-scaling-stroke; }
.reach { fill: transparent; }
.corner { fill: #fff; stroke: #0b57d0; stroke-width: 3px; }
.corner.first, .spot, .add-corner { fill: #0b57d0; stroke: #fff; stroke-width: 3px; }
.corner.picked { fill: #b3261e; stroke: #fff; }
.add-corner { opacity: 0.85; }
.dot-text { font: 700 14px system-ui, -apple-system, "Segoe UI", sans-serif; fill: #fff; pointer-events: none; }
[data-handle] { cursor: grab; }

dialog.sheet form > * + * { margin-top: 12px; }
dialog.sheet ul, dialog.sheet ol, .steps ol { margin: 0; padding-left: 24px; }
.steps h3 { margin: 12px 0 4px; font-size: 18px; }

/* The bar under the plan: the mode text takes a full line, its buttons follow, and Undo keeps to the right. */
#mode-bar { flex-wrap: wrap; }
#mode-banner:empty { display: none; }
#mode-banner > span { flex: 1 1 100%; }
#undo { margin-left: auto; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 699px) { #mode-banner { flex: 1 1 100%; } }

/* Markers. Fixed colours, as for outlines. */
.marker-shape .halo { fill: none; stroke: #fff; stroke-width: 6px; }
.marker-shape .body { stroke: #111; stroke-width: 2px; }
.outlet .body { fill: #0b57d0; }
.switch .body { fill: #188038; }
.light .body { fill: #f9ab00; }
.other .body, .custom .body { fill: #8430ce; }
.marker-text { font: 700 12px system-ui, -apple-system, "Segoe UI", sans-serif; fill: #fff; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.marker-badge, .marker-label { font: 700 16px system-ui, -apple-system, "Segoe UI", sans-serif; stroke: #fff; stroke-width: 4px; paint-order: stroke; pointer-events: none; }
.marker-badge { fill: #b3261e; }
.marker-label { fill: #111; text-anchor: middle; }
.ring { fill: none; stroke: #b3261e; stroke-width: 3px; }
.pulse .ring { animation: pulse 0.7s ease-out 3; }
@keyframes pulse { from { transform: scale(0.6); opacity: 1; } to { transform: scale(1.7); opacity: 0.25; } }
@media (prefers-reduced-motion: reduce) { .pulse .ring { animation: none; } } /* a steady ring instead */
.marker.moving .body { stroke: #b3261e; stroke-width: 3px; }
.glyph { flex: none; }

/* The Add tab and its sheets */
.pick-row { display: flex; align-items: center; gap: 8px; padding: 4px 16px; overflow-x: auto; }
.pick-row button { flex: none; }
.pick-row, .floor-switch { scrollbar-width: none; }
.pick-row::-webkit-scrollbar, .floor-switch::-webkit-scrollbar { display: none; }
button.recent, button.type-button { display: flex; align-items: center; gap: 8px; text-align: left; }
button.type-button { width: 100%; }
.type-button > span { display: flex; flex-direction: column; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.scroll { max-height: 50vh; overflow: auto; }
.scroll h3 { margin: 12px 0 6px; font-size: 18px; }
.plan-hint { margin: 0; padding: 4px 16px; }
#mode-banner .result { display: block; font-size: 22px; }
dialog.sheet.marker h2 { font-size: 32px; }
details > summary { display: flex; align-items: center; min-height: 44px; font-weight: 600; cursor: pointer; }
details > * + * { margin-top: 12px; }

/* The Map tab */
input[type="search"] { flex: 1 1 100%; min-width: 9em; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg); }
input:focus-visible { border-color: var(--accent); }
/* The screen never scrolls as a whole: the floor chips and filters stay put, the plan keeps what is left, and a device's
   details sit over the foot of the plan (or under the list) and scroll inside their own capped height. */
.plan-screen .plan { min-height: 0; }
.map-body { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.details { flex: none; max-height: 40%; overflow: auto; padding: 12px 16px; border-top: 1px solid var(--line); background: var(--bg); }
.map-body.on-plan .details { position: absolute; left: 0; right: 0; bottom: 0; max-height: 45%; box-shadow: var(--shadow-2); }
.details > * { margin: 0; }
.details > * + * { margin-top: 8px; }
.details h2 { font-size: 24px; }
.details ul { padding-left: 24px; }
.list { flex: 1 1 0; min-height: 140px; overflow: auto; padding: 0 16px 16px; }
.list h3 { margin: 16px 0 8px; font-size: 18px; }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.rows li.key-row { flex-direction: row; align-items: center; gap: 12px; }
.key-mark { flex: none; width: 28px; text-align: center; font-size: 20px; color: var(--danger); }
@media (min-width: 700px) {
  .map-body { flex-direction: row; }
  .details, .map-body.on-plan .details { position: static; width: 340px; max-height: none; border-top: 0; border-left: 1px solid var(--line); box-shadow: none; }
}

/* The Switches tab */
.marker.dim { opacity: 0.45; }
.marker.dim .body { stroke-dasharray: 3 2; }
.link-line { stroke: #b3261e; stroke-width: 2px; vector-effect: non-scaling-stroke; pointer-events: none; }

/* The Breakers tab. A space is at least 44 points tall and never relies on colour to say what it is. */
button.big { min-height: 64px; font-size: 20px; }
.page > button.big { align-self: stretch; }
.panel-head { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; background: var(--bg); }
.panel-picture { display: flex; gap: 8px; }
.panel-col { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
button.space { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; min-height: 56px; padding: 6px 10px; text-align: left; border: 2px solid var(--fg); border-radius: var(--radius-sm); background: var(--bg); }
button.space.double { min-height: 118px; border-width: 4px; }
button.space.todo { border: 2px dotted var(--line-strong); color: var(--muted); }
button.space.empty { border: 2px dashed var(--fg); }
button.space.highlight { outline: 4px solid var(--danger); outline-offset: 2px; }
button.space:disabled { opacity: 0.4; }
.space-pair { display: flex; flex-direction: column; gap: 2px; }
.space-pair button.space { min-height: 58px; }
.space-no { font-weight: 700; }
.space-label { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; }
button.numbering { display: flex; align-items: center; gap: 12px; text-align: left; }
.mini { flex: none; padding: 4px 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); font: 14px/1.2 ui-monospace, Consolas, monospace; white-space: pre; }
.card { font-size: 20px; }
.card h3 { margin: 8px 0 0; font-size: 22px; }
.card ul { margin: 0; padding-left: 24px; }
.page h3 { margin: 8px 0 0; font-size: 18px; }
/* A notice: a Web Awesome callout, set apart from the page by a panel, a border and an accent edge. */
.home-card { margin: 0; font-size: 18px; border-left: 4px solid var(--accent); }
.home-card > * { margin: 0; }
.home-card > * + * { margin-top: 8px; }
.home-card button.plain { padding-left: 0; }

/* Five tabs on a phone: tighter, at the smallest text size allowed, so the words do not run into each other. */
@media (max-width: 699px) { #tabs button { padding: 8px 2px; font-size: 16px; } }

/* The breaker test */
button.step { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; width: 100%; min-height: 64px; text-align: left; }
button.step.main span { color: inherit; }
/* A step with nothing to do is dimmed by colour, not opacity, so its words stay readable (4.5:1). */
button.step:disabled { opacity: 1; color: var(--muted); }
button.step:disabled span { color: var(--muted); }
button.dead-toggle[aria-pressed="true"]::before { content: none; } /* it says "No power" in words instead of a tick */
button.dead-toggle[aria-pressed="true"] { border-color: var(--danger); }
.found { font-size: 22px; font-weight: 600; }
#top-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
#top-banner button { background: var(--bg); color: var(--fg); border-color: var(--bg); min-height: 52px; font-size: 18px; }

/* Print. The paper on the screen is the printout: black on white whatever the theme, borders and words instead of
   shading or colour, sizes in points and inches, and no type below 10 pt. */
.print-line { align-items: center; }
body:has(.print-page) #mode-bar { display: none; } /* the Undo bar offers actions from other screens */
.paper-fit { overflow-x: auto; }
.paper-fit { margin: 0 16px 16px; }
.paper { box-sizing: content-box; width: 7.25in; margin: 0 auto; padding: 0.25in; color-scheme: light; background: #fff; color: #000; font: 10pt/1.25 system-ui, -apple-system, "Segoe UI", sans-serif; }
.sheet-page + .sheet-page { margin-top: 0.25in; padding-top: 0.25in; border-top: 1px dashed #000; }
.paper-head { display: flex; flex-wrap: wrap; gap: 2pt 12pt; margin-bottom: 6pt; font-weight: 400; text-align: left; }
.paper-head strong { flex: 1 1 100%; font-size: 13pt; }
.door-card { width: 5in; padding: 0.1in; border: 1px solid #000; }
.door-card.wide { width: 100%; }
.door-cols { display: flex; gap: 6pt; }
.door-col { flex: 1; display: flex; flex-direction: column; gap: 2pt; min-width: 0; }
.door-cell { border: 1px solid #000; }
.door-cell.double { border-width: 2.5pt; }
.door-cell.empty { border-style: dashed; }
.door-line { display: flex; gap: 4pt; min-height: 27pt; padding: 1pt 4pt; } /* 40 spaces fit one page */
.door-cell.double .door-line { min-height: 56pt; }
.door-line + .door-line { border-top: 1px solid #000; }
.door-no { flex: none; min-width: 1.6em; font-size: 11pt; white-space: nowrap; }
.door-text { flex: 1; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 0 6pt; min-width: 0; overflow-wrap: anywhere; }
.door-label { flex: 1; font-weight: 600; }
.door-facts { flex: none; }
.door-rooms { flex: 1 1 100%; }
.door-line.write .door-text { margin-bottom: 5pt; border-bottom: 1px solid #000; }
.full-list { width: 100%; border-collapse: collapse; text-align: left; }
.full-list th, .full-list td { padding: 2pt 8pt 2pt 0; vertical-align: top; }
.full-list .full-breaker th { padding-top: 8pt; border-bottom: 1px solid #000; font-size: 11pt; }
.full-list tr { break-inside: avoid; }
@page { margin: 0.5in; }
@media print {
  :root { color-scheme: light; --bg: #fff; --fg: #000; }
  html, body { height: auto; }
  body { display: block; }
  #header, #top-banner, #tabs, #mode-bar, #toast, .no-print { display: none !important; }
  #screen { overflow: visible; }
  .paper-fit { margin: 0; }
  .paper { margin: 0; padding: 0; zoom: 1 !important; }
  .sheet-page + .sheet-page { margin: 0; padding: 0; border: 0; break-before: page; }
}

/* The chip in the header, and the calm banner (the nudge to back up is not an alarm). */
#chip { flex: none; }
.narrow-only { display: inline; }
@media (min-width: 700px) { .narrow-only { display: none; } }
#top-banner.calm { background: var(--panel); color: var(--fg); border-bottom: 1px solid var(--line); font-weight: 400; }
#top-banner.calm span { flex: 1 1 240px; }
#top-banner.calm .how { display: block; margin-top: 4px; }
#top-banner.calm button { border-color: var(--line-strong); }

/* PDF page thumbnails: a grid that fills the width (2 columns on a phone, more when wide); the sheet scrolls, not the grid. */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
button.page-thumb { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; min-height: 0; padding: 8px; }
button.page-thumb canvas { max-width: 100%; height: auto; max-height: 220px; object-fit: contain; }
