/* ============================================
   CSS VARIABLES - Single source of truth
   ============================================ */
:root {
  /* Brand Colors */
  --color-primary: #f97316;
  --color-primary-light: #fb923c;
  --color-secondary: #3b82f6;
  --color-secondary-dark: #2563eb;

  /* Tag Colors */
  --color-emotion: #4ade80;
  --color-pause: #f97316;
  --color-speed: #fb923c;
  --color-emphasis: #c084fc;
  --color-pitch: #fbbf24;
  --color-volume: #a78bfa;
  --color-voice: #38bdf8;
  --color-invalid: #ef4444;

  /* Dark Theme */
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #ffffff;
  --text-secondary: #cbd5e1;
  --text-tertiary: #94a3b8;
  --border-color: rgba(71, 85, 105, 0.3);

  /* Spacing */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-xl: 12px;
}

/* Light Mode Variables */
.light-mode {
  color-scheme: light;
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #334155;
  --text-tertiary: #64748b;
  --border-color: #cbd5e1;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ============================================
   SYNTAX HIGHLIGHTING - Base + Variants
   ============================================ */
[class^="tag-"] {
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  display: inline-block;
  border: 1.5px solid;
}

.tag-emotion { color: var(--color-emotion); background: rgba(74, 222, 128, 0.15); border-color: rgba(74, 222, 128, 0.4); }
.tag-pause { color: var(--color-pause); background: rgba(249, 115, 22, 0.15); border-color: rgba(249, 115, 22, 0.4); }
.tag-speed { color: var(--color-speed); background: rgba(251, 146, 60, 0.15); border-color: rgba(251, 146, 60, 0.4); }
.tag-emphasis { color: var(--color-emphasis); background: rgba(192, 132, 252, 0.15); border-color: rgba(192, 132, 252, 0.4); }
.tag-pitch { color: var(--color-pitch); background: rgba(251, 191, 36, 0.15); border-color: rgba(251, 191, 36, 0.4); }
.tag-volume { color: var(--color-volume); background: rgba(167, 139, 250, 0.15); border-color: rgba(167, 139, 250, 0.4); }
.tag-voice { color: var(--color-voice); background: rgba(56, 189, 248, 0.15); border-color: rgba(56, 189, 248, 0.4); }
.tag-invalid { color: var(--color-invalid); background: rgba(239, 68, 68, 0.15); border-color: rgba(239, 68, 68, 0.5); text-decoration: wavy underline; }
.tag-closing { color: var(--color-emotion); background: rgba(74, 222, 128, 0.1); border-color: rgba(74, 222, 128, 0.3); opacity: 0.9; }

/* Light Mode Tag Variants */
.light-mode .tag-emotion { color: #059669; background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.3); }
.light-mode .tag-pause { color: #ea580c; background: rgba(249, 115, 22, 0.1); border-color: rgba(249, 115, 22, 0.3); }
.light-mode .tag-speed { color: #dc2626; background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); }
.light-mode .tag-emphasis { color: #9333ea; background: rgba(147, 51, 234, 0.1); border-color: rgba(147, 51, 234, 0.3); }
.light-mode .tag-pitch { color: #ca8a04; background: rgba(234, 179, 8, 0.1); border-color: rgba(234, 179, 8, 0.3); }
.light-mode .tag-volume { color: #7c3aed; background: rgba(124, 58, 237, 0.1); border-color: rgba(124, 58, 237, 0.3); }
.light-mode .tag-voice { color: #0284c7; background: rgba(2, 132, 199, 0.1); border-color: rgba(2, 132, 199, 0.3); }
.light-mode .tag-invalid { color: #dc2626; background: rgba(220, 38, 38, 0.1); border-color: rgba(220, 38, 38, 0.4); }
.light-mode .tag-closing { color: #059669; background: rgba(16, 185, 129, 0.08); border-color: rgba(16, 185, 129, 0.25); opacity: 0.85; }

/* ============================================
   EDITOR & PLACEHOLDERS
   ============================================ */
#text-editor:empty:before,
.emotion-block-text-editable:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
  pointer-events: none;
}

#text-editor {
  background: var(--bg-primary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.emotion-block-text-editable {
  flex: 1;
  padding: 6px 8px;
  background: rgba(30, 41, 59, 0.2);
  border: 1px solid rgba(71, 85, 105, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  min-height: 36px;
  line-height: 1.5;
  outline: none;
  overflow-wrap: break-word;
  word-break: break-word;
}

.emotion-block-text-editable:focus {
  border-color: rgba(59, 130, 246, 0.5);
  background: rgba(30, 41, 59, 0.3);
}

.light-mode .emotion-block-text-editable {
  background: rgba(248, 250, 252, 0.8);
  border-color: #e2e8f0;
  color: var(--text-primary);
}

/* ============================================
   SIDEBAR
   ============================================ */
#sidebar {
  background: var(--bg-secondary);
  border-right-color: var(--border-color);
  transition: transform 0.3s ease;
}

#sidebar.collapsed { transform: translateX(-100%); }

#main-content {
  transition: margin-left 0.3s ease;
}

#main-content.sidebar-open {
  margin-left: 288px;
}

/* ============================================
   SCROLLBAR
   ============================================ */
.custom-scrollbar::-webkit-scrollbar {
  width: 8px;
}

.custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
  border-radius: var(--radius-sm);
}

.custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(71, 85, 105, 0.8);
  border-radius: var(--radius-sm);
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.9);
}

.light-mode .custom-scrollbar::-webkit-scrollbar-track {
  background: rgba(241, 245, 249, 0.5);
}

.light-mode .custom-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.6);
}

.light-mode .custom-scrollbar::-webkit-scrollbar-thumb:hover {
  background: rgba(100, 116, 139, 0.8);
}

/* ============================================
   VOICE SEGMENT CARDS
   ============================================ */
.voice-segment-card {
  background: rgba(30, 41, 59, 0.2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px;
  transition: all 0.15s ease;
  cursor: pointer;
  position: relative;
}

.voice-segment-card:hover {
  background: rgba(30, 41, 59, 0.3);
  border-color: rgba(100, 116, 139, 0.5);
}

.voice-segment-card.active {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.4);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.2);
}

.voice-segment-card.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: -1px;
  bottom: -1px;
  width: 3px;
  background: var(--color-secondary);
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.voice-segment-card.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.segment-drag-handle {
  cursor: grab;
  opacity: 0.5;
  transition: opacity 0.2s ease;
}

.segment-drag-handle:hover { opacity: 1; }
.segment-drag-handle:active { cursor: grabbing; }

.segment-number {
  color: var(--text-tertiary);
  font-size: 0.75rem;
  font-weight: 600;
}

/* Light Mode Voice Cards */
.light-mode .voice-segment-card {
  background: rgba(255, 255, 255, 0.6);
  border-color: rgba(203, 213, 225, 0.6);
}

.light-mode .voice-segment-card:hover {
  background: rgba(248, 250, 252, 0.8);
  border-color: rgba(148, 163, 184, 0.5);
}

.light-mode .voice-segment-card.active {
  background: rgba(219, 234, 254, 0.4);
  border-color: rgba(59, 130, 246, 0.4);
  box-shadow: 0 0 0 1px rgba(59, 130, 246, 0.15);
}

/* ============================================
   EMOTION BLOCKS
   ============================================ */
.emotion-block.active {
  background: rgba(168, 85, 247, 0.06);
  border: 1px solid rgba(168, 85, 247, 0.3);
  box-shadow: 0 0 0 1px rgba(168, 85, 247, 0.1);
}

.emotion-block.active::before {
  content: '';
  position: absolute;
  left: -1px;
  top: -1px;
  bottom: -1px;
  width: 2px;
  background: #a855f7;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

/* ============================================
   RANGE SLIDERS
   ============================================ */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
}

input[type="range"]::-webkit-slider-track,
input[type="range"]::-moz-range-track {
  background: rgba(71, 85, 105, 0.5);
  height: 6px;
  border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  background: var(--color-secondary);
  height: 16px;
  width: 16px;
  border-radius: 50%;
  margin-top: -5px;
}

input[type="range"]::-moz-range-thumb {
  background: var(--color-secondary);
  height: 16px;
  width: 16px;
  border-radius: 50%;
  border: none;
}

input[type="range"]:hover::-webkit-slider-thumb,
input[type="range"]:hover::-moz-range-thumb {
  background: var(--color-secondary-dark);
}

.light-mode input[type="range"]::-webkit-slider-track,
.light-mode input[type="range"]::-moz-range-track {
  background: rgba(203, 213, 225, 0.7);
}

/* ============================================
   PAUSE PILLS
   ============================================ */
.pause-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(249, 115, 22, 0.12);
  border: 1px solid rgba(249, 115, 22, 0.3);
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--color-speed);
  cursor: pointer;
  user-select: none;
  vertical-align: middle;
  margin: 0 2px;
  transition: all 0.15s ease;
}

.pause-pill:hover {
  background: rgba(249, 115, 22, 0.2);
  border-color: rgba(249, 115, 22, 0.5);
  transform: scale(1.03);
}

.pause-pill .pause-icon { font-size: 10px; }
.pause-pill .pause-duration { font-family: 'Inter', monospace; }
.pause-pill .pause-delete { font-size: 10px; opacity: 0.6; margin-left: 2px; }
.pause-pill .pause-delete:hover { opacity: 1; color: var(--color-invalid); }

.light-mode .pause-pill {
  background: rgba(249, 115, 22, 0.15);
  border-color: rgba(234, 88, 12, 0.4);
  color: #ea580c;
}

.light-mode .pause-pill:hover {
  background: rgba(249, 115, 22, 0.25);
}

/* Pause Dropdown */
.pause-dropdown {
  position: absolute;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  z-index: 100;
  min-width: 90px;
}

.pause-dropdown button {
  display: block;
  width: 100%;
  padding: 5px 10px;
  text-align: left;
  font-size: 11px;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.12s;
}

.pause-dropdown button:hover {
  background: rgba(59, 130, 246, 0.15);
  color: #e0e7ff;
}

.light-mode .pause-dropdown {
  background: var(--bg-primary);
  border-color: var(--border-color);
}

.light-mode .pause-dropdown button {
  color: var(--text-primary);
}

.light-mode .pause-dropdown button:hover {
  background: rgba(59, 130, 246, 0.1);
}

/* ============================================
   LIGHT MODE OVERRIDES
   ============================================ */
.light-mode body {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 50%, #f1f5f9 100%);
  color: var(--text-primary);
}

.light-mode nav,
.light-mode #sidebar {
  background: rgba(255, 255, 255, 0.95);
  border-color: #e2e8f0;
}

/* Comprehensive Text Color Overrides */
.light-mode .text-white,
.light-mode nav .text-white,
.light-mode #sidebar .text-white {
  color: #0f172a !important;
}

.light-mode .text-slate-200,
.light-mode nav .text-slate-200,
.light-mode #sidebar .text-slate-200 {
  color: #334155 !important;
}

.light-mode .text-slate-300,
.light-mode nav .text-slate-300,
.light-mode #sidebar .text-slate-300 {
  color: #475569 !important;
}

.light-mode .text-slate-400,
.light-mode nav .text-slate-400,
.light-mode #sidebar .text-slate-400 {
  color: #64748b !important;
}

.light-mode .text-slate-500 {
  color: #94a3b8 !important;
}

.light-mode input,
.light-mode select,
.light-mode textarea {
  background: var(--bg-primary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

.light-mode input::placeholder,
.light-mode textarea::placeholder {
  color: var(--text-tertiary);
}

.light-mode input:focus,
.light-mode select:focus,
.light-mode textarea:focus {
  border-color: var(--color-secondary);
  ring-color: var(--color-secondary);
}

.light-mode .bg-slate-800\/50,
.light-mode .bg-slate-900\/50 {
  background: rgba(255, 255, 255, 0.8);
}

.light-mode .bg-slate-800\/30,
.light-mode .bg-slate-900\/30 {
  background: rgba(241, 245, 249, 0.6);
}

.light-mode .border-slate-600,
.light-mode .border-slate-700,
.light-mode .border-slate-800 {
  border-color: var(--border-color);
}

.light-mode button,
.light-mode button span,
.light-mode button *,
.light-mode a.button {
  color: #000000 !important;
}

.light-mode .bg-slate-800 {
  background: var(--bg-primary);
}

.light-mode code {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.light-mode .bg-slate-950,
.light-mode .bg-slate-950\/50,
.light-mode .bg-slate-950\/80 {
  background: #f8fafc;
}

.light-mode .bg-amber-500\/10 {
  background: rgba(251, 191, 36, 0.15);
}

.light-mode .border-amber-500\/30 {
  border-color: rgba(245, 158, 11, 0.4);
}

.light-mode .text-amber-200 {
  color: #92400e;
}

.light-mode .text-amber-100 {
  color: #78350f;
}

.light-mode #empty-state,
.light-mode p,
.light-mode h1,
.light-mode h2,
.light-mode h3,
.light-mode h4,
.light-mode h5,
.light-mode h6,
.light-mode span,
.light-mode div {
  color: var(--text-primary);
}

.light-mode .bg-slate-900\/10 {
  background: rgba(241, 245, 249, 0.3) !important;
}

/* ============================================
   MOBILE RESPONSIVE - Consolidated
   ============================================ */
@media (max-width: 1024px) {
  /* Sidebar as Bottom Sheet */
  #sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-radius: 24px 24px 0 0;
    border-right: none;
    border-top: 1px solid rgba(148, 163, 184, 0.2);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
  }

  #sidebar.active { transform: translateY(0); }

  #sidebar::before {
    content: '';
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: rgba(148, 163, 184, 0.5);
    border-radius: 2px;
  }

  #sidebar > div { padding-top: 2rem; }

  /* Backdrop overlay */
  body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-in-out;
  }

  body.sidebar-open::before {
    opacity: 1;
    pointer-events: auto;
  }

  #main-content {
    margin-left: 0;
    width: 100%;
    padding: 1rem 0.75rem 6rem 0.75rem;
    min-height: 100vh;
  }

  /* Floating Action Button */
  .mobile-fab {
    position: fixed;
    bottom: 24px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--color-secondary), #8b5cf6);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    border: none;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .mobile-fab:active { transform: scale(0.92); }
  .mobile-fab svg { width: 24px; height: 24px; color: white; }
  .mobile-fab.active { transform: rotate(45deg); }

  .sidebar-open #main-content { margin-left: 0; }

  /* Navigation */
  nav { padding: 0; }
  nav .max-w-7xl { padding: 0.75rem 1rem; }
  #sidebar-toggle { display: none; }
  #nav-usage,
  #upgrade-btn,
  #user-greeting { display: none; }

  nav a[href="/login"] { padding: 0.5rem; font-size: 0; }
  nav a[href="/login"]::before { content: '→'; font-size: 1.125rem; font-weight: 600; }

  #user-tier { padding: 0.5rem 0.75rem; font-size: 0.75rem; font-weight: 700; border-radius: var(--radius-lg); }
  nav .text-lg { font-size: 1rem; }
  nav img.w-6 { width: 1.5rem; height: 1.5rem; }

  /* Converter Interface */
  #main-content .bg-slate-800\/50 {
    padding: 1rem;
    border-radius: 16px;
    height: calc(100vh - 7rem);
    display: flex;
    flex-direction: column;
  }

  #main-content h2 { font-size: 1.125rem; margin-bottom: 0.5rem; }
  #main-content > section > div > div > p { font-size: 0.8125rem; margin-bottom: 0.75rem; }

  #mode-visual,
  #mode-ssml { padding: 0.5rem 1rem; font-size: 0.8125rem; }

  #convert-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  #visual-builder-container,
  #ssml-editor-container {
    flex: 1;
    min-height: 0;
  }

  .segment-card {
    padding: 0.875rem;
    border-radius: var(--radius-xl);
    margin-bottom: 0.75rem;
  }

  /* Action buttons - sticky */
  #action-buttons {
    position: sticky;
    bottom: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.98) 80%, transparent);
    padding: 1rem 0 0.5rem 0;
    margin: 0 -1rem -1rem -1rem;
    display: flex;
    gap: 0.75rem;
    z-index: 10;
  }

  #action-buttons button[type="submit"] {
    flex: 1;
    padding: 1rem;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--radius-xl);
    box-shadow: 0 4px 20px rgba(249, 115, 22, 0.3);
  }

  #action-buttons button:not([type="submit"]) {
    padding: 1rem;
    border-radius: var(--radius-xl);
    min-width: 56px;
  }

  #charCounter,
  #charCounter-ssml { font-size: 0.875rem; font-weight: 600; }

  /* SSML Reference - Hide on mobile */
  #main-content + section { display: none; }

  button,
  a,
  select,
  input[type="range"] {
    min-height: 44px;
    min-width: 44px;
  }

  button svg { width: 1.25rem; height: 1.25rem; }
}

@media (max-width: 768px) {
  .md\\:grid-cols-2 { grid-template-columns: 1fr; }

  footer .grid-cols-1 { gap: 1.5rem; }
  footer { padding-top: 2rem; }
  footer .py-12 { padding-top: 2rem; padding-bottom: 2rem; }
}

@media (max-width: 640px) {
  h1 { font-size: 1.5rem; line-height: 2rem; }
  h2 { font-size: 1.25rem; line-height: 1.75rem; }
  h3 { font-size: 1rem; line-height: 1.5rem; }
  #main-content h2 { font-size: 1rem; }
  #main-content p { font-size: 0.75rem; }

  /* AI Modal */
  #ai-modal .bg-slate-800 {
    margin: 1rem;
    max-height: calc(100vh - 2rem);
    max-width: calc(100vw - 2rem);
  }

  #ai-modal .p-6 { padding: 1rem; }
  #ai-modal .grid-cols-1 { grid-template-columns: 1fr; }
  #ai-modal .flex.gap-3 { flex-direction: column; gap: 0.75rem; }
  #ai-modal button { width: 100%; }
}

/* Prevent horizontal scroll */
body { overflow-x: hidden; }

#main-content,
#sidebar,
.max-w-7xl { max-width: 100vw; }

#empty-state { min-height: 300px; }

.voice-segment-card.dragging * { user-select: none; }
