/* Skambalas shared stylesheet.
 *
 * Both pages -- the live event console and the browser call page -- load this
 * one file, so a token changed here changes both. No framework, no bundler,
 * no CDN: the whole visual system is these custom properties plus the rules
 * below (spec D3).
 *
 * The console is projected onto a meeting-room screen at roughly 1280x720
 * during a demo, which drives most of the choices here: a 16px base instead
 * of the 14px this started at, row padding that keeps the table readable from
 * the back of a room, and a "muted" grey that is still comfortably above 4.5:1
 * on the panel background rather than the usual decorative grey-on-grey.
 */

:root {
  /* Surfaces, darkest to lightest. Three steps is enough to separate page,
     panel and table header without anything looking like a gradient. */
  --bg: #0b0e14;
  --panel: #141a24;
  --raised: #1b2331;
  --line: #273142;
  --line-soft: #1f2836;

  /* Text. --muted is deliberately light: it labels things on a projector. */
  --text: #e9eef7;
  --muted: #a6b4cb;
  --accent: #7aa2ff;

  /* Component colour coding. These are the pipeline stages, and the same
     hues are used for the connection badge (stt green / err red). */
  --stt: #5fd97a;
  --llm: #d2a8ff;
  --tts: #ffa657;
  --tool: #ffd866;
  --err: #ff7b72;
  /* Transient trouble, as distinct from the terminal red of --err. */
  --warn: #ffc857;

  --radius: 10px;
  --radius-sm: 7px;

  /* One spacing rhythm, used everywhere. Nothing picks its own numbers. */
  --gap-1: 6px;
  --gap-2: 12px;
  --gap-3: 20px;
  --gap-4: 32px;

  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03), 0 8px 28px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Every interactive element gets the same visible focus ring; the default
   outline disappears against a dark background on some browsers. */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

.muted {
  color: var(--muted);
}

/* ---------------------------------------------------------------- nav ---
   Shared header: wordmark, the two page links, then status and logout
   pushed to the right. Sticky, because the event table scrolls past it. */

.nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--gap-3);
  flex-wrap: wrap;
  padding: 14px var(--gap-3);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.nav .brand {
  display: flex;
  align-items: center;
  gap: var(--gap-1);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: var(--text);
}

.nav .brand::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.nav .links {
  display: flex;
  align-items: center;
  gap: var(--gap-1);
}

.nav .links a {
  display: block;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 550;
  text-decoration: none;
}

.nav .links a:hover {
  background: var(--raised);
  color: var(--text);
  text-decoration: none;
}

/* The current page is marked with aria-current in the markup, so the styling
   and the accessibility signal cannot drift apart. */
.nav .links a[aria-current="page"] {
  background: var(--raised);
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.nav .spacer {
  margin-left: auto;
}

.nav form {
  margin: 0;
}

/* -------------------------------------------------------------- badge ---
   Status pill. `.live` / `.down` / `.stopped` are set from dashboard.js; the
   call page reuses the bare `.badge` for its own state labels.

   The three states are separated on two axes, not just hue, because this is
   read off a projector by people who are not looking for it:

     .live    green,  round dot, pulsing  -- events are arriving
     .down    amber,  round dot, pulsing  -- a retry is scheduled; wait
     .stopped red,    SQUARE dot, static  -- terminal; nothing will happen

   The moving dot means "something is still happening on its own". A stopped
   stream is the one state where that is false, so it is the one state whose
   dot neither moves nor is round -- the distinction survives a bad projector
   and a red-deficient viewer. */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--gap-1);
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.badge::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: currentColor;
}

.badge.live {
  color: var(--stt);
  border-color: rgba(95, 217, 122, 0.45);
  background: rgba(95, 217, 122, 0.12);
}

.badge.live::before {
  animation: pulse 2s ease-in-out infinite;
}

.badge.down {
  color: var(--warn);
  border-color: rgba(255, 200, 87, 0.45);
  background: rgba(255, 200, 87, 0.12);
}

.badge.down::before {
  animation: pulse 2s ease-in-out infinite;
}

.badge.stopped {
  color: var(--err);
  border-color: rgba(255, 123, 114, 0.5);
  background: rgba(255, 123, 114, 0.14);
}

.badge.stopped::before {
  border-radius: 1px;
  animation: none;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

/* With motion suppressed the dots stop carrying the "still happening"
   signal, so shape has to. The stopped state keeps its square; the two live
   states keep their circle. */
@media (prefers-reduced-motion: reduce) {
  .badge.live::before,
  .badge.down::before {
    animation: none;
  }
}

/* --------------------------------------------------------------- card ---
   The one panel primitive. Both pages build their layout out of these. */

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

.centred {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--gap-3);
}

/* ------------------------------------------------------------ layout ---- */

main {
  padding: var(--gap-3);
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
}

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

.toolbar label {
  display: flex;
  align-items: center;
  gap: var(--gap-1);
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stream {
  overflow: hidden;
}

/* ------------------------------------------------------------ controls -- */

button,
select,
input {
  font: inherit;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

button {
  cursor: pointer;
  font-weight: 550;
}

button:hover,
select:hover {
  border-color: var(--accent);
}

button.ghost {
  background: transparent;
  color: var(--muted);
}

button.ghost:hover {
  color: var(--text);
}

select {
  min-width: 13ch;
  font-family: var(--font-mono);
}

/* -------------------------------------------------------------- table --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 15px;
}

/* Not sticky: the nav above it already claims `top: 0`, and new rows are
   prepended, so the header is next to the newest event without scrolling. */
thead th {
  background: var(--raised);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
  text-align: left;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: rgba(122, 162, 255, 0.07);
}

/* Latency and turn index are read as a column, so they are right-aligned and
   set in tabular figures -- digits stay in their lane as rows stream in. */
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.evt {
  color: var(--accent);
}

.c-stt {
  color: var(--stt);
}

.c-llm {
  color: var(--llm);
}

.c-tts {
  color: var(--tts);
}

.c-tool {
  color: var(--tool);
}

.c-other,
.c-platform,
.c-media,
.c-network,
.c-telephony {
  color: var(--muted);
}

/* Anything over the 800 ms bar. Colour alone is not the whole signal -- the
   weight change carries it too, for a projector that eats saturation. */
.slow {
  color: var(--err);
  font-weight: 700;
}

.detail {
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 52ch;
}

.empty {
  padding: 56px var(--gap-3);
  color: var(--muted);
  text-align: center;
  font-size: 17px;
}

/* -------------------------------------------------------------- login --- */

.login {
  display: flex;
  flex-direction: column;
  gap: var(--gap-2);
  width: min(380px, 100%);
  padding: var(--gap-4);
}

.login h1 {
  font-size: 24px;
}

.login p {
  margin-bottom: var(--gap-1);
}

.login input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
}

.login input::placeholder {
  color: var(--muted);
}

.login button {
  width: 100%;
  padding: 12px 14px;
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e14;
  font-weight: 650;
}

.login button:hover {
  filter: brightness(1.1);
}

/* Shown only on a rejected password, in place of a JSON body the browser
   would otherwise render as bare text on a blank page. */
.login .error {
  color: var(--err);
  font-weight: 650;
}

/* --------------------------------------------------------------- call --- */

.call-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-2);
  padding: var(--gap-4);
  text-align: center;
}

.call-btn {
  padding: 16px 40px;
  font-size: 17px;
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e14;
}

.call-btn:hover {
  filter: brightness(1.1);
}

.call-btn:disabled {
  opacity: 0.6;
  cursor: default;
  filter: none;
}

/* The primary control restyles itself when it means "end the call" rather
   than "start one" -- the same colour the terminal badge state uses, so
   ending a call reads as the deliberate, unambiguous action it is. */
.call-btn.hangup {
  background: var(--err);
  border-color: var(--err);
}

#agent-audio {
  display: none;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: var(--gap-1);
  max-height: 55vh;
  overflow-y: auto;
  padding: var(--gap-3);
}

.transcript .line {
  margin: 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--raised);
  max-width: 70ch;
  white-space: pre-wrap;
  word-break: break-word;
}

.transcript .line.caller {
  align-self: flex-end;
  background: rgba(122, 162, 255, 0.12);
}

.transcript .who {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

/* Narrow screens: the nav wraps rather than overflowing, and the detail
   column stops reserving width it cannot use. */
@media (max-width: 720px) {
  .nav {
    gap: var(--gap-2);
  }

  .nav .spacer {
    margin-left: 0;
  }

  .detail {
    max-width: none;
  }

  .transcript .line {
    max-width: 100%;
  }
}
