/* ═══════════════════════════════════════════════════════════════════
   ESP-AI Voice Test — Styles
   Responsive layout with collapsible config panel
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #16161e;
  --bg-card: #1e1e2a;
  --bg-input: #252534;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.3);
  --success: #2ecc71;
  --danger: #e74c3c;
  --warning: #f39c12;
  --border: #2a2a3e;
  --radius: 10px;
  --font: 'Inter', -apple-system, sans-serif;
  --sidebar-width: 320px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ─── Layout ──────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  height: 100dvh;
  position: relative;
}

/* ─── Config Toggle Button ────────────────────── */

.config-toggle {
  display: none; /* Hidden on desktop */
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 100;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.config-toggle svg {
  width: 20px;
  height: 20px;
}

.config-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.config-toggle.active {
  background: var(--accent);
  color: white;
}

/* ─── Config Panel ────────────────────────────── */

.config-panel {
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  transition: transform 0.3s ease, opacity 0.3s ease;
  will-change: transform;
}

.config-panel h2 {
  font-size: 18px;
  font-weight: 600;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.field input,
.field select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  width: 100%;
  min-width: 0;
}

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.btn {
  padding: 10px 20px;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  filter: brightness(1.15);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.child-info {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
}

.child-name {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 8px;
}

.child-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  word-break: break-word;
}

.status-bar {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-secondary);
  padding: 10px;
  background: var(--bg-card);
  border-radius: var(--radius);
  text-align: center;
}

.status-bar.error { color: var(--danger); }
.status-bar.success { color: var(--success); }

.hidden { display: none !important; }

/* ─── Chat Area ───────────────────────────────── */

.chat-area {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.chat-header h1 {
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.connection-badge {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.connection-badge.connected {
  background: rgba(46, 204, 113, 0.15);
  color: var(--success);
}

.connection-badge.connecting {
  background: rgba(243, 156, 18, 0.15);
  color: var(--warning);
}

/* ─── Transcript ──────────────────────────────── */

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.transcript-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  text-align: center;
  font-size: 14px;
  padding: 20px;
}

.msg {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  animation: fadeIn 0.3s ease;
  word-break: break-word;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--bg-card);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  font-style: italic;
  max-width: 90%;
}

.msg .timestamp {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

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

/* ─── Controls ────────────────────────────────── */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.mic-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mic-btn:hover:not(:disabled) {
  background: var(--accent);
  color: white;
  box-shadow: 0 0 20px var(--accent-glow);
}

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

.mic-btn.active {
  background: var(--danger);
  color: white;
  animation: pulse 1.5s infinite;
}

.mic-btn svg {
  width: 28px;
  height: 28px;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
  50%     { box-shadow: 0 0 0 12px rgba(231, 76, 60, 0); }
}

.visualizer-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px;
  min-width: 0;
  flex: 0 1 300px;
}

.visualizer-container canvas {
  display: block;
  width: 100%;
  height: 60px;
  border-radius: calc(var(--radius) - 4px);
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.volume-control input[type="range"] {
  width: 80px;
  accent-color: var(--accent);
}

/* ═══════════════════════════════════════════════════════════════════
   Responsive Breakpoints
   ═══════════════════════════════════════════════════════════════════ */

/* ─── Tablet (≤ 900px) — Narrower sidebar ─────── */

@media (max-width: 900px) {
  :root {
    --sidebar-width: 280px;
  }
}

/* ─── Mobile (≤ 768px) — Full overlay panel ───── */

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }

  .config-toggle {
    display: flex;
  }

  .config-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    height: 100dvh;
    z-index: 90;
    border-right: 1px solid var(--border);
    transform: translateX(0);
    padding-top: 64px; /* Space for toggle button */
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }

  .config-panel.collapsed {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
  }

  .chat-header {
    padding: 16px 16px 16px 64px; /* Space for toggle button */
  }

  .chat-header h1 {
    font-size: 16px;
  }

  .transcript {
    padding: 16px;
  }

  .msg {
    max-width: 85%;
  }

  .controls {
    padding: 16px;
    gap: 16px;
  }

  .visualizer-container {
    flex: 0 1 200px;
  }
}

/* ─── Small Mobile (≤ 480px) — Stack controls ─── */

@media (max-width: 480px) {
  .chat-header h1 {
    font-size: 14px;
  }

  .controls {
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .controls > * {
    order: 0;
  }

  .mic-btn {
    order: -1; /* Mic button first */
    width: 72px;
    height: 72px;
  }

  .mic-btn svg {
    width: 32px;
    height: 32px;
  }

  .visualizer-container {
    flex: 1 1 100%;
    width: 100%;
  }

  .volume-control input[type="range"] {
    width: 120px;
  }

  .msg {
    max-width: 90%;
    font-size: 13px;
  }

  .transcript {
    padding: 12px;
    gap: 8px;
  }
}

/* ─── Landscape Mobile ────────────────────────── */

@media (max-height: 500px) and (orientation: landscape) {
  .controls {
    padding: 8px 16px;
    gap: 12px;
  }

  .mic-btn {
    width: 48px;
    height: 48px;
  }

  .mic-btn svg {
    width: 22px;
    height: 22px;
  }

  .visualizer-container canvas {
    height: 40px;
  }

  .chat-header {
    padding: 8px 16px;
  }

  .chat-header h1 {
    font-size: 14px;
  }
}
