/* whatscaller — a softphone console.
 *
 * The visual model is a piece of rack equipment: a blue-slate chassis, engraved
 * silkscreen labels, and two signal colours that mean different things — amber for the
 * voice path (the "line in use" lamp) and cyan for telemetry. Nothing is decorative
 * that could be a readout instead.
 *
 * Committed to a single dark treatment: this is an instrument panel, and a light
 * version would be a different instrument.
 */

:root {
  color-scheme: dark;

  --rack:    #131820;  /* chassis */
  --panel:   #1a212c;  /* raised panel face */
  --panel-2: #212a38;  /* recessed key */
  --etch:    #2a3442;  /* engraved hairline */
  --label:   #8a97a8;  /* silkscreen */
  --readout: #e6edf5;  /* primary readout */
  --line:    #ffb454;  /* voice path / in use */
  --meter:   #4fd1c5;  /* telemetry */
  --fault:   #ff6b6b;

  --sans: 'Archivo', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Martian Mono', ui-monospace, 'SF Mono', 'Cascadia Mono', monospace;

  --gap: 1rem;
  --radius: 5px;
  --hair: 1px solid var(--etch);
  --lift: inset 0 1px 0 rgb(255 255 255 / 0.045);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background:
    radial-gradient(120% 80% at 50% -20%, #1b2331 0%, transparent 60%),
    var(--rack);
  color: var(--readout);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

/* --- silkscreen: the engraved panel label ------------------------------- */
.silk {
  font-family: var(--mono);
  font-size: 9.5px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--label);
}

/* --- panels ------------------------------------------------------------- */
.panel {
  background: linear-gradient(var(--panel), #171e28);
  border: var(--hair);
  border-radius: var(--radius);
  box-shadow: var(--lift), 0 12px 32px rgb(0 0 0 / 0.35);
}
.panel__title {
  display: block;
  padding: 0.7rem 1rem;
  margin: 0;
  border-bottom: var(--hair);
}

/* --- brand -------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand__name {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
}
.brand__lamp {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--etch);
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.5);
}
.brand__lamp[data-on='true'] {
  background: var(--meter);
  box-shadow: 0 0 10px rgb(79 209 197 / 0.55);
}

/* --- sign in ------------------------------------------------------------ */
.gate { display: grid; place-items: center; min-height: 100dvh; padding: var(--gap); }
.gate__panel { width: min(24rem, 100%); padding: 1.5rem; display: grid; gap: 0.9rem; }
.brand--gate { justify-content: center; margin-bottom: 0.2rem; }
.gate__lede { margin: 0 0 0.4rem; text-align: center; color: var(--label); font-size: 13.5px; }

.field { display: grid; gap: 0.35rem; }
.field input, select {
  width: 100%;
  padding: 0.6rem 0.7rem;
  background: var(--rack);
  border: var(--hair);
  border-radius: 4px;
  color: var(--readout);
  font: inherit;
  font-size: 14px;
}
.field input:focus-visible, select:focus-visible, .btn:focus-visible,
.key:focus-visible, .readout__number:focus-visible {
  outline: 2px solid var(--meter);
  outline-offset: 2px;
}
.field input::placeholder { color: #55606f; }

/* --- buttons ------------------------------------------------------------ */
.btn {
  appearance: none;
  padding: 0.55rem 0.9rem;
  border-radius: 4px;
  border: var(--hair);
  background: var(--panel-2);
  box-shadow: var(--lift);
  color: var(--readout);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 60ms ease;
}
.btn:hover { border-color: #3a475a; background: #26303f; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn--ghost { background: transparent; }
/* Selected reads as a tinted fill so it cannot be confused with the focus ring,
 * which is also cyan. */
.btn--ghost.is-on { border-color: var(--meter); color: var(--meter); background: rgb(79 209 197 / 0.12); }
.btn--quiet { background: transparent; border-color: transparent; color: var(--label); }
.btn--go { background: var(--line); border-color: var(--line); color: #241704; font-weight: 700; }
.btn--go:hover { background: #ffc471; border-color: #ffc471; }
.btn--end { background: transparent; border-color: var(--fault); color: var(--fault); }
.btn--end:hover { background: rgb(255 107 107 / 0.12); border-color: var(--fault); }
.btn--file { display: inline-grid; place-items: center; }

/* --- console layout ----------------------------------------------------- */
.console {
  max-width: 68rem;
  margin: 0 auto;
  padding: var(--gap);
  display: grid;
  gap: var(--gap);
}
.rail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap);
  padding-bottom: 0.85rem;
  border-bottom: var(--hair);
}
.rail__switcher { display: grid; gap: 0.25rem; min-width: 12rem; margin-inline-start: auto; }
.rail__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.deck { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 20rem) minmax(0, 1fr); align-items: start; }
@media (max-width: 46rem) { .deck { grid-template-columns: 1fr; } }

/* --- dial --------------------------------------------------------------- */
.dial { display: grid; }
.dial > :not(.panel__title) { margin-inline: 1rem; }
.dial > :last-child { margin-bottom: 1rem; }

.readout {
  display: flex; align-items: center; gap: 0.5rem;
  margin-top: 1rem; padding: 0.5rem 0.65rem;
  background: var(--rack); border: var(--hair); border-radius: 4px;
}
.readout__number {
  flex: 1; min-width: 0;
  background: none; border: 0; color: var(--readout);
  font-family: var(--mono); font-size: 17px; font-weight: 500; letter-spacing: 0.02em;
}
.readout__number::placeholder { color: #4a5464; letter-spacing: 0.02em; }
.readout__erase {
  background: none; border: 0; color: var(--label);
  font-size: 15px; cursor: pointer; padding: 0.15rem 0.3rem;
}
.readout__erase:hover { color: var(--readout); }

.keypad { margin-top: 0.85rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.45rem; }
.key {
  display: grid; place-items: center; gap: 1px;
  padding: 0.6rem 0;
  background: var(--panel-2); border: var(--hair); border-radius: 4px;
  box-shadow: var(--lift);
  color: var(--readout); cursor: pointer;
  transition: background 100ms ease, transform 60ms ease;
}
.key:hover { background: #28323f; }
.key:active { transform: translateY(1px); background: #2e3949; }
.key__digit { font-size: 19px; font-weight: 600; line-height: 1; }
.key__sub { font-family: var(--mono); font-size: 7.5px; letter-spacing: 0.14em; color: var(--label); min-height: 9px; }

.modes { margin-top: 1rem; padding: 0; border: 0; display: grid; gap: 0.45rem; }
.modes legend { padding: 0; margin-bottom: 0.15rem; }
.mode { display: flex; align-items: center; gap: 0.5rem; font-size: 13.5px; color: #c4cfdd; cursor: pointer; }
.mode input { accent-color: var(--line); }

.filepick { margin-top: 0.7rem; display: flex; gap: 0.5rem; align-items: center; }
.filepick select { flex: 1; min-width: 0; }

.btn--call { margin-top: 1rem; padding-block: 0.75rem; font-size: 11.5px; }

/* --- line panel: the instrument ---------------------------------------- */
.line > :not(.panel__title) { margin: 1rem; }
.line__hint { margin: 0; font-size: 13px; color: #6f7c8d; max-width: 38ch; }

.line__head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.line__peer { font-family: var(--mono); font-size: 15px; font-weight: 500; }
.line__phase { margin-inline-end: auto; }
.line__timer { font-family: var(--mono); font-size: 15px; font-variant-numeric: tabular-nums; color: var(--line); }

/* Idle is a dormant instrument, not a blank panel: the meters and counters stay on
 * screen so the shape of the readout is familiar before the first call. */
.line.is-idle .line__peer { color: var(--label); }
.line.is-idle .line__timer { color: var(--etch); }
.line.is-idle .meters, .line.is-idle .telemetry { opacity: 0.45; }

.lamp {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--etch); flex: none;
  box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.5);
}
.lamp[data-phase='calling'], .lamp[data-phase='ringing'], .lamp[data-phase='connecting'] {
  background: var(--line); animation: pulse 1.1s ease-in-out infinite;
}
.lamp[data-phase='active'] { background: var(--line); box-shadow: 0 0 12px rgb(255 180 84 / 0.6); }
.lamp[data-phase='ended'] { background: var(--fault); }
.lamp--ring { background: var(--line); animation: pulse 1.1s ease-in-out infinite; margin-bottom: 0.4rem; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Segmented meters: the voice path made visible, one segment per 1/24 of full scale. */
.meters { display: grid; gap: 0.7rem; }
.meter { display: grid; gap: 0.3rem; }
.meter__bar { display: flex; gap: 2px; height: 16px; }
.meter__seg {
  flex: 1; border-radius: 1px;
  background: #222b38; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.35);
  transition: background 70ms linear;
}
.meter__bar[data-dir='tx'] .meter__seg.is-lit { background: var(--line); }
.meter__bar[data-dir='rx'] .meter__seg.is-lit { background: var(--meter); }
.meter__seg.is-lit.is-hot { background: var(--fault); }

.telemetry {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
  gap: 0.8rem; margin: 0; padding-top: 0.9rem; border-top: var(--hair);
}
.telemetry div { display: grid; gap: 0.25rem; }
.telemetry dd {
  margin: 0; font-family: var(--mono); font-size: 13px;
  font-variant-numeric: tabular-nums; color: var(--readout);
}
.pips { display: flex; gap: 3px; }
.pip { width: 7px; height: 7px; border-radius: 50%; background: #222b38; box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.4); }
.pip.is-lit { background: var(--meter); }

.line__controls { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; padding-top: 0.9rem; border-top: var(--hair); }
.line__controls .line__hint { flex: 1 1 16rem; }
.line__controls .btn--end { margin-inline-start: auto; }
.btn[aria-pressed='true'] { border-color: var(--line); color: var(--line); }

/* --- dialogs ------------------------------------------------------------ */
.dlg {
  width: min(24rem, calc(100vw - 2rem));
  padding: 0 0 1rem;
  border: var(--hair);
  color: var(--readout);
}
.dlg::backdrop { background: rgb(8 11 15 / 0.72); backdrop-filter: blur(3px); }
.dlg > :not(.panel__title) { margin: 0.9rem 1rem 0; }
.dlg__methods { display: flex; gap: 0.5rem; }
.dlg__methods .btn { flex: 1; }
.dlg__actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1.1rem; }

.pairing { display: grid; gap: 0.6rem; justify-items: center; text-align: center; }
.pairing__qr {
  width: 100%; max-width: 15rem; aspect-ratio: 1; border-radius: 4px;
  background: #fff; padding: 0.6rem;
}
.pairing__code {
  margin: 0; font-family: var(--mono); font-size: 26px; font-weight: 700;
  letter-spacing: 0.22em; color: var(--line);
}
.pairing__steps { margin: 0; font-size: 13px; color: var(--label); max-width: 30ch; }

.dlg--ring { text-align: center; }
.dlg--ring .lamp--ring { margin-inline: auto; }
.ring__peer { margin: 0; font-family: var(--mono); font-size: 18px; }
.ring__account { display: block; }
.dlg--ring .dlg__actions { justify-content: center; }

/* --- notices ------------------------------------------------------------ */
.notice { margin: 0.7rem 0 0; font-size: 13px; }
.notice--fault { color: var(--fault); }
.footnote { margin: 0; font-size: 12px; color: #5d6a7b; max-width: 60ch; }

.toast {
  position: fixed; inset-inline: 0; bottom: calc(1rem + env(safe-area-inset-bottom));
  margin-inline: auto; width: max-content; max-width: calc(100vw - 2rem);
  padding: 0.55rem 0.9rem;
  background: var(--panel); border: var(--hair); border-radius: 4px;
  box-shadow: 0 10px 28px rgb(0 0 0 / 0.5);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
