* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  max-width: 920px;
  margin: 2rem auto;
  padding: 0 1.25rem 4rem;
  color: #1f2328;
  background: #fafbfc;
}

header h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
.config { color: #57606a; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85rem; margin: 0 0 1.25rem; }
.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}
.file-btn:hover { background: #f6f8fa; }

.mic-banner {
  background: #fff8c5;
  border: 1px solid #d4a72c;
  border-radius: 6px;
  color: #4d2d00;
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0 0 1rem;
  padding: 0.65rem 0.85rem;
}

.tabs {
  display: flex;
  gap: .25rem;
  border-bottom: 1px solid #d0d7de;
  margin-bottom: 1.25rem;
}
.tab {
  background: none; border: none;
  padding: .55rem 1rem; cursor: pointer;
  font-size: 0.95rem; color: #57606a;
  border-bottom: 2px solid transparent;
}
.tab:hover { color: #1f2328; }
.tab.active { color: #1f2328; border-bottom-color: #0969da; font-weight: 600; }

.panel { display: none; }
.panel.active { display: block; }
.panel h2 { margin-top: 0; font-size: 1.15rem; }
.hint { color: #57606a; font-size: 0.9rem; margin: 0 0 1rem; }

.row {
  display: flex; gap: 1rem;
  align-items: center; flex-wrap: wrap;
  margin: .75rem 0;
}
.row label {
  display: flex; flex-direction: column;
  font-size: 0.8rem; color: #57606a;
  gap: .25rem;
}
.row label > * { font-size: 0.95rem; }

button {
  padding: .5rem 1.1rem;
  border: 1px solid #d0d7de;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
  font-family: inherit;
}
button:hover:not(:disabled) { background: #f6f8fa; }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary {
  background: #0969da; color: white;
  border-color: #0969da;
}
button.primary:hover:not(:disabled) { background: #0860c4; }

textarea, input[type="number"], select {
  padding: .45rem .55rem;
  border: 1px solid #d0d7de;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
  background: white;
}
textarea { width: 100%; resize: vertical; }
input[type="number"] { width: 6rem; }

pre {
  background: #f6f8fa;
  padding: 1rem;
  border-radius: 6px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 420px;
  overflow: auto;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
  line-height: 1.45;
}

audio { display: block; width: 100%; margin: .75rem 0; }

.meter {
  height: 8px;
  background: #eaeef2;
  border-radius: 4px;
  margin: .5rem 0 1rem;
  overflow: hidden;
}
.meter > div {
  height: 100%;
  background: linear-gradient(90deg, #0969da, #1f883d);
  width: 0;
  transition: width 80ms linear;
}

.status {
  color: #57606a;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
}

/* Conversation tab */
.status {
  padding: .15rem .55rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
.status::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px; border-radius: 50%;
  background: #888;
}
.state-idle::before     { background: #888; }
.state-listening::before { background: #0969da; animation: pulse 1.4s infinite ease-in-out; }
.state-speaking::before  { background: #1f883d; animation: pulse 0.6s infinite ease-in-out; }
.state-processing::before{ background: #bf8700; animation: pulse 0.9s infinite ease-in-out; }
.state-playing::before   { background: #8250df; animation: pulse 1.1s infinite ease-in-out; }
.state-error::before     { background: #cf222e; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

.meter { position: relative; }
.threshold-marker {
  position: absolute; top: -2px; bottom: -2px;
  width: 2px; background: #cf222e;
  left: 4%;  /* updated by JS */
  pointer-events: none;
}

.conv-log {
  background: #f6f8fa;
  border-radius: 6px;
  padding: .75rem 1rem;
  max-height: 420px;
  overflow: auto;
  margin-top: 1rem;
  font-size: 0.95rem;
}
.conv-log:empty::before {
  content: "Conversation will appear here…";
  color: #8c959f;
  font-style: italic;
}
.conv-turn {
  margin: .35rem 0;
  padding: .5rem .75rem;
  border-radius: 8px;
  max-width: 88%;
  line-height: 1.4;
}
.conv-turn.user {
  background: #ddf4ff;
  border: 1px solid #b6e3ff;
  margin-left: auto;
  text-align: right;
}
.conv-turn.bot {
  background: white;
  border: 1px solid #d0d7de;
}
.conv-turn.system {
  background: transparent;
  color: #8c959f;
  font-size: 0.8rem;
  font-style: italic;
  border: none;
  text-align: center;
  max-width: 100%;
}
/* Phase 1.5 — filler turns (perceived-latency cover audio that played
   in front of the LLM substance). Distinct yellow-tinted background +
   italic so the tester can immediately tell it from real bot speech. */
.conv-turn.filler {
  background: #fff8d6;
  border: 1px dashed #d4a72c;
  color: #57606a;
  font-style: italic;
}
.conv-turn.filler .role { color: #8a6d3b; }
.conv-turn.filler .role::after {
  content: "  (filler — played while LLM was composing)";
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  color: #b08d3a;
  font-size: 0.7rem;
}
/* Phase 2 — intent-cache hit: a fully-cached response served from disk,
   skipping STT+LLM+TTS. Green tint so successful cache hits visibly
   distinguish from a normal LLM turn. */
.conv-turn.intent-cache {
  background: #e7f4dd;
  border: 1px solid #76b86a;
}
.conv-turn.intent-cache .role::after {
  content: "  (cached intent — served from disk)";
  font-style: normal;
  text-transform: none;
  letter-spacing: 0;
  color: #4a7a3f;
  font-size: 0.7rem;
}
.conv-turn .role {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #57606a;
  margin-bottom: .15rem;
  display: flex;
  gap: .65rem;
  align-items: baseline;
  flex-wrap: wrap;
}
.conv-turn .role .ts {
  text-transform: none;
  letter-spacing: 0;
  color: #8c959f;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.conv-turn .role .turn-meta {
  text-transform: none;
  letter-spacing: 0;
  color: #8c959f;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.7rem;
}
.conv-turn.user .role { justify-content: flex-end; }
.conv-turn .turn-audio {
  width: 100%;
  margin-top: .4rem;
  height: 32px;
}

/* Voices tab */
.voices-list { display: flex; flex-direction: column; gap: .65rem; margin-bottom: 1.5rem; }
.voice-bucket {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  padding: .6rem .8rem;
  background: white;
}
.voice-bucket header {
  display: flex; gap: .5rem; align-items: baseline;
  margin-bottom: .35rem;
}
.voice-bucket header h4 { margin: 0; font-size: 0.95rem; }
.voice-bucket header .count { color: #57606a; font-size: 0.8rem; }
.voice-sample {
  display: flex; gap: .75rem; align-items: center;
  padding: .25rem 0;
  border-top: 1px solid #f0f2f5;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
}
.voice-sample:first-of-type { border-top: none; }
.voice-sample .name { flex: 1; }
.voice-sample .meta { color: #57606a; font-size: 0.8rem; }
.voice-sample button {
  padding: .15rem .55rem;
  font-size: 0.8rem;
}
.voice-sample button.danger {
  color: #cf222e;
  border-color: #ffd1d1;
}
.voice-sample button.danger:hover:not(:disabled) {
  background: #ffeaea;
}

.upload-result {
  margin: 1rem 0;
  padding: .65rem .85rem;
  border-radius: 6px;
  font-size: 0.9rem;
}
.upload-result:empty { display: none; }
.upload-result.success { background: #dafbe1; border: 1px solid #aceebb; }
.upload-result.error   { background: #ffebe9; border: 1px solid #ffcecb; color: #82071e; }
.upload-result code {
  background: #f6f8fa;
  padding: .1rem .35rem;
  border-radius: 4px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}

.panel h3 { margin-top: 1.5rem; font-size: 1rem; }
.panel h4 { margin-top: 1rem; margin-bottom: .35rem; font-size: 0.9rem; color: #57606a; }

/* ── AutoVYN Data panel ─────────────────────────────────────────────────── */
.av-toolbar { display: flex; align-items: center; gap: .75rem; margin: .5rem 0 1rem; }
.av-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.av-table th, .av-table td { padding: .35rem .4rem; border-bottom: 1px solid #2a2a3a; text-align: left; }
.av-table th { color: #9aa; font-weight: 600; }
.av-table td input { width: 100%; box-sizing: border-box; background: #16161f; border: 1px solid #2a2a3a; color: #e8e8f0; border-radius: 4px; padding: .25rem .35rem; font-size: .82rem; }
.av-table td.av-id { color: #7a7a8a; font-family: monospace; white-space: nowrap; }
.av-row-actions { display: flex; gap: .3rem; white-space: nowrap; }
.av-row-actions button { padding: .2rem .5rem; font-size: .78rem; }
.av-save { background: #2d6a4f; }
.av-del { background: #6a2d2d; }
.av-dirty td input { border-color: #c9a227; }
.av-add { margin-top: .6rem; }
.av-form { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.av-form input { background: #16161f; border: 1px solid #2a2a3a; color: #e8e8f0; border-radius: 4px; padding: .3rem .4rem; font-size: .82rem; }
