:root {
  --bg: #0e1117;
  --panel: #161b24;
  --panel-2: #1d2430;
  --border: #2a3342;
  --text: #e6ebf2;
  --muted: #8b96a8;
  --accent: #4f8cff;
  --green: #2dd4a7;
  --red: #ff6b6b;
  --amber: #ffb454;
  /* Speaker roles: the clinician side is blue, the patient side is teal, and
     the pairing is used consistently on badges, borders, and message edges. */
  --clinician: #4f8cff;
  --patient: #2dd4a7;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* The `hidden` attribute must win.
   A class that sets `display` outranks the browser's own
   `[hidden] { display: none }`, so an element written as hidden — the quota
   notice, the account bar, the allowance meter — renders anyway, as an empty
   band. Stating it here, with the weight to beat a class, keeps `hidden`
   meaning hidden however an element is styled later. */
[hidden] {
  display: none !important;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand h1 { font-size: 18px; margin: 0; font-weight: 600; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--muted); }
.logo { font-size: 22px; }

.mic-controls { display: flex; align-items: center; gap: 14px; min-width: 0; }

.meter {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--green), var(--amber));
  transition: width 60ms linear;
}

.status {
  font-size: 13px;
  color: var(--muted);
  min-width: 80px;
  text-align: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
}
.status.listening { color: var(--accent); }
.status.speaking { color: var(--green); }
.status.error { color: var(--red); }

.mic-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.mic-btn.live { background: var(--red); }
.mic-btn:hover { filter: brightness(1.1); }
/* Grayed out while starting/stopping (clicks are ignored then). */
.mic-btn:disabled {
  background: var(--panel-2);
  color: var(--muted);
  cursor: default;
  filter: none;
}

/* ---------- Encounter setup ---------- */
.settings {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.setting-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.setting-label { font-size: 13px; color: var(--muted); white-space: nowrap; }
.settings-toggle { display: none; }
.spacer { flex: 1; }
.hint { font-size: 12px; color: var(--muted); flex: 1 1 200px; min-width: 0; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.subtle { color: var(--muted); }
.btn.icon { padding: 7px 10px; font-size: 15px; line-height: 1; }

.select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  max-width: 100%;
}
.select.grow { flex: 0 1 320px; }

.checkbox {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.checkbox input { accent-color: var(--accent); }


/* ---------- Messages ---------- */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 60px;
  font-size: 15px;
  line-height: 1.7;
}
.msg {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  max-width: min(760px, 92%);
}
/* Clinician turns hug the left, patient turns the right, so the direction of
   the conversation is readable at a glance without reading the badges. */
.msg[data-role="clinician"] { border-left-color: var(--clinician); align-self: flex-start; }
.msg[data-role="patient"] { border-left-color: var(--patient); align-self: flex-end; }
.msg.error { border-color: var(--red); }

.msg-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
/* Subtle per-role tint so the two sides read apart at a glance. */
.msg[data-role="clinician"] {
  background: linear-gradient(90deg, rgba(79, 140, 255, 0.06), transparent 45%) var(--panel);
}
.msg[data-role="patient"] {
  background: linear-gradient(270deg, rgba(45, 212, 167, 0.06), transparent 45%) var(--panel);
}

/* Per-turn speaker toggle: the active side is the speaker; clicking the
   other side reassigns the turn and re-runs the interpretation. */
.role-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.role-toggle button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
}
.role-toggle button + button { border-left: 1px solid var(--border); }
.role-toggle button:disabled { opacity: 0.5; cursor: default; }
.role-toggle button.on[data-set-role="clinician"] {
  background: rgba(79, 140, 255, 0.16);
  color: var(--clinician);
  font-weight: 600;
}
.role-toggle button.on[data-set-role="patient"] {
  background: rgba(45, 212, 167, 0.16);
  color: var(--patient);
  font-weight: 600;
}

/* A turn whose detected language contradicts the speaker's preset. */
.lang-warn {
  background: rgba(255, 180, 84, 0.15);
  color: var(--amber);
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.lang-badge { margin-left: auto; }

.blob {
  border-left: 3px solid var(--border);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 8px 12px;
}
.blob + .blob { margin-top: 8px; }
.blob.source { border-left-color: var(--muted); }
.blob.translation { border-left-color: var(--green); }

.blob-lang {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
}
.speak-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
.speak-btn:hover { color: var(--accent); }
.speak-btn:disabled { opacity: 0.5; cursor: default; }

.blob-text {
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}
.blob.translation .blob-text { font-size: 16px; }
.blob-text.pending { color: var(--muted); font-style: italic; }
.blob-text.streaming::after {
  content: '▍';
  color: var(--green);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Numbers spoken in the source that did not survive into the interpretation.
   Advisory only — a language that spells numbers out will trip it. */
.number-flag {
  display: flex;
  gap: 7px;
  align-items: baseline;
  margin-top: 7px;
  padding: 6px 10px;
  border-radius: 6px;
  background: rgba(255, 180, 84, 0.12);
  border: 1px solid rgba(255, 180, 84, 0.35);
  color: var(--amber);
  font-size: 12.5px;
  line-height: 1.5;
}
.number-flag b { font-variant-numeric: tabular-nums; }

.same-lang-note {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--muted);
  font-style: italic;
}

/* ---------- Mobile (must stay last so it overrides the base rules) ---------- */
@media (max-width: 720px) {
  .topbar { padding: 10px 14px; }
  /* Controls drop to their own full-width row under the title. */
  .mic-controls { flex: 1 0 100%; }
  .meter { flex: 1; width: auto; min-width: 50px; }
  .mic-btn { white-space: nowrap; }
  .settings { padding: 10px 14px; }
  .messages { padding: 14px; }
  .msg { max-width: 100%; }
  .select.grow { flex: 1 1 100%; }
  .hint { flex-basis: 100%; }
  /* The whole setup section can be collapsed on small screens. */
  .settings-toggle {
    display: block;
    width: 100%;
    text-align: left;
    background: var(--panel);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
  }
  .settings.collapsed { display: none; }
}

/* ---------- Account bar ----------
   Who is signed in, what is left of the weekly allowance, and the way to
   lift it. Sits between the header and the encounter setup. */
.account-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  font-size: 13px;
}
.account-email { color: var(--text); font-weight: 500; }
.plan-badge {
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}
.plan-badge.pro {
  background: rgba(45, 212, 167, 0.16);
  color: var(--patient);
  font-weight: 600;
}

.quota-wrap { display: flex; align-items: center; gap: 8px; }
.quota-meter {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: var(--panel-2);
  overflow: hidden;
}
.quota-fill {
  display: block;
  height: 100%;
  width: 0;
  background: var(--patient);
  transition: width 200ms ease;
}
.quota-fill.low { background: var(--amber); }
.quota-fill.spent { background: var(--red); }
.quota-text { color: var(--muted); font-variant-numeric: tabular-nums; }

.btn.accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn.accent:hover { filter: brightness(1.1); }

/* The allowance is spent: interpreting is paused until the window frees up. */
.quota-notice {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 180, 84, 0.12);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.55;
}

/* ---------- Sign-in page ---------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
}
.auth-card h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 20px;
}
.auth-lede { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 0 22px; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-label { font-size: 12px; color: var(--muted); }
.auth-input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 15px;
  padding: 11px 13px;
}
.auth-input:focus { outline: none; border-color: var(--accent); }
.auth-submit { margin-top: 6px; width: 100%; }
.auth-msg {
  margin: 16px 0 0;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13.5px;
  line-height: 1.55;
}
.auth-msg.ok { background: rgba(45, 212, 167, 0.14); color: var(--patient); }
.auth-msg.error { background: rgba(255, 107, 107, 0.14); color: var(--red); }
.auth-msg a { color: inherit; }
.auth-foot {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}

@media (max-width: 720px) {
  .account-bar { padding: 8px 14px; }
  .quota-meter { width: 84px; }
  .quota-notice { padding: 12px 14px; }
}

/* Interface-language picker: compact enough to sit in the account bar and
   on the sign-in card without drawing attention to itself. */
.lang-select {
  padding: 5px 8px;
  font-size: 12.5px;
  max-width: 9.5em;
}
.auth-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.auth-top h1 { flex: 1; }
