/* =============================================================================
   VidPipe Studio — Core Components
   Uses tokens from tokens.css. NO duplicate variables. Modern + minimal.
   ============================================================================= */

/* =============================================================================
   LAYOUT — Sidebar / Topbar / Stage
   ============================================================================= */

.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
}
.sidebar-brand {
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--color-border);
}
.sidebar-nav { flex: 1; padding: var(--space-2); overflow-y: auto; }
.sidebar-item {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: none;
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  font-family: inherit;
  transition: all var(--duration-fast) var(--ease);
  text-align: left;
}
.sidebar-item:hover { background: var(--color-surface-2); color: var(--color-text); }
.sidebar-item.active { background: var(--color-brand-soft); color: var(--color-brand); font-weight: var(--weight-semibold); }
.sidebar-item i { width: 18px; text-align: center; font-size: var(--text-base); }
.sidebar-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--color-border);
  font-size: var(--text-sm);
  color: var(--color-text-3);
}

.topbar {
  position: fixed;
  top: 0; right: 0;
  left: var(--sidebar-w);
  height: var(--topbar-h);
  background: var(--bg-blur);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  z-index: 90;
  gap: var(--space-3);
}
.topbar.no-sidebar { left: 0; }

.stage {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  padding: var(--space-8);
  min-height: calc(100vh - var(--topbar-h) - var(--navbar-h));
  padding-bottom: calc(var(--navbar-h) + var(--space-5));
  width: 100%;
  max-width: calc(100vw - var(--sidebar-w));
}
.stage.no-sidebar { margin-left: 0; padding: var(--space-8) var(--space-10); max-width: 960px; margin-inline: auto; }
.stage.full-width { max-width: none; }

.nav-bar {
  position: fixed;
  bottom: 0; right: 0;
  left: var(--sidebar-w);
  height: var(--navbar-h);
  background: var(--bg-blur);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-6);
  z-index: 90;
}
.nav-bar.no-sidebar { left: 0; }

/* Step dots — pipeline progress */
.step-dots { display: flex; align-items: center; gap: var(--space-1); }
.step-dot {
  width: 8px; height: 8px;
  border-radius: var(--radius-pill);
  border: none;
  cursor: pointer;
  background: var(--color-text-4);
  transition: all var(--duration-base) var(--ease);
  padding: 0;
}
.step-dot.done { background: var(--color-brand); opacity: 0.5; }
.step-dot.active { background: var(--color-brand); width: 28px; border-radius: var(--radius-xs); opacity: 1; }
.step-dot.pending { background: var(--color-text-4); }

/* =============================================================================
   COMPONENTS
   ============================================================================= */

/* --- Cards --- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.card:hover { border-color: var(--color-border-strong); }
.card-dark {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.card-interactive { cursor: pointer; }
.card-interactive:hover { border-color: var(--color-brand); box-shadow: var(--shadow-md); transform: var(--lift); }
.card-selected { border-color: var(--color-brand); box-shadow: var(--ring-brand); }

/* --- New: card internal structure (header / body / footer) --- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.card-body {
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  margin-bottom: var(--space-3);
}
.card-footer {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  align-items: center;
}
.card-footer .right { margin-left: auto; }

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease);
  text-decoration: none;
  white-space: nowrap;
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--color-brand);
  color: #fff;
}
.btn-primary:hover { background: var(--color-brand-hover); box-shadow: var(--shadow-brand); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}
.btn-secondary:hover { border-color: var(--color-border-stronger); background: var(--color-surface-2); }

.btn-danger { background: var(--color-danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-success { background: var(--color-success); color: #fff; }
.btn-success:hover { opacity: 0.9; }
.btn-ghost { background: transparent; color: var(--color-text-2); border: none; }
.btn-ghost:hover { color: var(--color-text); background: var(--color-surface-2); }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-sm); border-radius: var(--radius-sm); gap: var(--space-1); }
.btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); border-radius: var(--radius-md); }
.btn-icon { padding: var(--space-2); width: 36px; height: 36px; border-radius: var(--radius-md); }
.btn-icon.sm { width: 30px; height: 30px; padding: var(--space-1); }

/* --- New: gradient brand CTA button (e.g. "→ Use in Pipeline") --- */
.btn-accent {
  background: var(--grad-brand);
  color: #fff;
  box-shadow: var(--shadow-brand);
  border: none;
}
.btn-accent:hover {
  transform: var(--lift);
  box-shadow: 0 8px 20px rgba(91, 94, 244, 0.30);
}
.btn-accent:focus-visible { outline: none; box-shadow: var(--ring-brand), var(--shadow-brand); }

/* --- Inputs --- */
.input,
input[type="text"],
input[type="url"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  outline: none;
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
  line-height: var(--leading-normal);
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px var(--color-brand-soft);
}
.input::placeholder, input::placeholder, textarea::placeholder { color: var(--color-text-3); }
textarea { min-height: 80px; resize: vertical; line-height: var(--leading-relaxed); }
select { cursor: pointer; }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.01em;
  line-height: 1;
}
.badge-accent { background: var(--color-brand-soft); color: var(--color-brand); }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-warning { background: var(--color-warn-soft); color: var(--color-warn); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-info { background: var(--color-info-soft); color: var(--color-info); }

/* --- Info Boxes --- */
.info-box {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  border-left: 3px solid var(--color-text-4);
  background: var(--color-surface-2);
  color: var(--color-text-2);
}
.info-box.success { border-left-color: var(--color-success); background: var(--color-success-soft); }
.info-box.error { border-left-color: var(--color-danger); background: var(--color-danger-soft); color: var(--color-danger); }
.info-box.warning { border-left-color: var(--color-warn); background: var(--color-warn-soft); }

/* --- Prompt/Code Boxes --- */
.prompt-box {
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.prompt-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-text-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.prompt-box-body {
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow-y: auto;
  background: var(--color-surface-2);
  color: var(--color-text-2);
}

/* --- Scene Card --- */
.scene-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--duration-fast) var(--ease), box-shadow var(--duration-fast) var(--ease);
}
.scene-card:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-sm); }

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(9, 9, 11, 0.50);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: fadeIn 0.15s ease;
}
.modal-box {
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-2xl);
  padding: var(--space-8);
  max-width: 600px;
  width: 92%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: slideUp 0.25s var(--ease);
}

/* --- Stats --- */
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.stat-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--duration-fast) var(--ease);
}
.stat-card:hover { border-color: var(--color-border-strong); }
.stat-card .stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tighter);
}
.stat-card .stat-label {
  font-size: var(--text-xs);
  color: var(--color-text-3);
  margin-top: var(--space-1);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

/* --- Spinner --- */
.spin {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-brand);
  border-radius: var(--radius-pill);
  animation: spin 0.7s linear infinite;
}
.spin-lg { width: 36px; height: 36px; border-width: 3px; }

/* --- Avatar --- */
.avatar {
  width: 36px; height: 36px;
  border-radius: var(--radius-pill);
  background: var(--color-brand-soft);
  color: var(--color-brand);
  display: flex; align-items: center; justify-content: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-md);
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-lg); }

/* --- Divider --- */
.divider { height: 1px; background: var(--color-border); margin: var(--space-4) 0; }

/* --- Section header --- */
.section-header {
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  color: var(--color-text-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-3);
  padding: 0 var(--space-1);
}

/* --- Progress Bar --- */
.progress-bar {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: var(--radius-pill);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-brand);
  border-radius: var(--radius-pill);
  transition: width 0.3s var(--ease);
}

/* --- Tab bar (unified pattern across all multi-tab pages) --- */
.tab-bar {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-5);
}
.tab-bar-item {
  padding: var(--space-3) var(--space-5);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text-3);
  transition: all var(--duration-fast) var(--ease);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}
.tab-bar-item:hover { color: var(--color-text-2); }
.tab-bar-item.active {
  color: var(--color-brand);
  border-bottom-color: var(--color-brand);
  font-weight: var(--weight-semibold);
}

/* --- Stat tile (Posthog-style big number + label) --- */
.stat-tile {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  transition: border-color var(--duration-fast) var(--ease);
}
.stat-tile:hover { border-color: var(--color-border-strong); }
.stat-tile-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--color-text-3);
  margin-bottom: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}
.stat-tile-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tighter);
  line-height: var(--leading-tight);
}
.stat-tile-sub {
  font-size: var(--text-xs);
  color: var(--color-text-3);
  margin-top: var(--space-1);
}

/* --- Video grid (Brain tab thumbnails) --- */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-3);
}
.video-thumb {
  position: relative;
  width: 80px;
  height: 106px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-thumb img { width: 100%; height: 100%; object-fit: cover; }
.video-thumb-play {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.40);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease);
  cursor: pointer;
}
.video-thumb:hover .video-thumb-play { opacity: 1; }
.video-thumb-play i { color: #fff; font-size: var(--text-xl); }

/* --- Input search variant (with leading icon) --- */
.input-search {
  position: relative;
}
.input-search input {
  padding-left: 36px;
}
.input-search i {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-3);
  font-size: var(--text-base);
  pointer-events: none;
}

/* --- RTL utility (apply to Arabic text blocks) --- */
.rtl {
  direction: rtl;
  text-align: right;
}

/* --- Score badge (semi-circle with color based on value) --- */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  flex-shrink: 0;
}
.score-badge.high { background: var(--color-success-soft); color: var(--color-success); }
.score-badge.mid { background: var(--color-warn-soft); color: var(--color-warn); }
.score-badge.low { background: var(--color-danger-soft); color: var(--color-danger); }
.score-badge.none { background: var(--color-surface-2); color: var(--color-text-3); }

/* --- Drop zone (file upload area) --- */
.drop-zone {
  border: 2px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  padding: var(--space-8) var(--space-5);
  text-align: center;
  cursor: pointer;
  transition: all var(--duration-base) var(--ease);
  background: var(--color-surface);
}
.drop-zone:hover {
  border-color: var(--color-brand);
  background: var(--color-brand-soft);
}
.drop-zone-icon {
  font-size: var(--text-2xl);
  color: var(--color-brand);
  margin-bottom: var(--space-2);
  display: block;
}
.drop-zone-title {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
}
.drop-zone-sub {
  font-size: var(--text-xs);
  color: var(--color-text-3);
  margin-top: var(--space-1);
}

/* =============================================================================
   PREMIUM DARK THEME — glass, glow, gradient (loaded LAST so it wins)
   ============================================================================= */

/* Glass-morphism card variant — for hero panels, brain stats, etc. */
.card-glass {
  background: rgba(255, 255, 255, 0.03);
  -webkit-backdrop-filter: blur(14px) saturate(160%);
  backdrop-filter: blur(14px) saturate(160%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

/* Gradient brand text — for hero headings ("Scripts Studio", "Pipeline", etc.) */
.text-gradient,
.text-gradient-brand {
  background: var(--grad-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

/* Hero page header — bigger, bolder, gradient */
.page-title {
  font-size: var(--text-4xl);
  font-weight: var(--weight-extrabold);
  letter-spacing: var(--tracking-tighter);
  line-height: var(--leading-tight);
  margin-bottom: var(--space-2);
}
.page-subtitle {
  font-size: var(--text-md);
  color: var(--color-text-2);
  margin-bottom: var(--space-6);
}

/* =============================================================================
   DARK MODE OVERRIDES — kick in only when html[data-theme="dark"]
   These use !important to win over component-level inline styles.
   Functionality untouched — only colors.
   ============================================================================= */

[data-theme="dark"] .card,
[data-theme="dark"] .card-dark,
[data-theme="dark"] .scene-card,
[data-theme="dark"] .stat-card,
[data-theme="dark"] .stat-tile {
  background: var(--color-surface) !important;
  border-color: var(--color-border) !important;
  color: var(--color-text);
}

[data-theme="dark"] .card:hover,
[data-theme="dark"] .stat-tile:hover,
[data-theme="dark"] .stat-card:hover {
  border-color: rgba(91, 94, 244, 0.30) !important;
  box-shadow: 0 0 0 1px rgba(91, 94, 244, 0.18), 0 8px 24px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .card-interactive:hover {
  border-color: var(--color-brand) !important;
  box-shadow: var(--shadow-brand) !important;
  transform: var(--lift);
}
[data-theme="dark"] .card-selected {
  border-color: var(--color-brand) !important;
  box-shadow: var(--shadow-brand), var(--shadow-glow) !important;
}

/* Force inputs/selects/textareas dark — beats inline browser defaults */
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="url"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="password"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="search"],
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .input {
  background: #0F0F17 !important;
  border-color: rgba(255, 255, 255, 0.12) !important;
  color: var(--color-text) !important;
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--color-text-3) !important; }

[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  border-color: var(--color-brand) !important;
  box-shadow: var(--ring-brand) !important;
}

/* Custom select arrow on dark */
[data-theme="dark"] select {
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A1A1AA' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") !important;
  background-repeat: no-repeat !important;
  background-position: right 12px center !important;
  padding-right: 36px !important;
}

/* Sidebar — already dark via tokens, but add brand glow on active item */
[data-theme="dark"] .sidebar {
  background: linear-gradient(180deg, #0E0E16 0%, #0A0A0F 100%);
  border-right-color: rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] .sidebar-item.active {
  background: linear-gradient(90deg, rgba(91, 94, 244, 0.18) 0%, rgba(91, 94, 244, 0.06) 100%);
  color: #E4E4FF;
  box-shadow: inset 3px 0 0 var(--color-brand), 0 0 24px -8px rgba(91, 94, 244, 0.4);
}
[data-theme="dark"] .sidebar-item i { font-size: var(--text-lg); }
[data-theme="dark"] .sidebar-item:hover { background: rgba(255, 255, 255, 0.04); }

/* Topbar glass */
[data-theme="dark"] .topbar,
[data-theme="dark"] .nav-bar {
  background: rgba(10, 10, 15, 0.72);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  backdrop-filter: blur(20px) saturate(180%);
  border-color: rgba(255, 255, 255, 0.06);
}

/* Tab bar — glass background with brand-glow active state */
[data-theme="dark"] .tab-bar {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: var(--space-1);
  gap: var(--space-1);
}
[data-theme="dark"] .tab-bar-item {
  border-radius: var(--radius-sm);
  border-bottom: none !important;
  padding: var(--space-2) var(--space-4);
  margin-bottom: 0;
}
[data-theme="dark"] .tab-bar-item.active {
  background: var(--grad-brand);
  color: #fff !important;
  box-shadow: 0 4px 14px rgba(91, 94, 244, 0.40);
}
[data-theme="dark"] .tab-bar-item:hover:not(.active) { background: rgba(255, 255, 255, 0.04); color: var(--color-text); }

/* Buttons — bigger gradient lift for the accent CTA */
[data-theme="dark"] .btn-accent {
  background: var(--grad-brand);
  color: #fff !important;
  border: none;
  box-shadow: 0 8px 24px rgba(91, 94, 244, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
[data-theme="dark"] .btn-accent:hover {
  transform: var(--lift);
  box-shadow: 0 14px 32px rgba(91, 94, 244, 0.50), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  filter: brightness(1.05);
}

[data-theme="dark"] .btn-primary {
  background: var(--grad-brand);
  color: #fff;
  box-shadow: 0 6px 18px rgba(91, 94, 244, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.16);
}
[data-theme="dark"] .btn-primary:hover { filter: brightness(1.08); transform: var(--lift); }

[data-theme="dark"] .btn-secondary {
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text);
  border: 1px solid rgba(255, 255, 255, 0.10);
}
[data-theme="dark"] .btn-secondary:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.18);
}

[data-theme="dark"] .btn-ghost { color: var(--color-text-2); }
[data-theme="dark"] .btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--color-text); }

/* Drop zone — glass with brand glow */
[data-theme="dark"] .drop-zone {
  background: rgba(255, 255, 255, 0.02);
  border-color: rgba(255, 255, 255, 0.14);
}
[data-theme="dark"] .drop-zone:hover {
  background: rgba(91, 94, 244, 0.06);
  border-color: var(--color-brand);
  box-shadow: var(--shadow-glow);
}

/* Modal — glass backdrop */
[data-theme="dark"] .modal-overlay {
  background: rgba(5, 5, 10, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  backdrop-filter: blur(16px) saturate(160%);
}
[data-theme="dark"] .modal-box {
  background: linear-gradient(180deg, #16161E 0%, #11111A 100%);
  border: 1px solid rgba(255, 255, 255, 0.10);
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.70), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* Info boxes / prompt boxes — proper dark surfaces */
[data-theme="dark"] .info-box { background: rgba(255, 255, 255, 0.03); }
[data-theme="dark"] .prompt-box { border-color: rgba(255, 255, 255, 0.10); }
[data-theme="dark"] .prompt-box-header,
[data-theme="dark"] .prompt-box-body { background: rgba(255, 255, 255, 0.025); }

/* Score badge — keep colored variants but darken neutrals */
[data-theme="dark"] .score-badge.none { background: rgba(255, 255, 255, 0.06); color: var(--color-text-3); }

/* Loading screen */
[data-theme="dark"] .loading-screen { background: var(--color-bg); }

/* Generic killer override — anything inline-styled white becomes surface */
[data-theme="dark"] [style*="background: white"],
[data-theme="dark"] [style*="background:white"],
[data-theme="dark"] [style*="background: #fff"],
[data-theme="dark"] [style*="background:#fff"],
[data-theme="dark"] [style*="background-color: white"],
[data-theme="dark"] [style*="background-color:white"],
[data-theme="dark"] [style*="background-color: #fff"],
[data-theme="dark"] [style*="background-color:#fff"],
[data-theme="dark"] [style*="background: #FFF"],
[data-theme="dark"] [style*="background:#FFF"] {
  background: var(--color-surface) !important;
  background-color: var(--color-surface) !important;
  color: var(--color-text);
}
[data-theme="dark"] [style*="background: #fafafa"],
[data-theme="dark"] [style*="background:#fafafa"],
[data-theme="dark"] [style*="background: #FAFAFA"],
[data-theme="dark"] [style*="background: #f4f4f5"],
[data-theme="dark"] [style*="background: #F4F4F5"],
[data-theme="dark"] [style*="background: #f5f5f5"],
[data-theme="dark"] [style*="background: #F5F5F5"] {
  background: var(--color-surface-2) !important;
  background-color: var(--color-surface-2) !important;
}

/* =============================================================================
   ANIMATIONS
   ============================================================================= */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse { 50% { opacity: 0.4; } }
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.fade-in { animation: fadeIn 0.2s ease; }
.slide-in { animation: slideInRight 0.25s ease; }
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-2) 25%, var(--color-surface) 50%, var(--color-surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-md);
}

/* =============================================================================
   UTILITIES
   ============================================================================= */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-base); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--color-text-3); }
.font-medium { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold { font-weight: var(--weight-bold); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid { display: grid; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.overflow-hidden { overflow: hidden; }
.relative { position: relative; }
.absolute { position: absolute; }

/* --- Loading Screen --- */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  gap: var(--space-6);
  background: var(--color-bg);
}
.loading-screen h1 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-extrabold);
  color: var(--color-text);
  letter-spacing: var(--tracking-tighter);
}

/* --- Range Slider --- */
input[type="range"] {
  -webkit-appearance: none;
  height: 4px;
  background: var(--color-surface-2);
  border-radius: var(--radius-pill);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: var(--radius-pill);
  background: var(--color-brand);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* --- Checkbox --- */
input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--color-brand);
  cursor: pointer;
}

/* --- Table --- */
table { width: 100%; border-collapse: collapse; }
th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  text-align: left;
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border-strong);
}
td {
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-base);
}
tr:hover td { background: var(--color-surface-2); }

/* =============================================================================
   RESPONSIVE GRID
   ============================================================================= */
.r-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.r-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.r-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.r-grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: var(--space-3); }

/* =============================================================================
   RESPONSIVE
   ============================================================================= */
@media (max-width: 1440px) {
  .stage { padding: var(--space-6) var(--space-8); }
  .stage.no-sidebar { padding: var(--space-6) var(--space-8); max-width: 960px; }
}

@media (max-width: 1280px) {
  :root { --sidebar-w: 220px; }
  .stage { padding: var(--space-5) var(--space-6); }
  .stage.no-sidebar { max-width: 860px; }
  .btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--text-base); }
  .r-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1024px) {
  :root { --sidebar-w: 56px; --topbar-h: 50px; --navbar-h: 50px; }
  .sidebar { width: var(--sidebar-w); }
  .sidebar-brand > div > div:last-child { display: none; }
  .sidebar-item span, .sidebar-item:not(i) { font-size: 0; }
  .sidebar-item { justify-content: center; padding: var(--space-3); }
  .sidebar-item i { font-size: var(--text-lg); margin: 0; }
  .sidebar-footer { display: none; }
  .sidebar-nav .section-header { display: none; }
  .stage { padding: var(--space-4) var(--space-5); }
  .stage.no-sidebar { max-width: 780px; }
  .modal-box { max-width: 520px; width: 94%; padding: var(--space-6); }
  .card { padding: var(--space-4); }
  .card-dark { padding: var(--space-4); }
  .stat-grid, .stat-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .r-grid-2 { grid-template-columns: 1fr; }
  .r-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .r-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .prompt-box-body { max-height: 200px; font-size: var(--text-xs); }
}
