/* ============================================================
   MedScribe — Professional Medical Transcription UI
   ============================================================ */

/* ---------- Google Font ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ---------- Design Tokens ---------- */
:root {
  --bg: #070d18;
  --bg-gradient: linear-gradient(145deg, #070d18 0%, #0c1628 40%, #0a1222 100%);
  --surface: rgba(14, 22, 40, 0.92);
  --surface-2: rgba(20, 30, 54, 0.85);
  --surface-3: rgba(26, 38, 66, 0.7);
  --border: rgba(55, 80, 130, 0.35);
  --border-hover: rgba(55, 80, 130, 0.55);
  --text: #e8edf7;
  --text-secondary: #8fa3c4;
  --text-muted: #5b7099;

  --accent: #00d9a6;
  --accent-dim: rgba(0, 217, 166, 0.12);
  --accent-glow: rgba(0, 217, 166, 0.25);
  --accent-gradient: linear-gradient(135deg, #00d9a6 0%, #00b8d4 100%);

  --danger: #ff6b7a;
  --warn: #ffb74d;
  --ok: #66e0a8;

  --sidebar-w: 340px;
  --topbar-h: 60px;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --transition: 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 20px rgba(0, 217, 166, 0.15);

  --btn-generate-text: #070d18;
  --topbar-bg: rgba(7, 13, 24, 0.85);
  --sidebar-bg: rgba(10, 16, 30, 0.95);
  --input-bg: rgba(7, 13, 24, 0.8);
  --modal-bg: rgba(14, 22, 40, 0.98);
  --waveform-bg: rgba(7, 13, 24, 0.6);
  --log-bg: rgba(7, 13, 24, 0.9);
}

/* ---------- Light Mode ---------- */
[data-theme="light"] {
  --bg: #f0f2f5;
  --bg-gradient: linear-gradient(145deg, #f0f2f5 0%, #e8ecf1 40%, #f4f6f9 100%);
  --surface: rgba(255, 255, 255, 0.92);
  --surface-2: rgba(240, 243, 248, 0.9);
  --surface-3: rgba(230, 234, 242, 0.8);
  --border: rgba(180, 195, 220, 0.45);
  --border-hover: rgba(150, 170, 200, 0.6);
  --text: #1a2332;
  --text-secondary: #4a5b73;
  --text-muted: #7a8da6;

  --accent: #00b88d;
  --accent-dim: rgba(0, 184, 141, 0.1);
  --accent-glow: rgba(0, 184, 141, 0.2);
  --accent-gradient: linear-gradient(135deg, #00b88d 0%, #0097a7 100%);

  --danger: #e53e4f;
  --warn: #e09520;
  --ok: #1ba85c;

  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 16px rgba(0, 184, 141, 0.12);

  --btn-generate-text: #ffffff;
  --topbar-bg: rgba(255, 255, 255, 0.88);
  --sidebar-bg: rgba(248, 250, 253, 0.97);
  --input-bg: rgba(240, 243, 248, 0.9);
  --modal-bg: rgba(255, 255, 255, 0.98);
  --waveform-bg: rgba(235, 240, 248, 0.7);
  --log-bg: rgba(240, 243, 248, 0.95);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: var(--bg-gradient);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  padding: 0 20px;
  background: var(--topbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  gap: 16px;
}

/* Burger button */
.burger {
  width: 40px;
  height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  padding: 8px;
  transition: var(--transition);
  flex-shrink: 0;
}
.burger:hover {
  background: var(--surface-2);
  border-color: var(--border);
}
.burger span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: var(--transition);
  transform-origin: center;
}
.burger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.burger.active span:nth-child(2) { opacity: 0; }
.burger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

/* Logo & title */
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.topbar-brand img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}
.topbar-brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-spacer { flex: 1; }

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: var(--transition);
  white-space: nowrap;
}
.status-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: var(--transition);
}
.status-badge.ready { color: var(--ok); border-color: rgba(102, 224, 168, 0.35); }
.status-badge.ready .dot { background: var(--ok); animation: pulse-dot 2s ease-in-out infinite; }
.status-badge.loading { color: var(--warn); border-color: rgba(255, 183, 77, 0.35); }
.status-badge.loading .dot { background: var(--warn); animation: pulse-dot 1s ease-in-out infinite; }
.status-badge.error { color: var(--danger); border-color: rgba(255, 107, 122, 0.35); }
.status-badge.error .dot { background: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
}
.sidebar-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--border);
  z-index: 200;
  transform: translateX(-100%);
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar.open {
  transform: translateX(0);
}

.sidebar-section {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-section:last-child { border-bottom: none; }

.sidebar-heading {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 14px;
}

/* ---------- Download / Model Progress ---------- */
.progress-container {
  margin-top: 14px;
  display: none;
}
.progress-container.visible { display: block; }

.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent-gradient);
  border-radius: 3px;
  transition: width 0.4s ease;
  position: relative;
}
.progress-bar-fill.indeterminate {
  width: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-label {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ---------- Sidebar Inputs ---------- */
.sidebar label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 12px 0 6px;
}
.sidebar label:first-child { margin-top: 0; }

.sidebar input[type="url"],
.sidebar input[type="number"],
.sidebar input[type="file"],
.sidebar select,
.sidebar textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  transition: border-color var(--transition);
  outline: none;
}
.sidebar input:focus,
.sidebar select:focus,
.sidebar textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.sidebar textarea { resize: vertical; line-height: 1.5; }
.sidebar select { cursor: pointer; }

.sidebar .row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.sidebar .help-text {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* Sidebar buttons */
.sidebar .btn-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- Runtime Log (in sidebar) ---------- */
.log-container { flex: 1; min-height: 0; }
.log-container details { cursor: pointer; }
.log-container summary {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.log-container summary::before {
  content: '▸';
  transition: var(--transition);
  display: inline-block;
}
.log-container details[open] summary::before { transform: rotate(90deg); }

.runtime-log {
  margin-top: 8px;
  padding: 10px;
  background: var(--log-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.72rem;
  color: var(--text-muted);
  max-height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-top: var(--topbar-h);
  padding: 32px 24px 60px;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  transition: var(--transition);
}

/* ---------- Welcome / Status Hero ---------- */
.welcome-card {
  text-align: center;
  padding: 28px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.welcome-card .icon { font-size: 2.4rem; margin-bottom: 10px; }
.welcome-card h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 6px;
}
.welcome-card p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.5;
  max-width: 480px;
  margin: 0 auto;
}
.welcome-card.ready { border-color: rgba(0, 217, 166, 0.3); }
.welcome-card.ready h2 { color: var(--ok); }

/* ---------- Recording Section ---------- */
.recording-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
}
.recording-section.active {
  border-color: rgba(255, 107, 122, 0.4);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(255, 107, 122, 0.08);
}
.recording-section.paused {
  border-color: rgba(255, 183, 77, 0.4);
}

.section-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* Waveform canvas */
.waveform-wrapper {
  position: relative;
  width: 100%;
  height: 96px;
  background: var(--waveform-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 16px;
}
.waveform-wrapper canvas {
  width: 100%;
  height: 100%;
  display: block;
}
.waveform-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  pointer-events: none;
  transition: opacity var(--transition);
}
.waveform-placeholder.hidden { opacity: 0; }

/* Recording timer */
.recording-timer {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  margin-bottom: 16px;
  transition: color var(--transition);
  display: none;
}
.recording-timer.visible { display: block; }
.recording-timer.active { color: var(--danger); }
.recording-timer.paused { color: var(--warn); }

/* Controls row */
.controls-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Audio playback section */
.audio-playback {
  margin-top: 16px;
  display: none;
}
.audio-playback.visible { display: block; }
.audio-playback audio { width: 100%; border-radius: var(--radius-sm); }
.audio-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.audio-meta span { font-weight: 600; color: var(--text-secondary); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}
.btn:hover {
  background: var(--surface-3);
  border-color: var(--border-hover);
  transform: translateY(-1px);
}
.btn:active { transform: translateY(0); }
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--accent-gradient);
  border-color: transparent;
  color: var(--btn-generate-text);
  font-weight: 700;
}
.btn-primary:hover {
  box-shadow: var(--shadow-glow);
  border-color: transparent;
  background: var(--accent-gradient);
  filter: brightness(1.1);
}
.btn-primary:disabled {
  filter: none;
  box-shadow: none;
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(255, 107, 122, 0.3);
}
.btn-danger:hover {
  background: rgba(255, 107, 122, 0.1);
  border-color: rgba(255, 107, 122, 0.5);
}

.btn-record {
  width: 56px;
  height: 56px;
  padding: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff4d5e 0%, #e63946 100%);
  border: 3px solid rgba(255, 77, 94, 0.3);
  color: white;
  font-size: 1.3rem;
  position: relative;
}
.btn-record:hover {
  box-shadow: 0 0 24px rgba(255, 77, 94, 0.35);
  border-color: rgba(255, 77, 94, 0.6);
  transform: scale(1.05);
}
.btn-record:disabled {
  transform: none;
  box-shadow: none;
}
.btn-record.recording {
  animation: record-pulse 1.5s ease-in-out infinite;
}

@keyframes record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 77, 94, 0.4); }
  50% { box-shadow: 0 0 0 14px rgba(255, 77, 94, 0); }
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  font-size: 1.1rem;
}

/* Small text buttons in sidebar */
.btn-sm {
  padding: 8px 14px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* ---------- Generate Button ---------- */
.generate-section {
  text-align: center;
}

.btn-generate {
  padding: 16px 36px;
  font-size: 1rem;
  border-radius: var(--radius-pill);
  background: var(--accent-gradient);
  border: 2px solid transparent;
  color: var(--btn-generate-text);
  font-weight: 800;
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}
.btn-generate:hover {
  box-shadow: 0 6px 30px rgba(0, 217, 166, 0.3);
  transform: translateY(-2px);
}
.btn-generate:disabled {
  transform: none;
  box-shadow: none;
}

/* Generation spinner */
.generation-progress {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}
.generation-progress.visible {
  display: flex;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.generation-status {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.cancel-row {
  margin-top: 8px;
}

/* ---------- Output Section ---------- */
.output-section {
  display: none;
  flex-direction: column;
  gap: 16px;
}
.output-section.visible {
  display: flex;
}

.output-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.output-header h3 {
  font-size: 0.9rem;
  font-weight: 700;
}

.output-actions {
  display: flex;
  gap: 6px;
}
.output-actions .btn {
  padding: 6px 12px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.output-body {
  padding: 18px;
}

.output-body textarea {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.65;
  resize: vertical;
  outline: none;
}

/* Collapsible transcript */
.transcript-collapse {
  border-top: 1px solid var(--border);
}
.transcript-collapse summary {
  padding: 14px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
}
.transcript-collapse summary:hover {
  background: var(--surface-2);
}
.transcript-collapse summary::before {
  content: '▸';
  display: inline-block;
  transition: var(--transition);
  font-size: 0.7rem;
}
.transcript-collapse[open] summary::before {
  transform: rotate(90deg);
}

.transcript-body {
  padding: 0 18px 18px;
}
.transcript-body textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--waveform-bg);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1.65;
  padding: 12px;
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
}
.transcript-body textarea:focus {
  border-color: var(--accent);
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: calc(var(--topbar-h) + 12px);
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(16px);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.4s ease forwards;
  pointer-events: auto;
}
.toast.success { border-color: rgba(0, 217, 166, 0.4); color: var(--ok); }
.toast.error { border-color: rgba(255, 107, 122, 0.4); color: var(--danger); }
.toast.info { border-color: rgba(0, 184, 212, 0.4); color: #4dd0e1; }

.toast.out { animation: toast-out 0.3s ease forwards; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ---------- Disclaimer Footer ---------- */
.disclaimer-footer {
  margin-top: 12px;
  padding: 24px;
  border: 1px solid rgba(255, 183, 77, 0.2);
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 183, 77, 0.04) 0%, rgba(255, 107, 122, 0.04) 100%);
  box-shadow: var(--shadow-lg);
}

.disclaimer-heading {
  text-align: center;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--warn);
  letter-spacing: 0.02em;
  margin-bottom: 18px;
}

.disclaimer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.disclaimer-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.disclaimer-item:hover {
  border-color: rgba(255, 183, 77, 0.35);
  box-shadow: 0 2px 12px rgba(255, 183, 77, 0.06);
}

.disclaimer-icon {
  font-size: 1.3rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.disclaimer-item strong {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--warn);
  margin-bottom: 4px;
}

.disclaimer-item p {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.disclaimer-note {
  text-align: center;
  padding: 12px 16px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.disclaimer-note strong { color: var(--warn); font-weight: 600; }

@media (max-width: 600px) {
  .disclaimer-grid { grid-template-columns: 1fr; }
  .disclaimer-footer { padding: 16px; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 100%;
  }
  .topbar-brand h1 { font-size: 1rem; }
  .main-content { padding: 20px 14px 60px; }
  .controls-row { gap: 8px; }
  .btn { padding: 10px 14px; font-size: 0.82rem; }
  .btn-generate { padding: 14px 28px; font-size: 0.92rem; }
  .btn-record { width: 50px; height: 50px; }
  .btn-icon { width: 40px; height: 40px; }
  .welcome-card { padding: 20px 16px; }
  .audio-meta { flex-direction: column; gap: 4px; }
}

@media (min-width: 769px) {
  .sidebar-overlay { display: none !important; }
}

/* ---------- upload button style fix ---------- */
input[type="file"] { cursor: pointer; }
input[type="file"]::file-selector-button {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  margin-right: 10px;
  transition: var(--transition);
}
input[type="file"]::file-selector-button:hover {
  background: var(--surface-3);
}

/* ---------- Help Button ---------- */
.btn-help {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  margin-right: 8px;
}
.btn-help:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  transform: scale(1.1);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition);
  padding: 20px;
}
.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 560px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.95);
  transition: transform var(--transition);
}
.modal-overlay.visible .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
}
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}
.modal-close:hover {
  background: var(--surface-3);
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.help-step {
  display: flex;
  gap: 16px;
  margin-bottom: 22px;
  align-items: flex-start;
}
.help-step-number {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  background: var(--accent-gradient);
  color: var(--btn-generate-text);
  font-weight: 800;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.help-step h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 6px;
}
.help-step p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin: 0 0 6px;
}
.help-step ul {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
.help-step code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.help-requirements {
  margin-top: 20px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.help-requirements h4 {
  font-size: 0.9rem;
  margin: 0 0 10px;
}
.help-requirements ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ---------- Theme Toggle Button ---------- */
.btn-theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
  font-size: 1.05rem;
  padding: 0;
  position: relative;
}
.btn-theme-toggle:hover {
  background: var(--surface-3);
  border-color: var(--border-hover);
  transform: scale(1.1);
}

/* Sun/moon icon visibility */
.theme-icon-sun,
.theme-icon-moon {
  position: absolute;
  transition: opacity var(--transition), transform var(--transition);
  line-height: 1;
}

/* Dark mode (default): show sun icon to switch to light */
.theme-icon-sun { opacity: 1; transform: scale(1); }
.theme-icon-moon { opacity: 0; transform: scale(0.5); }

/* Light mode: show moon icon to switch to dark */
[data-theme="light"] .theme-icon-sun { opacity: 0; transform: scale(0.5); }
[data-theme="light"] .theme-icon-moon { opacity: 1; transform: scale(1); }

/* Smooth body transition for theme switch */
body {
  transition: background var(--transition), color var(--transition);
}
