/* ==========================================================================
   JayNotes design system
   Spec 12: professional and calm, glanceable, generous spacing, one type
   scale, one spacing rhythm, colour reserved for status and priority.
   ========================================================================== */

:root {
  /* One type scale, used everywhere. */
  --t-xs: 0.6875rem;   /* 11 */
  --t-sm: 0.8125rem;   /* 13 */
  --t-md: 0.9375rem;   /* 15 */
  --t-lg: 1.125rem;    /* 18 */
  --t-xl: 1.5rem;      /* 24 */
  --t-2xl: 2rem;       /* 32 */
  --t-3xl: 2.75rem;    /* 44 */

  /* One spacing rhythm. */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 24px; --s-6: 32px; --s-7: 48px; --s-8: 64px;

  --r-sm: 8px; --r-md: 12px; --r-lg: 18px; --r-full: 999px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;

  --nav-w: 216px;
  --header-h: 60px;
  --speed: 160ms;
}

/* Compact density — the desktop app's default, and available in the browser.
   Same components, tighter rhythm; nothing is removed. */
[data-density="compact"] {
  --t-3xl: 2rem;
  --t-2xl: 1.5rem;
  --s-4: 12px; --s-5: 16px; --s-6: 22px; --s-7: 30px;
  --nav-w: 76px;
  --header-h: 48px;
}

/* --------------------------------------------------------------- palettes */

[data-theme="light"] {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #eceff4;
  --surface-3: #e2e7ee;
  --line: #d9e0e8;
  --line-strong: #c3ccd8;
  --ink: #0f1419;
  --ink-2: #4a5561;
  --ink-3: #6f7c8b;
  --accent: #2f5fd0;
  --accent-hover: #2850b8;
  --accent-ink: #ffffff;
  --accent-soft: #e5edfd;
  --ok: #0b7a63;
  --ok-soft: #dff3ee;
  --warn: #a2570a;
  --warn-soft: #fdf0dc;
  --warn-strong: #d98324;
  --alert: #b3261e;
  --alert-soft: #fce9e7;
  --alert-strong: #d93b30;
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-2: 0 6px 16px rgba(16, 24, 40, .10), 0 2px 4px rgba(16, 24, 40, .06);
  --shadow-3: 0 18px 40px rgba(16, 24, 40, .18);
}

[data-theme="dark"] {
  --bg: #0c1015;
  --surface: #151b23;
  --surface-2: #1c242e;
  --surface-3: #243040;
  --line: #29333f;
  --line-strong: #3a4756;
  --ink: #e8eef5;
  --ink-2: #a8b4c2;
  --ink-3: #7d8b9b;
  --accent: #7aa2ff;
  --accent-hover: #94b4ff;
  --accent-ink: #0b1220;
  --accent-soft: #1b2942;
  --ok: #38d6b0;
  --ok-soft: #10302b;
  --warn: #f0b34a;
  --warn-soft: #33280f;
  --warn-strong: #f0a02a;
  --alert: #ff6f61;
  --alert-soft: #3a1a17;
  --alert-strong: #ff5544;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 8px 20px rgba(0, 0, 0, .45);
  --shadow-3: 0 20px 44px rgba(0, 0, 0, .6);
}

/* ------------------------------------------------------------------ reset */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;      /* the app scrolls its regions, never the window */
}
/* The login screen is the one page that may scroll as a whole — it has no
   shell, and on a very short window the card still has to be reachable. */
body:has(.login) { overflow: auto; }

h1, h2, h3, h4, p, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.noscript { padding: var(--s-6); text-align: center; }

/* Spec 12 — visible keyboard focus everywhere, and nowhere on mouse clicks. */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Spec 12 — respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* --------------------------------------------------------------- primitives */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: 38px;
  padding: 0 var(--s-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--t-sm);
  font-weight: 550;
  cursor: pointer;
  transition: background var(--speed), border-color var(--speed), transform var(--speed);
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }

.btn.danger { color: var(--alert); border-color: color-mix(in srgb, var(--alert) 40%, var(--line)); }
.btn.danger:hover { background: var(--alert-soft); }

.btn.small { min-height: 30px; padding: 0 var(--s-3); font-size: var(--t-xs); }
.btn.block { width: 100%; }

.field { display: flex; flex-direction: column; gap: var(--s-2); }
.field > label { font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: var(--t-xs); color: var(--ink-3); }

.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color var(--speed), box-shadow var(--speed);
}
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
  outline: none;
}
.textarea { min-height: 84px; resize: vertical; padding-top: var(--s-3); }
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }

.chip {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 3px var(--s-2);
  border-radius: var(--r-full);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--t-xs);
  font-weight: 600;
  letter-spacing: .01em;
  /* Names can be long and tiles can be narrow — truncate rather than overflow. */
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.alert { background: var(--alert-soft); color: var(--alert); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-1);
}

.muted { color: var(--ink-3); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: var(--s-3); }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: flex; flex-direction: column; gap: var(--s-3); }

.avatar {
  width: 32px; height: 32px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--surface-3);
  color: var(--ink-2);
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .02em;
  position: relative;
}
.avatar.lg { width: 40px; height: 40px; font-size: var(--t-sm); }
.avatar[data-online="true"]::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--surface);
}

/* ==========================================================================
   Login
   ========================================================================== */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: var(--s-5);
  background:
    radial-gradient(1100px 460px at 50% -180px,
      color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  padding: var(--s-6);
  display: flex; flex-direction: column; gap: var(--s-4);
}
.login-brand { display: flex; align-items: center; gap: var(--s-3); margin-bottom: var(--s-2); }
.login-brand img { width: 38px; height: 38px; }
.login-brand h1 { font-size: var(--t-xl); letter-spacing: -0.02em; }
.login-brand p { font-size: var(--t-sm); color: var(--ink-3); }

.password-field { position: relative; }
.password-field .input { padding-right: 78px; }
.password-field .reveal {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  min-height: 28px; padding: 0 var(--s-2);
  font-size: var(--t-xs);
}

.form-error {
  padding: var(--s-3);
  border-radius: var(--r-sm);
  background: var(--alert-soft);
  color: var(--alert);
  font-size: var(--t-sm);
  border: 1px solid color-mix(in srgb, var(--alert) 30%, transparent);
}
.form-note {
  padding: var(--s-3);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: var(--t-sm);
}

/* ==========================================================================
   Shell
   ========================================================================== */

/* The root is the whole window, and nothing inside it is allowed to make the
   window itself scroll. The trial banner is a sibling of the shell, so the
   shell takes the remaining height rather than a flat 100vh — otherwise the
   page is always taller than the viewport by exactly the banner. */
.root {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.shell {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas: "brand header" "nav main";
}

.brand {
  grid-area: brand;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  -webkit-app-region: drag;
  /* macOS hiddenInset: the traffic lights sit in this column. */
}
/* Push brand content below the three traffic-light buttons. They occupy
   roughly 70px wide x 20px high and are vertically centred in the header.
   Adding left-padding clears them so the logo does not overlap. */
[data-platform="darwin"][data-desktop="true"] .brand {
  padding-left: 78px;
}
.brand img { width: 26px; height: 26px; }
.brand .name { font-weight: 700; letter-spacing: -0.01em; }
[data-density="compact"] .brand .name { display: none; }

.topbar {
  grid-area: header;
  display: flex; align-items: center; gap: var(--s-3);
  padding: 0 var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  -webkit-app-region: drag;
  min-width: 0;
  overflow: hidden;
}
.topbar > * { -webkit-app-region: no-drag; }
.topbar h2 {
  font-size: var(--t-lg); font-weight: 650; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.topbar .sub { font-size: var(--t-xs); color: var(--ink-3); white-space: nowrap; }

.nav {
  grid-area: nav;
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-3);
  border-right: 1px solid var(--line);
  background: var(--surface);
  overflow-y: auto;
}
.nav-item {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border: 0; border-radius: var(--r-sm);
  background: transparent;
  color: var(--ink-2);
  font-size: var(--t-sm); font-weight: 550;
  cursor: pointer; text-align: left;
  transition: background var(--speed), color var(--speed);
}
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}
.nav-item .icon { width: 18px; height: 18px; flex: 0 0 auto; }
.nav-item .badge {
  margin-left: auto;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: var(--r-full);
  background: var(--alert); color: #fff;
  font-size: var(--t-xs); font-weight: 700;
}
.nav-item { position: relative; }
/* The icon-only rail is only ever used by the wide sidebar layout. Below 900px
   navigation moves to the bottom, where the labels are worth their height. */
@media (min-width: 900px) {
  [data-density="compact"] .nav-item { justify-content: center; padding: var(--s-3) 0; }
  [data-density="compact"] .nav-item .label { display: none; }
  [data-density="compact"] .nav-item .badge {
    position: absolute; margin: 0; transform: translate(14px, -12px);
  }
}

/* ==========================================================================
   The page shell, and the scrolling rule
   --------------------------------------------------------------------------
   Layout budget: the desktop window is 680 x 850, which leaves roughly
   640 x 630 of usable content. Every screen is designed to fit that without
   scrolling, and where content genuinely overflows, ONE inner region scrolls —
   never the page, and never two regions at once.

   So .main does not scroll. A view builds a .page: a fixed .page-head, one
   .page-scroll that takes the remaining height, and a fixed .page-foot holding
   the primary action. That is what keeps Send on screen.
   ========================================================================== */

.main {
  grid-area: main;
  overflow: hidden;
  padding: var(--s-4) var(--s-5);
  min-height: 0;
}
.main-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.page {
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  height: 100%;
  min-height: 0;
}
.page-head { flex: 0 0 auto; display: flex; flex-direction: column; gap: var(--s-3); }
.page-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  padding-right: 2px;         /* room for the scrollbar without a jump */
}
.page-foot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding-top: var(--s-2);
  border-top: 1px solid var(--line);
}
/* Screens where scrolling the whole page is fine — settings, admin. */
.page.scrolls { overflow-y: auto; }

.section-head { display: flex; align-items: baseline; gap: var(--s-3); }
.section-head h3 { font-size: var(--t-lg); font-weight: 650; letter-spacing: -0.01em; }
.section-head .count { font-size: var(--t-sm); color: var(--ink-3); }

.connection {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-xs); font-weight: 600; color: var(--ink-3);
}
.connection .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3);
}
.connection[data-state="online"] .dot { background: var(--ok); }
.connection[data-state="reconnecting"] .dot,
.connection[data-state="connecting"] .dot { background: var(--warn-strong); animation: pulse 1.4s infinite; }
.connection[data-state="revoked"] .dot { background: var(--alert); }

@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

.trial-banner {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-2) var(--s-4);
  background: var(--warn-soft); color: var(--warn);
  font-size: var(--t-sm); font-weight: 600;
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
}

[data-platform="darwin"] .trial-banner {
  padding-left: 82px;
  -webkit-app-region: drag;
}
[data-platform="darwin"] .trial-banner > * {
  -webkit-app-region: no-drag;
}


/* ==========================================================================
   Room signal board — the flagship
   ========================================================================== */

.board-toolbar {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
}

/* Four across at 630px of usable width, so twelve rooms are three rows and
   nothing scrolls (layout budget: "Room signals — no scroll up to ~12 rooms"). */
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(144px, 1fr));
  gap: var(--s-3);
  align-content: start;
}
@media (min-width: 900px) {
  .board { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: var(--s-4); }
}

.room {
  position: relative;
  display: flex; flex-direction: column; gap: var(--s-1);
  min-height: 136px;
  padding: var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  cursor: pointer;
  text-align: left;
  transition: transform var(--speed), box-shadow var(--speed), background var(--speed), border-color var(--speed);
}
[data-density="compact"] .room { min-height: 112px; padding: var(--s-3); }
.room:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.room:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.room .room-name {
  font-size: var(--t-xl);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
[data-density="compact"] .room .room-name { font-size: var(--t-lg); }

.room .room-hint { font-size: var(--t-sm); color: var(--ink-3); margin-top: auto; }
.room .room-swatch {
  position: absolute; top: var(--s-4); right: var(--s-4);
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--swatch, var(--line-strong));
}

/* Active: colour carries meaning, and escalates with the wait. */
.room[data-active="true"] { border-width: 2px; }
.room[data-severity="fresh"] {
  background: var(--warn-soft);
  border-color: var(--warn-strong);
}
.room[data-severity="waiting"] {
  background: color-mix(in srgb, var(--warn-soft) 70%, var(--alert-soft));
  border-color: var(--warn-strong);
}
.room[data-severity="overdue"] {
  background: var(--alert-soft);
  border-color: var(--alert-strong);
}
/* A gentle breath, not a strobe: this runs all day with customers present. */
.room[data-severity="overdue"][data-acked="false"] {
  animation: breathe 2.6s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { box-shadow: var(--shadow-1); }
  50% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--alert) 22%, transparent); }
}

.room .timer {
  font-family: var(--mono);
  font-size: var(--t-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.room[data-severity="fresh"] .timer,
.room[data-severity="waiting"] .timer { color: var(--warn); }
.room[data-severity="overdue"] .timer { color: var(--alert); }

.room .room-actions { display: flex; gap: var(--s-2); flex-wrap: wrap; margin-top: var(--s-1); }
.room .room-meta { font-size: var(--t-xs); color: var(--ink-2); }

.room-empty {
  display: grid; place-items: center;
  min-height: 148px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-lg);
  color: var(--ink-3);
  font-size: var(--t-sm);
}

/* ==========================================================================
   Alerts — in-app stack (the desktop app renders these as OS-level windows)
   ========================================================================== */

.alert-stack {
  position: fixed; top: var(--s-4); right: var(--s-4);
  display: flex; flex-direction: column; gap: var(--s-3);
  width: min(360px, calc(100vw - 32px));
  z-index: 60;
  pointer-events: none;
}
.alert {
  pointer-events: auto;
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-4);
  border-radius: var(--r-md);
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  box-shadow: var(--shadow-3);
  animation: slide-in 200ms ease-out;
}
@keyframes slide-in {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}
.alert[data-priority="elevated"] { border-left-color: var(--warn-strong); }
.alert[data-priority="urgent"] { border-left-color: var(--alert-strong); }
.alert[data-kind="signal"] { border-left-color: var(--warn-strong); }

.alert .alert-head { display: flex; align-items: center; gap: var(--s-2); }
.alert .alert-title { font-size: var(--t-sm); font-weight: 700; }
.alert .alert-body { font-size: var(--t-md); line-height: 1.45; }
.alert .alert-quote {
  padding: var(--s-2) var(--s-3);
  border-left: 3px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--t-sm);
  color: var(--ink-2);
}
.alert .alert-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.alert .alert-reply { display: flex; gap: var(--s-2); }
.alert .alert-reply .input { min-height: 34px; }

/* ==========================================================================
   Broadcast — the two-step send
   --------------------------------------------------------------------------
   Sending must be possible in under five seconds, standing, mid-task, with one
   hand. That rules out dropdowns and typing in step 1: everything is a large
   target, and the whole of step 2 fits without scrolling except the template
   library, which is the one thing allowed to overflow.
   ========================================================================== */

.step-label {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-3);
}
.step-label .num {
  width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px;
}

.who-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: var(--s-2);
}
.who-tile {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  min-height: 64px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer; text-align: left;
  transition: background var(--speed), border-color var(--speed), transform var(--speed);
}
.who-tile:hover { background: var(--surface-2); border-color: var(--accent); }
.who-tile:active { transform: translateY(1px); }
.who-tile .who-name { font-size: var(--t-md); font-weight: 650; letter-spacing: -0.01em; }
.who-tile .who-count { font-size: var(--t-xs); color: var(--ink-3); }
.who-tile.wide { grid-column: 1 / -1; }
.who-tile.everyone { border-color: var(--accent); background: var(--accent-soft); }
.who-tile.everyone .who-name { color: var(--accent); }
/* An empty department is still shown — but marked, so nobody broadcasts into
   a void and then wonders why no one came. */
.who-tile[data-empty="true"] { opacity: .72; border-style: dashed; }
.who-tile[data-empty="true"] .who-count { color: var(--warn); font-weight: 650; }

.recipient-bar {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.recipient-bar .to { font-size: var(--t-xs); color: var(--ink-3); font-weight: 650; }
.recipient-bar .who { font-size: var(--t-sm); font-weight: 700; }

.template-group { display: flex; flex-direction: column; gap: var(--s-2); }
.template-group > .group-name {
  font-size: var(--t-xs); font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-3);
  position: sticky; top: 0;
  background: var(--bg);
  padding: 2px 0;
}
.template-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(184px, 1fr)); gap: var(--s-2); }
.template-btn {
  display: flex; flex-direction: column; gap: 2px;
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer; text-align: left;
}
.template-btn:hover { border-color: var(--accent); background: var(--surface-2); }
.template-btn .t-title { font-size: var(--t-sm); font-weight: 650; }
.template-btn .t-body {
  font-size: var(--t-xs); color: var(--ink-3);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* The live preview: filled slots read as settled, empty ones as outstanding. */
.preview {
  padding: var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: var(--t-md);
  line-height: 1.5;
}
.preview .slot-filled {
  padding: 1px 6px; border-radius: var(--r-sm);
  background: var(--accent-soft); color: var(--accent); font-weight: 650;
}
.preview .slot-empty {
  padding: 1px 6px; border-radius: var(--r-sm);
  background: transparent; color: var(--warn);
  border: 1px dashed var(--warn-strong); font-weight: 650;
}

.segmented { display: flex; gap: 2px; padding: 2px; border-radius: var(--r-sm); background: var(--surface-2); }
.segmented button {
  flex: 1; min-height: 32px; padding: 0 var(--s-2);
  border: 0; border-radius: calc(var(--r-sm) - 1px);
  background: transparent; color: var(--ink-2);
  font-size: var(--t-xs); font-weight: 650; cursor: pointer;
}
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.segmented button[aria-pressed="true"][data-priority="info"] { color: var(--accent); }
.segmented button[aria-pressed="true"][data-priority="warning"] { color: var(--warn); }
.segmented button[aria-pressed="true"][data-priority="critical"] { color: var(--alert); }

.accent-row { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.accent-dot {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  background: var(--swatch);
  padding: 0;
}
.accent-dot[aria-pressed="true"] { border-color: var(--ink); }
.accent-dot[data-accent="none"] { background: transparent; border: 2px dashed var(--line-strong); }

details.more > summary {
  cursor: pointer; list-style: none;
  font-size: var(--t-xs); font-weight: 650; color: var(--ink-3);
  padding: var(--s-1) 0;
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::before { content: "▸ "; }
details.more[open] > summary::before { content: "▾ "; }

/* ==========================================================================
   Announcements, messages, lists
   ========================================================================== */

.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s-5); align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.compose { padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-3); }
.priority-picker { display: flex; gap: var(--s-2); }
.priority-option {
  flex: 1;
  padding: var(--s-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: var(--t-xs); font-weight: 650;
  cursor: pointer;
}
.priority-option[aria-pressed="true"][data-priority="normal"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent);
}
.priority-option[aria-pressed="true"][data-priority="elevated"] {
  background: var(--warn-soft); border-color: var(--warn-strong); color: var(--warn);
}
.priority-option[aria-pressed="true"][data-priority="urgent"] {
  background: var(--alert-soft); border-color: var(--alert-strong); color: var(--alert);
}

.feed { display: flex; flex-direction: column; gap: var(--s-3); }
.feed-item {
  padding: var(--s-4);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  display: flex; flex-direction: column; gap: var(--s-2);
}
.feed-item[data-priority="elevated"] { border-left-color: var(--warn-strong); }
.feed-item[data-priority="urgent"] { border-left-color: var(--alert-strong); }
.feed-item .feed-head { display: flex; align-items: center; gap: var(--s-2); font-size: var(--t-xs); color: var(--ink-3); }
.feed-item .feed-body { font-size: var(--t-md); }
.feed-item .replies { display: flex; flex-direction: column; gap: var(--s-2); padding-left: var(--s-3); border-left: 2px solid var(--line); }
.feed-item .reply { font-size: var(--t-sm); color: var(--ink-2); }

.quote {
  padding: var(--s-2) var(--s-3);
  border-left: 3px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  font-size: var(--t-sm);
  color: var(--ink-2);
}

/* ==========================================================================
   Messages
   --------------------------------------------------------------------------
   Everybody in the practice is listed down the left, so starting a
   conversation is one click on a name rather than a trip through a menu.

   The rail and the history scroll independently. That is two scrolling areas,
   which is fine: what the layout budget forbids is one scrollbar INSIDE
   another. These are siblings, and the composer never moves.
   ========================================================================== */

.chat {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: var(--s-3);
}
@media (min-width: 1100px) { .chat { grid-template-columns: 248px minmax(0, 1fr); } }

.chat-people,
.chat-thread {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}

/* ------------------------------------------------------------- the rail --- */

.rail-head { flex: 0 0 auto; padding: var(--s-2); border-bottom: 1px solid var(--line); }
.rail-head .input { min-height: 32px; font-size: var(--t-sm); }

.rail-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: var(--s-2);
  overscroll-behavior: contain;
}
.rail-group + .rail-group { margin-top: var(--s-3); }
.rail-label {
  font-size: 10px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 var(--s-2) var(--s-1);
}

.rail-row {
  display: flex; align-items: center; gap: var(--s-2);
  width: 100%;
  padding: 6px var(--s-2);
  border: 0; border-radius: var(--r-sm);
  background: transparent; color: inherit;
  cursor: pointer; text-align: left;
  transition: background var(--speed);
}
.rail-row:hover { background: var(--surface-2); }
.rail-row[aria-current="true"] { background: var(--accent-soft); }
.rail-row[aria-current="true"] .rail-name { color: var(--accent); font-weight: 700; }

.rail-name {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--t-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rail-avatar {
  position: relative; flex: 0 0 auto;
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--ink-2);
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
/* The same presence dot as the directory — one idea, one shape. */
.rail-avatar[data-online="true"]::after {
  content: ""; position: absolute; right: -1px; bottom: -1px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok); border: 2px solid var(--surface);
}
.rail-glyph {
  flex: 0 0 auto; width: 26px; text-align: center;
  color: var(--ink-3); font-weight: 700; font-size: var(--t-md);
}
.rail-badge {
  flex: 0 0 auto;
  min-width: 18px; height: 18px; padding: 0 5px;
  display: grid; place-items: center; border-radius: var(--r-full);
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; font-weight: 700;
}
.rail-empty { padding: var(--s-3) var(--s-2); color: var(--ink-3); font-size: var(--t-sm); }

/* ----------------------------------------------------------- the thread --- */

.thread-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
}
.thread-head .back { display: none; }        /* only earns its place when narrow */
.thread-name { font-size: var(--t-sm); font-weight: 650; }
.thread-sub { font-size: var(--t-xs); color: var(--ink-3); }

.thread-scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-2);
  overscroll-behavior: contain;
}
.thread-compose {
  flex: 0 0 auto;
  display: flex; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-top: 1px solid var(--line);
}
.thread-empty {
  flex: 1 1 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--s-2); padding: var(--s-5); text-align: center;
}
.thread-empty p { font-size: var(--t-sm); max-width: 30ch; }
.thread-empty-mark {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink-3);
}

.msg { display: flex; gap: var(--s-2); align-items: flex-start; }
.msg .bubble {
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r-md);
  background: var(--surface-2);
  max-width: 62ch;
  overflow-wrap: anywhere;
}
.msg[data-mine="true"] { flex-direction: row-reverse; }
.msg[data-mine="true"] .bubble { background: var(--accent-soft); }
.msg .meta { font-size: var(--t-xs); color: var(--ink-3); margin-bottom: 2px; }
/* Consecutive messages from one person read as a single turn. */
.msg[data-run-on="true"] { margin-top: calc(var(--s-2) * -1 + 2px); }
.msg-spacer { flex: 0 0 auto; width: 32px; }

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; }
.list-row .title { font-weight: 600; font-size: var(--t-sm); }
.list-row .sub { font-size: var(--t-xs); color: var(--ink-3); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--s-4); }

/* ------------------------------------------------------------- schedule (6.8) */

.schedule-card {
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.schedule-wrapper {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.schedule-wrapper::-webkit-scrollbar {
  height: 4px;
}
.schedule-wrapper::-webkit-scrollbar-track {
  background: transparent;
}
.schedule-wrapper::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--r-full);
}
.schedule-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--ink-3);
}

table.schedule {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--t-sm);
  table-layout: fixed;
}

table.schedule thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  padding: var(--s-2) var(--s-1);
  border-bottom: 1px solid var(--line);
  font-size: var(--t-xs);
  color: var(--ink-3);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.schedule th.col-person {
  width: 130px;
  text-align: left;
  padding-left: var(--s-3);
  padding-right: var(--s-2);
  position: sticky;
  left: 0;
  z-index: 3;
  background: var(--surface-2);
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.06);
}

/* Each of the 7 day columns shares the remaining width equally */
table.schedule th.col-day {
  width: calc((100% - 130px) / 7);
}

table.schedule tbody tr {
  transition: background var(--speed);
}
table.schedule tbody tr:hover {
  background: var(--surface-2);
}

table.schedule tbody td {
  padding: var(--s-1) var(--s-1);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  text-align: center;
  overflow: hidden;
}
table.schedule tbody tr:last-child td {
  border-bottom: 0;
}

table.schedule td.col-person {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--surface);
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 6px -2px rgba(0, 0, 0, 0.06);
  padding-left: var(--s-3);
  padding-right: var(--s-2);
  text-align: left;
}
table.schedule tbody tr:hover td.col-person {
  background: var(--surface-2);
}

.person-cell {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  white-space: nowrap;
  overflow: hidden;
}
.person-name {
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shifts-cell {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  padding: 3px 2px;
  width: 100%;
}

.shift-pill {
  position: relative;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 5px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--line));
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  cursor: default;
  transition: background var(--speed), border-color var(--speed);
}
.shift-pill:hover {
  background: color-mix(in srgb, var(--accent) 18%, var(--surface));
}

.shift-times {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}
.shift-start,
.shift-end {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.shift-end {
  color: var(--ink-3);
  font-weight: 500;
}

.shift-delete {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  padding: 0;
  line-height: 1;
  font-size: 12px;
  color: var(--ink-3);
  border-radius: 4px;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--speed), color var(--speed), background var(--speed);
}
.shift-pill:hover .shift-delete {
  opacity: 1;
}
.shift-delete:hover {
  color: var(--alert);
  background: var(--alert-soft);
}

.empty-shift {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  opacity: 0.4;
  font-size: var(--t-sm);
  padding: 6px 0;
}

/* ------------------------------------------------------------------ modal */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  padding: var(--s-4);
  background: color-mix(in srgb, #0b0f14 55%, transparent);
  animation: fade-in 140ms ease-out;
}
@keyframes fade-in { from { opacity: 0 } to { opacity: 1 } }
.modal {
  width: min(520px, 100%);
  max-height: 86vh; overflow-y: auto;
  padding: var(--s-5);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; gap: var(--s-4);
}
.modal h3 { font-size: var(--t-lg); font-weight: 650; }
.modal-actions { display: flex; gap: var(--s-2); justify-content: flex-end; }

/* ------------------------------------------------------------------- tour */

.tour {
  position: fixed; z-index: 90; bottom: var(--s-5); left: 50%; transform: translateX(-50%);
  width: min(460px, calc(100vw - 32px));
  padding: var(--s-4);
  border-radius: var(--r-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column; gap: var(--s-3);
}
.tour .steps { display: flex; gap: 4px; }
.tour .steps span { flex: 1; height: 3px; border-radius: 2px; background: var(--line); }
.tour .steps span[data-done="true"] { background: var(--accent); }

/* ---------------------------------------------- the platform owner console */

.platform-shell {
  grid-template-columns: var(--nav-w) 1fr;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-areas: "brand header" "main main";
}
@media (max-width: 899px) {
  .platform-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
    grid-template-areas: "header" "main";
  }
}
.tally-row { display: flex; gap: var(--s-3); flex-wrap: wrap; }

/* ==========================================================================
   Mini mode — the compact desktop window
   ========================================================================== */

body.mini {
  background: var(--surface);
  overflow: hidden;
}
.mini-shell {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
}
.mini-head {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  -webkit-app-region: drag;
  font-size: var(--t-xs);
  font-weight: 650;
  color: var(--ink-2);
  user-select: none;
}
.mini-head .btn,
.mini-head .connection {
  -webkit-app-region: no-drag;
}
[data-platform="darwin"] .mini-head {
  padding-left: 82px;
}
.mini-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-3); display: flex; flex-direction: column; gap: var(--s-2); }
.mini-foot { flex: 0 0 auto; padding: var(--s-3); border-top: 1px solid var(--line); display: flex; gap: var(--s-2); min-height: 58px; align-items: center; }

.mini-room {
  display: flex; align-items: center; gap: var(--s-3);
  padding: var(--s-3);
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  width: 100%; text-align: left; cursor: pointer;
}
.mini-room[data-severity="fresh"] { background: var(--warn-soft); border-color: var(--warn-strong); }
.mini-room[data-severity="waiting"] { background: var(--warn-soft); border-color: var(--warn-strong); }
.mini-room[data-severity="overdue"] { background: var(--alert-soft); border-color: var(--alert-strong); }
.mini-room .name { font-weight: 650; font-size: var(--t-sm); }
.mini-room .timer { margin-left: auto; font-family: var(--mono); font-weight: 650; }
.mini-quiet { padding: var(--s-5) var(--s-3); text-align: center; color: var(--ink-3); font-size: var(--t-sm); }

/* ==========================================================================
   Narrow windows — monitor sizes vary a lot (spec 12)
   ========================================================================== */

/* ==========================================================================
   Below 900px the interface is a tall narrow panel, not a wide desktop app:
   one column, navigation along the bottom. The desktop window is 680 wide, so
   this — not the sidebar layout — is what most staff actually use all day.
   ========================================================================== */

@media (max-width: 899px) {
  .shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr auto;
    grid-template-areas: "header" "main" "nav";
  }
  .brand { display: none; }
  [data-platform="darwin"] .root:not(:has(.trial-banner:not(:empty))) .topbar {
    padding-left: 82px;
  }
  .nav {
    flex-direction: row; justify-content: space-between;
    border-right: 0; border-top: 1px solid var(--line);
    padding: var(--s-2) var(--s-3);
    gap: var(--s-1);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav-item {
    flex: 1 1 0;
    min-width: 56px;
    flex-direction: column; gap: 3px;
    padding: var(--s-2) var(--s-1);
    font-size: var(--t-xs);
    justify-content: center;
  }
  .nav-item .label { font-size: 10px; display: block; }
  .nav-item .badge { position: absolute; margin: 0; transform: translate(16px, -14px); }
  .main { padding: var(--s-4); }
  /* One column: two-column layouts do not work at this width. */
  .split { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .alert-stack { top: auto; bottom: 96px; right: var(--s-3); left: var(--s-3); width: auto; }
}

/* Below 560px there is not room for a rail and a thread at once, so choosing
   somebody slides the conversation over the list, with a way back. */
@media (max-width: 559px) {
  .chat { grid-template-columns: minmax(0, 1fr); }
  .chat[data-showing="list"] .chat-thread { display: none; }
  .chat[data-showing="thread"] .chat-people { display: none; }
  .thread-head .back { display: inline-flex; }
}

/* Very short windows (a 1366x768 laptop, or a deliberately small one): give
   the content every pixel the chrome does not need. */
@media (max-height: 700px) {
  :root { --header-h: 52px; --s-5: 18px; --s-6: 24px; }
  .room { min-height: 118px; }
}
