/* ===================================================
   1. CSS Custom Properties
   =================================================== */
:root {
  /* DePaul Core Palette */
  --color-blue-core: #003DA5;
  --color-blue-light: #0072CE;
  --color-blue-pale: #6DA4D8;
  --color-navy: #00205B;
  --color-navy-deep: #001741;
  --color-scarlet: #CE112D;
  --color-scarlet-hover: #A80D24;
  --color-white: #FFFFFF;
  --color-black: #000000;
  --color-gray: #D1D1D1;

  /* Extended Neutrals */
  --color-gray-50: #F8FAFC;
  --color-gray-100: #F1F5F9;
  --color-gray-200: #E2E8F0;
  --color-gray-300: #CBD5E1;
  --color-gray-400: #94A3B8;
  --color-gray-500: #64748B;
  --color-gray-600: #475569;
  --color-gray-700: #334155;
  --color-gray-800: #1E293B;
  --color-gray-900: #0F172A;

  /* Semantic Colors */
  --color-success: #10B981;
  --color-success-bg: #ECFDF5;
  --color-success-text: #065F46;
  --color-warning: #F59E0B;
  --color-warning-bg: #FFFBEB;
  --color-warning-text: #92400E;
  --color-error: #EF4444;
  --color-error-bg: #FEF2F2;
  --color-error-text: #991B1B;
  --color-info-bg: #EFF6FF;
  --color-info-text: #1E40AF;

  /* Light Mode Theme Tokens */
  --bg-app: var(--color-gray-100);
  --bg-surface: var(--color-white);
  --bg-surface-raised: var(--color-white);
  --bg-surface-hover: var(--color-gray-50);
  --bg-sidebar: var(--color-navy-deep);
  --bg-input: var(--color-white);
  --bg-code: var(--color-gray-100);

  --text-primary: var(--color-gray-900);
  --text-secondary: var(--color-gray-600);
  --text-tertiary: var(--color-gray-400);
  --text-on-dark: var(--color-white);
  --text-on-dark-muted: rgba(255, 255, 255, 0.55);
  --text-link: var(--color-blue-core);

  --border-default: var(--color-gray-200);
  --border-subtle: var(--color-gray-100);
  --border-focus: var(--color-blue-core);

  --shadow-sm: 0 1px 2px rgba(0, 32, 91, 0.05);
  --shadow-md: 0 1px 3px rgba(0, 32, 91, 0.07), 0 4px 12px rgba(0, 32, 91, 0.05);
  --shadow-lg: 0 4px 6px rgba(0, 32, 91, 0.05), 0 10px 24px rgba(0, 32, 91, 0.08);

  /* Script Viewer Colors (Light) */
  --script-bg: var(--color-white);
  --script-text: var(--color-gray-900);
  --script-scene-heading: var(--color-navy);
  --script-character-name: var(--color-blue-core);
  --script-parenthetical: var(--color-gray-500);
  --script-dialogue: var(--color-gray-800);
  --script-action: var(--color-gray-700);
  --script-transition: var(--color-gray-500);
  --script-active-bg: #FFF7ED;
  --script-active-border: var(--color-scarlet);

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;

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

  /* Spacing (4px base) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* Type Scale */
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 0.9375rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
}

[data-theme="dark"] {
  --bg-app: var(--color-gray-900);
  --bg-surface: var(--color-gray-800);
  --bg-surface-raised: #243044;
  --bg-surface-hover: var(--color-gray-700);
  --bg-sidebar: #0A1628;
  --bg-input: var(--color-gray-700);
  --bg-code: var(--color-gray-800);

  --text-primary: var(--color-gray-100);
  --text-secondary: var(--color-gray-400);
  --text-tertiary: var(--color-gray-500);
  --text-on-dark: var(--color-white);
  --text-on-dark-muted: rgba(255, 255, 255, 0.45);
  --text-link: var(--color-blue-pale);

  --border-default: var(--color-gray-700);
  --border-subtle: var(--color-gray-800);
  --border-focus: var(--color-blue-light);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.3), 0 10px 24px rgba(0, 0, 0, 0.25);

  /* Script Viewer Colors (Dark) */
  --script-bg: var(--color-gray-800);
  --script-text: var(--color-gray-200);
  --script-scene-heading: var(--color-blue-pale);
  --script-character-name: var(--color-blue-pale);
  --script-parenthetical: var(--color-gray-400);
  --script-dialogue: var(--color-gray-200);
  --script-action: var(--color-gray-300);
  --script-transition: var(--color-gray-400);
  --script-active-bg: rgba(206, 17, 45, 0.12);
  --script-active-border: var(--color-scarlet);

  --color-success-bg: rgba(16, 185, 129, 0.12);
  --color-success-text: #6EE7B7;
  --color-warning-bg: rgba(245, 158, 11, 0.12);
  --color-warning-text: #FCD34D;
  --color-error-bg: rgba(239, 68, 68, 0.12);
  --color-error-text: #FCA5A5;
  --color-info-bg: rgba(0, 61, 165, 0.12);
  --color-info-text: var(--color-blue-pale);
}

/* ===================================================
   2. Reset / Base
   =================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-app);
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ===================================================
   3. Typography
   =================================================== */
h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text-primary);
  margin: 0 0 var(--space-1);
}

h2 {
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text-secondary);
  margin: 0 0 var(--space-6);
  font-weight: 400;
}

h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
  color: var(--text-primary);
  margin: 0 0 var(--space-2);
}

p {
  margin: 0 0 var(--space-4);
}

code {
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 0.9em;
  background: var(--bg-code);
  color: var(--color-scarlet);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

/* ===================================================
   4. Layout
   =================================================== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-sidebar);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-6) var(--space-4) var(--space-4);
}

.brand-diamond {
  color: var(--color-blue-light);
  font-size: 1rem;
  line-height: 1;
}

.brand-name {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--color-white);
}

.sidebar-section-label {
  padding: 0 var(--space-4) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-on-dark-muted);
}

.sidebar-nav {
  flex: 1;
}

.sidebar-footer {
  padding: var(--space-4);
}

.sidebar-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.08);
  margin-bottom: var(--space-3);
}

.sidebar-version {
  font-size: var(--text-xs);
  color: var(--text-on-dark-muted);
  padding: 0 var(--space-2);
  margin-top: var(--space-2);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: none;
  border: none;
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius-md);
  color: var(--text-on-dark-muted);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-align: left;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-white);
}

/* --- Nav Items --- */
.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-list li {
  margin: 2px var(--space-2);
}

.nav-list a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border-left: 3px solid transparent;
  text-decoration: none;
  color: var(--text-on-dark-muted);
  font-size: var(--text-sm);
  font-weight: 400;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.nav-list a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-white);
  text-decoration: none;
}

.nav-list a.active {
  background: rgba(0, 61, 165, 0.3);
  color: var(--color-white);
  border-left-color: var(--color-scarlet);
  font-weight: 500;
}

.nav-list a svg {
  flex-shrink: 0;
  opacity: 0.75;
}

.nav-list a.active svg,
.nav-list a:hover svg {
  opacity: 1;
}

/* --- Main Content --- */
.main-content {
  margin-left: 240px;
  flex: 1;
  min-height: 100vh;
  background: var(--bg-app);
}

.page-content {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--space-8);
}

/* --- Page Header --- */
.page-header {
  margin-bottom: var(--space-6);
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.page-subtitle {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin: 0;
  font-weight: 400;
}

/* --- Cards --- */
.page-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-6);
  transition: box-shadow var(--transition-base);
}

/* ===================================================
   5. Components
   =================================================== */

/* --- Buttons (override Bootstrap) --- */
.btn {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-5);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast),
              box-shadow var(--transition-fast), transform var(--transition-fast),
              color var(--transition-fast);
  white-space: nowrap;
  line-height: 1;
}

.btn:focus-visible {
  outline: 2px solid var(--color-blue-pale);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--color-blue-core) !important;
  color: var(--color-white) !important;
  border-color: var(--color-blue-core) !important;
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-blue-light) !important;
  border-color: var(--color-blue-light) !important;
  box-shadow: 0 1px 3px rgba(0, 61, 165, 0.3);
  transform: translateY(-1px);
  color: var(--color-white) !important;
}

.btn-primary:active {
  background: #002D7A !important;
  transform: translateY(0);
}

/* CTA / Scarlet — for Start Table Read, Download, Play */
.btn-cta {
  background: var(--color-scarlet) !important;
  color: var(--color-white) !important;
  border-color: var(--color-scarlet) !important;
  font-weight: 600;
}

.btn-cta:hover:not(:disabled) {
  background: var(--color-scarlet-hover) !important;
  border-color: var(--color-scarlet-hover) !important;
  box-shadow: 0 1px 3px rgba(206, 17, 45, 0.3);
  transform: translateY(-1px);
  color: var(--color-white) !important;
}

.btn-cta:active {
  transform: translateY(0);
}

.btn-cta:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Bootstrap btn-success → re-skin as scarlet CTA */
.btn-success {
  background: var(--color-scarlet) !important;
  color: var(--color-white) !important;
  border-color: var(--color-scarlet) !important;
  font-weight: 600;
}

.btn-success:hover:not(:disabled) {
  background: var(--color-scarlet-hover) !important;
  border-color: var(--color-scarlet-hover) !important;
  color: var(--color-white) !important;
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-default) !important;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-surface-hover) !important;
  border-color: var(--color-gray-300) !important;
  color: var(--text-primary) !important;
}

.btn-outline-secondary {
  background: transparent !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-default) !important;
}

.btn-outline-secondary:hover:not(:disabled) {
  background: var(--bg-surface-hover) !important;
  border-color: var(--color-gray-300) !important;
  color: var(--text-primary) !important;
}

.btn-danger,
.btn-outline-danger {
  background: transparent !important;
  color: var(--color-error) !important;
  border-color: var(--color-error) !important;
}

.btn-danger:hover:not(:disabled),
.btn-outline-danger:hover:not(:disabled) {
  background: var(--color-error-bg) !important;
}

.btn-warning {
  background: var(--color-warning) !important;
  color: #fff !important;
  border-color: var(--color-warning) !important;
}

.btn-warning:hover:not(:disabled) {
  background: #D97706 !important;
  border-color: #D97706 !important;
  color: #fff !important;
}

.btn-icon {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0 !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* --- Form Controls (override Bootstrap) --- */
.form-control,
.form-select {
  background: var(--bg-input) !important;
  border: 1px solid var(--border-default) !important;
  border-radius: var(--radius-md) !important;
  padding: var(--space-2) var(--space-3) !important;
  font-size: var(--text-base) !important;
  color: var(--text-primary) !important;
  min-height: 36px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--color-blue-core) !important;
  box-shadow: 0 0 0 3px rgba(0, 61, 165, 0.12) !important;
  outline: none;
  background: var(--bg-input) !important;
  color: var(--text-primary) !important;
}

.form-select-sm {
  font-size: var(--text-sm) !important;
  padding: var(--space-1) var(--space-3) !important;
  min-height: 32px;
}

/* --- Tables (override Bootstrap) --- */
.table {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  border: none !important;
  box-shadow: none;
  font-size: var(--text-base);
  margin-bottom: 0;
  color: var(--text-primary);
  --bs-table-bg: transparent;
  --bs-table-striped-bg: transparent;
  --bs-table-hover-bg: var(--bg-surface-hover);
  --bs-table-border-color: var(--border-subtle);
}

.table thead th {
  background: var(--bg-app) !important;
  color: var(--text-secondary) !important;
  font-weight: 600 !important;
  font-size: var(--text-xs) !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  padding: var(--space-3) var(--space-4) !important;
  border-bottom: 1px solid var(--border-default) !important;
  border-top: none !important;
}

.table td {
  padding: var(--space-3) var(--space-4) !important;
  vertical-align: middle !important;
  border-bottom: 1px solid var(--border-subtle) !important;
  color: var(--text-primary) !important;
  border-top: none !important;
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover td {
  background: var(--bg-surface-hover);
}

.table tbody tr:last-child td {
  border-bottom: none !important;
}

/* --- Alerts (override Bootstrap) --- */
.alert {
  border-radius: var(--radius-lg) !important;
  border: 1px solid transparent;
  border-left-width: 3px !important;
  font-size: var(--text-base);
  padding: var(--space-3) var(--space-4) !important;
}

.alert-success {
  background: var(--color-success-bg) !important;
  border-left-color: var(--color-success) !important;
  color: var(--color-success-text) !important;
  border-color: transparent;
}

.alert-warning {
  background: var(--color-warning-bg) !important;
  border-left-color: var(--color-warning) !important;
  color: var(--color-warning-text) !important;
  border-color: transparent;
}

.alert-danger {
  background: var(--color-error-bg) !important;
  border-left-color: var(--color-error) !important;
  color: var(--color-error-text) !important;
  border-color: transparent;
}

.alert-info {
  background: var(--color-info-bg) !important;
  border-left-color: var(--color-blue-core) !important;
  color: var(--color-info-text) !important;
  border-color: transparent;
}

/* --- Progress Bar (override Bootstrap) --- */
.progress {
  height: 4px !important;
  border-radius: 999px !important;
  background: var(--border-default) !important;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--color-blue-core), var(--color-blue-light)) !important;
  transition: width 400ms ease;
}

/* --- Badges --- */
.badge-provider {
  background: var(--color-blue-core);
  color: var(--color-white);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px var(--space-3);
  border-radius: 999px;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
}

.badge-status {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 3px var(--space-3);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.badge-status.connected {
  background: var(--color-success-bg);
  color: var(--color-success-text);
}

.badge-status.disconnected {
  background: var(--color-error-bg);
  color: var(--color-error-text);
}

.badge-status.checking {
  background: var(--bg-code);
  color: var(--text-secondary);
}

/* Override Bootstrap badges */
.badge.bg-primary { background: var(--color-blue-core) !important; }
.badge.bg-success { background: var(--color-success) !important; }
.badge.bg-danger  { background: var(--color-error) !important; }
.badge.bg-secondary { background: var(--color-gray-600) !important; }
.badge.rounded-pill { border-radius: 999px !important; }

/* --- Spinner --- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-default);
  border-top-color: var(--color-blue-core);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
  display: inline-block;
}

.spinner-border {
  color: var(--color-blue-core) !important;
}

/* --- Provider Status Bar --- */
.provider-status-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

.provider-status-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  font-weight: 500;
}

/* ===================================================
   6. Page-specific
   =================================================== */

/* --- Upload Area --- */
.upload-area {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-16) var(--space-10);
  text-align: center;
  background: var(--bg-surface-hover);
  transition: all var(--transition-base);
  cursor: pointer;
  position: relative;
  display: block;
  user-select: none;
}

.upload-area:hover,
.upload-area.drag-over {
  border-color: var(--color-blue-core);
  background: var(--color-info-bg);
  box-shadow: 0 0 0 4px rgba(0, 61, 165, 0.08);
}

.upload-icon {
  color: var(--color-blue-pale);
  margin-bottom: var(--space-4);
  display: block;
}

.upload-title {
  font-size: var(--text-lg);
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
  line-height: 1.4;
}

.upload-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
  display: block;
}

.upload-formats {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}

.format-pill {
  background: var(--bg-code);
  color: var(--text-secondary);
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: var(--text-xs);
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
}

.upload-size-note {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin: 0;
  display: block;
}

.upload-input-overlay {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Compact change-file bar */
.change-file-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface-hover);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
  position: relative;
}

.change-file-bar .file-label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.change-file-bar .file-name {
  font-size: var(--text-sm);
  color: var(--text-primary);
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.change-file-link {
  font-size: var(--text-sm);
  color: var(--text-link);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  position: relative;
}

.change-file-link:hover {
  text-decoration: underline;
}

.change-file-link input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

/* Script Info Card */
.script-info-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
  margin-bottom: var(--space-5);
}

.script-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  line-height: 1.3;
}

.script-author {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin-bottom: var(--space-5);
}

.stats-row {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

.stat-block {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.character-list-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
}

.character-pills {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}

.character-pill {
  background: var(--color-info-bg);
  color: var(--color-info-text);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 3px var(--space-3);
  border-radius: 999px;
  border: 1px solid rgba(0, 61, 165, 0.15);
}

[data-theme="dark"] .character-pill {
  background: rgba(0, 61, 165, 0.2);
  color: var(--color-blue-pale);
  border-color: rgba(109, 164, 216, 0.2);
}

/* --- Playback Page --- */
.playback-header {
  margin-bottom: var(--space-5);
}

.playback-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px); /* 64px = 2 × --space-8 (.page-content padding) */
  overflow: hidden;
}

.playback-controls-panel {
  flex-shrink: 0;
  padding-bottom: var(--space-4);
  background: var(--bg-app);
  border-bottom: 1px solid var(--border-default);
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.playback-script-area {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) 0;
}

.playback-controls {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.now-playing-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  min-height: 28px;
}

.now-playing-label {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

.current-speaker {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-blue-core);
}

.download-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  padding: var(--space-4) var(--space-5);
  background: var(--bg-surface-hover);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-5);
}

/* --- Playback Speed Buttons --- */
.speed-btn {
  padding: 2px 7px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: none;
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.speed-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.speed-btn.active {
  background: var(--blue-core);
  border-color: var(--blue-core);
  color: #fff;
  font-weight: 600;
}

/* --- Scene Jump Navigation --- */
.scene-nav {
  margin-top: var(--space-3);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.scene-nav-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface);
  border: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
}

.scene-nav-toggle:hover { background: var(--bg-hover); }

.scene-nav-list {
  max-height: 160px;
  overflow-y: auto;
  background: var(--bg-app);
}

.scene-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-1-5) var(--space-3);
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scene-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }

.scene-nav-item.active {
  color: var(--blue-core);
  font-weight: 600;
  background: var(--script-active-bg);
}

/* --- Playback Options Bar --- */
.playback-options {
  display: flex;
  gap: var(--space-6);
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
}

.playback-options .option-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.playback-options .option-label {
  font-weight: 500;
  white-space: nowrap;
}

/* --- Oval Slide Toggle Switch --- */

/* Hide the native checkbox but keep it accessible */
.slide-toggle input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* The toggle track (the oval pill) */
.slide-toggle .slider {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  background: var(--color-gray-300);
  border-radius: 12px;
  cursor: pointer;
  transition: background-color var(--transition-base);
  flex-shrink: 0;
  vertical-align: middle;
}

/* The knob (the round circle that slides) */
.slide-toggle .slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: var(--color-white);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform var(--transition-base);
}

/* Checked state — slide knob right, track turns scarlet */
.slide-toggle input[type="checkbox"]:checked + .slider {
  background: var(--color-scarlet);
}

.slide-toggle input[type="checkbox"]:checked + .slider::after {
  transform: translateX(20px);
}

/* Focus ring when toggle is focused via keyboard */
.slide-toggle input[type="checkbox"]:focus-visible + .slider {
  outline: 2px solid var(--color-blue-pale);
  outline-offset: 2px;
}

/* Hover effect on track */
.slide-toggle .slider:hover {
  opacity: 0.9;
}

/* Flanking labels for two-option toggles (e.g., Line/Block) */
.toggle-label {
  font-size: var(--text-xs);
  font-weight: 400;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: default;
  transition: color var(--transition-fast), font-weight var(--transition-fast);
}

.toggle-label.active {
  color: var(--text-primary);
  font-weight: 600;
}

/* Dark mode: darken the OFF track so it's visible on dark surfaces */
[data-theme="dark"] .slide-toggle input[type="checkbox"]:not(:checked) + .slider {
  background: var(--color-gray-600);
}

/* --- Info Pages (About, Guide) --- */
.info-page {
  max-width: 720px;
}

.info-page h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-top: var(--space-10);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
}

.info-page h3 {
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--text-primary);
  margin-top: var(--space-6);
  margin-bottom: var(--space-2);
}

.info-page p {
  font-size: var(--text-base);
  line-height: 1.75;
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

.info-page ul,
.info-page ol {
  padding-left: var(--space-6);
  margin-bottom: var(--space-4);
}

.info-page li {
  font-size: var(--text-base);
  line-height: 1.75;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.info-page .step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--color-scarlet);
  color: var(--color-white);
  border-radius: 50%;
  font-size: var(--text-sm);
  font-weight: 700;
  flex-shrink: 0;
  margin-right: var(--space-3);
}

.info-page .step-header {
  display: flex;
  align-items: center;
  margin-bottom: var(--space-3);
}

.info-page .step-header h2 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: var(--text-lg);
}

.info-page .feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.info-page .feature-item {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}

.info-page .feature-icon {
  color: var(--color-scarlet);
  flex-shrink: 0;
  margin-top: 2px;
}

.info-page .feature-text strong {
  display: block;
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.info-page .feature-text span {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.info-page .toc {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-8);
}

.info-page .toc-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.info-page .toc ol {
  margin: 0;
  padding-left: var(--space-5);
}

.info-page .toc li {
  margin-bottom: var(--space-1);
}

.info-page .toc a {
  color: var(--text-link);
  text-decoration: none;
  font-size: var(--text-sm);
}

.info-page .toc a:hover {
  text-decoration: underline;
}

.info-page .cta-section {
  margin-top: var(--space-10);
  padding-top: var(--space-8);
  border-top: 1px solid var(--border-subtle);
  text-align: center;
}

.info-page .cta-section p {
  font-size: var(--text-md);
  color: var(--text-secondary);
  margin-bottom: var(--space-4);
}

/* Nav section labels */
.nav-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-on-dark-muted);
  padding: var(--space-4) var(--space-4) var(--space-1);
  margin-top: var(--space-2);
  list-style: none;
}

/* --- Script Viewer --- */
.script-viewer {
  overflow-y: visible;
  padding: var(--space-8) var(--space-10);
  font-family: 'Courier Prime', 'Courier New', Courier, monospace;
  font-size: 14px;
  line-height: 1.75;
  background: var(--script-bg);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  scroll-behavior: smooth;
}

.script-element {
  padding: var(--space-1) var(--space-2);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  transition: background-color var(--transition-base), border-color var(--transition-base);
  margin-bottom: var(--space-3);
}

.script-element.active {
  background: var(--script-active-bg);
  border-left-color: var(--script-active-border);
  padding-left: var(--space-3);
}

.script-element.scene-heading {
  font-weight: 700;
  text-transform: uppercase;
  text-decoration: underline;
  color: var(--script-scene-heading);
  margin-top: var(--space-8);
  margin-bottom: var(--space-3);
  padding: var(--space-1) var(--space-2);
  background: rgba(0, 32, 91, 0.04);
  border-radius: var(--radius-sm);
}

[data-theme="dark"] .script-element.scene-heading {
  background: rgba(109, 164, 216, 0.06);
}

.script-element.action {
  color: var(--script-action);
  margin: 0 auto;
  max-width: 80%;
  padding: var(--space-1) 0;
}

.script-element.transition {
  text-align: right;
  text-transform: uppercase;
  color: var(--script-transition);
  font-weight: 500;
  font-size: 0.9em;
}

.dialogue-block {
  margin: var(--space-2) auto;
  max-width: 60%;
}

.dialogue-block .character-name {
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--script-character-name);
  font-size: 0.85em;
  letter-spacing: 0.06em;
  margin-bottom: 0;
}

.dialogue-block .parenthetical {
  text-align: center;
  font-style: italic;
  color: var(--script-parenthetical);
  font-size: 0.9em;
}

.dialogue-block .dialogue {
  text-align: left;
  color: var(--script-dialogue);
}

/* ===================================================
   7. Animations
   =================================================== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-content {
  animation: fadeInUp var(--transition-slow) ease both;
}

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

@media (prefers-reduced-motion: reduce) {
  .page-content {
    animation: none;
  }
  .script-viewer {
    scroll-behavior: auto;
  }
}

/* ===================================================
   8. Utilities
   =================================================== */
.text-muted { color: var(--text-secondary) !important; }
.text-tertiary { color: var(--text-tertiary) !important; }

/* ===================================================
   9. Responsive overrides
   =================================================== */
@media (max-width: 1023px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
  }

  .brand-name,
  .sidebar-section-label,
  .sidebar-version,
  .nav-list a span,
  .theme-toggle .theme-label {
    display: none;
  }

  .sidebar-brand {
    justify-content: center;
    padding: var(--space-5) 0;
  }

  .nav-list a {
    justify-content: center;
    padding: var(--space-3);
    border-left: none;
  }

  .nav-list a.active {
    border-left: none;
    border-bottom: 2px solid var(--color-scarlet);
  }

  .theme-toggle {
    justify-content: center;
  }

  .main-content {
    margin-left: 60px;
  }
}

@media (max-width: 767px) {
  .sidebar {
    display: none;
  }

  .main-content {
    margin-left: 0;
  }

  .page-content {
    padding: var(--space-5) var(--space-4);
  }

  .script-viewer {
    padding: var(--space-4);
  }

  .dialogue-block {
    max-width: 90%;
  }

  .script-element.action {
    max-width: 95%;
  }
}

/* Blazor error boundary */
.blazor-error-boundary {
  background: var(--color-error-bg);
  border-left: 3px solid var(--color-error);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  color: var(--color-error-text);
}

.blazor-error-boundary::after {
  content: "An error has occurred. Please refresh the page.";
}

/* Validation */
.valid.modified:not([type=checkbox]) {
  outline: 1px solid var(--color-success);
}

.invalid {
  outline: 1px solid var(--color-error);
}

.validation-message {
  color: var(--color-error);
  font-size: var(--text-sm);
}

/* --- Sidebar User Section --- */
.sidebar-user-section {
  padding: 0 var(--space-4) var(--space-3);
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar-user-name {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-on-dark);
  padding: var(--space-1) var(--space-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-links {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar-user-links a,
.sidebar-user-links .sidebar-logout-btn {
  display: block;
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-8);
  font-size: var(--text-sm);
  color: var(--text-on-dark-muted);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.sidebar-user-links a:hover,
.sidebar-user-links .sidebar-logout-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-on-dark);
}

.sidebar-user-links a.active {
  color: var(--color-white);
}

.sidebar-logout-form {
  margin: 0;
}

.sidebar-user-anon {
  flex-direction: row;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-2);
}

.sidebar-user-anon a {
  font-size: var(--text-sm);
  color: var(--text-on-dark-muted);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.sidebar-user-anon a:hover {
  color: var(--text-on-dark);
}

/* --- Auth Pages (Login / Register) --- */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  background: var(--bg-base);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
  margin-bottom: var(--space-6);
}

.auth-brand .brand-diamond {
  color: var(--color-scarlet);
  font-size: 1.25rem;
}

.auth-title {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-primary);
}

.auth-heading {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-5);
  text-align: center;
}

.auth-footer-text {
  text-align: center;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-5);
  margin-bottom: 0;
}

.auth-footer-text a {
  color: var(--color-blue-core);
  text-decoration: none;
}

.auth-footer-text a:hover {
  text-decoration: underline;
}

/* --- Section Headings (Profile / Admin) --- */
.section-heading {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

/* Responsive: hide user names/links on small sidebar */
@media (max-width: 1023px) {
  .sidebar-user-name span,
  .sidebar-user-links {
    display: none;
  }
  .sidebar-user-anon {
    justify-content: center;
  }
  .sidebar-user-anon a {
    display: none;
  }
}
