/*
 * Mini Dialer — shadcn/ui design system, no React runtime.
 *
 * WHY IT LOOKS LIKE SHADCN BUT ISN'T REACT
 *
 * shadcn/ui is a React + Tailwind component collection with a build step. This
 * product must install with `sudo ./install.sh` on a bare server with no npm,
 * so shipping a React toolchain would break the one property the brief calls
 * non-negotiable. What is adopted here is shadcn's DESIGN SYSTEM, verbatim:
 * its exact HSL token contract (--background, --foreground, --primary,
 * --muted, --border, --ring, --radius), its neutral scale, its component
 * anatomy (card > header/content, button variants, input + ring focus), and
 * its restraint. Swapping in a real React build later means replacing
 * templates/ and this file, and nothing behind them.
 *
 * Layout: a phone below 640px, a softphone panel above it. Fluid from 320px to
 * 1920px, and nothing scrolls sideways.
 */

/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light dark;

  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --popover: 0 0% 100%;
  --popover-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 5.9% 10%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 3.8% 46.1%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 72.2% 50.6%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 33%;
  --success-foreground: 0 0% 98%;
  --warning: 38 92% 45%;
  --border: 240 5.9% 90%;
  --input: 240 5.9% 90%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;

  --key-size: clamp(56px, 17vw, 72px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 3.9%;
    --card-foreground: 0 0% 98%;
    --popover: 240 10% 3.9%;
    --popover-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 64.9%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --destructive: 0 62.8% 50%;
    --destructive-foreground: 0 0% 98%;
    --success: 142 60% 45%;
    --warning: 38 92% 55%;
    --border: 240 3.7% 15.9%;
    --input: 240 3.7% 15.9%;
    --ring: 240 4.9% 83.9%;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100dvh; overflow-x: hidden; }

.screen[hidden], [hidden] { display: none !important; }

.screen--center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}

.text-center { text-align: center; }

/* ---------------------------------------------------------------- card */

.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 3px 0 hsl(var(--foreground) / .06), 0 1px 2px -1px hsl(var(--foreground) / .06);
  width: 100%;
  max-width: 34rem;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}
.card--narrow { max-width: 24rem; }
.card__header { padding: 24px 24px 0; }
.card__content { padding: 24px; }
.card__title { font-size: 1.125rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 4px; }
.card__desc { font-size: .8125rem; color: hsl(var(--muted-foreground)); margin: 0; }

.stack { display: flex; flex-direction: column; gap: 16px; }
.stack--tight { gap: 10px; }
.row { display: flex; align-items: center; }
.row--gap { gap: 8px; }
.row--between { justify-content: space-between; align-items: flex-start; }
.row--wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.grid--2 { grid-template-columns: 1fr 1fr; }

.separator { height: 1px; background: hsl(var(--border)); margin: 4px 0; }

/* ---------------------------------------------------------------- form */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.label {
  font-size: .8125rem;
  font-weight: 500;
  line-height: 1;
  color: hsl(var(--foreground));
}
.field__hint { font-size: .75rem; color: hsl(var(--muted-foreground)); margin: 0; }

.input, .select {
  display: flex;
  width: 100%;
  height: 40px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--input));
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  padding: 8px 12px;
  font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
.select { appearance: none; padding-right: 32px;
  background-image: linear-gradient(45deg, transparent 50%, hsl(var(--muted-foreground)) 50%),
                    linear-gradient(135deg, hsl(var(--muted-foreground)) 50%, transparent 50%);
  background-position: calc(100% - 16px) 17px, calc(100% - 11px) 17px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.input::placeholder { color: hsl(var(--muted-foreground)); }
.input:focus-visible, .select:focus-visible, .btn:focus-visible, .key:focus-visible, .ctl:focus-visible {
  outline: none;
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring) / .45);
}
.input:disabled, .select:disabled { opacity: .5; cursor: not-allowed; }

.range { width: 100%; accent-color: hsl(var(--primary)); }

.disclosure { border-top: 1px solid hsl(var(--border)); padding-top: 12px; }
.disclosure > summary {
  cursor: pointer;
  font-size: .8125rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  list-style: none;
  padding: 4px 0;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "▸ "; }
.disclosure[open] > summary::before { content: "▾ "; }
.disclosure > * + * { margin-top: 12px; }

/* ---------------------------------------------------------------- button */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  height: 40px;
  padding: 0 16px;
  cursor: pointer;
  transition: background-color .15s, opacity .15s, color .15s;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}
.btn:hover { background: hsl(var(--secondary) / .8); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn--block { width: 100%; }
.btn--sm { height: 32px; font-size: .8125rem; padding: 0 12px; }
.btn--primary { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); }
.btn--primary:hover { background: hsl(var(--primary) / .9); }
.btn--ghost { background: transparent; border-color: hsl(var(--border)); color: hsl(var(--foreground)); }
.btn--ghost:hover { background: hsl(var(--accent)); }
.btn--destructive { background: hsl(var(--destructive)); color: hsl(var(--destructive-foreground)); min-width: 132px; }
.btn--destructive:hover { background: hsl(var(--destructive) / .9); }
.btn--call { background: hsl(var(--success)); color: hsl(var(--success-foreground)); min-width: 132px; }
.btn--call:hover { background: hsl(var(--success) / .9); }
.btn--icon {
  height: 36px; width: 36px; padding: 0;
  background: transparent; color: hsl(var(--muted-foreground));
}
.btn--icon:hover { background: hsl(var(--accent)); color: hsl(var(--foreground)); }

/* ---------------------------------------------------------------- misc */

.badge {
  display: inline-flex; align-items: center;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  padding: 2px 10px;
  font-size: .75rem;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.badge--mock { border-color: hsl(var(--warning)); color: hsl(var(--warning)); }

.banner {
  padding: 10px 16px;
  font-size: .8125rem;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--muted));
  color: hsl(var(--foreground));
}
.banner.destructive { background: hsl(var(--destructive) / .1); color: hsl(var(--destructive)); border-color: hsl(var(--destructive) / .3); }
.banner.warning { background: hsl(var(--warning) / .12); color: hsl(var(--warning)); border-color: hsl(var(--warning) / .35); }

.msg { font-size: .8125rem; margin: 0; min-height: 1.2em; color: hsl(var(--muted-foreground)); }
.msg.error { color: hsl(var(--destructive)); }
.msg.ok { color: hsl(var(--success)); }

.passcode {
  display: block;
  font: 600 1.25rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .12em;
  background: hsl(var(--muted));
  border: 1px dashed hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 16px;
  text-align: center;
  user-select: all;
  overflow-wrap: anywhere;
}

/* Connect progress list (§19) */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps li {
  font-size: .8125rem;
  color: hsl(var(--muted-foreground));
  display: flex; align-items: center; gap: 8px;
}
.steps li::before { content: "○"; width: 1em; }
.steps li[data-status="ok"] { color: hsl(var(--success)); }
.steps li[data-status="ok"]::before { content: "✓"; }
.steps li[data-status="active"]::before { content: "●"; }
.steps li[data-status="fail"] { color: hsl(var(--destructive)); }
.steps li[data-status="fail"]::before { content: "✕"; }
.steps li[data-status="skip"] { opacity: .55; }
.steps li[data-status="skip"]::before { content: "–"; }

/* ---------------------------------------------------------------- topbar */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border));
  position: sticky; top: 0; z-index: 5;
}
.topbar__identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar__text { display: flex; flex-direction: column; min-width: 0; }
.topbar__text strong { font-size: .875rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__sub { font-size: .75rem; color: hsl(var(--muted-foreground)); white-space: nowrap; }
.topbar__actions { display: flex; align-items: center; gap: 8px; }

.status-dot {
  width: 8px; height: 8px; flex: 0 0 8px; border-radius: 9999px;
  background: hsl(var(--muted-foreground));
  box-shadow: 0 0 0 3px hsl(var(--muted-foreground) / .18);
}
.status-dot[data-state="ready"] { background: hsl(var(--success)); box-shadow: 0 0 0 3px hsl(var(--success) / .2); }
.status-dot[data-state="connecting"],
.status-dot[data-state="registering"],
.status-dot[data-state="reconnecting"] { background: hsl(var(--warning)); box-shadow: 0 0 0 3px hsl(var(--warning) / .2); }
.status-dot[data-state="error"] { background: hsl(var(--destructive)); box-shadow: 0 0 0 3px hsl(var(--destructive) / .2); }

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

.dialer {
  max-width: 26rem;
  margin: 0 auto;
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}

.display {
  display: flex; align-items: center; gap: 4px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 4px 8px 4px 14px;
}
.display__number {
  flex: 1; min-width: 0;
  border: 0; background: transparent; color: hsl(var(--foreground));
  font: 600 clamp(20px, 6vw, 26px)/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  letter-spacing: .02em;
  padding: 12px 0; text-align: center;
}
.display__number:focus { outline: none; }
.display__number::placeholder { font-size: .875rem; font-family: inherit; letter-spacing: normal; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; justify-items: center; }
.key {
  width: 100%; max-width: var(--key-size); aspect-ratio: 1;
  border-radius: 9999px;
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  cursor: pointer;
  display: grid; place-content: center; gap: 1px;
  transition: transform .06s ease, background-color .12s ease;
}
.key:hover { background: hsl(var(--accent)); }
.key:active { transform: scale(.96); }
.key__digit { font-size: clamp(18px, 5vw, 22px); font-weight: 500; }
.key__letters { font-size: 9px; letter-spacing: .12em; color: hsl(var(--muted-foreground)); }
.keypad--dtmf .key { border-color: hsl(var(--ring) / .6); }

.call-actions { display: flex; justify-content: center; gap: 12px; }

.callstate { display: flex; align-items: baseline; justify-content: center; gap: 10px; min-height: 22px; }
.callstate__label { font-size: .8125rem; font-weight: 500; color: hsl(var(--muted-foreground)); }
.callstate__label[data-state="connected"] { color: hsl(var(--success)); }
.callstate__label[data-state="failed"] { color: hsl(var(--destructive)); }
.callstate__timer { font: 500 .8125rem ui-monospace, SFMono-Regular, Menlo, monospace; color: hsl(var(--muted-foreground)); }

.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ctl {
  font: 500 .8125rem/1 inherit;
  padding: 12px 4px; min-height: 42px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  cursor: pointer;
}
.ctl:hover:not(:disabled) { background: hsl(var(--accent)); }
.ctl[data-active="1"] { background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); border-color: transparent; }
/*
 * A refused capability is shown, disabled, with the platform's reason in its
 * tooltip — so a user learns what their plan is missing instead of wondering
 * where a button went. An UNKNOWN capability is hidden instead: the platform
 * never mentioned it, so there is nothing truthful to say about it.
 */
.ctl:disabled { opacity: .45; cursor: not-allowed; }
.ctl[data-capability-state="refused"]::after {
  content: "•"; color: hsl(var(--warning)); margin-left: 4px;
}

.incoming__number {
  font: 600 clamp(20px, 5.5vw, 26px)/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 8px 0 4px; overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: hsl(240 10% 3.9% / .6);
  display: grid; place-items: center;
  padding: 16px;
  overflow-y: auto;
}

/* --------------------------------------------------------- connection list */

.conn-list { display: flex; flex-direction: column; gap: 8px; }
.conn {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  padding: 12px;
}
.conn[data-active="1"] { border-color: hsl(var(--ring)); background: hsl(var(--accent) / .5); }
.conn__body { flex: 1; min-width: 0; }
.conn__name { font-weight: 500; display: flex; align-items: center; gap: 8px; }
.conn__meta { font-size: .75rem; color: hsl(var(--muted-foreground)); overflow-wrap: anywhere; }
.conn__actions { display: flex; gap: 6px; flex-shrink: 0; }

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

@media (min-width: 640px) {
  .dialer { padding: 24px 20px 32px; gap: 16px; }
  :root { --key-size: 68px; }
}

@media (min-width: 1024px) {
  .dialer {
    max-width: 27rem;
    margin: 28px auto;
    background: hsl(var(--card));
    border: 1px solid hsl(var(--border));
    border-radius: var(--radius);
    box-shadow: 0 4px 6px -1px hsl(var(--foreground) / .07), 0 2px 4px -2px hsl(var(--foreground) / .07);
    padding: 24px;
  }
  .key, .display { background: hsl(var(--background)); }
}

@media (max-height: 640px) and (min-width: 640px) {
  :root { --key-size: 54px; }
  .dialer { gap: 10px; margin: 12px auto; }
}

@media (prefers-reduced-motion: reduce) {
  .key, .btn, .input { transition: none; }
}

/* Compact — fits the embedded FAB panel (~600px tall) and short windows with no
   scrolling: smaller keys, tighter spacing, letters/description hidden. */
@media (max-height: 700px) {
  :root { --key-size: 46px; }
  .screen--center { min-height: 0; padding: 8px 10px; }
  .dialer { padding: 10px 12px 12px; gap: 8px; }
  .card__header { padding: 12px 14px 0; }
  .card__content { padding: 12px 14px; }
  .card { max-height: none; }
  .stack { gap: 8px; }
  .stack--tight { gap: 6px; }
  .field { gap: 3px; }
  .keypad { gap: 5px; }
  .key__digit { font-size: 16px; }
  .key__letters { display: none; }
  .display { padding: 6px 10px; }
  .display__number { font-size: 20px; }
  .controls { gap: 6px; }
  .input, .select { height: 34px; }
  .card__desc { display: none; }
}

/* Settings sections — the Mini Dialer design's Extensions / Caller ID / DepthRoute AI. */
.sect { display: flex; flex-direction: column; gap: 12px; padding: 16px;
        border: 1px solid hsl(var(--border)); border-radius: var(--radius); }
.sect__title { font-size: .72rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
               color: hsl(var(--muted-foreground)); margin: 0; }
.sect__panel { display: flex; flex-direction: column; gap: 12px; padding: 14px;
               border: 1px solid hsl(var(--border)); border-radius: calc(var(--radius) - 2px); }
.sect__panel-title { font-size: .7rem; font-weight: 600; letter-spacing: .07em; text-transform: uppercase;
                     color: hsl(var(--muted-foreground)); }
.pill { font-size: .72rem; font-weight: 600; border-radius: 999px; }
.pill[data-state="off"] { color: hsl(var(--warning)); }
.pill[data-state="on"]  { color: hsl(var(--success)); }

/* ------------------------------------------------------------ transcript */
/*
 * Sits inline under the dialer, not in an overlay: a transcript is read WHILE
 * talking, so covering the call controls with it would be the wrong shape.
 */
.transcript {
  max-width: 26rem;
  margin: 0 auto;
  padding: 0 16px 16px;
}
.transcript__head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding-bottom: 6px;
}
.transcript__title {
  font-size: .75rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: hsl(var(--muted-foreground));
}
.transcript__body {
  max-height: 15rem;
  overflow-y: auto;
  overscroll-behavior: contain;      /* scrolling the transcript must not scroll the page */
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--muted) / .35);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.transcript__body:empty { display: none; }

.transcript__line { display: flex; flex-direction: column; gap: 1px; font-size: .8125rem; }
.transcript__who {
  font-size: .6875rem; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: hsl(var(--muted-foreground));
}
.transcript__line[data-speaker="agent"] .transcript__who { color: hsl(var(--primary)); }
.transcript__text { overflow-wrap: anywhere; }
/* A non-final line is still being revised by the recogniser — shown as
   provisional rather than presented as settled text. */
.transcript__line[data-interim="1"] .transcript__text { opacity: .6; font-style: italic; }

@media (min-width: 1024px) {
  .transcript { max-width: 27rem; padding: 0 24px 24px; }
}
