:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #151515;
  background: #f5f5f3;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; }

button, input, textarea, select { font: inherit; letter-spacing: 0; }

button { cursor: pointer; }

.topbar {
  min-height: 104px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(20px, 4vw, 64px) 20px;
  background: #fff;
  border-bottom: 1px solid #d8d8d5;
}

h1, h2, h3, p { margin: 0; }
h1 { margin-top: 4px; font-size: 25px; font-weight: 620; }
h2 { margin-top: 3px; font-size: 19px; font-weight: 620; }
h3 { font-size: 15px; font-weight: 650; }

.eyebrow {
  color: #666663;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.system-state { display: flex; align-items: center; gap: 8px; color: #555; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #999; }
.status-dot.ok { background: #25834b; }
.status-dot.warn { background: #b27618; }
.auth-form { display: flex; gap: 6px; margin-left: auto; }
.auth-form[hidden] { display: none; }
.auth-form input { width: 160px; min-height: 34px; }
.auth-form button { min-height: 34px; padding: 0 12px; background: #fff; border: 1px solid #aaa; border-radius: 4px; font-size: 12px; font-weight: 650; }

.tabs {
  height: 48px;
  display: flex;
  gap: 24px;
  padding: 0 clamp(20px, 4vw, 64px);
  background: #fff;
  border-bottom: 1px solid #d8d8d5;
}

.tab {
  flex: none;
  padding: 0;
  white-space: nowrap;
  color: #666;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 600;
}

.tab.active { color: #111; border-bottom-color: #111; }

main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 70px; }
.view { display: none; }
.view.active { display: block; }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid #cfcfcb;
}

.subsection { margin-top: 42px; }

label { display: grid; gap: 8px; color: #4c4c49; font-size: 12px; font-weight: 650; }
input, textarea, select {
  width: 100%;
  min-height: 40px;
  padding: 9px 11px;
  color: #171717;
  background: #fff;
  border: 1px solid #c9c9c5;
  border-radius: 4px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: #222; box-shadow: 0 0 0 2px rgba(0, 0, 0, .08); }

.field-grid { display: grid; gap: 18px; margin-top: 20px; }
.field-grid + label, .field-grid + textarea, form > label { margin-top: 20px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.compact-fields input { max-width: 190px; }

.primary {
  min-height: 38px;
  padding: 0 16px;
  color: #fff;
  background: #171717;
  border: 1px solid #171717;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 650;
}
.primary:hover { background: #333; }
.primary:disabled, button:disabled { cursor: wait; opacity: .55; }

.toggle-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin-top: 20px; background: #d7d7d3; border: 1px solid #d7d7d3; }
.toggle-grid.single { grid-template-columns: 1fr; margin-top: 0; }
.toggle-row { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 16px; background: #fff; }
.toggle-row span { display: grid; gap: 4px; }
.toggle-row strong { color: #1b1b1b; font-size: 13px; }
.toggle-row small { color: #70706d; font-size: 12px; font-weight: 450; line-height: 1.35; }
.toggle-row input { width: 36px; min-height: 20px; accent-color: #171717; }

.testing-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, .85fr); gap: 20px; margin-top: 20px; }
.voice-hint { color: #70706d; font-size: 13px; margin: 8px 0 16px; }
.voice-controls { display: flex; align-items: center; gap: 10px; }
.voice-controls .status-dot { width: 9px; height: 9px; }
#voice-status-label { font-size: 12px; color: #666; }
.panel { padding: 20px; background: #fff; border: 1px solid #d3d3cf; border-radius: 6px; }
.panel.no-padding { padding: 0; margin-top: 20px; overflow: hidden; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-title button { min-height: 34px; padding: 0 12px; background: #fff; border: 1px solid #aaa; border-radius: 4px; font-size: 12px; font-weight: 650; }

.conversation { height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 10px; padding: 18px 0; }
.message { max-width: 82%; padding: 10px 12px; border: 1px solid #d3d3cf; border-radius: 5px; font-size: 13px; line-height: 1.45; white-space: pre-wrap; }
.message.sms { max-width: none; background: #f4f4f1; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.caller { align-self: flex-start; background: #f4f4f1; }
.message.agent { align-self: flex-end; color: #fff; background: #232323; border-color: #232323; }
.composer { display: grid; grid-template-columns: 1fr auto; gap: 8px; border-top: 1px solid #ddd; padding-top: 14px; }
.composer input { min-width: 0; }

.metric-row { display: flex; align-items: baseline; justify-content: space-between; margin-top: 20px; padding: 14px 0; border-top: 1px solid #ddd; border-bottom: 1px solid #ddd; }
.metric-row strong { font-size: 22px; }
.metric-row span { color: #666; font-size: 12px; }
.result-list { display: grid; max-height: 350px; overflow: auto; }
.result { display: grid; gap: 5px; padding: 13px 0; border-bottom: 1px solid #e3e3df; }
.result-header { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; font-weight: 700; }
.result p { color: #60605d; font-size: 12px; line-height: 1.4; }
.pass { color: #28784a; }
.fail { color: #a1322b; }

.call-count { display: flex; align-items: baseline; gap: 7px; }
.call-count strong { font-size: 25px; }
.call-count span { color: #666; font-size: 12px; }
.table-header, .event-row { display: grid; grid-template-columns: 1fr 1.4fr 140px; gap: 16px; align-items: center; padding: 12px 16px; }
.table-header { color: #666; background: #eeeeeb; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.event-row { border-top: 1px solid #e0e0dc; font-size: 12px; }
.event-row code { overflow: hidden; color: #555; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 30px 16px; color: #777; font-size: 13px; text-align: center; }

.latency-filter { width: 180px; gap: 5px; }
.latency-filter select { min-height: 34px; padding: 6px 9px; }
.latency-note { max-width: 900px; margin-top: 14px; color: #666; font-size: 12px; line-height: 1.5; }
.latency-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin-top: 20px; background: #d7d7d3; border: 1px solid #d7d7d3; }
.latency-metric { min-width: 0; display: grid; gap: 5px; padding: 14px 16px; background: #fff; }
.latency-metric span { overflow: hidden; color: #666; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.latency-metric strong { font-size: 19px; }
.latency-metric small { color: #777; font-size: 10px; }
.latency-list-heading { display: flex; align-items: baseline; justify-content: space-between; margin: 30px 0 10px; }
.latency-list-heading span { color: #777; font-size: 11px; }
.latency-turns { display: grid; gap: 8px; }
.latency-turn { padding: 0; overflow: hidden; }
.latency-turn summary { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 18px; cursor: pointer; list-style: none; }
.latency-turn summary::-webkit-details-marker { display: none; }
.latency-turn summary::before { content: "›"; flex: 0 0 auto; color: #777; font-size: 20px; transition: transform .12s; }
.latency-turn[open] summary::before { transform: rotate(90deg); }
.latency-identity { min-width: 0; flex: 1; display: flex; align-items: center; gap: 9px; }
.latency-identity > strong { font-size: 13px; white-space: nowrap; }
.latency-identity > span:last-child { overflow: hidden; color: #666; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.transport-badge, .stage-name { padding: 3px 6px; color: #4a4a47; background: #eeeeeb; border-radius: 3px; font-size: 9px; font-weight: 750; text-transform: uppercase; white-space: nowrap; }
.transport-badge.twilio { color: #8a2525; background: #f8e7e6; }
.transport-badge.browser { color: #225e44; background: #e4f2ea; }
.transport-badge.playground { color: #385481; background: #e7edf7; }
.latency-total { flex: 0 0 auto; display: grid; gap: 2px; text-align: right; }
.latency-total strong { font-size: 16px; }
.latency-total time { color: #777; font-size: 10px; }
.turn-metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid #e2e2de; border-bottom: 1px solid #e2e2de; }
.turn-metrics .latency-metric { border-right: 1px solid #e2e2de; }
.turn-metrics .latency-metric:last-child { border-right: 0; }
.turn-metrics .latency-metric strong { font-size: 15px; }
.stage-list { padding: 5px 18px 12px; }
.stage-row { display: grid; grid-template-columns: 68px minmax(130px, 1fr) 100px 80px; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid #ecece8; font-size: 11px; }
.stage-row:last-child { border-bottom: 0; }
.stage-row > span:nth-child(3) { color: #777; }
.stage-row > strong:last-of-type { text-align: right; }
.stage-row small { grid-column: 2 / -1; color: #777; }
.stage-name.llm { color: #385481; background: #e7edf7; }
.stage-name.safety { color: #7a5520; background: #f5ecdc; }
.stage-name.tts { color: #225e44; background: #e4f2ea; }
.stage-name.tool { color: #6b3b78; background: #f1e5f5; }
.stage-name.transport { color: #555; background: #ededed; }

#toast { position: fixed; right: 20px; bottom: 20px; max-width: min(380px, calc(100vw - 40px)); padding: 11px 14px; color: #fff; background: #171717; border-radius: 4px; font-size: 13px; opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease; }
#toast.show { opacity: 1; transform: translateY(0); }
#toast.error { background: #8f2924; }

@media (max-width: 820px) {
  .field-grid.three, .field-grid.four, .testing-grid { grid-template-columns: 1fr 1fr; }
  .testing-grid { grid-template-columns: 1fr; }
  .compact-fields input { max-width: none; }
  .latency-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .turn-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 590px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .auth-form { width: 100%; margin-left: 0; }
  .auth-form input { width: 100%; }
  .tabs { gap: 18px; overflow-x: auto; }
  main { width: min(100% - 28px, 1180px); padding-top: 24px; }
  .field-grid.two, .field-grid.three, .field-grid.four, .toggle-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .section-heading .primary { width: 100%; }
  .table-header, .event-row { grid-template-columns: 1fr 100px; }
  .table-header span:nth-child(2), .event-row code { display: none; }
  .latency-filter { width: 100%; }
  .latency-summary { grid-template-columns: 1fr 1fr; }
  .latency-turn summary { align-items: flex-start; }
  .latency-identity { align-items: flex-start; flex-wrap: wrap; }
  .latency-identity > span:last-child { width: 100%; }
  .stage-row { grid-template-columns: 58px minmax(100px, 1fr) 64px; }
  .stage-row > span:nth-child(3) { display: none; }
}

.section-heading > button:not(.primary), .tl-head button { min-height: 32px; padding: 0 12px; color: #171717; background: #fff; border: 1px solid #aaa; border-radius: 4px; font-size: 12px; font-weight: 650; }
.section-heading > button:not(.primary):hover, .tl-head button:hover { border-color: #171717; }

.test-line-status { display: flex; align-items: center; gap: 8px; margin-top: 16px; color: #4c4c49; font-size: 13px; }
.test-line-status .status-dot { flex: none; }
.test-line-status.ok .status-dot { background: #25834b; }
.test-line-status.warn .status-dot { background: #b27618; }
.test-line-status.warn { color: #7a5520; }

.test-line-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; margin: 16px 0 0; background: #d7d7d3; border: 1px solid #d7d7d3; border-radius: 6px; overflow: hidden; }
.test-line-summary div { display: grid; gap: 4px; min-width: 0; padding: 14px 16px; background: #fff; }
.test-line-summary dt { color: #70706d; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.test-line-summary dd { margin: 0; color: #171717; font-size: 15px; font-weight: 650; overflow-wrap: anywhere; }

.test-line-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 20px; margin-top: 20px; }
.test-line-column { display: grid; gap: 20px; min-width: 0; }
.tl-panel { min-width: 0; background: #fff; border: 1px solid #d3d3cf; border-radius: 6px; overflow: hidden; }
.tl-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; margin: 0; padding: 8px 16px; color: #666; background: #eeeeeb; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.tl-head h3 { font-size: inherit; font-weight: inherit; }
.tl-rows { margin: 0; }
.tl-rows > div { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 16px; padding: 10px 16px; border-top: 1px solid #e3e3df; font-size: 13px; line-height: 1.45; }
.tl-rows > div:first-child { border-top: 0; }
.tl-rows dt { color: #70706d; }
.tl-rows dd { min-width: 0; margin: 0; color: #171717; overflow-wrap: anywhere; }
.tl-rows code { font-size: 12px; }
.tl-hours > div { padding-block: 7px; font-variant-numeric: tabular-nums; }
.tl-hours > div.today { background: #f7f7f4; }
.tl-hours > div.today dt, .tl-hours > div.today dd { color: #171717; font-weight: 650; }
.tl-empty { padding: 12px 16px; color: #70706d; font-size: 13px; }

.knowledge-section { display: grid; gap: 8px; padding: 12px 16px 14px; border-top: 1px solid #e3e3df; }
.knowledge-section:first-child { border-top: 0; }
.knowledge-section h4 { margin: 0; color: #4c4c49; font-size: 12px; font-weight: 650; }
.knowledge-section pre, .test-line-prompt pre { margin: 0; color: #262624; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.tl-stock { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); column-gap: 24px; margin: 0; padding: 4px 16px 8px; list-style: none; }
.tl-stock li { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; min-width: 0; padding: 7px 0; border-bottom: 1px solid #efefeb; font-size: 13px; }
.tl-stock li span { white-space: nowrap; }
.tl-stock code { flex: none; color: #70706d; font-size: 11px; }

.test-line-prompt { margin-top: 20px; }
.tl-hint { padding: 12px 16px 0; color: #70706d; font-size: 13px; }
.test-line-prompt pre { max-height: 560px; overflow: auto; margin: 12px 16px 16px; padding: 14px 16px; background: #f7f7f4; border: 1px solid #e3e3df; border-radius: 4px; }

@media (max-width: 900px) {
  .test-line-grid { grid-template-columns: 1fr; }
  .test-line-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 590px) {
  .test-line-summary { grid-template-columns: 1fr; }
  .tl-rows > div { grid-template-columns: 1fr; gap: 2px; }
  .tl-hours > div { grid-template-columns: 110px minmax(0, 1fr); gap: 16px; }
  .test-line-prompt pre { margin: 12px; }
}
