:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --line: #d9e1e7;
  --text: #17212b;
  --muted: #6e7c89;
  --primary: #167f78;
  --primary-dark: #116760;
  --customer: #eef5ff;
  --bot: #edf8f5;
  --danger: #b82b2b;
  --warning: #8a5a00;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.55; }

.lab-topbar {
  min-height: 92px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #16202b;
  color: #eef4f8;
}

.lab-topbar h1, .lab-topbar p { margin: 0; }
.lab-topbar h1 { margin-top: 3px; font-size: 25px; letter-spacing: 0; }
.lab-topbar p { margin-top: 3px; color: #aebbc7; font-size: 13px; }
.back-link { color: #70d4cd; text-decoration: none; font-size: 13px; }
.status-line { display: flex; align-items: center; gap: 12px; }

.call-launch {
  padding: 12px 24px;
  display: flex;
  align-items: flex-end;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.call-launch-main {
  display: flex;
  align-items: end;
  gap: 10px;
}
.phone-field { width: min(360px, 42vw); }
.call-button { min-width: 170px; }
.lab-options { flex: 1; min-width: 0; }
.lab-options summary { cursor: pointer; color: var(--muted); font-weight: 650; }
.lab-options[open] summary { margin-bottom: 8px; }

.lab-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

label { display: grid; gap: 5px; color: var(--muted); font-size: 12px; font-weight: 650; }
input, select, textarea {
  width: 100%;
  border: 1px solid #bdc9d2;
  border-radius: var(--radius);
  padding: 9px 10px;
  color: var(--text);
  background: #fff;
  letter-spacing: 0;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #88c9c4; outline-offset: 1px; }

.primary, .secondary {
  min-height: 38px;
  border-radius: var(--radius);
  padding: 8px 14px;
  border: 1px solid transparent;
}
.primary { background: var(--primary); color: white; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #fff; color: var(--text); border-color: #bdc9d2; }

.lab-layout {
  height: calc(100vh - 166px);
  min-height: 560px;
  padding: 14px 24px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 14px;
}

.conversation-pane, .debug-pane {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.pane-header {
  min-height: 68px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.pane-header h2, .pane-header p { margin: 0; }
.pane-header h2 { font-size: 18px; letter-spacing: 0; }
.pane-header p { margin-top: 3px; color: var(--muted); font-size: 12px; }
.state-badge { padding: 5px 8px; border-radius: 6px; background: #edf1f4; font: 12px ui-monospace, monospace; }

.customer-context {
  min-height: 48px;
  padding: 9px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fbfb;
  font-size: 13px;
}
.customer-context strong { font-size: 14px; }
.customer-context span { color: var(--muted); }
.customer-context[data-status="ambiguous"],
.customer-context[data-status="unavailable"] { background: #fff9e9; }
.customer-context[data-status="not_found"],
.customer-context[data-status="invalid_input"] { background: #f6f8fa; }

.conversation { flex: 1; overflow: auto; padding: 16px; display: grid; align-content: start; gap: 12px; }
.conversation-empty { align-self: center; justify-self: center; margin: 0; color: var(--muted); }
.message { width: min(86%, 680px); padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.message.bot { justify-self: start; background: var(--bot); border-color: #b9ded8; }
.message.customer { justify-self: end; background: var(--customer); border-color: #cbdaf1; }
.message-header { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.message p { margin: 0; line-height: 1.4; }

.composer { padding: 12px 16px; border-top: 1px solid var(--line); background: #fafcfd; }
.composer-actions { margin-top: 8px; display: flex; justify-content: flex-end; gap: 8px; }
.voice-button { min-width: 168px; }
.voice-button.is-listening { background: var(--danger); }
.voice-button.is-interrupting { background: #a65b00; }
.composer-status { margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.composer-status.is-recording { color: var(--danger); font-weight: 700; }

.decision-summary { margin: 12px 14px 0; padding: 10px 12px; display: flex; justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.decision-summary span { color: var(--muted); }
.decision-summary[data-decision="handoff"] { border-color: #e4a7a7; background: #fff3f3; }
.decision-summary[data-decision="clarify"] { border-color: #e0c98d; background: #fff9e9; }

.debug-timeline { flex: 1; overflow: auto; padding: 14px; display: grid; align-content: start; gap: 8px; }
.debug-event { padding: 9px 10px; border-left: 3px solid #9aa9b5; background: #f6f8fa; }
.debug-event.tool { border-left-color: #3777b9; }
.debug-event.handoff { border-left-color: var(--danger); }
.debug-event strong { display: block; font-size: 13px; }
.debug-event p { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
.raw-json { border-top: 1px solid var(--line); padding: 10px 14px; }
.raw-json summary { cursor: pointer; font-weight: 650; }
.raw-json pre { max-height: 260px; overflow: auto; font-size: 11px; white-space: pre-wrap; }
.error-banner { margin: 10px 24px 0; padding: 10px 12px; color: #7b1717; background: #fff1f1; border: 1px solid #e8b6b6; border-radius: var(--radius); }
.is-hidden { display: none; }

@media (max-width: 900px) {
  .lab-topbar { align-items: flex-start; }
  .status-line { flex-direction: column; align-items: flex-end; }
  .call-launch { align-items: stretch; flex-direction: column; }
  .call-launch-main { width: 100%; }
  .phone-field { width: 100%; }
  .lab-controls { grid-template-columns: 1fr 1fr; }
  .lab-layout { height: auto; grid-template-columns: 1fr; }
  .conversation-pane { min-height: 640px; }
  .debug-pane { min-height: 520px; }
}

@media (max-width: 560px) {
  .lab-topbar, .call-launch, .lab-layout { padding-left: 12px; padding-right: 12px; }
  .lab-topbar { display: grid; }
  .status-line { align-items: flex-start; }
  .call-launch-main { align-items: stretch; flex-direction: column; }
  .call-button { width: 100%; }
  .lab-controls { grid-template-columns: 1fr; }
  .composer-actions { flex-wrap: wrap; }
  .composer-actions button { flex: 1 1 150px; }
  .message { width: 94%; }
}
