/* Hearing Demo — Clinical UI */

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --primary: #0077b6;
  --primary-hover: #005f8a;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --success: #059669;
  --success-hover: #047857;
  --warning: #d97706;
  --danger: #dc2626;
  --dark: #0f172a;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Header ---- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--dark);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.header-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: -0.01em;
}

.header-hint {
  font-size: 11px;
  color: #64748b;
  letter-spacing: 0.02em;
}

/* ---- Setup Panel ---- */

.setup-panel {
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.setup-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.setup-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.setup-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  min-width: 48px;
}

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-outline {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
}

.btn-outline:hover {
  background: rgba(0, 119, 182, 0.06);
}

.btn-play {
  background: var(--success);
  color: #fff;
}

.btn-play:hover:not(:disabled) {
  background: var(--success-hover);
}

.btn-stop {
  background: #475569;
  color: #fff;
}

.btn-stop:hover:not(:disabled) {
  background: #334155;
}

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

.btn-mic-hero {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  border: 2px solid #10b981;
  border-radius: 8px;
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-mic-hero:hover {
  background: rgba(16, 185, 129, 0.25);
  border-color: #34d399;
  color: #34d399;
}

.btn-mic-hero.active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

/* ---- Mic Controls ---- */

.mic-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mic-select {
  padding: 6px 10px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  background: rgba(255,255,255,0.08);
  color: #cbd5e1;
  font-size: 12px;
  font-family: inherit;
  max-width: 200px;
  cursor: pointer;
  transition: all 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2394a3b8'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.mic-select:hover:not(:disabled) {
  border-color: rgba(255,255,255,0.3);
  background-color: rgba(255,255,255,0.12);
}

.mic-select:focus {
  outline: none;
  border-color: #10b981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

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

.mic-select option {
  background: #1e293b;
  color: #cbd5e1;
}

.file-name {
  font-size: 13px;
  color: var(--text-muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Speech Banana Toggle ---- */

.speech-banana-toggle {
  margin-left: auto;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.toggle-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
  cursor: pointer;
}

/* ---- Preset Buttons ---- */

.preset-bar {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.btn-preset {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preset:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-preset.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ---- Custom Audiogram Entry ---- */

.audiogram-entry {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.audiogram-entry.hidden {
  display: none;
}

.threshold-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.freq-input {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.freq-input label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
}

.freq-input input {
  width: 68px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

.freq-input input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 119, 182, 0.15);
}

/* ---- Mode Toggle ---- */

.mode-section {
  padding: 12px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  text-align: center;
  flex-shrink: 0;
}

.mode-toggle {
  display: inline-flex;
  background: #cbd5e1;
  border-radius: 10px;
  padding: 3px;
}

.mode-btn {
  padding: 10px 32px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  background: transparent;
  color: #64748b;
  min-width: 160px;
}

.mode-btn:hover:not(.active) {
  color: #334155;
  background: rgba(255,255,255,0.5);
}

.mode-full.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 119, 182, 0.35);
}

.mode-filtered.active {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.35);
}

.preset-description {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 6px;
  min-height: 20px;
  transition: color 0.2s;
}

.preset-description.hint {
  color: var(--warning);
  font-weight: 500;
}

/* ---- Main Display / Spectrogram ---- */

.main-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 180px;
  background: #0a0a12;
}

.canvas-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#spectrogram, #overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

#spectrogram { z-index: 1; }
#overlay { z-index: 2; pointer-events: none; }

/* ---- Drop Zone ---- */

.drop-zone {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 10, 18, 0.92);
  cursor: pointer;
  transition: background 0.2s;
}

.drop-zone.hidden {
  display: none;
}

.drop-zone.drag-over {
  background: rgba(0, 119, 182, 0.2);
}

.drop-content {
  text-align: center;
  color: #94a3b8;
}

.drop-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.drop-content p {
  font-size: 16px;
  font-weight: 500;
  color: #cbd5e1;
  margin-bottom: 4px;
}

.drop-content span {
  font-size: 13px;
}

/* ---- Level Meter ---- */

.level-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 20px;
  background: var(--dark);
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.meter-label {
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.meter-track {
  flex: 1;
  max-width: 200px;
  height: 6px;
  background: #1e293b;
  border-radius: 3px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  width: 0%;
  background: #10b981;
  border-radius: 3px;
  transition: width 0.08s linear;
}

.meter-fill.warning { background: var(--warning); }
.meter-fill.danger { background: var(--danger); }

.meter-value {
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: right;
}

.meter-warning {
  font-size: 14px;
  color: var(--danger);
}

.meter-warning.hidden { display: none; }

.safety-label {
  font-size: 10px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 8px;
}

.safety-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #1e293b;
  border-radius: 2px;
  outline: none;
}

.safety-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: var(--warning);
  border-radius: 50%;
  cursor: pointer;
}

.safety-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: var(--warning);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.threshold-value {
  font-size: 10px;
  color: var(--warning);
  font-weight: 500;
  min-width: 55px;
  font-variant-numeric: tabular-nums;
}

/* ---- Band Controls ---- */

.band-section {
  padding: 10px 20px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.bands-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.band-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
  min-width: 0;
}

.band-freq {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.band-atten {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.band-atten.has-loss {
  color: var(--danger);
}

/* Toggle switch */

.toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 18px;
  transition: background 0.2s;
}

.toggle-track::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-track {
  background: var(--primary);
}

.toggle input:checked + .toggle-track::before {
  transform: translateX(14px);
}

/* ---- Volume ---- */

.volume-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.volume-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.volume-slider {
  flex: 1;
  max-width: 180px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: #cbd5e1;
  border-radius: 2px;
  outline: none;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
}

.volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

.volume-value {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
  .header { padding: 8px 14px; }
  .header-hint { display: none; }
  .btn-mic-hero { padding: 8px 16px; font-size: 14px; }
  .mic-controls { flex-wrap: wrap; }
  .mic-select { max-width: 160px; font-size: 11px; }
  .setup-panel { padding: 10px 14px; gap: 8px; }
  .setup-row { gap: 8px; }

  .mode-btn {
    padding: 8px 16px;
    font-size: 13px;
    min-width: 120px;
  }

  .bands-row { flex-wrap: wrap; }
  .band-card { flex: 0 0 calc(25% - 6px); }

  .threshold-row { gap: 4px; }
  .freq-input input { width: 56px; }

  .level-meter { flex-wrap: wrap; padding: 6px 14px; }
  .safety-label { margin-left: 0; }
}

@media (max-width: 480px) {
  .band-card { flex: 0 0 calc(33.33% - 6px); }
  .preset-bar { gap: 3px; }
  .btn-preset { padding: 4px 8px; font-size: 11px; }
}

/* ---- Utility ---- */

.hidden {
  display: none !important;
}
