:root {
  color-scheme: light;
  --capisca-teal: #0f766e;
  --capisca-green: #2e9d5b;
  --capisca-coral: #ee6c4d;
  --capisca-coral-bright: #f68a63;
  --capisca-gray: #4d4d4d;
  --capisca-spectrum: linear-gradient(90deg,#0f766e 0%,#d99a3d 50%,#ee6c4d 100%);
  --bg-white: #ffffff;
  --bg-light: #fafbfc;
  --bg-subtle: #f0f4f8;
  --text-primary: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-pill: 9999px;
  --shadow-sm: 0 2px 4px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.10);
  --shadow-primary: 0 4px 20px rgba(15,118,110,.15);
  --transition: 0.3s cubic-bezier(0.4,0,0.2,1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -14rem, rgba(15,118,110,.10), transparent 32rem),
    linear-gradient(180deg, var(--bg-white) 0%, var(--bg-light) 46%, var(--bg-subtle) 100%);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

.spectrum-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 3px;
  background: var(--capisca-spectrum);
}

.app-shell {
  width: min(100%, 980px);
  padding: clamp(1rem, 2vw, 2rem);
}

.app-header {
  min-height: 72px;
  margin-bottom: 1rem;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
}

.brand-mark {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
}

.wordmark-row {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.app-title {
  color: var(--text-primary);
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  letter-spacing: 0;
  line-height: 1;
}

.eyebrow,
.diag-label,
.form-label {
  color: var(--text-muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-width: 6.6rem;
  justify-content: center;
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-pill);
  background: var(--bg-white);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  padding: 0.5rem 0.85rem;
  text-transform: uppercase;
  box-shadow: var(--shadow-sm);
}

[data-state="LISTENING"] .status-pill {
  border-color: rgba(50,146,57,.28);
  background: rgba(50,146,57,.10);
  color: var(--capisca-green);
}

[data-state="LOCAL_LOADING"] .status-pill,
[data-state="TTS_CHECKING"] .status-pill,
[data-state="BRAIN_WAKING"] .status-pill,
[data-state="WARMING"] .status-pill,
[data-state="PREPARING"] .status-pill,
[data-state="THINKING"] .status-pill {
  border-color: rgba(247,147,26,.32);
  background: rgba(247,147,26,.12);
  color: #b45f08;
}

[data-state="BRAIN_OFFLINE"] .status-pill,
[data-state="ERROR"] .status-pill {
  border-color: rgba(190,18,60,.28);
  background: rgba(190,18,60,.10);
  color: #be123c;
}

[data-state="SPEAKING"] .status-pill {
  border-color: rgba(15,118,110,.30);
  background: rgba(15,118,110,.10);
  color: var(--capisca-teal);
}

.voice-stage {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 1rem;
  margin: 0 auto 1.5rem;
  padding: clamp(1.5rem, 4vw, 2.5rem) 1rem 1.25rem;
}

.voice-pick {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.voice-pick-label {
  font-size: 0.85rem;
  opacity: 0.8;
  margin: 0;
}

.voice-pick .form-select {
  width: auto;
  min-width: 12rem;
}

.mic-wrap {
  position: relative;
  display: grid;
  width: 148px;
  height: 148px;
  place-items: center;
}

.status-orbit {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 132px;
  height: 132px;
  border-radius: var(--radius-pill);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

[data-state="LISTENING"] .status-orbit {
  border: 1px solid rgba(50,146,57,.26);
  animation: listenPulse 1.9s ease-out infinite;
}

[data-state="LOCAL_LOADING"] .status-orbit,
[data-state="TTS_CHECKING"] .status-orbit,
[data-state="BRAIN_WAKING"] .status-orbit,
[data-state="PREPARING"] .status-orbit,
[data-state="WARMING"] .status-orbit {
  border: 1px solid rgba(247,147,26,.32);
  animation: speakPulse 0.95s ease-in-out infinite alternate;
}

[data-state="SPEAKING"] .status-orbit {
  border: 1px solid rgba(247,147,26,.32);
  animation: speakPulse 0.95s ease-in-out infinite alternate;
}

.mic-button {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 104px;
  height: 104px;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--capisca-teal);
  color: #ffffff;
  padding: 0.9rem 0.65rem 0.75rem;
  box-shadow: var(--shadow-primary);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

.mic-button::before {
  content: "";
  position: absolute;
  inset: -35% auto -35% -70%;
  width: 52%;
  background: linear-gradient(100deg, transparent 0%, rgba(255,255,255,.42) 50%, transparent 100%);
  transform: skewX(-18deg);
  transition: left 0.7s cubic-bezier(0.4,0,0.2,1);
}

.mic-button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg), var(--shadow-primary);
}

.mic-button:hover:not(:disabled)::before {
  left: 118%;
}

.mic-button:disabled {
  cursor: default;
  opacity: 0.95;
}

[data-state="LISTENING"] .mic-button {
  background: var(--capisca-green);
}

[data-state="LOCAL_LOADING"] .mic-button,
[data-state="TTS_CHECKING"] .mic-button,
[data-state="BRAIN_WAKING"] .mic-button,
[data-state="PREPARING"] .mic-button,
[data-state="WARMING"] .mic-button {
  background: var(--capisca-coral);
}

[data-state="BRAIN_OFFLINE"] .mic-button,
[data-state="ERROR"] .mic-button {
  background: #be123c;
}

[data-state="SPEAKING"] .mic-button {
  background: var(--capisca-coral);
}

.mic-button:focus-visible,
.stop-button:focus-visible {
  outline: 3px solid rgba(15,118,110,.30);
  outline-offset: 4px;
}

.mic-glyph {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
  width: 26px;
  height: 38px;
  margin-bottom: 1rem;
  border: 3px solid currentColor;
  border-radius: 18px;
}

.mic-glyph::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 3px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: currentColor;
  transform: translateX(-50%);
}

.mic-glyph::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -17px;
  width: 24px;
  height: 12px;
  border-right: 3px solid currentColor;
  border-bottom: 3px solid currentColor;
  border-left: 3px solid currentColor;
  border-radius: 0 0 16px 16px;
  transform: translateX(-50%);
}

.mic-label {
  position: relative;
  z-index: 1;
  max-width: 100%;
  min-height: 0.9rem;
  overflow: hidden;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-button {
  min-width: 9.25rem;
  border: 1px solid rgba(247,147,26,.32);
  border-radius: var(--radius-pill);
  background: #fff8ef;
  color: #b45f08;
  font-weight: 700;
  padding: 0.7rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stop-button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.stop-button:disabled {
  display: none;
}

.status-detail {
  color: var(--text-secondary);
  font-size: 0.98rem;
  max-width: min(100%, 42rem);
  text-align: center;
}

.warmup-notice {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid rgba(247,147,26,.22);
  border-radius: var(--radius-pill);
  background: rgba(247,147,26,.10);
  color: #9a5208;
  font-size: 0.9rem;
  font-weight: 700;
  padding: 0.55rem 0.85rem;
}

.warmup-notice[hidden] {
  display: none;
}

.conversation-wrap {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.conversation-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem 0.6rem clamp(1rem, 3vw, 1.5rem);
  border-bottom: 1px solid #e6edf4;
}

.conversation-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--text-muted);
}

.conversation-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  min-width: 0;
}

.responsiveness-badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.9rem;
  border: 1px solid rgba(50,146,57,.22);
  border-radius: var(--radius-pill);
  background: rgba(50,146,57,.08);
  color: var(--capisca-green);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1;
  padding: 0.35rem 0.65rem;
  white-space: nowrap;
}

.reset-btn {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.85rem;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.reset-btn:hover {
  color: var(--capisca-teal);
  border-color: var(--capisca-teal);
  background: rgba(15,118,110,.05);
}

.transcript-panel {
  height: min(48vh, 520px);
  min-height: 320px;
  overflow: auto;
  padding: clamp(1rem, 3vw, 1.5rem);
  scroll-behavior: smooth;
}

.transcript-panel:empty::before {
  content: "Your conversation will appear here.";
  display: grid;
  min-height: 100%;
  place-items: center;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
}

.turn {
  display: flex;
  flex-direction: column;
  margin-bottom: 1rem;
}

.turn-user {
  align-items: flex-end;
}

.turn-assistant {
  align-items: flex-start;
}

.role {
  margin: 0 0 0.28rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.text {
  max-width: min(78%, 42rem);
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-md);
  background: var(--bg-white);
  color: var(--text-primary);
  line-height: 1.48;
  padding: 0.82rem 1rem;
  white-space: pre-wrap;
  box-shadow: var(--shadow-sm);
}

.turn-user .text {
  border-color: rgba(15,118,110,.20);
  background: var(--capisca-teal);
  color: #ffffff;
}

.turn-pending .text {
  opacity: 0.62;
}

.diagnostics-panel {
  margin-top: 1.5rem;
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-lg);
  background: var(--bg-white);
  box-shadow: var(--shadow-sm);
  padding: clamp(1rem, 3vw, 1.4rem);
}

.panel-title {
  color: var(--text-primary);
  font-size: 1.15rem;
  font-weight: 800;
}

.diagnostic-badge {
  border-radius: var(--radius-pill);
  background: rgba(50,146,57,.10);
  color: var(--capisca-green);
  font-size: 0.76rem;
  font-weight: 800;
  padding: 0.35rem 0.65rem;
  text-transform: uppercase;
}

.diag-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}

.diag-card,
.settings-panel,
.event-log-wrap {
  border: 1px solid #d9e2ec;
  border-radius: var(--radius-md);
  background: var(--bg-white);
  padding: 1rem;
}

.diag-value {
  min-height: 1.45rem;
  margin-top: 0.5rem;
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.form-control {
  border-color: #cbd5e1;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  min-height: 2.45rem;
}

.form-control:focus {
  border-color: rgba(15,118,110,.68);
  box-shadow: 0 0 0 0.2rem rgba(15,118,110,.12);
}

.event-log {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  max-height: 220px;
  overflow: auto;
}

.event-row {
  border-radius: var(--radius-sm);
  background: var(--bg-light);
  color: var(--capisca-gray);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  padding: 0.5rem 0.6rem;
  overflow-wrap: anywhere;
}

@keyframes listenPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(50,146,57,.24);
    transform: translate(-50%, -50%) scale(0.96);
  }
  100% {
    box-shadow: 0 0 0 24px rgba(50,146,57,0);
    transform: translate(-50%, -50%) scale(1.06);
  }
}

@keyframes speakPulse {
  from {
    box-shadow: 0 0 0 6px rgba(247,147,26,.16);
    transform: translate(-50%, -50%) scale(0.98);
  }
  to {
    box-shadow: 0 0 0 18px rgba(247,147,26,.04);
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@media (max-width: 760px) {
  .app-header {
    align-items: flex-start !important;
    flex-direction: column;
    gap: 0.9rem;
  }

  .app-header > .d-flex {
    width: 100%;
    justify-content: space-between;
  }

  .brand-mark {
    width: 42px;
    height: 42px;
  }

  .status-pill {
    min-width: 5.85rem;
  }

  .mic-button {
    width: 92px;
    height: 92px;
    gap: 0.25rem;
    padding: 0.75rem 0.55rem 0.65rem;
  }

  .mic-wrap {
    width: 124px;
    height: 124px;
  }

  .status-orbit {
    width: 108px;
    height: 108px;
  }

  .mic-glyph {
    width: 23px;
    height: 34px;
    margin-bottom: 0.9rem;
  }

  .mic-label {
    font-size: 0.66rem;
  }

  .text {
    max-width: 92%;
  }

  .conversation-head {
    align-items: flex-start;
  }

  .conversation-actions {
    flex-wrap: wrap;
  }

  .responsiveness-badge {
    font-size: 0.68rem;
    padding-inline: 0.5rem;
  }

  .diag-grid {
    grid-template-columns: 1fr;
  }
}

/* --- Demo sign-in gate ------------------------------------------------------------------------ */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 4vw, 2rem);
  background:
    radial-gradient(circle at 50% -10rem, rgba(15,118,110,.12), transparent 30rem),
    linear-gradient(180deg, var(--bg-white) 0%, var(--bg-light) 46%, var(--bg-subtle) 100%);
}

.login-card {
  width: min(100%, 400px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: clamp(1.5rem, 4vw, 2.25rem);
  background: var(--bg-white);
  border: 1px solid rgba(15,118,110,.08);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-card::before {
  content: "";
  height: 3px;
  margin: -0.25rem -0.5rem 0.5rem;
  border-radius: var(--radius-pill);
  background: var(--capisca-spectrum);
}

.login-brand {
  justify-content: center;
  gap: .6rem;
}

.login-brand .brand-mark {
  width: 40px;
  height: 40px;
}

.login-sub {
  margin: -.25rem 0 .25rem;
  text-align: center;
  color: var(--text-secondary);
  font-size: .95rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.login-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.login-input {
  width: 100%;
  padding: .7rem .85rem;
  border: 1px solid #d7e0ea;
  border-radius: var(--radius-sm);
  background: var(--bg-white);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.login-input:focus {
  outline: none;
  border-color: var(--capisca-teal);
  box-shadow: 0 0 0 3px rgba(15,118,110,.12);
}

.login-submit {
  margin-top: .25rem;
  padding: .75rem 1rem;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--capisca-spectrum);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: filter var(--transition), transform var(--transition);
}

.login-submit:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.login-submit:disabled {
  opacity: .65;
  cursor: default;
}

.login-error {
  margin: 0;
  text-align: center;
  color: #c0392b;
  font-size: .9rem;
  font-weight: 600;
}

/* --- post-session feedback card --------------------------------------------------------- */
.feedback-card[hidden] { display: none; }   /* class display:flex would beat the UA [hidden] rule */
.feedback-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px 24px;
  background: var(--bg-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.feedback-title {
  font-weight: 600;
  color: var(--text-primary);
}
.feedback-thumbs {
  display: flex;
  gap: 10px;
}
.fb-thumb {
  font-size: 1.3rem;
  line-height: 1;
  padding: 8px 16px;
  border: 1px solid var(--bg-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-light);
  transition: var(--transition);
}
.fb-thumb:hover { box-shadow: var(--shadow-sm); }
.fb-thumb.selected {
  border-color: var(--capisca-teal);
  background: var(--bg-subtle);
  box-shadow: var(--shadow-primary);
}
.fb-select-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.fb-select-label {
  min-width: 64px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.fb-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/* Provider toggle: reuses the .fb-chip idiom; it drives the NEXT session's backend, so it
   locks (dimmed, inert) while a session is live — switching mid-call isn't a thing. */
.provider-toggle {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.provider-chip:disabled { opacity: 0.55; pointer-events: none; }
.search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.search-toggle input { width: 18px; height: 18px; accent-color: var(--capisca-teal); }
.search-toggle:has(input:disabled) { opacity: 0.55; }
.fb-chip {
  font-size: 0.85rem;
  line-height: 1;
  padding: 7px 14px;
  border: 1px solid var(--bg-subtle);
  border-radius: var(--radius-pill);
  background: var(--bg-light);
  color: var(--text-secondary);
  transition: var(--transition);
}
.fb-chip:hover { box-shadow: var(--shadow-sm); }
.fb-chip.selected {
  border-color: var(--capisca-teal);
  background: var(--bg-subtle);
  color: var(--text-primary);
  box-shadow: var(--shadow-primary);
}
.feedback-text {
  border: 1px solid var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font: inherit;
  color: var(--text-primary);
  resize: vertical;
}
.feedback-text:focus { outline: 2px solid var(--capisca-teal); outline-offset: 1px; }
.feedback-actions {
  display: flex;
  gap: 10px;
}
.feedback-send {
  padding: 8px 22px;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--capisca-teal);
  color: #fff;
  font-weight: 600;
  transition: var(--transition);
}
.feedback-send:disabled { opacity: 0.45; }
.feedback-skip {
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-muted);
}
.feedback-skip:hover { color: var(--text-secondary); }
