/* ═══════════════════════════════════════════════════════════════════════════
   Wake Word Factory — Premium Dark UI
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ─── Design Tokens ──────────────────────────────────────────────────────── */
:root {
  --bg-base: #07070d;
  --bg-surface: #0d0d15;
  --bg-card: rgba(255, 255, 255, 0.03);
  --bg-card-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(0, 212, 255, 0.3);
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --text-muted: #5f6368;
  --cyan: #00d4ff;
  --purple: #7b2ff7;
  --green: #34d399;
  --orange: #ff6b35;
  --red: #ef4444;
  --gradient: linear-gradient(135deg, #00d4ff, #7b2ff7);
  --gradient-subtle: linear-gradient(135deg, rgba(0,212,255,0.1), rgba(123,47,247,0.1));
  --glow-cyan: 0 0 40px rgba(0, 212, 255, 0.15);
  --glow-purple: 0 0 40px rgba(123, 47, 247, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Background Effect ──────────────────────────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(0, 212, 255, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(123, 47, 247, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse at 50% 80%, rgba(255, 107, 53, 0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  position: relative;
  z-index: 1;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.app-header {
  text-align: center;
  margin-bottom: 3rem;
}

.app-header .logo {
  font-size: 2.5rem;
  font-weight: 800;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.app-header .subtitle {
  color: var(--text-secondary);
  font-size: 1rem;
  font-weight: 400;
}

.gpu-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.4rem 1rem;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 100px;
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 500;
}

.gpu-badge.offline {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--red);
}

/* ─── Stepper ────────────────────────────────────────────────────────────── */
.stepper {
  display: flex;
  justify-content: center;
  gap: 0;
  margin-bottom: 2.5rem;
  position: relative;
}

.stepper::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 15%;
  right: 15%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  position: relative;
  z-index: 1;
  padding: 0 1.5rem;
  transition: all 0.3s ease;
}

.step-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.3s ease;
}

.step-item.active .step-circle {
  background: var(--gradient);
  border-color: transparent;
  color: white;
  box-shadow: var(--glow-cyan);
}

.step-item.completed .step-circle {
  background: var(--green);
  border-color: transparent;
  color: white;
}

.step-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: color 0.3s ease;
  white-space: nowrap;
}

.step-item.active .step-label { color: var(--cyan); }
.step-item.completed .step-label { color: var(--green); }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.card:hover { border-color: var(--border-active); }

.card-title {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.card-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

/* ─── Step Panels ────────────────────────────────────────────────────────── */
.step-panel { display: none; animation: fadeIn 0.4s ease; }
.step-panel.active { display: block; }

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

/* ─── Inputs ─────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  width: 100%;
  padding: 0.8rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 1rem;
  transition: all 0.3s ease;
  outline: none;
}

.form-input:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.form-input::placeholder { color: var(--text-muted); }

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  outline: none;
  text-decoration: none;
}

.btn-primary {
  background: var(--gradient);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 212, 255, 0.2);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 212, 255, 0.3);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--red);
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-success {
  background: rgba(52, 211, 153, 0.15);
  border: 1px solid rgba(52, 211, 153, 0.3);
  color: var(--green);
}
.btn-success:hover { background: rgba(52, 211, 153, 0.25); }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
}

.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; }
.btn-lg { padding: 1rem 2rem; font-size: 1rem; }

/* ─── TTS Toggle Switch ─────────────────────────────────────────────────── */
.tts-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.tts-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: opacity 0.3s ease;
  user-select: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gradient);
  border-radius: 24px;
  transition: all 0.3s ease;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s ease;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
  background: var(--text-secondary);
}

/* ─── Navigation Buttons ─────────────────────────────────────────────────── */
.step-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

/* ─── Audio Recorder ─────────────────────────────────────────────────────── */
.recorder-container {
  text-align: center;
  padding: 2rem 0;
}

.record-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--gradient);
  border: 4px solid rgba(255,255,255,0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  transition: all 0.3s ease;
  position: relative;
  font-size: 2rem;
  color: white;
}

.record-btn:hover {
  transform: scale(1.05);
  box-shadow: var(--glow-cyan);
}

.record-btn.recording {
  animation: recordPulse 1.5s ease-in-out infinite;
  background: linear-gradient(135deg, var(--red), var(--orange));
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
}

.record-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.record-status.recording { color: var(--red); font-weight: 600; }

/* Waveform */
.waveform-container {
  width: 100%;
  height: 80px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.waveform-canvas {
  width: 100%;
  height: 100%;
}

/* Clips List */
.clips-list {
  margin-top: 1.5rem;
}

.clip-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 0.5rem;
  transition: all 0.2s ease;
}

.clip-item:hover { border-color: var(--border-active); }

.clip-name {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-family: var(--mono);
}

.clip-actions { display: flex; gap: 0.5rem; }

/* ─── Presets ────────────────────────────────────────────────────────────── */
.presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.preset-card {
  padding: 1.2rem;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: center;
  transition: all 0.3s ease;
}

.preset-card:hover { border-color: var(--border-active); }

.preset-card.selected {
  border-color: var(--cyan);
  background: var(--gradient-subtle);
}

.preset-icon { font-size: 1.5rem; margin-bottom: 0.5rem; }
.preset-name { font-weight: 600; font-size: 0.9rem; }
.preset-desc { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }
.preset-time { font-size: 0.7rem; color: var(--cyan); margin-top: 0.5rem; font-weight: 500; }

/* ─── Progress ───────────────────────────────────────────────────────────── */
.progress-section { margin-top: 1.5rem; }

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 100px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-bar {
  height: 100%;
  background: var(--gradient);
  border-radius: 100px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-steps {
  display: flex;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.progress-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.progress-step.active { color: var(--cyan); }
.progress-step.done { color: var(--green); }

.progress-step .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.progress-step.active .dot {
  background: var(--cyan);
  animation: dotPulse 1s ease infinite;
}
.progress-step.done .dot { background: var(--green); }

@keyframes dotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.5); }
}

/* Log Output */
.log-output {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.8;
  color: var(--text-secondary);
}

.log-output::-webkit-scrollbar { width: 6px; }
.log-output::-webkit-scrollbar-track { background: transparent; }
.log-output::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
}

.log-line { padding: 1px 0; }
.log-line.step { color: var(--cyan); font-weight: 500; }
.log-line.metric { color: var(--green); }
.log-line.warning { color: var(--orange); }
.log-line.error { color: var(--red); font-weight: 600; }
.log-line.complete { color: var(--green); font-weight: 600; }

/* ─── Models List ────────────────────────────────────────────────────────── */
.models-section {
  margin-top: 3rem;
}

.models-section h2 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.model-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  transition: all 0.3s ease;
}

.model-card:hover { border-color: var(--border-active); }

.model-info { flex: 1; }

.model-name {
  font-weight: 600;
  font-size: 1rem;
  font-family: var(--mono);
}

.model-phrase {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.model-status {
  display: inline-flex;
  padding: 0.2rem 0.6rem;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-ready {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
}
.status-training {
  background: rgba(0, 212, 255, 0.15);
  color: var(--cyan);
}
.status-created {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}
.status-error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}
.status-deployed {
  background: rgba(123, 47, 247, 0.15);
  color: var(--purple);
  border: 1px solid rgba(123, 47, 247, 0.3);
}

.model-actions {
  display: flex;
  gap: 0.5rem;
}

/* ─── Dataset Setup ──────────────────────────────────────────────────────── */
.dataset-status {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
  margin: 1rem 0;
}

.dataset-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
}

.dataset-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dataset-dot.ready { background: var(--green); }
.dataset-dot.missing { background: var(--red); }
.dataset-dot.downloading {
  background: var(--cyan);
  animation: dotPulse 1s ease infinite;
}

/* ─── Alert Banner ───────────────────────────────────────────────────────── */
.alert {
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.alert-info {
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.2);
  color: var(--cyan);
}

.alert-warning {
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.2);
  color: var(--orange);
}

.alert-success {
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.2);
  color: var(--green);
}

/* ─── Deploy Section ─────────────────────────────────────────────────────── */
.deploy-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.deploy-card {
  padding: 2rem;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  text-align: center;
  transition: all 0.3s ease;
}

.deploy-card:hover { border-color: var(--border-active); }

.deploy-icon { font-size: 2.5rem; margin-bottom: 1rem; }
.deploy-title { font-weight: 600; font-size: 1.1rem; margin-bottom: 0.5rem; }
.deploy-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }

/* ─── Toast ──────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toast {
  padding: 0.8rem 1.2rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  animation: toastIn 0.3s ease;
  max-width: 350px;
  backdrop-filter: blur(20px);
}

.toast.success { border-color: rgba(52, 211, 153, 0.3); }
.toast.error { border-color: rgba(239, 68, 68, 0.3); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ─── Loading Spinner ────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-container { padding: 1rem; }
  .app-header .logo { font-size: 1.8rem; }
  .stepper { flex-wrap: wrap; gap: 0.5rem; }
  .stepper::before { display: none; }
  .form-row { grid-template-columns: 1fr; }
  .presets { grid-template-columns: 1fr; }
  .deploy-options { grid-template-columns: 1fr; }
  .step-item { padding: 0 0.75rem; }
  .progress-steps { flex-wrap: wrap; gap: 0.5rem; }
}
