/*
 * styles.css: Mark's Command Center look.
 * Owner: Miya (frontend-dev-2).
 * Dark "Jarvis HUD": deep navy, thin cyan lines, one amber for approvals.
 * Mobile-first. System fonts only, no external assets, CSS-only background.
 *
 * v2 layout (index.html), all DIRECT children of <body>:
 *   #topbar, #conversations (drawer), #stage (#team-left | #orb-wrap |
 *   #team-right), #approvals, #chat (transcript), #composer
 * It switches on via body:has(> #stage). The v1 layout (#team-panel) still
 * works via body:has(> #team-panel). login.html and the dev page use neither.
 *
 * Transcript: open iff body.transcript-open (app.js adds it on load at
 * >= 1280px and toggles it from #transcript-btn).
 */

/* ------------------------------------------------------------------ */
/* Tokens                                                              */
/* ------------------------------------------------------------------ */
:root {
  color-scheme: dark;

  --bg: #0b1220;          /* page */
  --surface: #111a2b;     /* panels */
  --surface-2: #172238;   /* raised: bubbles, hover */
  --surface-3: #1e2b45;   /* active items */
  --border: #26344f;
  --border-strong: #3a4b6b;

  --text: #e6ecf5;        /* 15:1 on --bg */
  --text-muted: #9fadc4;  /* 7.5:1 on --bg, 7:1 on --surface */

  --accent: #4cc2ff;      /* the one accent: 9:1 on --bg */
  --accent-strong: #7fd4ff;
  --accent-ink: #04111d;  /* text on accent buttons */
  --accent-tint: rgba(76, 194, 255, 0.14);

  /* Status colours (semantic, used sparingly) */
  --ok: #5fd49a;
  --warn: #f5c451;
  --danger: #ff8a8a;

  --mark-bubble: #133a5c; /* Sir Mark's messages, accent-tinted navy */

  --radius: 12px;
  --radius-sm: 8px;
  --tap: 44px;            /* minimum touch target */
  --gap: 12px;

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

  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* ------------------------------------------------------------------ */
/* Base                                                                */
/* ------------------------------------------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] {
  display: none !important;
}

a {
  color: var(--accent);
}

a:hover {
  color: var(--accent-strong);
}

h1, h2, h3 {
  line-height: 1.25;
}

code,
pre {
  font-family: var(--mono);
  font-size: 0.9em;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* Visible focus for keyboard users everywhere. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------------------------------------------------ */
/* Buttons                                                             */
/* ------------------------------------------------------------------ */
button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.btn,
#topbar button,
#new-conv,
#send,
#stop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover,
#topbar button:hover,
#new-conv:hover,
#stop:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}

.btn--primary,
#send {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn--primary:hover,
#send:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--accent-ink);
}

.btn--ghost {
  background: transparent;
}

.btn--danger,
#stop {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn--danger:hover,
#stop:hover {
  background: rgba(255, 138, 138, 0.12);
  border-color: var(--danger);
}

.btn--small {
  min-height: 36px;
  padding: 0 12px;
  font-size: 0.875rem;
}

/* Keep small visual buttons at a 44px hit area on touch screens. */
@media (pointer: coarse) {
  .btn--small {
    min-height: var(--tap);
  }
}

.btn:disabled,
#send:disabled,
#stop:disabled {
  opacity: 0.5;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* ------------------------------------------------------------------ */
/* App shell (index.html). Mobile first: one column.                   */
/* ------------------------------------------------------------------ */
body:has(> #team-panel) {
  height: 100vh;              /* fallback */
  height: 100dvh;             /* follows the mobile browser toolbars */
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top"
    "chat"
    "team"
    "composer";
}

/* ---- Top bar ---- */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

#topbar h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#topbar button {
  padding: 0 10px;
  background: transparent;
  border-color: transparent;
}

#topbar button:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

/* Mute button shows its state via aria-pressed. */
#mute-btn[aria-pressed="true"] {
  color: var(--warn);
  border-color: var(--warn);
}

#voice-btn[aria-expanded="true"] {
  background: var(--accent-tint);
  border-color: var(--accent);
}

/* ---- Conversations: slide-in drawer on phones ---- */
#conversations {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(86vw, 320px);
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(-105%);
  visibility: hidden; /* keeps closed-drawer links out of the Tab order */
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
  z-index: 40;
}

body.drawer-open #conversations {
  transform: none;
  visibility: visible;
  transition: transform 0.22s ease, visibility 0s;
}

/* Dim the chat behind the open drawer. Clicks land on <body>, so app.js
   can close the drawer on a body click outside #conversations. */
body.drawer-open::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(3, 7, 15, 0.6);
  z-index: 30;
}

#conversations h2 {
  margin: 4px 4px 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

#new-conv {
  width: 100%;
  border-style: dashed;
}

#conv-list {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conv-item {
  margin: 0 0 4px;
}

.conv-item__btn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.conv-item__btn:hover {
  background: var(--surface-2);
}

.conv-item.is-active .conv-item__btn {
  background: var(--surface-3);
  border-left-color: var(--accent);
}

.conv-item__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conv-item__time {
  flex: 0 0 auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---- Chat ---- */
#chat {
  grid-area: chat;
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 12px;
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
}

#busy-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* Three soft dots before the busy text. */
#busy-indicator::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 12px 0 0 var(--accent), 24px 0 0 var(--accent);
  margin-right: 24px;
  animation: mcc-breathe 1.4s ease-in-out infinite;
}

/* ---- Team panel: compact horizontal strip on phones ---- */
#team-panel {
  grid-area: team;
  min-width: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#team-panel h2 {
  /* The strip is self-explanatory on phones; keep the heading for screen readers. */
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

#team-list {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  overflow-x: auto;
  scrollbar-width: none;
}

#team-list::-webkit-scrollbar {
  display: none;
}

/* ---- Composer ---- */
#composer {
  grid-area: composer;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(12px, env(safe-area-inset-left));
  padding-right: max(12px, env(safe-area-inset-right));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

#input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: var(--tap);
  max-height: 40vh;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: max(16px, 1rem); /* >= 16px so iOS Safari doesn't zoom on focus */
  line-height: 1.4;
  resize: none;
}

#input::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

#input:focus-visible,
#input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

#send,
#stop {
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ */
/* LEGACY desktop (old index.html with #team-panel): conv | chat | team */
/* ------------------------------------------------------------------ */
@media (min-width: 1024px) {
  body:has(> #team-panel) {
    grid-template-columns: 280px minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top  top      top"
      "conv chat     team"
      "conv composer team";
  }

  body:has(> #team-panel) #menu-btn {
    display: none !important;
  }

  body:has(> #team-panel) #conversations {
    grid-area: conv;
    position: static;
    width: auto;
    min-height: 0;
    padding: 12px;
    box-shadow: none;
    transform: none;
    visibility: visible;
    transition: none;
  }

  body.drawer-open:has(> #team-panel)::after {
    content: none;
  }

  body:has(> #team-panel) #messages {
    padding: 24px max(24px, calc((100% - 820px) / 2));
  }

  body:has(> #team-panel) #composer {
    padding: 12px max(24px, calc((100% - 820px) / 2)) 16px;
  }

  body:has(> #team-panel) #team-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-top: 0;
    border-left: 1px solid var(--border);
  }

  body:has(> #team-panel) #team-panel h2 {
    position: static;
    width: auto;
    height: auto;
    margin: 16px 16px 4px;
    overflow: visible;
    clip: auto;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
  }

  body:has(> #team-panel) #team-list {
    flex-direction: column;
    padding: 8px 12px 16px;
    overflow-x: hidden;
    overflow-y: auto;
  }
}

/* ------------------------------------------------------------------ */
/* v2 "Jarvis" shell (index.html with #stage). Mobile first.           */
/* ------------------------------------------------------------------ */
body:has(> #stage) {
  --hud-line: rgba(76, 194, 255, 0.28);
  --hud-line-faint: rgba(76, 194, 255, 0.12);
  --panel: rgba(13, 21, 37, 0.94);
  --orb-size: min(55vw, 40vh);
  --node-avatar: 40px;
  --connector: 0px;

  height: 100vh;              /* fallback */
  height: 100dvh;             /* follows the mobile browser toolbars */
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "top"
    "stage"
    "approvals"
    "composer";
}

@supports (height: 1dvh) {
  body:has(> #stage) {
    --orb-size: min(55vw, 40dvh);
  }
}

/* HUD background: soft centre glow + fine grid (static, CSS only). */
body:has(> #stage),
body.login-page {
  background:
    radial-gradient(ellipse 60% 50% at 50% 38%, rgba(76, 194, 255, 0.10), transparent 70%),
    linear-gradient(rgba(76, 194, 255, 0.04) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(76, 194, 255, 0.04) 1px, transparent 1px) 0 0 / 44px 44px,
    var(--bg);
}

/* Scanlines: a fixed, non-interactive overlay behind the content. */
body:has(> #stage)::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px);
}

body:has(> #stage) #topbar {
  background: rgba(9, 15, 27, 0.88);
  border-bottom-color: var(--hud-line);
}

body:has(> #stage) #topbar h1 {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent-strong);
}

#transcript-btn[aria-expanded="true"] {
  background: var(--accent-tint);
  border-color: var(--accent);
}

/* Narrow phones: 5 topbar buttons + title don't fit at 375px. The title
   stays for screen readers only, buttons get tighter (still 44px tall). */
@media (max-width: 479px) {
  body:has(> #stage) #topbar {
    gap: 2px;
  }

  body:has(> #stage) #topbar h1 {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  body:has(> #stage) #topbar button {
    padding: 0 7px;
    font-size: 0.82rem;
  }

  body:has(> #stage) #transcript-btn {
    margin-left: auto;
  }
}

/* ---- Stage: team-left | orb | team-right ---- */
#stage {
  grid-area: stage;
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  grid-template-rows: auto;
  align-content: start;
  align-items: center;
  column-gap: 8px;
  padding: 12px 8px 8px;
  padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right));
  overflow-x: hidden;
  overflow-y: auto;
  container-type: inline-size;
}

#team-left,
#team-right {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}

#team-left {
  grid-column: 1;
  align-items: flex-end;
}

#team-right {
  grid-column: 3;
  align-items: flex-start;
}

#orb-wrap {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

#stage #orb {
  display: block;
  width: var(--orb-size);
  height: var(--orb-size);
  max-width: 100%;
}

/* Subtitle under the orb: 2 lines max, fades in/out (.is-visible, app.js). */
#orb-caption {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  width: min(46ch, 100%);
  min-height: calc(2 * 1.45em); /* reserve the space so nothing jumps */
  margin: 4px auto 0;
  font-size: 0.95rem;
  line-height: 1.45;
  text-align: center;
  color: var(--text);
  text-shadow: 0 0 12px rgba(76, 194, 255, 0.35);
  opacity: 0;
  transition: opacity 0.4s ease;
}

#orb-caption.is-visible {
  opacity: 1;
}

#stage #busy-indicator {
  justify-content: center;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

/* ---- Approvals (v3.1): toast stack. Phones: fixed under #topbar, full
   width. >= 600px: top-right, max 380px. Never over the composer or mic. ---- */
#approvals {
  position: fixed;
  z-index: 25; /* above the transcript sheet, below the drawer */
  top: calc(max(8px, env(safe-area-inset-top)) + 56px);
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  max-height: calc(100vh - 220px); /* leaves the composer + mic clear */
  max-height: calc(100dvh - 220px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px; /* room for focus rings */
  pointer-events: none; /* only the toasts themselves take clicks */
}

#approvals > * {
  pointer-events: auto;
}

#approvals:empty,
#approvals:not(:has(> *)) {
  display: none;
}

@media (min-width: 600px) {
  #approvals {
    left: auto;
    right: max(16px, env(safe-area-inset-right));
    width: min(388px, calc(100vw - 32px));
  }
}

/* ---- Transcript (#chat). Phones: bottom sheet over the stage. ---- */
body:has(> #stage) #chat {
  grid-area: stage;
  align-self: end;
  z-index: 15;
  height: 72%;
  max-height: calc(100% - 48px);
  margin: 0 6px;
  border: 1px solid var(--hud-line);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  background: var(--panel);
  box-shadow: 0 -12px 32px rgba(0, 0, 0, 0.5);
  visibility: hidden;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

body.transcript-open:has(> #stage) #chat {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
}

/* Small HUD label on top of the panel (sheet grabber on phones). */
body:has(> #stage) #chat::before {
  content: "Transcript";
  flex: 0 0 auto;
  padding: 10px 16px 6px;
  border-bottom: 1px solid var(--hud-line-faint);
  font-family: var(--mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
}

body:has(> #stage) #messages {
  padding: 12px;
}

body:has(> #stage) #composer {
  position: relative;
  z-index: 20;
  background: rgba(9, 15, 27, 0.92);
  border-top-color: var(--hud-line);
}

body:has(> #stage) #input {
  background: rgba(5, 10, 20, 0.85);
  border-color: var(--hud-line);
}

/* Tablets: room for a summary under each chip. */
@media (min-width: 600px) {
  body:has(> #stage) {
    --node-avatar: 48px;
  }

  #team-left,
  #team-right {
    gap: 22px;
  }
}

/* ---- Desktop: team | orb | team, transcript on the right ---- */
@media (min-width: 1024px) {
  body:has(> #stage) {
    --orb-size: min(46vh, 42vw);
    --node-avatar: 56px;
    --connector: clamp(20px, 3.2vw, 64px);
  }

  @supports (width: 1cqi) {
    body:has(> #stage) {
      --orb-size: min(46vh, 42vw, 44cqi);
    }
  }

  body.transcript-open:has(> #stage) {
    grid-template-columns: minmax(0, 1fr) clamp(320px, 28vw, 440px);
    grid-template-areas:
      "top       top"
      "stage     chat"
      "approvals chat"
      "composer  chat";
  }

  #stage {
    align-content: center;
    column-gap: var(--connector);
    padding: 16px 24px;
  }

  #team-left,
  #team-right {
    gap: 40px;
  }

  #orb-caption {
    font-size: 1.02rem;
  }

  /* Keep toasts clear of the open transcript column. */
  body.transcript-open #approvals {
    right: calc(clamp(320px, 28vw, 440px) + 16px);
  }

  body:has(> #stage) #chat {
    display: none;
  }

  body.transcript-open:has(> #stage) #chat {
    display: flex;
    grid-area: chat;
    align-self: stretch;
    height: auto;
    max-height: none;
    margin: 0;
    border: 0;
    border-left: 1px solid var(--hud-line);
    border-radius: 0;
    box-shadow: none;
    transform: none;
    transition: none;
  }

  body:has(> #stage) #messages {
    padding: 16px;
  }

  body:has(> #stage) #composer {
    padding: 12px max(24px, calc((100% - 820px) / 2)) 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* ------------------------------------------------------------------ */
/* Messages (components.js renderMessage)                               */
/* ------------------------------------------------------------------ */
.msg {
  max-width: min(85%, 72ch);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-wrap: anywhere;
  animation: mcc-rise 0.18s ease-out;
}

.msg__meta {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.msg__sender {
  font-weight: 650;
  color: var(--text);
}

.msg__body code {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border);
}

.msg__pre {
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #070c16;
  overflow-x: auto;
  white-space: pre;
}

.msg__pre code {
  padding: 0;
  border: 0;
  background: none;
}

.msg__body strong {
  font-weight: 700;
  color: #fff;
}

/* Sir Mark: right side, accent-tinted. */
.msg--mark {
  align-self: flex-end;
  background: var(--mark-bubble);
  border-color: #1f5582;
  border-bottom-right-radius: 4px;
}

.msg--mark .msg__meta {
  justify-content: flex-end;
}

/* Jarvis: left side, the main voice of the page. */
.msg--jarvis {
  align-self: flex-start;
  border-left: 3px solid var(--accent);
  border-bottom-left-radius: 4px;
}

.msg--jarvis .msg__sender {
  color: var(--accent);
}

/* Team members: quieter, smaller. */
.msg--team {
  align-self: flex-start;
  max-width: min(85%, 64ch);
  background: var(--surface);
  font-size: 0.925rem;
}

/* System notes: centred, muted, no bubble. */
.msg--system {
  align-self: center;
  max-width: 90%;
  padding: 4px 12px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

.msg--system .msg__meta {
  justify-content: center;
}

.msg--system .msg__sender {
  color: var(--text-muted);
}

/* Streaming draft: soft blinking caret after the text. */
.msg--draft .msg__body::after {
  content: "";
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.15em;
  background: var(--accent);
  animation: mcc-caret 1s steps(2, start) infinite;
}

.msg--draft {
  animation: none;
}

/* ------------------------------------------------------------------ */
/* Team rows (components.js setTeamStatus)                              */
/* ------------------------------------------------------------------ */
.team-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

.team-row__avatar {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
}

/* Subtle identity tint per person (text stays --text for contrast). */
.team-row[data-agent="Jarvis"] .team-row__avatar { border-color: var(--accent); }
.team-row[data-agent="Macky"] .team-row__avatar { border-color: #d8b25a; }
.team-row[data-agent="Malik"] .team-row__avatar { border-color: #a992e6; }
.team-row[data-agent="Ming"] .team-row__avatar { border-color: #6cc79a; }
.team-row[data-agent="Miya"] .team-row__avatar { border-color: #e690b4; }

.team-row__info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.team-row__head {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

.team-row__name {
  font-weight: 650;
  font-size: 0.9rem;
}

.team-row__role {
  display: none; /* phones: strip is compact */
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.team-row__summary {
  max-width: 14em;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Idle rows on phones: just avatar + name, to keep the strip short. */
.team-row--idle .team-row__summary {
  display: none;
}

.team-row__status {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
}

.team-row__dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-strong);
}

.team-row--working .team-row__dot {
  background: var(--accent);
  animation: mcc-pulse 1.6s ease-in-out infinite;
}

.team-row--working {
  border-color: rgba(76, 194, 255, 0.5);
}

.team-row--done .team-row__dot {
  background: var(--ok);
}

.team-row--failed .team-row__dot {
  background: var(--danger);
}

.team-row--failed {
  border-color: rgba(255, 138, 138, 0.5);
}

@media (min-width: 1024px) {
  .team-row {
    align-items: flex-start;
    border-radius: var(--radius-sm);
    padding: 10px;
  }

  .team-row__info {
    flex: 1 1 auto;
  }

  .team-row__head {
    flex-wrap: wrap;
  }

  .team-row__role {
    display: inline;
  }

  .team-row__summary,
  .team-row--idle .team-row__summary {
    display: block;
    max-width: none;
    white-space: normal;
    overflow: visible;
  }

  .team-row__status {
    padding-top: 6px;
  }
}

/* ------------------------------------------------------------------ */
/* v2 team nodes (components.js setTeamStatus into #team-left/right)    */
/* Phones: compact chips (avatar, name, state). Desktop: avatar next to */
/* the orb, text on the outside, dashed connector toward the orb.       */
/* ------------------------------------------------------------------ */
.team-node {
  --node-color: var(--accent);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  max-width: 280px;
  min-width: 0;
  text-align: center;
}

.team-node[data-agent="Macky"] { --tint: #d8b25a; }
.team-node[data-agent="Malik"] { --tint: #a992e6; }
.team-node[data-agent="Ming"] { --tint: #6cc79a; }
.team-node[data-agent="Miya"] { --tint: #e690b4; }

.team-node__avatar {
  position: relative;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--node-avatar, 40px);
  height: var(--node-avatar, 40px);
  border-radius: 50%;
  border: 1.5px solid var(--tint, var(--border-strong));
  background: radial-gradient(circle at 50% 40%, #17304d, #0a1424 70%);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

/* Faint outer HUD ring, always there. */
.team-node__avatar::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px dashed rgba(76, 194, 255, 0.28);
}

/* Spinning arc: only visible while working. */
.team-node__spin {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--node-color);
  border-right-color: var(--node-color);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.team-node__initial {
  font-family: var(--mono);
  font-weight: 700;
  font-size: calc(var(--node-avatar, 40px) * 0.4);
  color: var(--text);
}

.team-node__info {
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: inherit;
}

.team-node__name {
  font-weight: 650;
  font-size: 0.82rem;
  line-height: 1.25;
}

.team-node__role {
  display: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.team-node__state {
  font-family: var(--mono);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.team-node__summary {
  display: none;
  max-width: 100%;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* Connector toward the orb (desktop only: --connector is 0 on phones). */
.team-node::after {
  content: "";
  position: absolute;
  top: calc(var(--node-avatar, 40px) / 2 - 1px);
  width: var(--connector, 0px);
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--node-color) 0 6px, transparent 6px 12px);
  opacity: 0.18;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.team-node--left::after { left: 100%; }
.team-node--right::after { right: 100%; }

/* Working: glow, spinning ring, animated connector. */
.team-node--working .team-node__avatar {
  box-shadow: 0 0 18px rgba(76, 194, 255, 0.55), inset 0 0 10px rgba(76, 194, 255, 0.25);
}

.team-node--working .team-node__spin {
  opacity: 1;
  animation: mcc-spin 1.2s linear infinite;
}

.team-node--working .team-node__state {
  color: var(--accent);
}

.team-node--working::after {
  opacity: 1;
  box-shadow: 0 0 8px rgba(76, 194, 255, 0.5);
  animation: mcc-dash-right 0.6s linear infinite;
}

.team-node--right.team-node--working::after {
  animation-name: mcc-dash-left;
}

/* Done: brief green flash (components.js then switches to idle). */
.team-node--done {
  --node-color: var(--ok);
}

.team-node--done .team-node__state {
  color: var(--ok);
}

.team-node--flash .team-node__avatar {
  animation: mcc-flash-ok 1.5s ease-out;
}

/* Failed: red, stays until the next update. */
.team-node--failed {
  --node-color: var(--danger);
}

.team-node--failed .team-node__avatar {
  border-color: var(--danger);
  box-shadow: 0 0 14px rgba(255, 138, 138, 0.45);
}

.team-node--failed .team-node__state {
  color: var(--danger);
}

.team-node--failed::after {
  opacity: 0.6;
}

/* Tablets: show the summary (2 lines). */
@media (min-width: 600px) {
  .team-node__name {
    font-size: 0.9rem;
  }

  .team-node__summary {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
  }
}

/* Desktop: avatar on the orb side, text on the outside. */
@media (min-width: 1024px) {
  .team-node {
    flex-direction: row;
    align-items: flex-start;
    gap: 14px;
  }

  .team-node--left {
    flex-direction: row-reverse;
    text-align: right;
  }

  .team-node--left .team-node__info {
    align-items: flex-end;
  }

  .team-node--right .team-node__info {
    align-items: flex-start;
    text-align: left;
  }

  .team-node__info {
    flex: 1 1 auto;
    padding-top: 2px;
  }

  .team-node__name {
    font-size: 1rem;
  }

  .team-node__role {
    display: block;
  }

  .team-node__state {
    margin-top: 2px;
  }
}

/* ------------------------------------------------------------------ */
/* Approval toasts (components.js renderApprovalCard, v3.1): one line, */
/* amber accent. Also used in any .approval-stack (dev page).          */
/* ------------------------------------------------------------------ */
.approval-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.approval-card {
  position: relative;
  border: 1px solid var(--warn);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background:
    linear-gradient(rgba(245, 196, 81, 0.10), rgba(245, 196, 81, 0.03)),
    rgba(12, 18, 30, 0.97);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 14px rgba(245, 196, 81, 0.16);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Waiting for Mark: a slow amber pulse so it can't be missed. */
.approval-card:not(.is-resolved) {
  animation: mcc-amber-pulse 2.4s ease-in-out infinite;
}

.approval-card.is-overflow {
  display: none;
}

.approval-card.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
}

.approval-toast__row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 2px 4px 2px 8px;
}

.approval-toast__avatar {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--warn);
  color: var(--warn);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
}

.approval-toast__summary {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 0.9rem;
  font-weight: 600;
}

.approval-toast__details-btn,
.approval-toast__btn,
.approval-more {
  flex: 0 0 auto;
  min-width: 36px;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.approval-toast__details-btn {
  color: var(--warn);
  font-size: 0.8rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.approval-toast__details-btn[aria-expanded="true"] {
  background: rgba(245, 196, 81, 0.12);
}

.approval-toast__actions {
  display: flex;
  gap: 4px;
}

.approval-toast__btn {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
}

.approval-card__approve {
  background: var(--warn);
  color: #1d1400;
}

.approval-card__decline {
  border-color: var(--border-strong);
}

.approval-toast__btn:hover:not(:disabled),
.approval-toast__details-btn:hover,
.approval-more:hover {
  filter: brightness(1.15);
}

.approval-toast__btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.approval-toast__details-btn:focus-visible,
.approval-toast__btn:focus-visible,
.approval-more:focus-visible,
.approval-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.approval-toast__status {
  flex: 0 0 auto;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.approval-toast__status:empty {
  display: none;
}

.approval-toast__detail {
  margin: 0 8px 8px;
  padding: 8px 10px;
  max-height: 30vh;
  overflow: auto;
  border: 1px solid rgba(245, 196, 81, 0.3);
  border-radius: 4px;
  background: rgba(5, 10, 20, 0.7);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.82rem;
}

.approval-toast__detail[hidden] {
  display: none;
}

.approval-more {
  align-self: flex-end;
  min-height: 32px;
  padding: 0 12px;
  border-color: var(--warn);
  border-radius: 999px;
  background: rgba(12, 18, 30, 0.97);
  color: var(--warn);
  font-size: 0.8rem;
  font-weight: 700;
}

.approval-card.is-resolved {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.approval-card.is-approved {
  border-left-color: var(--ok);
}

.approval-card.is-approved .approval-toast__status {
  color: var(--ok);
  font-weight: 700;
}

.approval-card.is-declined .approval-toast__status {
  color: var(--text);
  font-weight: 700;
}

/* Touch screens and phones: 44px tap targets. */
@media (pointer: coarse), (max-width: 599px) {
  .approval-toast__details-btn,
  .approval-toast__btn,
  .approval-more {
    min-width: var(--tap);
    min-height: var(--tap);
  }

  .approval-toast__row {
    min-height: 48px;
  }
}

/* ------------------------------------------------------------------ */
/* Voice picker (voice.js openPicker)                                   */
/* ------------------------------------------------------------------ */
.voice-picker {
  position: fixed;
  z-index: 60;
  width: min(380px, calc(100vw - 16px));
  max-height: min(70vh, 520px);
  display: flex;
  flex-direction: column;
  padding: 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

/* Phones: a bottom sheet above the home indicator. */
.voice-picker--sheet {
  left: 0;
  right: 0;
  bottom: 0;
  top: auto;
  width: 100%;
  max-height: 75vh;
  border-radius: var(--radius) var(--radius) 0 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.voice-picker__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.voice-picker__title {
  margin: 0 0 0 4px;
  font-size: 1rem;
}

.voice-picker__current,
.voice-picker__empty {
  margin: 4px 4px 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.voice-picker__list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.voice-picker__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px solid var(--border);
}

.voice-picker__item:last-child {
  border-bottom: 0;
}

.voice-picker__label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.voice-picker__label:hover {
  background: var(--surface-2);
}

.voice-picker__radio {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--accent);
}

.voice-picker__text {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.voice-picker__name {
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.voice-picker__lang {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.voice-picker__preview {
  flex: 0 0 auto;
}

/* ------------------------------------------------------------------ */
/* Login page (login.html): simple centred card                         */
/* Expected: <body class="login-page"><main class="login-card">…        */
/* ------------------------------------------------------------------ */
body.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  /* background: the HUD grid, see the v2 shell section */
}

/* Small idle orb above the login card. */
.login-orb {
  display: flex;
  justify-content: center;
}

.login-orb #orb {
  display: block;
  width: min(52vw, 32vh, 240px);
  height: min(52vw, 32vh, 240px);
}

.login-card {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  padding: 32px 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 1.4rem;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--text-muted);
}

/* The sign-in link looks like the primary button. */
.login-card a:not(.btn),
.login-card .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  text-decoration: none;
}

.login-card a:not(.btn):hover,
.login-card .btn:hover {
  background: var(--accent-strong);
  color: var(--accent-ink);
}

.login-error,
.login-card .error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  background: rgba(255, 138, 138, 0.1);
  color: var(--danger);
  font-size: 0.9rem;
}

/* ------------------------------------------------------------------ */
/* Animations                                                           */
/* ------------------------------------------------------------------ */
@keyframes mcc-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 194, 255, 0.55); }
  50% { box-shadow: 0 0 0 5px rgba(76, 194, 255, 0); }
}

@keyframes mcc-breathe {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

@keyframes mcc-caret {
  to { visibility: hidden; }
}

@keyframes mcc-spin {
  to { transform: rotate(360deg); }
}

/* Dashes flow toward the orb: left nodes move right, right nodes move left. */
@keyframes mcc-dash-right {
  from { background-position: 0 0; }
  to { background-position: 12px 0; }
}

@keyframes mcc-dash-left {
  from { background-position: 0 0; }
  to { background-position: -12px 0; }
}

@keyframes mcc-flash-ok {
  0% { border-color: var(--ok); box-shadow: 0 0 0 0 rgba(95, 212, 154, 0.9), 0 0 26px rgba(95, 212, 154, 0.8); }
  100% { box-shadow: 0 0 0 14px rgba(95, 212, 154, 0), 0 0 0 rgba(95, 212, 154, 0); }
}

@keyframes mcc-amber-pulse {
  0%, 100% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 12px rgba(245, 196, 81, 0.12); }
  50% { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55), 0 0 30px rgba(245, 196, 81, 0.38); }
}

@keyframes mcc-rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Reduced motion: no movement, no pulsing. State is still shown by colour
   and (for working) a steady ring, so nothing relies on animation. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .team-row--working .team-row__dot {
    animation: none;
    box-shadow: 0 0 0 3px rgba(76, 194, 255, 0.35);
  }

  #busy-indicator::before,
  .msg--draft .msg__body::after {
    animation: none;
    opacity: 1;
    visibility: visible;
  }

  /* Team nodes: a steady arc and a solid connector instead of motion. */
  .team-node--working .team-node__spin,
  .team-node--working::after,
  .team-node--flash .team-node__avatar {
    animation: none;
  }

  .team-node--flash .team-node__avatar {
    border-color: var(--ok);
    box-shadow: 0 0 16px rgba(95, 212, 154, 0.6);
  }

  .approval-card:not(.is-resolved) {
    animation: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55), 0 0 18px rgba(245, 196, 81, 0.3);
  }

  .approval-card {
    transition: none;
  }

  #chat,
  #orb-caption {
    transform: none !important;
  }
}

/* Windows high contrast / forced colours: keep dots and focus visible. */
@media (forced-colors: active) {
  .team-row__dot {
    forced-color-adjust: none;
    border: 1px solid CanvasText;
  }

  .msg,
  .approval-card,
  .team-row {
    border: 1px solid CanvasText;
  }

  .team-node__avatar,
  .team-node__spin {
    forced-color-adjust: none;
    border-color: CanvasText;
  }

  .team-node--working .team-node__avatar {
    outline: 2px solid Highlight;
    outline-offset: 4px;
  }
}

/* ------------------------------------------------------------------ */
/* Voice input (v3): #mic-btn, #talk-mode-btn, .send-countdown,        */
/* #listen-lang. Pulse rings stay within ~10px of the mic, so nothing   */
/* reaches #approvals (v3.1: fixed toasts at the top of the screen).    */
/* ------------------------------------------------------------------ */
body {
  --mic-size: 56px;
  --mic-red: #e5484d;        /* listening; white icon on it is 4:1 */
  --mic-red-ring: rgba(229, 72, 77, 0.55);
  --mic-cyan-ring: rgba(76, 194, 255, 0.55);
}

/* Room for the countdown bar as a full-width first row of the composer. */
#composer:has(> #mic-btn),
#composer:has(> .send-countdown) {
  flex-wrap: wrap;
}

#mic-btn {
  position: relative;
  flex: 0 0 auto;
  order: 10;                 /* last in the row: under the right thumb */
  display: inline-grid;
  place-items: center;
  width: var(--mic-size);
  height: var(--mic-size);
  min-width: var(--mic-size);
  padding: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 18px rgba(76, 194, 255, 0.35);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* no double-tap zoom delay on the main control */
  transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

#mic-btn svg {
  width: 45%;
  height: 45%;
  fill: currentColor;
  pointer-events: none;
}

#mic-btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

#mic-btn:active {
  transform: scale(0.96);
}

#mic-btn:focus-visible {
  outline: 3px solid var(--accent-strong);
  outline-offset: 3px;
}

#mic-btn[hidden] {
  display: none;
}

/* Pulse ring: a pseudo-element so the button itself never changes size. */
#mic-btn::before {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
}

/* Listening: red button, alternating red/cyan ring. */
#mic-btn.is-listening {
  background: var(--mic-red);
  border-color: var(--mic-red);
  color: #fff;
  box-shadow: 0 0 22px rgba(229, 72, 77, 0.45);
}

#mic-btn.is-listening::before {
  opacity: 1;
  animation: mcc-mic-ring 1.3s ease-out infinite;
}

/* Waiting for Sir Mark ("Tap to reply"): calm cyan breathing. */
#mic-btn.is-waiting::before {
  opacity: 1;
  animation: mcc-mic-wait 2.4s ease-in-out infinite;
}

#mic-btn:disabled,
#mic-btn[aria-disabled="true"] {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

#mic-btn:disabled::before,
#mic-btn[aria-disabled="true"]::before {
  animation: none;
  opacity: 0;
}

@keyframes mcc-mic-ring {
  0%   { box-shadow: 0 0 0 0 var(--mic-red-ring); }
  50%  { box-shadow: 0 0 0 10px rgba(229, 72, 77, 0); }
  51%  { box-shadow: 0 0 0 0 var(--mic-cyan-ring); }
  100% { box-shadow: 0 0 0 10px rgba(76, 194, 255, 0); }
}

@keyframes mcc-mic-wait {
  0%, 100% { box-shadow: 0 0 0 2px rgba(76, 194, 255, 0.15); }
  50%      { box-shadow: 0 0 0 8px rgba(76, 194, 255, 0.45); }
}

/* "Conversation mode" toggle. */
#talk-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

#talk-mode-btn::before {
  content: "";
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

#talk-mode-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

#talk-mode-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

#talk-mode-btn[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-tint);
  color: var(--accent-strong);
}

#talk-mode-btn[aria-pressed="true"]::before {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

#talk-mode-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#talk-mode-btn[hidden] {
  display: none;
}

/* "Sending… tap to cancel": a full-width bar above the composer row. The
   shrinking line shows the time left (--countdown-ms, default 1.2s). */
.send-countdown {
  --countdown-ms: 1200ms;
  position: relative;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  margin: 0;
  padding: 8px 14px 10px;
  overflow: hidden;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(9, 15, 27, 0.95);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
}

#composer > .send-countdown {
  flex: 1 0 100%;
  order: -1;                 /* first row, above the input and mic */
}

.send-countdown[hidden] {
  display: none;
}

.send-countdown:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.send-countdown::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  animation: mcc-countdown var(--countdown-ms) linear forwards;
}

@keyframes mcc-countdown {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* Recognition language: a small select. */
#listen-lang {
  flex: 0 0 auto;
  min-height: 36px;
  max-width: 11em;
  padding: 0 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
}

#listen-lang:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (pointer: coarse) {
  #listen-lang {
    min-height: var(--tap);
    font-size: 16px;         /* iOS zooms into controls under 16px */
  }
}

/* Phones and tablets: the mic is the dominant control. Text stays usable
   but compact: Send shrinks, the input keeps the remaining width. */
@media (max-width: 1023px) {
  body {
    --mic-size: 64px;
  }

  #composer:has(> #mic-btn) {
    align-items: center;
  }

  #composer:has(> #mic-btn) #send {
    padding: 0 12px;
  }

  #composer:has(> #mic-btn) #input {
    min-height: var(--tap);
  }
}

@media (max-width: 479px) {
  #composer:has(> #mic-btn) {
    gap: 6px;
  }

  #composer:has(> #mic-btn) #send {
    padding: 0 10px;
    font-size: 0.9rem;
  }

  #talk-mode-btn {
    padding: 0 10px;
    font-size: 0.8rem;
  }
}

/* Reduced motion: no pulsing. States stay distinct through colour and a
   steady ring, never through animation alone. */
@media (prefers-reduced-motion: reduce) {
  #mic-btn,
  #mic-btn:active {
    transition: none;
    transform: none;
  }

  #mic-btn.is-listening::before {
    animation: none;
    box-shadow: 0 0 0 5px var(--mic-red-ring);
  }

  #mic-btn.is-waiting::before {
    animation: none;
    box-shadow: 0 0 0 5px var(--mic-cyan-ring);
  }

  .send-countdown::after {
    animation: none;
    transform: none;
  }
}

@media (forced-colors: active) {
  #mic-btn {
    border-color: ButtonText;
  }

  #mic-btn.is-listening,
  #mic-btn.is-waiting,
  #talk-mode-btn[aria-pressed="true"] {
    outline: 3px solid Highlight;
    outline-offset: 3px;
  }

  #talk-mode-btn[aria-pressed="true"]::before,
  .send-countdown::after {
    forced-color-adjust: none;
    background: Highlight;
  }
}

/* ------------------------------------------------------------------ */
/* Dev page helpers (dev-components.html only)                          */
/* ------------------------------------------------------------------ */
.dev-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

.dev-page section {
  margin: 0 0 24px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.dev-page h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.dev-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.dev-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}

.dev-note {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.dev-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* v2 dev demos: orb, stage and nodes in a fixed-size frame. */
.dev-orb-frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #070d19;
}

.dev-orb-frame canvas {
  display: block;
  width: min(420px, 80vw);
  height: min(420px, 80vw);
}

.dev-orb-frame .dev-caption {
  min-height: 2.9em;
  margin: 4px 0 0;
  max-width: 46ch;
  text-align: center;
}

.dev-stage {
  --node-avatar: 56px;
  --connector: 40px;
  display: grid;
  grid-template-columns: 1fr 120px 1fr;
  align-items: center;
  column-gap: 40px;
  padding: 16px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #070d19;
  overflow: hidden;
}

.dev-stage__orb {
  grid-column: 2;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(76, 194, 255, 0.5), transparent 65%);
}

.dev-stage #team-left,
.dev-stage #team-right {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.dev-stage #team-left {
  grid-column: 1;
  grid-row: 1;
  align-items: flex-end;
}

.dev-stage #team-right {
  grid-column: 3;
  grid-row: 1;
  align-items: flex-start;
}

.dev-events {
  max-height: 8em;
  overflow: auto;
  margin: 8px 0 0;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.dev-narrow {
  max-width: 320px;
}

/* Approval toast demo stacks: same width as the real #approvals stack. */
.dev-toast-demo {
  max-width: 388px;
  margin-bottom: 16px;
}
