/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:          #0d0d0f;
  --surface:     #141418;
  --surface-2:   #1c1c22;
  --border:      #2a2a32;
  --accent:      #c8a96e;
  --accent-dim:  #8a7248;
  --text:        #e8e8ec;
  --text-muted:  #7a7a88;
  --text-faint:  #44444e;
  --success:     #5cb87a;
  --danger:      #c85858;
  --warn:        #c8a040;

  --radius:      6px;
  --panel-max:   760px;
  --font:        'Inter', 'Segoe UI', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --transition:  160ms ease;
}

html {
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* Embed mode: fill the iframe fully */
html, body {
  height: 100%;
}

body.embed-mode {
  height: 100%;
  overflow: hidden;
  background: transparent;
  --bg:          #1a2942;
  --surface:     rgba(18, 29, 47, 0.94);
  --surface-2:   rgba(26, 41, 66, 0.96);
  --border:      rgba(255, 255, 255, 0.12);
  --accent:      #7dc6c6;
  --accent-dim:  #53a7a7;
  --text:        #f3f7fb;
  --text-muted:  rgba(243, 247, 251, 0.68);
  --text-faint:  rgba(243, 247, 251, 0.42);
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Typography ────────────────────────────────────────────────────────── */
h1, h2, h3 { font-weight: 600; letter-spacing: -0.02em; }

/* ── Header ────────────────────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.header-inner {
  max-width: var(--panel-max);
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.logo-text {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-transform: uppercase;
}

.header-role {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── Main panel ────────────────────────────────────────────────────────── */
main.panel {
  flex: 1;
  max-width: var(--panel-max);
  width: 100%;
  margin: 32px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Embed: fill iframe height exactly, composer always at bottom */
body.embed-mode main.panel {
  max-width: 100%;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 10px;
  gap: 8px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Status bar ────────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background var(--transition);
}

.status-dot.idle       { background: var(--text-faint); }
.status-dot.connecting { background: var(--warn);
  animation: pulse 1.2s ease-in-out infinite; }
.status-dot.live       { background: var(--success);
  animation: pulse 2s ease-in-out infinite; }
.status-dot.error      { background: var(--danger); }
.status-dot.closed     { background: var(--text-muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.status-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.backend-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.voice-language-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}

.voice-language-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.voice-language-select {
  min-width: 130px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.84rem;
}

.voice-status {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 6px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.04);
}

.voice-status[data-state="error"]    { color: var(--danger); }
.voice-status[data-state="blocked"]  { color: var(--warn); }
.voice-status[data-state="speaking"] { color: var(--success); }

/* ── Transcript ─────────────────────────────────────────────────────────── */
.transcript-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* In embed mode the transcript grows to fill all available space */
body.embed-mode .transcript-section {
  flex: 1 1 0;     /* grow AND shrink from 0 — composer always fits */
  min-height: 150px;
}

.transcript-header {
  padding: 8px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.transcript-body {
  padding: 14px;
  min-height: 280px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: auto;
}

/* In embed mode: fill the transcript-section, explicit scroll */
body.embed-mode .transcript-body {
  flex: 1 1 0;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar */
.transcript-body::-webkit-scrollbar       { width: 4px; }
.transcript-body::-webkit-scrollbar-track { background: transparent; }
.transcript-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.transcript-placeholder {
  color: var(--text-faint);
  font-size: 0.85rem;
  font-style: italic;
  margin: auto;
  text-align: center;
  padding: 40px 0;
}

/* Individual messages */
.turn {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeIn 220ms ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.turn-label {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.turn.user  .turn-label { color: var(--accent-dim); }
.turn.agent .turn-label { color: var(--text-muted); }

.turn-text {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--text);
}

.turn.user  .turn-text {
  background: var(--surface-2);
  border-left: 2px solid var(--accent);
  padding: 8px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

.turn.agent .turn-text {
  border-left: 2px solid var(--border);
  padding: 8px 12px;
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* Streaming cursor */
.turn-text.streaming::after {
  content: '▌';
  color: var(--accent);
  animation: blink 700ms step-end infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* Action links below agent messages */
.turn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 14px;
  margin-top: 2px;
}

.turn-action-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--accent-dim);
  border-radius: 99px;
  transition: background var(--transition), opacity var(--transition);
}

.turn-action-link:hover {
  background: rgba(200, 169, 110, 0.12);
  opacity: 0.9;
}

body.embed-mode .turn-action-link {
  color: var(--accent);
  border-color: var(--accent-dim);
}

/* ── Lead summary panel ─────────────────────────────────────────────────── */
.lead-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.lead-panel-header {
  padding: 8px 14px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.lead-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0;
  padding: 6px 0;
}

.lead-grid dt {
  padding: 5px 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.03em;
  border-right: 1px solid var(--border);
}

.lead-grid dd {
  padding: 5px 14px;
  font-size: 0.82rem;
  color: var(--text);
  font-family: var(--font-mono);
}

.missing-notice {
  padding: 8px 14px;
  font-size: 0.78rem;
  color: var(--warn);
  border-top: 1px solid var(--border);
  background: rgba(200, 160, 64, 0.06);
}

/* ── Controls ───────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* ── Composer — always anchored at the bottom in embed mode ─────────────── */
.composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-shrink: 0;
}

body.embed-mode .composer {
  flex: 0 0 auto;   /* never grow, never shrink — always visible */
  padding: 10px 12px;
}

.composer-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.composer-input {
  width: 100%;
  min-height: 72px;
  max-height: 140px;
  resize: vertical;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  line-height: 1.5;
}

/* Standalone gets a taller textarea */
body:not(.embed-mode) .composer-input {
  min-height: 100px;
}

.composer-input:focus {
  outline: none;
  border-color: var(--accent-dim);
}

.composer-hint {
  font-size: 0.7rem;
  color: var(--text-faint);
  text-align: right;
}

.composer-actions {
  display: flex;
  justify-content: flex-end;
  flex-shrink: 0;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 20px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: opacity var(--transition), background var(--transition),
              border-color var(--transition);
  user-select: none;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-primary {
  background: var(--accent);
  color: #0d0d0f;
  border-color: var(--accent);
}
.btn-primary:not(:disabled):hover { opacity: 0.88; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:not(:disabled):hover { background: rgba(200, 88, 88, 0.1); }

/* ── Error notice ───────────────────────────────────────────────────────── */
.error-notice {
  padding: 10px 14px;
  background: rgba(200, 88, 88, 0.1);
  border: 1px solid rgba(200, 88, 88, 0.35);
  border-radius: var(--radius);
  color: var(--danger);
  font-size: 0.84rem;
  line-height: 1.5;
  flex-shrink: 0;
}

/* ── Footer ─────────────────────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  text-align: center;
  font-size: 0.73rem;
  color: var(--text-faint);
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* ── Embed-mode overrides ────────────────────────────────────────────────── */
body.embed-mode .site-header,
body.embed-mode .site-footer,
body.embed-mode .backend-note,
body.embed-mode .status-bar,
body.embed-mode .lead-panel,
body.embed-mode .controls,
body.embed-mode #modeNote,
body.embed-mode .voice-status {
  display: none;
}

body.embed-mode .transcript-section,
body.embed-mode .composer,
body.embed-mode .error-notice {
  border-radius: 10px;
}

body.embed-mode .composer-input {
  min-height: 48px;
  max-height: 72px;
  resize: none;
}

body.embed-mode .btn {
  width: 100%;
  justify-content: center;
}

body.embed-mode .transcript-header,
body.embed-mode .composer-label {
  font-size: 0.68rem;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .controls { flex-direction: column; }
  .btn      { width: 100%; justify-content: center; }
  .lead-grid { grid-template-columns: 110px 1fr; }
  .voice-language-row { flex-direction: column; align-items: flex-start; }
  .voice-language-select { width: 100%; }
  body.embed-mode main.panel { padding: 8px; }
  body.embed-mode .transcript-section { min-height: 180px; }
  body.embed-mode .composer { padding: 8px 10px; }
  body.embed-mode .composer-input { min-height: 44px; max-height: 64px; }
}
