/* 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;
}

.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;
}
.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;
}
/* 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; }
}

/* ---------------------------------------------------------------- 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; }

/* ---------------------------------------------------------------- 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: 24px;
}
/* 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-dots { display: flex; gap: 9px; }
.pin-dots i {
  width: 11px; height: 11px; border-radius: 50%;
  border: 1px solid var(--line); background: transparent;
}
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-keys { display: grid; grid-template-columns: repeat(3, 68px); gap: 10px; }
.pin-keys button {
  appearance: none; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--ink);
  font: 500 21px/1 var(--num); padding: 15px 0; cursor: pointer;
  box-shadow: 0 2px 0 var(--edge);
}
.pin-keys button:active { transform: translateY(2px); box-shadow: none; }
.pin-msg { font-size: 13px; color: var(--danger); min-height: 1.2em; }

/* ---------------------------------------------------------------- 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; }
}

/* ---------------------------------------------------------------- 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%; }
}

/* 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; }
}
