/* ── Majordomo V2.1 – UI ── */

:root {
  --sidebar-w: 240px;
  --sidebar-bg: #1a1d23;
  --sidebar-hover: #272b33;
  --sidebar-active: #6366f1;
  --sidebar-text: #9ca3af;
  --sidebar-text-bright: #f3f4f6;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-secondary: #6b7280;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--surface-alt);
  color: var(--text);
  margin: 0;
  min-height: 100vh;
}

/* ── Sidebar ── */

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
}

.sidebar-brand {
  padding: 24px 20px 20px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--sidebar-text-bright);
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand i { font-size: 1.4rem; color: var(--accent-light); }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all .15s ease;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
}
.sidebar-link.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.35);
}
.sidebar-link i { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  color: rgba(255,255,255,.3);
  font-size: 0.75rem;
}

/* ── Mobile ── */

.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--sidebar-bg);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 1030;
}
.topbar-brand { color: var(--sidebar-text-bright); font-weight: 600; font-size: 1.05rem; }

.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1035;
  display: none;
}
.sidebar-backdrop.open { display: block; }

@media (min-width: 992px) {
  .topbar { display: none !important; }
}

/* ── Main content ── */

.main-content {
  margin-left: var(--sidebar-w);
  padding: 32px 36px;
  min-height: 100vh;
}

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding-top: 72px; }
}

/* ── Page headers ── */

.page-header {
  margin-bottom: 28px;
}
.page-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.page-header p {
  color: var(--text-secondary);
  margin: 4px 0 0;
  font-size: 0.9rem;
}

/* ── Stat cards ── */

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s, transform .2s;
}
.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.stat-card .stat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  margin-bottom: 10px;
}
.stat-card .stat-value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
}
.stat-card .stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 3px;
}

.explorer-pill { border-radius: 8px; }
.explorer-pill-indigo  { background: #eef2ff; }
.explorer-pill-emerald { background: #ecfdf5; }

.stat-icon.indigo  { background: #eef2ff; color: #6366f1; }
.stat-icon.emerald { background: #ecfdf5; color: #10b981; }
.stat-icon.sky     { background: #f0f9ff; color: #0ea5e9; }
.stat-icon.amber   { background: #fffbeb; color: #f59e0b; }
.stat-icon.violet  { background: #f5f3ff; color: #8b5cf6; }

/* ── Cards ── */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card-header {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 0.875rem;
}

/* ── Tables ── */

.table {
  font-size: 0.875rem;
  --bs-table-bg: var(--surface);
}
.table thead th {
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom-width: 2px;
  padding: 10px 14px;
}
.table tbody td {
  padding: 10px 14px;
  vertical-align: middle;
}
.table-hover tbody tr:hover { background: #f3f4ff; }

.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.table-wrapper .table { margin-bottom: 0; }

/* ── Badges ── */

.badge-pass {
  background: #dcfce7 !important; color: #166534 !important;
  font-weight: 600; font-size: 0.75rem;
}
.badge-fail {
  background: #fee2e2 !important; color: #991b1b !important;
  font-weight: 600; font-size: 0.75rem;
}
.badge-na {
  background: #f3f4f6 !important; color: #6b7280 !important;
  font-weight: 600; font-size: 0.75rem;
}

.badge-basic { background: #dbeafe !important; color: #1e40af !important; font-weight: 600; font-size: 0.75rem; }
.badge-intermediate { background: #fef3c7 !important; color: #92400e !important; font-weight: 600; font-size: 0.75rem; }
.badge-advanced { background: #fae8ff !important; color: #86198f !important; font-weight: 600; font-size: 0.75rem; }

/* ── Code / pre ── */

pre, .code-block {
  font-family: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;
  font-size: 0.8rem;
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px 18px;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.6;
  border: 1px solid #313244;
}

.hash-prefix {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
  color: var(--accent);
  background: #eef2ff;
  padding: 2px 8px;
  border-radius: 4px;
}

/* ── Forms ── */

.form-control, .form-select {
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.875rem;
  padding: 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}

textarea.prompt-editor {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  min-height: 280px;
  background: #1e1e2e;
  color: #cdd6f4;
  border: 1px solid #313244;
  line-height: 1.6;
}
textarea.prompt-editor:focus {
  background: #1e1e2e;
  color: #cdd6f4;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.2);
}

.form-label {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  margin-bottom: 6px;
}

/* ── Buttons ── */

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 8px 20px;
  transition: all .15s;
}
.btn-primary:hover {
  background: #4f46e5;
  border-color: #4f46e5;
  box-shadow: 0 2px 8px rgba(99,102,241,.35);
}

.btn-outline-secondary {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.82rem;
}

.btn-outline-primary {
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
}

/* ── Empty states ── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}
.empty-state i {
  font-size: 2.5rem;
  color: #d1d5db;
  margin-bottom: 12px;
  display: block;
}
.empty-state p {
  font-size: 0.9rem;
  margin: 0;
}

/* ── Section titles ── */

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 28px 0 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title i { color: var(--accent); font-size: 1rem; }

/* ── Dashboard sections ── */

.dashboard-section {
  margin-bottom: 28px;
}

/* ── Heatmap (GitHub-style) ── */

.heatmap-scroll { overflow-x: auto; }

.heatmap-grid {
  display: grid;
  grid-template-columns: 40px repeat(24, 1fr);
  gap: 3px;
  align-items: center;
  min-width: 500px;
}

.heatmap-cell {
  aspect-ratio: 1;
  border-radius: 3px;
  min-width: 0;
  cursor: default;
  outline: 1px solid rgba(27, 31, 36, .04);
  outline-offset: -1px;
  transition: outline-color .1s;
}
.heatmap-cell:hover {
  outline: 2px solid var(--text-secondary);
  outline-offset: -1px;
}

.heatmap-level-0 { background: #ebedf0; }
.heatmap-level-1 { background: #c6cef7; }
.heatmap-level-2 { background: #9ba4f0; }
.heatmap-level-3 { background: #7578e8; }
.heatmap-level-4 { background: var(--accent); }

.heatmap-day-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-align: right;
  padding-right: 6px;
  line-height: 1;
}

.heatmap-hour-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  text-align: center;
  padding-bottom: 2px;
  white-space: nowrap;
}

.heatmap-legend {
  display: flex;
  align-items: center;
  gap: 3px;
  margin-top: 14px;
  justify-content: flex-end;
}

.heatmap-legend-cell {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  outline: 1px solid rgba(27, 31, 36, .04);
  outline-offset: -1px;
}

/* ── Rule columns (dashboard) ── */

.rule-col-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  font-size: 0.82rem;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.rule-col-header i { font-size: 1rem; }

.rule-col-improved  { color: #10b981; }
.rule-col-improved i { color: #10b981; }
.rule-col-attention { color: #f59e0b; }
.rule-col-attention i { color: #f59e0b; }

.rule-col-body { padding: 0; }

.rule-col-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.rule-col-row:last-child { border-bottom: none; }

.rule-col-row code {
  font-size: 0.8rem;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 4px;
}

.rule-col-empty {
  color: var(--text-secondary);
  min-height: 42px;
}

/* ── Status badges ── */

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
}
.status-pending  { background: #f3f4f6; color: #6b7280; }
.status-running  { background: #eef2ff; color: var(--accent); }
.status-done     { background: #dcfce7; color: #166534; }
.status-skipped  { background: #fef9c3; color: #854d0e; }
.status-error    { background: #fee2e2; color: #991b1b; }

/* ── Topic pills (V2.1) ── */

.topic-pill {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  border: none;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  background: var(--surface);
  color: var(--text-secondary);
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.topic-pill:hover {
  background: #eef2ff;
  color: var(--accent);
}
.topic-pill.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}

/* ── Topic mixed state indicator ── */
.topic-mixed-icon {
  color: #f59e0b;
  font-size: .7rem;
  margin-left: 2px;
  vertical-align: middle;
}

/* ── Topic cards (settings page — V2.1) ── */

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.topic-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  transition: border-color .2s, box-shadow .2s;
}

.topic-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.topic-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.topic-card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0;
}

.topic-card .level-counts {
  display: flex;
  gap: 6px;
  font-size: 0.72rem;
  margin-top: 6px;
}

.level-count {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
}

/* ── Toggle switch ── */

.form-switch-lg .form-check-input {
  width: 2.5em;
  height: 1.4em;
}

/* ── Feedback preview ── */

.feedback-preview {
  line-height: 1.65;
  font-size: 0.9rem;
}

.feedback-preview h1,
.feedback-preview h2,
.feedback-preview h3 {
  margin-top: 16px;
  margin-bottom: 8px;
}

.feedback-preview ul,
.feedback-preview ol {
  padding-left: 24px;
  margin-bottom: 12px;
}

/* ── Dev mode (amber theme) ── */

body.dev-mode {
  --sidebar-bg: #291c09;
  --sidebar-hover: #3d2a10;
  --sidebar-active: #f59e0b;
  --accent: #d97706;
  --accent-light: #f59e0b;
}

body.dev-mode .sidebar-link.active {
  box-shadow: 0 2px 8px rgba(245,158,11,.35);
}

body.dev-mode .btn-primary {
  background: var(--accent);
  border-color: var(--accent);
}
body.dev-mode .btn-primary:hover {
  background: #b45309;
  border-color: #b45309;
  box-shadow: 0 2px 8px rgba(245,158,11,.35);
}

body.dev-mode .table-hover tbody tr:hover { background: #fffbeb; }

body.dev-mode .form-control:focus,
body.dev-mode .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217,119,6,.15);
}

body.dev-mode .heatmap-level-1 { background: #fde68a; }
body.dev-mode .heatmap-level-2 { background: #fbbf24; }
body.dev-mode .heatmap-level-3 { background: #f59e0b; }
body.dev-mode .heatmap-level-4 { background: #d97706; }

body.dev-mode .topic-pill:hover { background: #fffbeb; color: var(--accent); }
body.dev-mode .topic-pill.active {
  box-shadow: 0 2px 8px rgba(245,158,11,.3);
}
body.dev-mode .topic-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(217,119,6,.12);
}

.prod-badge {
  display: inline-flex;
  align-items: center;
  background: #22c55e;
  color: #052e16;
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 7px;
  border-radius: 4px;
  margin-left: 6px;
}

.dev-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f59e0b;
  color: #451a03;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 10px;
  border-radius: 4px;
}

/* ── Submission Detail: Metric Pills ── */

.metric-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .78rem;
  color: var(--text-secondary);
}
.metric-pill strong {
  color: var(--text-primary);
  font-weight: 700;
}

/* ── Submission Detail: Topic Aggregate Badges ── */

.topic-agg {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: .78rem;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}
.topic-agg strong { font-size: .8rem; }
.topic-agg span { font-weight: 600; color: var(--text-secondary); }
.topic-agg-perfect {
  border-color: #bbf7d0;
  background: #f0fdf4;
}
.topic-agg-perfect span { color: #16a34a; }
.topic-agg-warn {
  border-color: #fecaca;
  background: #fef2f2;
}
.topic-agg-warn span { color: #dc2626; }

/* ── Submission Detail: Rule Groups ── */

.rule-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  overflow: hidden;
}
.rule-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: var(--surface-alt);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.rule-group-header::-webkit-details-marker { display: none; }
.rule-group[open] .rule-group-header .bi-chevron-down {
  transform: rotate(180deg);
}
.rule-group-body {
  padding: 4px 0;
}

/* ── Submission Detail: Rule Rows ── */

.rule-row-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  font-size: .82rem;
}
.rule-row-compact:hover {
  background: var(--surface-alt);
}
.rule-result-icon {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  font-size: .85rem;
}
.rule-name-compact {
  font-size: .78rem;
  font-family: var(--font-mono);
  color: var(--text-primary);
  background: none;
  padding: 0;
}

/* ── Submission Detail: Level Badges ── */

.badge-basic {
  background: #dbeafe;
  color: #1d4ed8;
}
.badge-intermediate {
  background: #fef3c7;
  color: #92400e;
}
.badge-advanced {
  background: #fce7f3;
  color: #9d174d;
}
.badge-pass {
  background: #dcfce7;
  color: #16a34a;
}
.badge-fail {
  background: #fee2e2;
  color: #dc2626;
}

/* ── Submission Detail: Feedback Preview ── */

.feedback-preview {
  font-size: .85rem;
  line-height: 1.6;
}
.feedback-preview h1, .feedback-preview h2, .feedback-preview h3 {
  font-size: 1rem;
  margin-top: 12px;
}

/* ── Pipeline Output Pre Blocks ── */

.pipeline-pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px;
  border-radius: 8px;
  font-size: .82rem;
  font-family: var(--font-mono);
  max-height: 500px;
  overflow: auto;
  margin: 0;
  border: none;
  line-height: 1.65;
}

/* Full Shabang preset button */
.full-shabang-btn {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border: none;
  font-size: .78rem;
  font-weight: 600;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: .02em;
  transition: opacity .2s, transform .1s;
}
.full-shabang-btn:hover {
  opacity: .9;
  color: #fff;
  transform: scale(1.02);
}
.full-shabang-btn:active {
  transform: scale(.98);
}

/* ── Dark Mode ── */

[data-bs-theme="dark"] {
  --surface: #1e1e2e;
  --surface-alt: #181825;
  --border: #313244;
  --text: #cdd6f4;
  --text-secondary: #a6adc8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow-md: 0 4px 6px rgba(0,0,0,.25), 0 2px 4px rgba(0,0,0,.15);
  color-scheme: dark;
}

[data-bs-theme="dark"] body {
  background: var(--surface-alt);
  color: var(--text);
}

[data-bs-theme="dark"] .table-hover tbody tr:hover { background: #262637; }
[data-bs-theme="dark"] .heatmap-level-0 { background: #313244; }

[data-bs-theme="dark"] .badge-pass { background: #1a3a2a !important; color: #4ade80 !important; }
[data-bs-theme="dark"] .badge-fail { background: #3a1a1a !important; color: #f87171 !important; }
[data-bs-theme="dark"] .badge-na { background: #313244 !important; color: #a6adc8 !important; }
[data-bs-theme="dark"] .badge-basic { background: #1e2a4a !important; color: #93c5fd !important; }
[data-bs-theme="dark"] .badge-intermediate { background: #3a2e1a !important; color: #fcd34d !important; }
[data-bs-theme="dark"] .badge-advanced { background: #3a1a3a !important; color: #f0abfc !important; }

[data-bs-theme="dark"] .explorer-pill-indigo  { background: #2a2a4a; color: #cdd6f4; }
[data-bs-theme="dark"] .explorer-pill-emerald { background: #1a3a2a; color: #cdd6f4; }

[data-bs-theme="dark"] .stat-icon.indigo  { background: #2a2a4a; color: #a5b4fc; }
[data-bs-theme="dark"] .stat-icon.emerald { background: #1a3a2a; color: #6ee7b7; }
[data-bs-theme="dark"] .stat-icon.sky     { background: #1a2a3a; color: #7dd3fc; }
[data-bs-theme="dark"] .stat-icon.amber   { background: #3a2e1a; color: #fcd34d; }
[data-bs-theme="dark"] .stat-icon.violet  { background: #2a1a3a; color: #c4b5fd; }

[data-bs-theme="dark"] .hash-prefix { background: #2a2a4a; color: var(--accent-light); }
[data-bs-theme="dark"] .topic-pill { background: var(--surface); color: var(--text-secondary); }
[data-bs-theme="dark"] .topic-pill:hover { background: #2a2a4a; color: var(--accent-light); }

[data-bs-theme="dark"] .status-pending { background: #313244; color: #a6adc8; }
[data-bs-theme="dark"] .status-running { background: #2a2a4a; color: var(--accent-light); }
[data-bs-theme="dark"] .status-done { background: #1a3a2a; color: #4ade80; }
[data-bs-theme="dark"] .status-skipped { background: #3a3520; color: #fbbf24; }
[data-bs-theme="dark"] .status-error { background: #3a1a1a; color: #f87171; }

[data-bs-theme="dark"] .metric-pill { background: #262637; border-color: #313244; }
[data-bs-theme="dark"] .topic-agg { background: #262637; border-color: #313244; }
[data-bs-theme="dark"] .topic-agg-perfect { background: #1a3a2a; border-color: #2a5a3a; }
[data-bs-theme="dark"] .topic-agg-warn { background: #3a1a1a; border-color: #5a2a2a; }

[data-bs-theme="dark"] .rule-group-header { background: #262637; }
[data-bs-theme="dark"] .rule-row-compact:hover { background: #262637; }
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background: #262637;
  border-color: #313244;
  color: var(--text);
}

[data-bs-theme="dark"] .empty-state i { color: #585b70; }

/* Dark mode dev-mode overrides */
[data-bs-theme="dark"] body.dev-mode {
  --sidebar-bg: #1a1508;
}
[data-bs-theme="dark"] body.dev-mode .table-hover tbody tr:hover { background: #2a2510; }
[data-bs-theme="dark"] body.dev-mode .topic-pill:hover { background: #2a2510; }
[data-bs-theme="dark"] body.dev-mode .heatmap-level-1 { background: #5a4a1a; }
[data-bs-theme="dark"] body.dev-mode .heatmap-level-2 { background: #7a6a2a; }
[data-bs-theme="dark"] body.dev-mode .heatmap-level-3 { background: #9a7a1a; }
[data-bs-theme="dark"] body.dev-mode .heatmap-level-4 { background: #d97706; }

/* Theme toggle button */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  background: none;
  color: var(--sidebar-text);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  width: 100%;
  transition: all .15s ease;
}
.theme-toggle:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-bright);
}
.theme-toggle i { font-size: 1.1rem; width: 20px; text-align: center; }

/* ── Mobile Improvements ── */

@media (max-width: 991.98px) {
  .main-content {
    padding: 16px 14px;
    padding-top: 72px;
  }

  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px;
  }
  .page-header h2 { font-size: 1.25rem; }

  /* Stat cards stack */
  .stat-card .stat-value { font-size: 1.4rem; }

  /* Tables scroll horizontally */
  .table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrapper .table {
    min-width: 600px;
  }
  .table-wrapper .table-wide {
    min-width: 800px;
  }

  /* Process page: stack filter row vertically */
  .process-filters {
    flex-direction: column;
    align-items: stretch !important;
  }
  .process-filters .ms-auto {
    margin-left: 0 !important;
    justify-content: space-between;
    width: 100%;
  }

  /* Topic grid single column */
  .topic-grid {
    grid-template-columns: 1fr;
  }

  /* Heatmap scroll hint */
  .heatmap-scroll {
    margin: 0 -14px;
    padding: 0 14px;
  }

  /* Forms full width */
  .prompt-editor {
    min-height: 200px;
  }
}

@media (max-width: 575.98px) {
  .main-content {
    padding: 12px 10px;
    padding-top: 66px;
  }

  .page-header h2 { font-size: 1.1rem; }

  .d-flex.flex-wrap.gap-3 {
    gap: 8px !important;
  }

  /* Compact stat pills */
  .stat-card {
    padding: 14px 16px;
  }
  .stat-card .stat-value { font-size: 1.2rem; }
}

/* ── Utility ── */
