/* Tokens and components from app/DESIGN.md. Tenant colours arrive as --brand and --brand-ink. */
:root {
  --brand: #2f3b52; --brand-ink: #ffffff;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #eceef2; --text: #14171c; --muted: #4f5662; --line: #c9ced6;
  --focus: #1d6fe0;
  --ok: #1d7a3a; --ok-bg: #e3f4e8; --warn: #8a5a00; --warn-bg: #fff3d6; --danger: #b3261e; --danger-bg: #fde7e5;
  --lamp-green: #1f9d4c; --lamp-red: #d32f2f; --lamp-amber: #e69500;
  --fs-sm: 15px; --fs-base: 17px; --fs-lg: 20px; --fs-xl: 24px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 12px; --bubble: 18px; --tap: 48px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #1a1d23; --surface-2: #252932; --text: #eef0f3; --muted: #a9b0bc; --line: #3a404b;
    --focus: #7fb2ff;
    --ok: #6fd38f; --ok-bg: #163322; --warn: #ffcc66; --warn-bg: #3a2e12; --danger: #ff8a80; --danger-bg: #3d1a18;
    --lamp-green: #3ccf6e; --lamp-red: #ff5c5c; --lamp-amber: #ffb733;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 var(--fs-base)/1.5 var(--font); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: var(--s3);
  min-height: 56px; padding: var(--s2) var(--s4); background: var(--brand); color: var(--brand-ink);
}
.topbar .title { flex: 1; min-width: 0; font-weight: 600; font-size: var(--fs-base); line-height: 1.25; overflow-wrap: anywhere; }
.topbar img { max-height: 32px; max-width: 160px; display: block; }
.topbar .quiet { color: var(--brand-ink); flex: none; font-size: var(--fs-sm); padding: var(--s2) var(--s1); }

main { max-width: 640px; margin: 0 auto; padding: var(--s4); }
h1 { font-size: var(--fs-xl); line-height: 1.25; margin: var(--s5) 0 var(--s3); }
h2 { font-size: var(--fs-lg); line-height: 1.35; margin: var(--s4) 0 var(--s3); }
p { margin: 0 0 var(--s3); }
.help { color: var(--muted); font-size: var(--fs-sm); line-height: 1.4; }
.stack > * + * { margin-top: var(--s3); }

/* Buttons */
button, .btn {
  display: inline-block; text-decoration: none; box-sizing: border-box;
  font: 600 var(--fs-base)/1.2 var(--font); min-height: var(--tap); min-width: var(--tap); padding: var(--s3) var(--s4);
  border-radius: var(--radius); border: 2px solid transparent; cursor: pointer; text-align: center;
  transition: background-color 150ms, border-color 150ms;
}
button.primary { background: var(--brand); color: var(--brand-ink); width: 100%; }
button.secondary, .btn.secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
button.quiet { background: transparent; color: var(--text); text-decoration: underline; padding: var(--s2); font-weight: 400; }
button.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
button.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
button:disabled { opacity: .5; pointer-events: none; }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.row > button { flex: 1 1 auto; }
.full { width: 100%; }

/* Equipment and intake choices */
.choices { display: grid; grid-template-columns: 1fr; gap: var(--s2); }
.choices.two { grid-template-columns: 1fr 1fr; }
.choice {
  display: flex; align-items: center; gap: var(--s3); width: 100%; text-align: left;
  background: var(--surface); color: var(--text); border: 2px solid var(--line);
}
.choice[aria-pressed="true"] { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
.dot { flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--text); background: transparent; }
.dot.green { background: var(--lamp-green); }
.dot.red { background: var(--lamp-red); }
.dot.amber { background: var(--lamp-amber); }
.field { margin: var(--s5) 0; }
.field h3 { margin: 0 0 var(--s2); font-size: var(--fs-base); }

/* Forms */
label { display: block; font-weight: 600; margin: var(--s4) 0 var(--s2); }
input[type="email"], input[type="text"], input[type="password"], textarea {
  width: 100%; font: 400 var(--fs-base)/1.5 var(--font); min-height: var(--tap); padding: var(--s3);
  color: var(--text); background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
}
textarea { min-height: 96px; resize: vertical; }
.check { display: flex; align-items: center; gap: var(--s3); min-height: var(--tap); font-weight: 400; margin: var(--s3) 0; }
.check input { width: 24px; height: 24px; flex: none; }

/* Banners and errors */
.banner { border-radius: var(--radius); padding: var(--s3) var(--s4); margin: var(--s3) 0; border: 2px solid currentColor; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner p { margin: 0; color: var(--text); }
.banner strong { display: block; margin-bottom: var(--s1); }

/* Chat */
.log { display: flex; flex-direction: column; gap: var(--s3); padding-bottom: var(--s4); }
.msg { max-width: 88%; }
.msg .bubble { padding: var(--s3) var(--s4); border-radius: var(--bubble); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.operator { align-self: flex-end; }
.msg.operator .bubble { background: var(--brand); color: var(--brand-ink); }
.msg.assistant .bubble { background: var(--surface-2); }
.msg.tech .bubble { background: var(--surface); border: 2px solid var(--ok); }
.msg .who { font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--s1); font-weight: 600; }
.msg.system { align-self: center; max-width: 100%; text-align: center; color: var(--muted); font-size: var(--fs-sm); }
.msg.waiting .bubble { color: var(--muted); }
.msg.safety { align-self: stretch; max-width: 100%; margin: 0; }
.sources { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); padding: 0 var(--s2); }
.outcomes { margin-top: var(--s2); }
.outcomes button { font-size: var(--fs-sm); padding: var(--s2) var(--s3); }
.recorded { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); padding: 0 var(--s2); }
.thumb { display: flex; align-items: center; gap: var(--s3); }
.thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius); border: 2px solid var(--line); }
.msg .photo { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); display: block; margin-top: var(--s2); }

.composer {
  position: sticky; bottom: 0; background: var(--bg); padding: var(--s3) 0 calc(var(--s3) + env(safe-area-inset-bottom));
  border-top: 2px solid var(--line);
}
.composer textarea { min-height: var(--tap); height: 56px; }
.send-row { display: flex; gap: var(--s2); align-items: flex-end; }
.send-row textarea { flex: 1; }
.send-row button { width: auto; flex: none; }
#actions { display: grid; gap: var(--s2); margin-bottom: var(--s3); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (min-width: 480px) { .choices.wide-two { grid-template-columns: 1fr 1fr; } }

/* Desk (DESIGN.md, Desk section) */
body.desk main { max-width: 1200px; }
.tabs {
  display: flex; gap: var(--s1); overflow-x: auto; background: var(--surface); border-bottom: 2px solid var(--line);
  padding: 0 var(--s4); position: sticky; top: 56px; z-index: 1;
}
.tabs button {
  background: transparent; color: var(--text); font-weight: 400; border: 0; border-bottom: 3px solid transparent;
  border-radius: 0; padding: var(--s3) var(--s3); flex: none;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--brand); font-weight: 600; }
.pill {
  display: inline-block; font-size: var(--fs-sm); line-height: 1.3; padding: 1px var(--s2); border-radius: 999px;
  border: 2px solid currentColor; color: var(--muted); background: var(--surface-2); white-space: nowrap;
}
.pill.critical, .pill.failed, .pill.danger { color: var(--danger); background: var(--danger-bg); }
.pill.high, .pill.warn { color: var(--warn); background: var(--warn-bg); }
.pill.sent, .pill.ok { color: var(--ok); background: var(--ok-bg); }
.pills { display: flex; flex-wrap: wrap; gap: var(--s1); align-items: center; }
.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: var(--s3) var(--s4); }
.cards { display: grid; gap: var(--s2); }
button.card { width: 100%; text-align: left; font-weight: 400; color: var(--text); display: grid; gap: var(--s1); }
button.card[aria-current="true"] { outline: 3px solid var(--focus); outline-offset: 0; }
.card .title-line { font-weight: 600; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.split { display: grid; gap: var(--s4); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-sm); }
.msg.internal .bubble { border: 2px dashed var(--line); }
.desk .msg { max-width: 100%; }
.desk .msg.system { align-self: stretch; text-align: left; }
.photos { display: flex; flex-wrap: wrap; gap: var(--s2); }
.photos img { width: 120px; height: 120px; object-fit: cover; border-radius: var(--radius); border: 2px solid var(--line); display: block; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.toolbar > button { flex: none; width: auto; }
.status-line { color: var(--ok); font-size: var(--fs-sm); min-height: 1.4em; margin: var(--s1) 0 0; }
.error-line { color: var(--danger); font-size: var(--fs-sm); margin: var(--s1) 0 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--s1) var(--s3); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
select, input[type="number"], input[type="file"] {
  font: 400 var(--fs-base)/1.5 var(--font); min-height: var(--tap); padding: var(--s2) var(--s3); color: var(--text);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); max-width: 100%;
}
fieldset { border: 2px solid var(--line); border-radius: var(--radius); margin: var(--s3) 0; padding: var(--s2) var(--s4) var(--s3); }
legend { font-weight: 600; padding: 0 var(--s1); }
fieldset .check { margin: var(--s1) 0; }
details > summary { cursor: pointer; font-weight: 600; min-height: var(--tap); display: flex; align-items: center; }
.section-head { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; justify-content: space-between; }
.section-head h2 { margin: var(--s4) 0 var(--s2); }
.big-link { font-size: var(--fs-lg); overflow-wrap: anywhere; word-break: break-all; }
.list-plain { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.review { display: grid; gap: var(--s3); }
.review textarea { min-height: 320px; }
.review .pre { max-height: 420px; overflow: auto; }
@media (min-width: 900px) {
  .split { grid-template-columns: 360px 1fr; align-items: start; }
  .split .queue-col { position: sticky; top: 120px; max-height: calc(100vh - 140px); overflow: auto; }
  .review { grid-template-columns: 1fr 1fr; }
  .back-to-queue { display: none; }
}
.mt { margin-top: var(--s3); }
.topbar .who-line { color: var(--brand-ink); font-size: var(--fs-sm); flex: none; }
@media (max-width: 599px) { .topbar .who-line { display: none; } }
@media (max-width: 899px) {
  .split.case-open .queue-col { display: none; }
  .split:not(.case-open) #case-col { display: none; }
}
.desk .msg.operator { align-self: flex-start; }
.desk .msg.safety .bubble { padding: 0; color: var(--text); }
#kb-review, #qr-out, #pv-out { scroll-margin-top: 120px; }
.status-line:empty { min-height: 0; margin: 0; }
.desk a { color: var(--focus); }
/* Narrow screens: the tab strip wraps onto two rows so every tab stays visible. */
@media (max-width: 599px) {
  .tabs { flex-wrap: wrap; overflow-x: visible; padding: 0 var(--s2); }
  .tabs button { padding: var(--s2) var(--s2); }
}
