/* SOURCE: regenerate frontend-dist with node frontend/build.mjs. */
/*
 * Keystone palette. Dark is the default (`:root`); light is the explicit opt-in
 * (`html[data-theme="light"]`). Brand anchors are the purple family and the gold.
 * Every text/background pair below was checked for WCAG AA (4.5:1 body text, 3:1 large
 * text and UI boundaries) by frontend/tests/theme-contrast.test.mjs.
 */
:root {
  color-scheme: dark;
  --bg: #160F1C;
  --surface: #211729;
  --surface-raised: #2B1E35;
  --field: #2A1D34;
  --field-border: #7A6A85;
  --ink: #F4EFF7;
  --muted: #C9BDD1;
  --plum: #2B1836;
  --aubergine: #442254;
  --gold: #E3C16A;
  --gold-strong: #D5AF49;
  --on-gold: #1E1426;
  --primary-bg: #D5AF49;
  --primary-ink: #1E1426;
  --primary-hover: #E4C15F;
  --paper: #FBF8F1;
  --success: #6ED39A;
  --success-solid: #1F7A4C;
  --alert: #FF98A8;
  --alert-solid: #B4233A;
  --line: #4A3A56;
  --focus: #E3C16A;
  --bar: #2B1836;
  --bar-ink: #FBF8F1;
  --bar-muted: #D9CFE0;
  --bar-line: #8E7C99;
  --button-bg: #2B1E35;
  --button-ink: #F4EFF7;
  --button-hover: #3A2A47;
  --readonly-bg: #1E1526;
  --backdrop: rgb(5 3 8 / 72%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #FBF8F1;
  --surface: #FBF8F1;
  --surface-raised: #FFFFFF;
  --field: #FFFFFF;
  --field-border: #8E8493;
  --ink: #17121B;
  --muted: #625A68;
  --gold: #8A6A12;
  --gold-strong: #D5AF49;
  --on-gold: #1E1426;
  --primary-bg: #442254;
  --primary-ink: #FFFFFF;
  --primary-hover: #2B1836;
  --success: #276749;
  --success-solid: #276749;
  --alert: #B4233A;
  --alert-solid: #B4233A;
  --line: #D9D3DC;
  --focus: #442254;
  --bar: #2B1836;
  --bar-ink: #FBF8F1;
  --bar-muted: #DAD2DF;
  --bar-line: #817187;
  --button-bg: #FFFFFF;
  --button-ink: #2B1836;
  --button-hover: #F0EBF2;
  --readonly-bg: #F1EDE7;
  --backdrop: rgb(23 18 27 / 62%);
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
h1, h2, h3, h4 { font-family: "Avenir Next", "Trebuchet MS", sans-serif; line-height: 1.2; }
h1, h2, h3, h4, p, label, button, summary, pre { overflow-wrap: anywhere; }
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; font-size: 1rem; }
button, a[href], summary { min-width: 44px; min-height: 44px; }
button {
  max-width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--button-bg);
  color: var(--button-ink);
  cursor: pointer;
  line-height: 1.4;
  white-space: normal;
}
button:hover { background: var(--button-hover); border-color: var(--muted); }
button:disabled { opacity: .65; cursor: default; }
/* Primary actions: Keystone gold on dark, aubergine on light. Always high contrast. */
.primary { background: var(--primary-bg); color: var(--primary-ink); border-color: var(--primary-bg); font-weight: 650; }
.primary:hover { background: var(--primary-hover); color: var(--primary-ink); border-color: var(--primary-hover); }
:where(button, a, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
.app-bar {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  background: var(--bar);
  color: var(--bar-ink);
  border-bottom: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) max(20px, calc((100% - 880px) / 2), env(safe-area-inset-right)) 14px max(20px, calc((100% - 880px) / 2), env(safe-area-inset-left));
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { display: block; width: 60px; max-width: 100%; height: auto; object-fit: contain; }
.app-bar .brand span { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.header-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; min-width: 0; }
.header-greeting { display: flex; gap: .3em; min-width: 0; margin-right: 8px; font-size: .9375rem; color: var(--bar-ink); white-space: nowrap; }
.greeting-name { min-width: 0; max-width: 16ch; overflow: hidden; text-overflow: ellipsis; }
.header-icon { display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; width: 44px; height: 44px; padding: 0; background: transparent; border-color: transparent; color: var(--bar-ink); }
.header-icon svg { flex: none; }
.header-icon:hover { background: var(--aubergine); border-color: var(--bar-line); color: var(--bar-ink); }
.app-bar :focus-visible { outline-color: #E3C16A; }
.capture, .form-host { width: min(100%, 920px); margin-inline: auto; padding-inline: max(20px, env(safe-area-inset-left)) max(20px, env(safe-area-inset-right)); }
.capture { padding-top: 20px; padding-bottom: 22px; }
.voice-controls { display: flex; flex-wrap: wrap; gap: 8px; }
.voice-controls .primary { min-width: 144px; }
.manual-entry { border-color: transparent; background: transparent; font-weight: 400; color: var(--ink); text-decoration: underline; text-underline-offset: 4px; text-decoration-color: var(--gold); }
.manual-entry:hover { background: var(--surface-raised); }
#voice-status { color: var(--muted); font-size: .875rem; margin-top: 10px; }
.form-host { padding-bottom: max(40px, env(safe-area-inset-bottom)); }
.shell > .panel { max-width: 880px; margin: 20px auto; padding: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
html[data-theme="light"] .panel { border-color: transparent; }
/* The form host owns outer gutters; the nested panel owns its inner spacing. */
.state-panel { min-width: 0; padding: 20px; }
.panel-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.panel-heading h2 { font-size: 1.5rem; letter-spacing: -.02em; }
.save-status { color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.save-help { color: var(--alert); font-size: .875rem; margin-top: 10px; }
.save-help:empty, .shift-time-label:empty { display: none; }
.note-step { padding-block: 22px 6px; }
.step-heading { display: flex; align-items: baseline; gap: 12px; font-size: 1.125rem; margin-bottom: 18px; color: var(--ink); }
.step-number { flex: 0 0 30px; font-family: system-ui, sans-serif; font-size: .6875rem; font-variant-numeric: tabular-nums; color: var(--gold); border-left: 2px solid var(--gold); border-bottom: 2px solid var(--gold); padding: 0 0 5px 6px; transform: translateY(-2px); }
.state-grid, .concerns-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.field { display: grid; gap: 6px; min-width: 0; margin-bottom: 16px; }
.field-label { font-size: .875rem; font-weight: 600; }
input, select, textarea { min-width: 0; max-width: 100%; width: 100%; min-height: 44px; border: 1px solid var(--field-border); border-radius: 7px; padding: 10px; color: var(--ink); background: var(--field); }
textarea { display: block; resize: vertical; line-height: 1.5; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input[readonly] { background: var(--readonly-bg); color: var(--muted); }
input[type="checkbox"], input[type="radio"] { flex: 0 0 20px; width: 20px; min-height: 20px; height: 20px; margin: 0; accent-color: var(--gold-strong); }
html[data-theme="light"] input[type="checkbox"], html[data-theme="light"] input[type="radio"] { accent-color: var(--aubergine); }
.shift-time-label { color: var(--muted); font-size: .875rem; margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.resident-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 20px; }
.check { display: flex; gap: 10px; align-items: center; min-width: 44px; min-height: 44px; padding-block: 8px; cursor: pointer; }
.check span { min-width: 0; }
.section-hint { color: var(--muted); font-size: .875rem; margin-bottom: 16px; }
.resident-row { padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-raised); margin-bottom: 16px; }
.resident-row h4 { color: var(--gold); font-size: 1.0625rem; margin-bottom: 16px; }
html[data-theme="light"] .resident-row h4 { color: var(--plum); }
.resident-row .field:last-child { margin-bottom: 0; }
.missing { background: var(--surface-raised); border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.missing strong { font-size: .875rem; }
.missing-list { list-style: none; margin: 8px 0 0; padding: 0; }
.missing-link { display: block; background: transparent; color: var(--ink); text-align: left; border-color: transparent; text-decoration: underline; text-decoration-color: var(--gold); text-underline-offset: 3px; padding: 10px 0; font-size: .875rem; }
.missing-link:hover { background: transparent; border-color: transparent; color: var(--gold); }
.signoff { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 18px; }
.signoff p { flex-basis: 100%; font-size: .875rem; }
.submission-status { color: var(--muted); font-variant-numeric: tabular-nums; }
.submission-error { color: var(--alert); }
.submission-status:empty, .submission-error:empty { display: none; }
.submit-done { background: var(--success-solid); border-color: var(--success-solid); color: #fff; }
.submit-error { background: var(--alert-solid); border-color: var(--alert-solid); color: #fff; }
.submit-warning { background: var(--surface-raised); border-color: var(--gold); color: var(--ink); }
.field-filled { outline: 2px solid var(--gold); outline-offset: 1px; }
.field-corrected { outline: 2px solid var(--alert); outline-offset: 1px; }
html[data-theme="light"] .field-corrected { outline-color: var(--aubergine); }
.field-filled:focus-visible, .field-corrected:focus-visible { outline-width: 3px; outline-offset: 3px; }
/* A native dialog supplies modality; the controller manages scroll and focus. */
.menu-sheet {
  color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  width: min(32rem, calc(100% - 32px)); max-width: 100%;
  max-height: calc(100dvh - 32px); margin: auto;
  padding: 20px; border-radius: 16px; overflow: auto;
  overscroll-behavior: contain;
}
.menu-sheet::backdrop { background: var(--backdrop); }
.sheet-heading { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; }
.sheet-heading h2 { font-size: 1.25rem; }
.sheet-heading button { background: transparent; color: var(--ink); }
.menu-group { display: grid; margin-block: 14px; border-top: 1px solid var(--line); }
.menu-group h3 { color: var(--gold); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
.menu-group h3 { border-bottom: 1px solid var(--line); padding: 10px 4px 8px; }
.menu-group button {
  position: relative; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line);
  border-radius: 0; padding: 12px 32px 12px 4px; background: transparent; color: var(--ink);
}
.menu-group button:hover { background: var(--surface-raised); }
.menu-group button::after {
  content: ''; position: absolute; right: 10px; width: 6px; height: 6px;
  border-right: 1px solid var(--muted); border-top: 1px solid var(--muted); transform: rotate(45deg);
}
.menu-sheet.destination-open .menu-group, .menu-sheet.destination-open .technical-panel { display: none; }
.technical-panel { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 20px; }
summary { padding-block: 12px; cursor: pointer; color: var(--muted); font-size: .875rem; }
.transcript { font-size: .875rem; white-space: pre-wrap; }
.transcript p { margin-block: 12px; }
.transcript .voice-note { color: var(--muted); font-style: italic; }
audio { display: block; width: 100%; min-width: 0; margin-block: 12px; }
.sheet-panel { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 20px; }
.sheet-panel h3 { margin-bottom: 12px; font-size: 1.125rem; }
.sheet-panel p { margin-block: 12px; }
.sheet-panel > button, .sheet-panel select { display: block; width: 100%; margin-block: 8px; }
.decision-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-block: 16px; }
.action-error { color: var(--alert); }
.action-error:empty { display: none; }
.handoff-entry { min-width: 0; margin-bottom: 16px; }
.handoff-entry .field { margin-bottom: 8px; }
.handoff-ack { background: var(--surface-raised); border-color: var(--line); color: var(--ink); font-size: .875rem; padding: 8px 12px; }
.receipt-row { border-bottom: 1px solid var(--line); padding-bottom: 16px; font-variant-numeric: tabular-nums; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .875rem; }
.welcome { max-width: 38rem; margin: 24px auto; padding: 20px max(20px, env(safe-area-inset-left)); }
.welcome .brand { color: var(--muted); font-size: .8125rem; margin-bottom: 20px; }
.welcome h1 { font-size: 1.75rem; color: var(--gold); margin-bottom: 16px; }
html[data-theme="light"] .welcome h1 { color: var(--plum); }
.welcome p { font-size: 1rem; margin-bottom: 12px; }
.welcome .recovery-notice { color: var(--gold); }
html[data-theme="light"] .welcome .recovery-notice { color: var(--aubergine); }
.welcome .link-notice { color: var(--alert); }
.theme-toggle { background: transparent; border-color: var(--line); color: var(--muted); font-size: .875rem; margin-top: 8px; }
.theme-toggle:hover { color: var(--ink); }
@media (max-width: 600px) {
  .state-panel { padding: 16px; }
  .state-grid, .concerns-grid, .resident-checks { grid-template-columns: minmax(0, 1fr); }
  .app-bar { grid-template-columns: 48px minmax(0, 1fr); padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); gap: 10px; }
  .brand img { width: 48px; }
  .header-greeting { margin-right: 2px; }
  .capture, .form-host { padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }
  .voice-controls .primary { flex-grow: 1; }
  .signoff { flex-direction: column; align-items: stretch; }
  .signoff button { width: 100%; }
  .menu-sheet { width: calc(100% - 16px); max-height: calc(100dvh - 16px); padding: 16px 16px max(16px, env(safe-area-inset-bottom)); margin: auto auto 8px; }
}
@media (max-width: 280px) {
  .app-bar { grid-template-columns: 20px minmax(0, 1fr); gap: 2px; padding-inline: 2px; }
  .app-bar .brand img { width: 20px; }
  .header-actions { gap: 0; }
  .header-greeting { font-size: .75rem; gap: 2px; margin-right: 0; }
  .capture, .form-host { padding-inline: 12px; }
  .voice-controls { flex-direction: column; }
  .voice-controls .primary { min-width: 44px; }
  .menu-sheet { padding-inline: 12px; }
  .resident-row, .missing { padding: 10px; }
  input, select, textarea { padding-inline: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.app-tooltip {
  position: fixed; inset: auto; margin: 0; padding: 9px 12px;
  width: max-content; max-width: min(280px, calc(100vw - 16px));
  border: 1px solid var(--field-border); border-radius: 8px;
  background: var(--surface-raised); color: var(--ink);
  font-size: .8125rem; line-height: 1.45; overflow-wrap: anywhere;
  box-shadow: 0 4px 16px #0004; pointer-events: auto;
}

/* At 200% phone reflow, retain Hi and full-sized actions; only the brand/name compress. */
@media (max-width: 190px) {
  .app-bar { grid-template-columns: 12px minmax(0, 1fr); padding-inline: 0; gap: 0; }
  .app-bar .brand img { width: 12px; }
  .header-greeting { font-size: .6875rem; }
}
