/* Phone&Fax — "Switchboard" theme (David's pick, 2026-07-22).
   Mid-century telephone hardware: Bakelite cream, oxblood buttons, monospaced
   numerals, squared 6px corners with a hard bottom edge so controls feel
   pressable. All color flows from tokens — never hardcode hex in a rule. */

:root {
  --bg: #e8e0d1;
  --surface: #f6f1e6;
  --surface-2: #efe7d8;
  --nav: #ded4c1;
  --line: #c9bda5;
  --line-soft: #d9cfba;
  --ink: #2b2118;
  --muted: #7d6b56;
  --accent: #8c2f22;
  --accent-hi: #a53a2a;
  --accent-soft: #f0e2d8;
  --btn-ink: #f8f3e9;
  --danger: #5c1f16;
  --good: #4a5f2a;
  --good-bg: #dfe3cb;
  --warn: #8a6a1c;
  --warn-bg: #f0e6cc;
  --edge: #c9bda5;              /* the "hard bottom edge" under pressable things */
  --shadow: 0 8px 18px rgba(70, 50, 30, .14);
  --glass: rgba(246, 241, 230, .86);
  --radius: 6px;
  --radius-sm: 4px;
  --font: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --num: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a15;
    --surface: #2b2419;
    --surface-2: #332b1f;
    --nav: #241e16;
    --line: #463a29;
    --line-soft: #3b3124;
    --ink: #efe4d0;
    --muted: #a08e73;
    --accent: #e0733f;
    --accent-hi: #f08a55;
    --accent-soft: #3a2a1c;
    --btn-ink: #231a12;
    --danger: #c4442c;
    --good: #a8bd6a;
    --good-bg: #33301c;
    --warn: #d8ab4d;
    --warn-bg: #3a3120;
    --edge: #17120d;
    --shadow: 0 10px 24px rgba(0, 0, 0, .5);
    --glass: rgba(43, 36, 25, .88);
  }
}

:root[data-theme="light"] {
  --bg: #e8e0d1; --surface: #f6f1e6; --surface-2: #efe7d8; --nav: #ded4c1;
  --line: #c9bda5; --line-soft: #d9cfba; --ink: #2b2118; --muted: #7d6b56;
  --accent: #8c2f22; --accent-hi: #a53a2a; --accent-soft: #f0e2d8;
  --btn-ink: #f8f3e9; --danger: #5c1f16; --good: #4a5f2a; --good-bg: #dfe3cb;
  --warn: #8a6a1c; --warn-bg: #f0e6cc; --edge: #c9bda5;
  --shadow: 0 8px 18px rgba(70, 50, 30, .14); --glass: rgba(246, 241, 230, .86);
}
:root[data-theme="dark"] {
  --bg: #1f1a15; --surface: #2b2419; --surface-2: #332b1f; --nav: #241e16;
  --line: #463a29; --line-soft: #3b3124; --ink: #efe4d0; --muted: #a08e73;
  --accent: #e0733f; --accent-hi: #f08a55; --accent-soft: #3a2a1c;
  --btn-ink: #231a12; --danger: #c4442c; --good: #a8bd6a; --good-bg: #33301c;
  --warn: #d8ab4d; --warn-bg: #3a3120; --edge: #17120d;
  --shadow: 0 10px 24px rgba(0, 0, 0, .5); --glass: rgba(43, 36, 25, .88);
}

* { box-sizing: border-box; }

/* An author `display:` rule beats the UA's [hidden] rule, so anything given a
   display below (.oncall, .keypad, .pin-gate, …) would stay visible while
   "hidden". Restate it once, globally, with enough weight to win. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;               /* §3: the page itself never scrolls */
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.num, .tnum { font-family: var(--num); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- app shell */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
#app[hidden] { display: none !important; }

.hdr {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--nav);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}
/* Small firm mark — present, not shouting. */
.brand-logo {
  height: 26px;
  width: auto;
  display: block;
  flex: 0 0 auto;
  align-self: center;
}
@media (max-width: 400px) { .brand-logo { height: 22px; } }

.brand h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  margin: 0;
  white-space: nowrap;
}
.brand .line-num {
  font-family: var(--num);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Identity switcher — pick which business/persona the app is showing. */
.id-switch-wrap { position: relative; align-self: center; flex: 0 1 auto; min-width: 0; }
.id-switch {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%;
  padding: 4px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2); color: var(--ink); cursor: pointer;
  font: 600 12.5px/1 inherit; white-space: nowrap;
}
.id-switch:hover { border-color: var(--accent); }
.id-switch #id-switch-name { overflow: hidden; text-overflow: ellipsis; max-width: 40vw; }
.id-caret { color: var(--muted); font-size: 10px; }
.id-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--accent); }
.id-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 50;
  min-width: 232px; max-width: 84vw; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(0,0,0,.24);
}
.id-menu[hidden] { display: none; }
.id-opt {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 9px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink); cursor: pointer; text-align: left; font: inherit;
}
.id-opt:hover { background: var(--surface-2); }
.id-opt[aria-selected="true"] { background: var(--accent-soft); }
.id-opt .id-dot { width: 10px; height: 10px; }
.id-opt .io-name { font-weight: 600; font-size: 13.5px; }
.id-opt .io-sub { font-size: 11.5px; color: var(--muted); font-family: var(--num); }
.id-opt .io-pending { font-size: 10px; color: var(--warn, #b8860b); text-transform: uppercase; letter-spacing: .04em; margin-left: auto; }
.id-opt .io-txt { min-width: 0; display: flex; flex-direction: column; gap: 1px; }

.hdr-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* registration lamp — shows whether the softphone is actually reachable */
.lamp {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  font-weight: 700; color: var(--muted); white-space: nowrap;
}
.dnd-pill {
  display: inline-flex; align-items: center; white-space: nowrap;
  font: 700 10.5px/1 var(--font); letter-spacing: .06em;
  color: var(--accent); background: var(--surface-2);
  border: 1px solid var(--accent); border-radius: 99px; padding: 4px 9px;
}
.dnd-pill[hidden] { display: none !important; }
.lamp .bulb {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); box-shadow: 0 0 0 2px var(--surface-2);
}
.lamp[data-state="ready"] { color: var(--good); }
.lamp[data-state="ready"] .bulb { background: var(--good); }
.lamp[data-state="busy"] { color: var(--accent); }
.lamp[data-state="busy"] .bulb { background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
.lamp[data-state="error"] { color: var(--danger); }
.lamp[data-state="error"] .bulb { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
@media (prefers-reduced-motion: reduce) { .lamp .bulb { animation: none !important } }

/* L / D / A segmented pill */
.lda { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.lda button {
  appearance: none; border: none; background: transparent; color: var(--muted);
  font: 700 11px/1 var(--font); letter-spacing: .06em;
  padding: 6px 9px; cursor: pointer;
}
.lda button + button { border-left: 1px solid var(--line); }
.lda button[aria-pressed="true"] { background: var(--accent); color: var(--btn-ink); }

/* ---------------------------------------------------------------- main */

#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;             /* §3: never sideways */
  overscroll-behavior: contain;
}

.tab {
  display: none;
  min-height: 100%;
  flex-direction: column;
  /* Track the window instead of stopping at a fixed cap — a 1500px ceiling
     stranded ~420px of a 1920 monitor. The vw term keeps sane gutters. */
  max-width: min(97vw, 2000px);
  margin: 0 auto;
  width: 100%;
  padding: 14px 16px 18px;
}
.tab.on { display: flex; }

.grid {
  display: grid;
  gap: 12px;
  /* auto-FIT, not auto-fill: auto-fill keeps empty tracks, so two cards on a
     wide screen sit in narrow columns with dead space beside them. auto-fit
     collapses the empties and lets the real cards take the width. */
  grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
  grid-auto-rows: min-content;    /* natural heights — 1fr stretches and causes overflow */
  align-content: start;
}

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 15px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card.wide { grid-column: 1 / -1; }

.card h2, .card h3 {
  font-size: 10.5px;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 10px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--line-soft);
}

/* ---------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  font: 600 14px/1 var(--font);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  background: var(--accent);
  color: var(--btn-ink);
  cursor: pointer;
  box-shadow: 0 2px 0 var(--edge);
  transition: transform .06s ease, box-shadow .06s ease, background .12s ease;
}
.btn:hover:not(:disabled) { background: var(--accent-hi); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 0 0 var(--edge); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.ghost {
  background: var(--surface-2);
  color: var(--ink);
  border-color: var(--line);
}
.btn.ghost:hover:not(:disabled) { background: var(--surface); }
.btn.end { background: var(--danger); color: #f8f3e9; }
.btn.sm { padding: 7px 11px; font-size: 12.5px; }
.btn.block { width: 100%; }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .btn:active:not(:disabled) { transform: none; }
}

/* ---------------------------------------------------------------- dialer */

.dialer { display: flex; flex-direction: column; gap: 12px; }

.readout {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
}
.readout input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--num);
  font-variant-numeric: tabular-nums;
  font-size: clamp(20px, 5vw, 28px);
  letter-spacing: .04em;
  text-align: center;
  padding: 0;
}
.readout input:focus { outline: none; }
.readout input::placeholder { color: var(--muted); opacity: .55; }
.readout .who {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  min-height: 1.2em;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.key {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  cursor: pointer;
  padding: clamp(9px, 1.6vh, 15px) 0;
  box-shadow: 0 2px 0 var(--edge);
  transition: transform .06s ease, box-shadow .06s ease, background .1s ease;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
}
.key .d { font-family: var(--num); font-size: clamp(19px, 2.6vh, 24px); font-weight: 500; line-height: 1; }
.key .l { font-size: 9px; letter-spacing: .14em; color: var(--muted); height: 10px; }
.key:hover { background: var(--surface); }
.key:active { transform: translateY(2px); box-shadow: 0 0 0 var(--edge); }
.key:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .key { transition: none; }
  .key:active { transform: none; }
}

.dial-actions { display: flex; gap: 8px; align-items: center; }
.dial-actions .btn { flex: 1; }
.btn.call { background: var(--good); color: #f4f6ea; }

/* active-call panel */
.oncall { display: flex; flex-direction: column; gap: 10px; }
.oncall-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.oncall .status {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  font-weight: 700; color: var(--accent);
}
.oncall .timer { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }
.oncall .who { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -.01em; }
.oncall .num-line { font-family: var(--num); font-size: 14px; color: var(--muted); margin: 2px 0 0; }

/* ---------------------------------------------------------------- lists */

.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line-soft);
  min-width: 0;
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-size: 14px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .s { font-size: 11.5px; color: var(--muted); margin: 2px 0 0; font-family: var(--num); }

.dir-in::before, .dir-out::before {
  font-family: var(--num); font-size: 13px; color: var(--muted);
}
.dir-in::before { content: "\2193"; }
.dir-out::before { content: "\2191"; }

.pill {
  font-size: 9.5px; letter-spacing: .09em; text-transform: uppercase; font-weight: 700;
  padding: 4px 8px; border-radius: 99px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.bad { background: var(--accent-soft); color: var(--danger); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }

.empty {
  text-align: center; color: var(--muted); font-size: 13.5px;
  padding: 22px 10px;
}

/* ---------------------------------------------------------------- drop zone */

.drop {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 22px 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .big { font-size: 14.5px; font-weight: 600; margin: 0 0 3px; }
.drop .sm { font-size: 12px; color: var(--muted); margin: 0; }

/* ---------------------------------------------------------------- forms */

label.fld { display: block; margin-bottom: 10px; }
label.fld .lab {
  display: block; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; margin-bottom: 5px;
}
input[type="text"], input[type="tel"], input[type="time"], input[type="email"], select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: 400 14.5px/1.4 var(--font);
  padding: 9px 11px;
}
input[type="tel"], input.num-in { font-family: var(--num); font-variant-numeric: tabular-nums; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 72px; }

/* ---------------------------------------------------------------- tab bar */

.tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--nav);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  appearance: none; border: none; background: transparent; cursor: pointer;
  color: var(--muted);
  font: 700 11px/1 var(--font);
  letter-spacing: .05em;
  padding: 11px 3px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  min-width: 40px;
}
.tabbar button .ic { font-size: 16px; line-height: 1; }
.tabbar button[aria-selected="true"] { color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }

/* unheard-voicemail count */
.tabbar .badge {
  position: absolute; transform: translate(18px, -22px);
  background: var(--accent); color: var(--btn-ink);
  font: 700 10px/1 var(--num); padding: 3px 5px; border-radius: 99px; min-width: 15px;
}
.tabbar button { position: relative; }

/* recording in progress */
.btn.recording {
  background: var(--danger);
  color: #f8f3e9;
  animation: rec-pulse 1.2s ease-in-out infinite;
}
@keyframes rec-pulse { 0%,100% { opacity: 1 } 50% { opacity: .6 } }
@media (prefers-reduced-motion: reduce) { .btn.recording { animation: none } }

.rows audio { width: 100%; max-width: 340px; margin-top: 8px; height: 34px; }

/* contacts directory */
.dir-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.dir-bar input { flex: 1; min-width: 0; }
.dir-bar .btn { flex: 0 0 auto; }
.dir-bar .btn[aria-pressed="true"] { background: var(--accent); color: var(--btn-ink); border-color: var(--accent); }

/* Dense by intent: this is a lookup list you scan, so more names on screen
   beats roomy rows. Name + subtitle sit on one line each, and the number
   button carries its label inline instead of stacked. */
/* ---- directory: card grid, A–Z picker, viewport-fit pagination ---- */

#dir-card { display: flex; flex-direction: column; min-height: 0; }

.az-rail {
  display: flex; flex-wrap: wrap; gap: 3px;
  margin-bottom: 10px; flex: 0 0 auto;
}
.az-rail button {
  appearance: none; cursor: pointer;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); color: var(--muted);
  font: 700 11px/1 var(--num); padding: 5px 7px; min-width: 24px;
}
.az-rail button:hover:not(:disabled) { background: var(--surface-2); color: var(--ink); }
.az-rail button[aria-pressed="true"] { background: var(--accent); color: var(--btn-ink); border-color: var(--accent); }
.az-rail button:disabled { opacity: .28; cursor: default; }

.dir-grid {
  flex: 1 1 auto; min-height: 0;
  display: grid; gap: 8px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  /* Pin the row height: a card whose content runs a couple of pixels tall
     would otherwise stretch its whole row and reintroduce an overflow.
     Must match DIR_CARD_H in app.js (dirPageSize divides by it to paginate). */
  grid-auto-rows: 74px;
  overflow: hidden;              /* pagination fits the page — never scroll */
}

/* Two internal rows: [avatar | name+subtitle] on top, [number chips] below.
   A single horizontal row can't fit a name AND two US phone numbers in a
   ~240–290px card — the numbers won a `flex:0 0 auto` fight and squeezed the
   name column to ~33px, so every name ellipsised to nothing. Giving the name
   its own full-width row is the only layout that keeps it readable at this
   width while still showing tappable numbers. */
.dir-card {
  display: grid;
  grid-template-columns: auto 1fr;   /* avatar | content */
  grid-template-rows: 1fr auto;      /* name-row | numbers-row */
  column-gap: 9px; row-gap: 2px; align-items: center;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; min-width: 0;
  height: 74px; position: relative;
}
/* On phones the directory scrolls (it isn't the fill-the-box grid), so a card
   with a recent-call line — a 3-line info block ~50px tall — no longer has to
   cram into the fixed 74px. At 74px the centered info block bled ~5px into the
   number-button row and the mobile number overlapped the "last call" text.
   Let the row and card grow to their content instead. */
@media (max-width: 699px) {
  #tab-contacts .dir-grid { grid-auto-rows: minmax(74px, max-content); overflow-y: auto; }
  #tab-contacts .dir-card { height: 100%; min-height: 74px; align-items: stretch; }
  #tab-contacts .dir-card .who { align-self: center; }
}
/* Avatar + name scale with the card (set via --avatar / --dname when the grid
   fills the box); both fall back to the compact defaults when unset (phones,
   dense pages). */
.dir-card .avatar { grid-column: 1; grid-row: 1 / span 2;
                    width: var(--avatar, 34px); height: var(--avatar, 34px);
                    font-size: calc(var(--avatar, 34px) * .32); align-self: center; }
/* Column stack, name FIRST so overflow clips the throwaway last-call line at
   the bottom — never the name. */
.dir-card .who { grid-column: 2; grid-row: 1; min-width: 0;
                 display: flex; flex-direction: column; justify-content: center;
                 overflow: hidden; }
.dir-card .who .t { font-size: var(--dname, 13px); font-weight: 600; margin: 0; flex: 0 0 auto;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-card .who .s { font-size: 10.5px; color: var(--muted); margin: 1px 0 0;
                    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-card .who .lastcall {
  font-size: 9.5px; color: var(--good); margin: 1px 0 0;
  font-family: var(--num); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Compact number chips on the second row: number only, tiny type badge, so
   two fit side by side. Overflow-hidden keeps a rare long pair from wrapping
   the card taller than its pinned row. */
.dir-card .nums { grid-column: 2; grid-row: 2;
                  display: flex; flex-direction: row; flex-wrap: nowrap;
                  gap: 4px; align-self: start; overflow: hidden; }
.dir-card .nums .dir-num { padding: 2px 6px; gap: 3px; flex: 0 1 auto; min-width: 0; }
.dir-card .nums .dir-num .lbl { font-size: 7px; }
.dir-card .nums .dir-num .val { font-size: 11px; overflow: hidden; text-overflow: ellipsis; }

/* Edit-in-My-Contacts. Quiet until hover so it doesn't compete with dialling.
   Pinned to the corner so it stays off the name and numbers. */
.dir-edit {
  position: absolute; top: 5px; right: 5px;
  width: 22px; height: 22px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 12px; opacity: .45;
}
.dir-edit:hover { opacity: 1; background: var(--surface); color: var(--accent); }
.dir-edit:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 1px; }

/* Fuzzy suggestions sit below a labelled divider so a near-miss is never
   mistaken for an exact hit. */
.dir-divider {
  grid-column: 1 / -1;
  font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  /* grid-auto-rows pins every row to 74px, so sit the label at the bottom of
     its row rather than letting it float in the middle of the gap. */
  display: flex; align-items: flex-end; padding-bottom: 4px;
  border-bottom: 1px solid var(--line-soft);
}
.dir-card.fuzzy { border-style: dashed; }

/* When the grid fills the box, cards grow to their cell. Center the name +
   numbers as one group (with the avatar) rather than pinning the name to the
   top and the numbers to the bottom of a tall card, and give a bit more air. */
.dir-grid.filled .dir-card {
  height: 100%;
  grid-template-rows: auto auto;
  align-content: center; row-gap: 8px;
  padding: 12px 16px; column-gap: 13px;
}
.dir-grid.filled .dir-card .who .s { font-size: 12px; margin-top: 3px; }
.dir-grid.filled .dir-card .nums { flex-wrap: wrap; margin-top: 2px; }
.dir-grid.filled .dir-card .nums .dir-num { padding: 4px 9px; }
.dir-grid.filled .dir-card .nums .dir-num .lbl { font-size: 8px; }
.dir-grid.filled .dir-card .nums .dir-num .val { font-size: 13px; }

.dir-pager {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: center;
  gap: 12px; padding-top: 9px; margin-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px; color: var(--muted); font-family: var(--num);
}
.dir-pager[hidden] { display: none !important; }

.dir-row { display: flex; align-items: center; gap: 9px; padding: 3px 2px;
           border-bottom: 1px solid var(--line-soft); min-width: 0; }
.dir-row:last-child { border-bottom: none; }

.avatar {
  flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
  object-fit: cover; background: var(--surface-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font: 700 10px/1 var(--font); color: var(--muted); letter-spacing: .02em;
}
.dir-who { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.dir-who .t { font-size: 13px; font-weight: 600; margin: 0; flex: 0 1 auto;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-who .s { font-size: 11px; color: var(--muted); margin: 0; flex: 1 1 auto;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dir-star { color: var(--accent); flex: 0 0 auto; font-size: 10px; }

.dir-nums { display: flex; gap: 5px; flex-wrap: nowrap; flex: 0 0 auto; }
.dir-num {
  appearance: none; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); box-shadow: 0 1px 0 var(--edge);
  padding: 3px 8px; color: var(--ink); font-family: inherit; text-align: left;
  display: flex; align-items: baseline; gap: 6px; white-space: nowrap;
}
.dir-num:hover { background: var(--surface); }
.dir-num:active { transform: translateY(1px); box-shadow: none; }
.dir-num .lbl { font-size: 8px; letter-spacing: .1em;
                text-transform: uppercase; color: var(--muted); font-weight: 700; }
.dir-num .val { font-family: var(--num); font-size: 12px;
                font-variant-numeric: tabular-nums; }

/* Narrow screens: the subtitle drops under the name and numbers wrap below. */
@media (max-width: 620px) {
  .dir-row { flex-wrap: wrap; padding: 5px 2px; }
  .dir-who { display: block; }
  .dir-who .s { margin-top: 1px; }
  .dir-nums { flex-basis: 100%; padding-left: 37px; flex-wrap: wrap; }
}

/* voicemail: save-destination bar */
.vm-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.vm-bar-info {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.vm-bar-info strong { color: var(--ink); font-weight: 600; }
.vm-bar-actions { display: flex; gap: 6px; flex-wrap: nowrap; flex: 0 0 auto; }
@media (max-width: 480px) {
  .vm-bar { padding: 8px 10px; gap: 8px; }
  .vm-bar-info { flex-basis: 100%; }
  .vm-bar-actions { flex: 1 1 auto; }
  .vm-bar-actions .btn { flex: 1; white-space: nowrap; }
}

/* voicemail player row */
.vm audio { width: 100%; margin-top: 8px; height: 34px; }
.vm.unheard .t::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 7px; vertical-align: middle;
}
/* ---------------------------------------------------------------- AI briefing
   Rendered inline under the call row that requested it. */
.brief-slot[hidden] { display: none !important; }
.brief {
  margin: 2px 0 10px; padding: 10px 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm);
}
.brief-head {
  margin: 0 0 6px; font-size: 10px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); font-weight: 700;
}
.brief-body { font-size: 13px; line-height: 1.55; color: var(--ink); }
.brief-body ul { margin: 0; padding-left: 17px; }
.brief-body li { margin: 0 0 4px; }
.brief-body p { margin: 0 0 5px; }
.brief-foot {
  margin: 8px 0 0; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 10.5px; color: var(--muted); flex-wrap: wrap;
}
.brief-loading, .brief-error {
  margin: 2px 0 10px; padding: 9px 12px; font-size: 12.5px;
  background: var(--surface-2); border: 1px dashed var(--line);
  border-radius: var(--radius-sm); color: var(--muted);
}
.brief-error { color: var(--danger); border-color: var(--danger); border-style: solid; }

.vm-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* On a phone the three action buttons need ~206px, and with `flex:0 1 auto`
   they take it out of the content column — squeezing the title, player,
   summary and transcript into ~87px (a 763px-tall wall of one-word lines).
   Give the content and the actions a full row each instead. */
@media (max-width: 620px) {
  .vm > .grow, .vm .vm-actions,
  .fax-in > .grow, .fax-in .vm-actions { flex: 1 1 100%; }
  .vm .vm-actions, .fax-in .vm-actions { margin-top: 8px; }
  .vm .vm-actions .btn, .fax-in .vm-actions .btn { flex: 1; white-space: nowrap; }
}

/* Call-log rows carry up to 4 actions (Brief/Call/Asana/Block) + pills. The
   Recent-calls column can be narrow even in a wide window (two-column layout),
   so wrapping must key off available space, NOT window width: the actions group
   sits at the end of the row when it fits and drops to its own line when it
   doesn't, and the name column keeps a floor so text never collapses to one
   word per line. */
.call-row { flex-wrap: wrap; row-gap: 6px; align-items: center; }
.call-row > .grow { min-width: 150px; }
.call-actions {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  flex: 0 1 auto; margin-left: auto;
}

/* ---------------------------------------------------------------- sms threads */
.thread-row { cursor: pointer; }
.thread-row:hover { background: var(--surface-2); }
.thread-row.unread .t { font-weight: 700; }
.thread-row.unread .s { color: var(--ink); }

/* thread modal: bubbles + a pinned compose bar */
#thread-modal .modal-body.thread-body { display: flex; flex-direction: column; gap: 7px; }
.bubble {
  max-width: 82%; padding: 8px 12px; border-radius: 14px; font-size: 14px; line-height: 1.4;
}
.bubble.out { align-self: flex-end; background: var(--accent); color: var(--btn-ink); border-bottom-right-radius: 5px; }
.bubble.in  { align-self: flex-start; background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.bubble.failed.out { background: var(--danger); }
.bubble-text { margin: 0; white-space: pre-wrap; word-break: break-word; }
.bubble-meta { margin: 3px 0 0; font-size: 10px; opacity: .7; font-family: var(--num); }
.bubble.in .bubble-meta { color: var(--muted); }

.thread-foot { flex: 0 0 auto; border-top: 1px solid var(--line-soft); padding: 10px 16px 14px; }
.compose { display: flex; flex-direction: column; gap: 7px; }
.compose #reply-text {
  width: 100%; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 11px; font: inherit; font-size: 14px; resize: vertical; min-height: 40px;
}
.compose #reply-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.compose-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.compose-actions .btn.sm { padding: 6px 16px; }
#thread-ai-out[hidden] { display: none !important; }
#thread-ai-out { margin-bottom: 8px; }
.ai-note { margin: 0; font-size: 12px; color: var(--good); font-weight: 600; }

/* quick-reply templates dropdown */
.reply-templates { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.reply-templates[hidden] { display: none !important; }
.tpl-item {
  appearance: none; text-align: left; cursor: pointer; width: 100%;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 8px 11px; font: inherit; font-size: 13px;
}
.tpl-item:hover { background: var(--surface); border-color: var(--accent); }

/* image bubble + attach preview */
.bubble-img { display: block; max-width: 200px; max-height: 220px; width: auto; height: auto;
              border-radius: 9px; margin-bottom: 4px; }
.img-attach { position: relative; display: inline-block; margin-bottom: 4px; }
.img-attach[hidden] { display: none !important; }
.img-attach img { max-width: 96px; max-height: 96px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.img-attach .img-x {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; border: none; cursor: pointer; font-size: 14px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}

/* ---------------------------------------------------------------- sms contact picker */
.sms-suggest {
  margin: -6px 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface-2); max-height: 240px; overflow-y: auto; overscroll-behavior: contain;
}
.sms-suggest[hidden] { display: none !important; }
.sms-sug {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px; width: 100%;
  appearance: none; background: transparent; border: none; cursor: pointer; text-align: left;
  padding: 9px 12px; border-bottom: 1px solid var(--line-soft); color: var(--ink); font: inherit;
}
.sms-sug:last-child { border-bottom: none; }
.sms-sug:hover, .sms-sug:focus-visible { background: var(--surface); outline: none; }
.sms-sug-name { font-size: 13.5px; font-weight: 600; }
.sms-sug-num { font-size: 12px; color: var(--muted); font-family: var(--num); white-space: nowrap; }
.sms-sug-type {
  font-family: var(--font); font-size: 9px; letter-spacing: .08em; text-transform: uppercase;
  font-weight: 700; color: var(--muted); margin-right: 4px;
}
.sms-sug-type.mob { color: var(--good); }
.sms-to-name { margin: -6px 0 10px; font-size: 12.5px; color: var(--good); font-weight: 600; }
.sms-to-name[hidden] { display: none !important; }

/* ---------------------------------------------------------------- history modal */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.5); padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.35);
}
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px 12px; border-bottom: 1px solid var(--line-soft); flex: 0 0 auto;
}
.modal-title { margin: 0; font-size: 17px; font-weight: 700; color: var(--ink); }
.modal-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-x {
  appearance: none; border: none; background: transparent; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--muted); padding: 0 2px; flex: 0 0 auto;
}
.modal-x:hover { color: var(--ink); }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; overscroll-behavior: contain; flex: 1 1 auto; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--line-soft); flex: 0 0 auto;
}
.modal-foot .btn:only-child { margin-left: auto; }

.hist-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.hist-item:last-child { border-bottom: none; }
.hist-ic {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin-top: 1px;
}
.hist-ic.in { color: var(--good); }
.hist-ic.out { color: var(--accent); }
.hist-ic.vm { color: var(--accent); }
.hist-t { margin: 0; font-size: 13.5px; font-weight: 600; color: var(--ink); }
.hist-s { margin: 1px 0 0; font-size: 11.5px; color: var(--muted); }
.hist-sum { margin: 5px 0 0; font-size: 12.5px; line-height: 1.45; color: var(--ink);
            border-left: 2px solid var(--accent); padding-left: 8px; }
.hist-item audio { width: 100%; margin-top: 7px; height: 32px; }
.hist-item .btn { margin-top: 7px; }

/* ---------------------------------------------------------------- ask */
#ask-card { margin-bottom: 10px; }
.ask-row { display: flex; gap: 8px; }
.ask-row #ask-input {
  flex: 1 1 auto; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--radius-sm); padding: 9px 12px; font: inherit; font-size: 14px;
}
.ask-row #ask-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.ask-row #ask-btn { flex: 0 0 auto; }
.ask-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
#ask-answer[hidden] { display: none !important; }
#ask-answer { margin-top: 12px; }
.ask-a {
  font-size: 13.5px; line-height: 1.55; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 11px 13px;
}
.ask-a ul { margin: 0; padding-left: 17px; }
.ask-a li { margin: 0 0 4px; }
.ask-a p { margin: 0 0 6px; }
.ask-a p:last-child, .ask-a li:last-child { margin-bottom: 0; }
.ask-foot { margin: 6px 0 0; font-size: 10.5px; color: var(--muted); }
.ask-loading, .ask-error {
  font-size: 12.5px; padding: 10px 13px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px dashed var(--line); color: var(--muted);
}
.ask-error { color: var(--danger); border-color: var(--danger); border-style: solid; }

/* ---------------------------------------------------------------- analytics */
.data-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 5px; }
.chip {
  appearance: none; cursor: pointer; font: 600 12px var(--num);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
  border-radius: 99px; padding: 4px 11px;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--btn-ink); }

.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px; margin-bottom: 10px;
}
.kpi {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px 13px;
}
.kpi-v { margin: 0; font: 700 24px/1 var(--num); color: var(--ink); letter-spacing: -.01em; }
.kpi-l { margin: 3px 0 0; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kpi-s { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#tab-data h3 { margin: 0 0 10px; font-size: 13px; }
.chart-note { margin: 8px 0 0; font-size: 11px; color: var(--muted); }

.chart-svg { width: 100%; height: 90px; display: block; }
.chart-axis { display: flex; justify-content: space-between; margin-top: 4px; font: 10px var(--num); color: var(--muted); }
.legend { display: flex; gap: 14px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

.obar { margin-bottom: 10px; }
.obar:last-child { margin-bottom: 0; }
.obar-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink); margin-bottom: 4px; }
.obar-top span:last-child { color: var(--muted); font-family: var(--num); }
.obar-track { height: 8px; background: var(--surface); border-radius: 99px; overflow: hidden; }
.obar-fill { height: 100%; border-radius: 99px; min-width: 2px; transition: width .3s; }

.hchart { display: flex; align-items: flex-end; gap: 2px; height: 74px; }
.hbar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.hbar-fill { width: 100%; background: var(--line); border-radius: 2px 2px 0 0; min-height: 1px; }
.hbar-fill.peak { background: var(--accent); }

@media (max-width: 620px) {
  .grid2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-v { font-size: 21px; }
}

/* received-fax summary (Claude read the PDF) */
.fax-summary {
  margin: 6px 0 0; font-size: 13px; line-height: 1.45; color: var(--ink);
  border-left: 2px solid var(--accent); padding-left: 8px;
}
.fax-in.unheard .t::before {
  content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); margin-right: 7px; vertical-align: middle;
}

/* Whisper transcript + Claude gist */
.vm-summary {
  margin: 6px 0 0; font-size: 13.5px; line-height: 1.45; color: var(--ink); font-weight: 500;
  border-left: 2px solid var(--accent); padding-left: 8px;
}
.vm-pending { margin: 6px 0 0; font-size: 12px; color: var(--muted); font-style: italic; }
.vm-transcript { margin-top: 8px; }
.vm-transcript > summary {
  cursor: pointer; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); font-weight: 700; list-style: none; user-select: none;
}
.vm-transcript > summary::-webkit-details-marker { display: none; }
.vm-transcript > summary::before { content: "▸ "; }
.vm-transcript[open] > summary::before { content: "▾ "; }
.vm-transcript > p {
  margin: 6px 0 0; font-size: 13px; line-height: 1.55; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm); padding: 8px 10px;
}
.tabbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(74px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 60;
  max-width: min(90vw, 460px);
  text-align: center;
}
#toast[hidden] { display: none !important; }
#toast.bad { background: var(--danger); color: #f8f3e9; }

/* ----------------------------------------------------------- build badge */
/* Top-left: sits in the header's top padding above the logo, clear of the status-bar
   blur (see the phone block near the end) and of the DND pill, lamp and L/D/A toggle. Tiny on
   purpose. --muted is only 3.48:1 on the light --nav, so each theme names its own value.
   Measured: #4a3d2e is 7.15:1 on --nav #ded4c1 and 8.01:1 on --bg #e8e0d1 (boot / PIN
   gate); #b8a68a is 6.96:1 on #241e16 and 7.28:1 on #1f1a15. Failure: --accent #8c2f22
   5.62:1 light, #f08a55 6.66:1 dark. The two browns replaced #5e4f3e / --muted (5.37:1
   and 5.20:1) on 2026-09-25: those passed on paper and were still unreadable on the
   phone, because the real background was the notch wash rather than the token. */
.app-version {
  position: fixed; z-index: 200; pointer-events: none;   /* above the PIN gate (100) and the call screen (60) */
  top: calc(env(safe-area-inset-top, 0px) + 2px);
  left: calc(env(safe-area-inset-left, 0px) + 16px);
  font: 600 10px/10px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .2px; color: #4a3d2e; white-space: nowrap;
}
.app-version.fail { color: #8c2f22; font-weight: 700; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .app-version { color: #b8a68a; }
  :root:not([data-theme="light"]) .app-version.fail { color: #f08a55; }
}
:root[data-theme="dark"] .app-version { color: #b8a68a; }
:root[data-theme="dark"] .app-version.fail { color: #f08a55; }

/* ------------------------------------------------- status-bar fill (iOS 26)
   iOS lays a blurred "scroll edge" wash over the top of an installed web app
   wherever WebKit cannot sample a flat color at the very top edge, and it
   bleeds about 10px PAST safe-area-inset-top. Measured on David's iPhone 16
   Pro, 2026-09-27: the build badge inside that band rendered as a smear whose
   darkest pixel was 1.52:1 against its own background. WebKit skips the wash
   when an OPAQUE, FIXED box touches the top edge and extends that box's color
   upward instead. The header is opaque and reaches the top edge but is NOT
   fixed, which is not enough, so this strip supplies the fixed one.
   z-index 50 keeps it under the modal scrim (60), the PIN gate (100) and the
   badge (200): while any of those covers the screen, that layer is the opaque
   box being sampled and the strip is not needed. Height collapses to 0 where
   there is no inset, so it costs a desktop nothing.
   UNVERIFIED ON A DEVICE. The phone block near the end of this file also
   clears the badge out of the bleed, so if this strip turns out to do nothing,
   nothing is left sitting in the smear. */
#statusfill {
  position: fixed; top: 0; left: 0; right: 0;
  height: env(safe-area-inset-top, 0px);
  background: var(--nav);
  z-index: 50; pointer-events: none;
}

/* ---------------------------------------------------------------- PIN gate */

.pin-gate {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  overflow: hidden;
}
/* Author display: rules beat the UA's [hidden] rule — restate it explicitly. */
.pin-gate[hidden] { display: none !important; }

.pin-gate .mark {
  font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
}
.pin-box{--pk-s:clamp(56px,min(10vh,22vw),84px);--pk-ink:var(--ink);--pk-muted:var(--muted);--pk-line:var(--line);--pk-surface:var(--surface);--pk-accent:var(--accent);--pk-accent-ink:var(--btn-ink);--pk-bad:var(--danger);
  display:flex;flex-direction:column;align-items:center;gap:clamp(12px,2.5vh,22px);
  touch-action:manipulation;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
.pin-dots{display:flex;gap:10px}
.pin-dots span{width:14px;height:14px;border-radius:50%;border:2px solid var(--pk-ink);box-sizing:border-box}
.pin-dots span.on{background:var(--pk-ink)}
.pin-box.busy .pin-dots span.on{animation:pinpulse .9s ease-in-out infinite}
@keyframes pinpulse{50%{opacity:.35}}
.pin-box.bad .pin-dots{animation:pinshake .35s}
@keyframes pinshake{20%,60%{transform:translateX(-8px)}40%,80%{transform:translateX(8px)}}
.pin-msg{min-height:1.3em;font-size:16px;line-height:1.3;color:var(--pk-muted);text-align:center;font-weight:700}
.pin-box.bad .pin-msg{color:var(--pk-ink)}
.pin-pad{touch-action:manipulation;display:grid;grid-template-columns:repeat(3,var(--pk-s));gap:clamp(10px,2vh,16px)}
.pin-pad button{height:var(--pk-s);width:var(--pk-s);border-radius:50%;border:1px solid var(--pk-line);background:var(--pk-surface);color:var(--pk-ink);
  font-family:inherit;font-weight:700;font-size:clamp(26px,4vh,32px);line-height:1;padding:0;touch-action:manipulation;-webkit-tap-highlight-color:transparent;cursor:pointer}
.pin-pad button:active{background:var(--pk-accent);color:var(--pk-accent-ink)}
.pin-pad button:disabled{opacity:.5}
.pin-pad .pin-del{border:none;background:transparent;font-size:24px}
@media (max-height:600px){.pin-box{--pk-s:56px;gap:8px}.pin-pad{gap:8px}}

/* ---------------------------------------------------------------- details */

details.sect {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
}
details.sect > summary {
  cursor: pointer;
  padding: 12px 15px;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase; font-weight: 700;
  color: var(--muted);
  list-style: none;
}
details.sect > summary::-webkit-details-marker { display: none; }
details.sect > summary::after { content: " +"; float: right; font-family: var(--num); }
details.sect[open] > summary::after { content: " \2212"; }
details.sect > .inner { padding: 0 15px 14px; border-top: 1px solid var(--line-soft); padding-top: 12px; }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 640px) {
  .tab { padding: 12px 12px 14px; }
  .grid { grid-template-columns: 1fr; }
  .brand .line-num { display: none; }
  /* The switcher now carries the identity, so the static app title can give up
     its room on a phone header instead of crowding it into an overflow. */
  .brand h1 { display: none; }
  .id-switch #id-switch-name { max-width: 46vw; }
  /* Anchor the dropdown to the viewport so it can't spill off the right edge. */
  .id-menu {
    position: fixed; left: 8px; right: 8px; top: 56px;
    min-width: 0; max-width: none; width: auto;
  }
}

/* ---------------------------------------------------------------- fit-the-viewport
   From tablet width up, the PAGE never scrolls. Cards are capped to the
   available height and any inherently-long list (a 5,900-name directory, call
   history) scrolls inside its own container instead. That's the native-app
   feel: chrome fixed, only the data moves. */
@media (min-width: 700px) {
  #main { overflow: hidden; }

  .tab { height: 100%; min-height: 0; }
  .tab > .grid { height: 100%; min-height: 0; align-content: start; }

  .card { max-height: 100%; min-height: 0; display: flex; flex-direction: column; }
  .card > h2, .card > h3 { flex: 0 0 auto; }

  /* The list is the part that gives — everything else keeps its natural size.
     The cap has to be in viewport units: the grid rows are min-content, so a
     percentage max-height resolves against the row's own natural height and
     caps nothing. Budget = header + tab bar + tab/card padding + card title. */
  .card > .rows {
    flex: 1 1 auto; min-height: 0;
    max-height: calc(100dvh - 235px);
    overflow-y: auto; overscroll-behavior: contain;
  }
  /* The Phone tab also carries the alerts banner above the two cards. */
  /* Below 900px the dialer and call log stack, so the log needs a tighter cap. */
  #tab-phone .card > .rows { max-height: calc(100dvh - 285px); }
  @media (max-width: 899px) { #tab-phone .card > .rows { max-height: calc(100dvh - 560px); } }

  /* Settings and the analytics dashboard are stacks of cards rather than a
     single list, so they scroll as a unit inside the fixed chrome. Without
     this the taller-than-viewport dashboard is clipped by #main's overflow
     with no way to reach the bottom. */
  #tab-settings > div, #tab-data > div { height: 100%; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

  /* The dialer must never be squeezed — a clipped keypad is unusable. */
  #card-dialer { max-height: none; }

  /* The directory is a single card that should OWN the height: with a
     min-content row its inner grid gets ~one row and paginates to 5 cards. */
  #tab-contacts > .grid { grid-auto-rows: minmax(0, 1fr); align-content: stretch; }
  #dir-card { max-height: none; height: 100%; }
}

/* ---------------------------------------------------------------- phone
   The fit-the-viewport system above starts at 700px, so until now a phone got
   the one thing rule §3 rules out: the whole page scrolling. Measured at
   402x874 with the real insets (62 top, 34 bottom), the Phone tab ran 1538px
   into a 671px window, so Recent calls sat 867px below the fold and its
   buttons were hidden behind the tab bar.

   Same shape as the tablet block: the dialer keeps its natural size, the call
   log is the part that gives and scrolls inside its own container. The page
   itself is left scrollable rather than clipped (#main keeps overflow-y:auto),
   so if a future device is shorter than the numbers below assume, the view
   degrades to a small scroll instead of stranding content with no way to
   reach it (rule §18). */
@media (max-width: 699px) {
  /* Fill the window exactly, then hand the slack to the log. */
  #tab-phone { height: 100%; min-height: 0; padding: 10px 16px 12px; }
  #tab-phone > .grid {
    display: flex; flex-direction: column;
    height: 100%; min-height: 0; gap: 10px;
  }
  #tab-phone #card-dialer { flex: 0 0 auto; }
  #tab-phone #card-calls {
    flex: 1 1 auto; min-height: 0;
    display: flex; flex-direction: column;
  }
  #tab-phone #card-calls > h2 { flex: 0 0 auto; }
  #tab-phone #card-calls > .rows {
    flex: 1 1 auto; min-height: 0;
    overflow-y: auto; overscroll-behavior: contain;
  }

  /* Condensing the dialer is what buys the log its room (rule §3: trim so it
     fits before you let anything scroll). Keys lose 6px of padding each, which
     is 51px across four rows and still leaves a 52px tap target, well over the
     44px minimum. The card keeps its own "Recent calls" title; the DIALER one
     goes, because a keypad does not need to be labelled as one. */
  #tab-phone .card { padding: 10px 12px; }
  #tab-phone #card-dialer > h2 { display: none; }
  #tab-phone .readout { padding: 9px 12px; }
  #tab-phone .keypad { gap: 6px; }
  #tab-phone .key { padding: 8px 0; }

  /* The badge sat at inset+1px, inside the iOS status-bar wash, and was
     illegible on the device in both builds so far. Push it clear of the ~10px
     bleed and give the header room for it. The smear ended 71.7px below the top
     on the device, so the badge now starts at inset+13. Costs 17px, paid for
     several times over by the condensing above. #statusfill may make this
     unnecessary; it
     stays until the phone says so. */
  .hdr { padding-top: calc(27px + env(safe-area-inset-top)); }
  .app-version { top: calc(env(safe-area-inset-top, 0px) + 13px); }
}

/* The unread counts were absolutely positioned with no anchor, so their static
   position was inside the tab button and translate(18px,-22px) lifted them OUT
   of the bar and onto whatever card sat behind it. On the Phone tab they
   landed on the Brief / Call / Asana buttons. Anchor them to the button. */
.tabbar .badge { top: 5px; left: 50%; transform: translateX(3px); }

/* ---------------------------------------------------------- short windows
   The fit-the-viewport rules assume a window tall enough to hold a card.
   A phone held sideways is not: measured at 874x402 with landscape insets,
   the Phone tab needed 441px inside a 263px #main, and because #main is
   overflow:hidden above 700px WIDE, 178px was clipped with no way to scroll
   to it. The Call button's top sat 164px below the bottom of the window, so
   the app simply could not place a call in landscape (rule §18: never a view
   you can get stuck in). Width said "tablet", height said otherwise.

   Below 560px tall, give the scrolling back. An iPhone in landscape is about
   400px, an iPad in landscape 768px, so this catches phones on their side and
   short desktop windows and leaves every tablet alone. */
@media (max-height: 560px) {
  #main { overflow-y: auto; }
  .tab { height: auto; min-height: 100%; }
  .tab > .grid { height: auto; }
  .card { max-height: none; }
  .card > .rows, #tab-phone .card > .rows { max-height: none; overflow-y: visible; }
  #tab-settings > div, #tab-data > div { height: auto; overflow-y: visible; }
  #tab-contacts > .grid { grid-auto-rows: min-content; align-content: start; }
  #dir-card { height: auto; }
}

/* Wide screens: dialer gets a fixed sane column, log fills the rest. */
@media (min-width: 900px) {
  #tab-phone .grid { grid-template-columns: minmax(300px, 360px) 1fr; }

  /* A .wide card spans every track, which forces the track count and stops
     auto-fit collapsing the extras — so the remaining cards would sit narrow
     with dead space beside them. Pin these tabs to a column count instead. */
  #tab-messages .grid { grid-template-columns: 1fr 1fr; }
  #tab-voicemail .grid { grid-template-columns: 1fr; }
}

/* History search (2026-10-02): the box above Recent calls, the who-line on each hit, the
   "possible matches" divider, and the footer that says how many more there are. */
.hist-bar { margin-bottom: 6px; }
.hist-who { margin: 0 0 1px; font-size: 12px; font-weight: 700; color: var(--accent); }
.hist-who .num { font-weight: 500; color: var(--muted); }
.search-divider { font-size: 12px; font-weight: 700; color: var(--muted); margin: 12px 0 4px; padding-top: 8px; border-top: 1px dashed var(--line-soft); }
.search-more { margin: 10px 0 0; font-size: 12px; color: var(--muted); text-align: center; }

/* ---- Pictures (2026-10-16): the texting line's pictures, a grid that scrolls inside its own card.
   Badge: --btn-ink on --accent measures 8.6:1 in light (#f8f3e9 on #8c2f22) and 6.5:1 in dark (#231a12 on #e0733f). */
.pic-hint { margin: 0 0 10px; font-size: 12.5px; color: var(--muted); }
.pic-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(min(30%, 120px), 1fr)); gap: 8px;
  max-height: min(56vh, 520px); overflow-y: auto; overscroll-behavior: contain;
}
.pic-grid .empty { grid-column: 1 / -1; }
.pic-tile {
  appearance: none; position: relative; aspect-ratio: 1; padding: 0; margin: 0; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-2);
}
.pic-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pic-tile .pic-badge {
  position: absolute; left: 6px; top: 6px; font-size: 11px; font-weight: 700; padding: 2px 6px;
  border-radius: var(--radius-sm); background: var(--accent); color: var(--btn-ink);
}
/* Photolab's status line (2026-10-17). Text is --ink and --muted on the card, the same pairs as the hint above it;
   the dot is decoration only (the words carry the state). */
.pl-status { margin: -4px 0 10px; font-size: 12.5px; color: var(--ink); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.pl-status[hidden] { display: none; }
.pl-status .pl-heard { color: var(--muted); }
.pl-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.pl-dot.pl-idle, .pl-dot.pl-rendering { background: var(--good); }
.pl-dot.pl-busy, .pl-dot.pl-held { background: var(--warn); }
.pic-card { max-width: min(920px, 100%); }
.pic-body { display: flex; align-items: center; justify-content: center; padding: 10px; }
.pic-body img { display: block; max-width: 100%; max-height: 64vh; object-fit: contain; border-radius: var(--radius-sm); }
.pic-foot { flex-wrap: wrap; justify-content: flex-start; }
.pic-foot #pic-done { margin-left: auto; }
