/* TrackHalal Premium Design System v4.0 — Billion-Dollar Quality */
/* Qistara Trust Design System — Inspired by Stripe, Linear, Notion, Vercel */
/* v4.0 April 14, 2026 — 4-Lane Design Debate (Grok 42/100 → targeting 90+) */
/* Grok: "Fix typography, shadows, hover states, focus rings, spacing rhythm" */

:root {
  --bg: #ffffff;
  --bg-subtle: #f8f9fa;
  --bg-app: #f1f3f5;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --surface-elevated: #ffffff;
  --border: #e2e5e9;
  --border-light: #edf0f3;
  --text: #111827;
  --text-secondary: #4b5563;
  --muted: #6b7280;
  --label: #9ca3af;
  --primary: #059669;
  --primary-light: #d1fae5;
  --primary-dark: #047857;
  --primary-gradient: linear-gradient(to bottom, #059669, #047857);
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --success: #059669;
  --success-light: #ecfdf5;
  --warning: #d97706;
  --warning-light: #fffbeb;
  --error: #dc2626;
  --error-light: #fef2f2;
  --radius-sm: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.03);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --shadow: 0 2px 4px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.03);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-xl: 0 8px 24px rgba(0,0,0,0.08), 0 4px 8px rgba(0,0,0,0.04);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --transition-fast: 0.12s ease-out;
  --transition: 0.2s ease-out;
}

/* v4.0 Typography Scale (Grok: "Vercel hierarchy") */
:root {
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;
}

/* v4.0 Focus Ring (Grok: "Accessibility — Apple HIG") */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* v4.0 Micro-interactions (Grok: "Stripe delight") */
button, .card, .tier-card, a[class] {
  transition: transform var(--transition-fast), box-shadow var(--transition), background var(--transition-fast), color var(--transition-fast);
}
button:hover:not(:disabled) { transform: translateY(-1px); }
.card:hover, .tier-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-xl); }

/* v5.0 Dark Mode — COMPLETE FIX (founder feedback: text invisible, cards broken) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --bg-subtle: #0f172a;
    --bg-app: #1e293b;
    --surface: #1e293b;
    --surface-hover: #334155;
    --surface-elevated: #1e293b;
    --border: #334155;
    --border-light: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --muted: #94a3b8;
    --label: #64748b;
    --primary-light: rgba(5, 150, 105, 0.15);
    --success-light: rgba(5, 150, 105, 0.12);
    --warning-light: rgba(217, 119, 6, 0.12);
    --error-light: rgba(220, 38, 38, 0.12);
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
    --shadow: 0 2px 4px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.5);
    --shadow-xl: 0 8px 24px rgba(0,0,0,0.6);
  }

  /* FORCE dark backgrounds on ALL cards, details, and white surfaces */
  .card, .tier-card, .template-card, .testimonial, .stat-card,
  .summary-card, .dossier-card, .cert-card, .supplier-card,
  .action-card, .result-card, .delta-product, .product-card,
  .alt-card, .problem-card, .fix-suggestion, .sw-card,
  details, .audit-form, .opp-form, .risk-form, .sim-form,
  .step1-form, .sub-form, .cmp-col, .sc-input input,
  [style*="background: white"], [style*="background:white"],
  [style*="background:#fff"], [style*="background: #fff"] {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
  }

  /* Fix text visibility inside cards */
  .card *, .tier-card *, .template-card *, .testimonial *,
  .stat-card *, .summary-card *, .action-card *, details *,
  .audit-form *, .opp-form *, .sim-form *, .cmp-col * {
    color: inherit;
  }

  /* Fix muted text in dark mode */
  .tier-desc, .tier-name-zh, .form-hint, .template-en,
  .cert-meta, .supplier-meta, .dossier-meta, .product-meta,
  .result-meta, .alt-why, .alt-notes, .alt-suppliers,
  [style*="color:var(--muted)"], [style*="color: var(--muted)"] {
    color: #94a3b8 !important;
  }

  /* Fix input/textarea in dark mode */
  input, textarea, select {
    background: #0f172a !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
  }

  /* Fix table in dark mode */
  table, th, td, .price-table, .usage-table {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
  }
  th { background: #005F4B !important; color: white !important; }
  tr:nth-child(even) { background: #0f172a !important; }

  /* Fix FAQ details/summary */
  details summary { color: #f1f5f9 !important; }
  details p { color: #cbd5e1 !important; }

  /* Fix pricing featured card */
  .tier-card.featured, .tier-card.recommended, .tier-card.popular {
    border: 2px solid #D4AF37 !important;
    box-shadow: 0 0 20px rgba(212, 175, 55, 0.15) !important;
  }
  .tier-card.featured .tier-price { color: #D4AF37 !important; }

  /* Fix CTA buttons visibility */
  .tier-btn, .go-btn, .run-btn, .cmp-btn, .opp-btn, .simulate-btn {
    background: linear-gradient(to bottom, #059669, #047857) !important;
    color: white !important;
  }
  .tier-btn.gold, .cta-btn, .unlock-btn {
    background: linear-gradient(to bottom, #D4AF37, #B8941F) !important;
    color: #ffffff !important;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  }

  /* Fix testimonial quotes */
  .testimonial q, .testimonial .q-zh, blockquote {
    color: #e2e8f0 !important;
  }

  /* Fix "What We Believe" and similar section cards */
  .trust-card, [class*="believe"], [class*="value-card"] {
    background: #1e293b !important;
    color: #f1f5f9 !important;
  }

  /* Fix team avatars */
  .team-card, [class*="team"] {
    background: #1e293b !important;
    color: #f1f5f9 !important;
  }

  /* Fix flow comparison cards */
  .flow-col.old { background: rgba(220, 38, 38, 0.1) !important; border-color: #dc2626 !important; }
  .flow-col.new { background: rgba(5, 150, 105, 0.1) !important; border-color: #059669 !important; }
  .flow-col h3 { color: inherit !important; }
  .flow-step { color: #cbd5e1 !important; }

  /* Fix the opp card */
  .opp-card { background: linear-gradient(135deg, #005F4B, #004636) !important; color: white !important; }

  /* Fix nav in dark mode */
  #trackhalal-nav { background: rgba(15, 23, 42, 0.95) !important; border-color: #334155 !important; }
  .th-nav-brand strong { color: #f1f5f9 !important; }
  .th-nav-dropdown-menu { background: #1e293b !important; border-color: #334155 !important; }
  .th-nav-dropdown-menu a { color: #cbd5e1 !important; }
  .th-nav-dropdown-menu a:hover { background: #334155 !important; color: #059669 !important; }

  /* Fix auth-guard overlay */
  #trackhalal-auth-overlay { background: rgba(15, 23, 42, 0.96) !important; }
  .trackhalal-auth-card { background: #1e293b !important; border-color: #334155 !important; color: #f1f5f9 !important; }

  /* Fix section titles */
  .section-title, h1, h2, h3 { color: #f1f5f9 !important; }

  /* Fix footer */
  .site-footer, .footer-demo { background: #0f172a !important; color: #94a3b8 !important; }

  /* v5.1: NUCLEAR dark mode — catch ALL remaining white backgrounds */
  [style*="background: white"],
  [style*="background:white"],
  [style*="background: #fff"],
  [style*="background:#fff"],
  [style*="background: #ffffff"],
  [style*="background:#ffffff"],
  [style*="background-color: white"],
  [style*="background-color:white"] {
    background: #1e293b !important;
    color: #f1f5f9 !important;
  }

  /* v5.1: Fix ALL inline dark text colors */
  [style*="color:#111"],
  [style*="color: #111"],
  [style*="color:#1a1a1a"],
  [style*="color: #1a1a1a"],
  [style*="color:#374151"],
  [style*="color: #374151"],
  [style*="color:#111827"],
  [style*="color: #111827"] {
    color: #f1f5f9 !important;
  }

  /* v5.1: Fix paywall partial overlay for dark mode */
  #th-paywall-partial {
    background: linear-gradient(to bottom, transparent, rgba(15,23,42,0.98) 30%, #0f172a) !important;
  }
  #th-paywall-partial h3 { color: #ffffff !important; }
  #th-paywall-partial p { color: #94a3b8 !important; }

  /* v5.1: Fix monospace code in textareas looking ugly */
  textarea {
    font-family: var(--font) !important;
    font-size: 0.82rem !important;
    line-height: 1.6 !important;
  }

  /* v5.1: Fix login card */
  .login-card {
    background: #1e293b !important;
    color: #f1f5f9 !important;
    box-shadow: 0 24px 48px rgba(0,0,0,0.4) !important;
  }
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
  font-family: var(--font);
  background: var(--bg-subtle);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 20px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(48px, env(safe-area-inset-bottom));
}

/* Header */
.header {
  padding: 32px 0 20px;
  margin-bottom: 24px;
}
.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.header h1 {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  margin-bottom: 4px;
}
.header p {
  font-size: 0.85rem;
  color: var(--muted);
}

/* Cards — Premium Elevated Surface */
.card {
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card:hover {
  box-shadow: var(--shadow-lg);
}
.card-header {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

/* Inputs */
label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  margin-bottom: 14px;
  font-family: var(--font);
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(5,150,105,0.12);
}
textarea { min-height: 80px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.btn-primary {
  background: var(--primary-gradient);
  color: white;
  border: 1px solid var(--primary-dark);
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.1);
  transition: all var(--transition-fast);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.1);
}
.btn-primary:active { transform: translateY(0); box-shadow: var(--shadow-xs); }
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--primary); color: var(--primary); }
.btn-gold {
  background: linear-gradient(to bottom, #D4AF37, #B8941F);
  color: #1a1a1a;
  border: 1px solid #B8941F;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.25);
  font-weight: 700;
  transition: all var(--transition-fast);
}
.btn-gold:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,0.3);
  background: linear-gradient(to bottom, #E0BD45, #C9A22A);
}

/* Grid */
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Footer */
.footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}

/* Status badges */
.badge {
  display: inline-flex;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}
.badge-green { background: var(--success-light); color: var(--success); }
.badge-amber { background: var(--warning-light); color: var(--warning); }
.badge-red { background: var(--error-light); color: var(--error); }

/* Check items */
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
}
.check-item:last-child { border-bottom: none; }
.check-item input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--primary);
  width: 16px;
  height: 16px;
}
.check-item span { font-size: 0.84rem; flex: 1; color: var(--text-secondary); }

/* Score/Progress */
.score-bar {
  height: 6px;
  background: var(--border-light);
  border-radius: 3px;
  overflow: hidden;
}
.score-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease; }

/* Brand */
.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  margin-bottom: 16px;
}
.brand-row.center { justify-content: center; }
.brand-row img {
  width: 28px;
  height: 28px;
  display: block;
}
.brand-row .brand-wordmark {
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text);
  line-height: 1;
}
.brand-row .brand-wordmark span {
  font-weight: 500;
  color: var(--text-secondary);
}
.brand-row.inverse .brand-wordmark {
  color: #f4fff9;
}
.brand-row.inverse .brand-wordmark span {
  color: rgba(244,255,249,0.82);
}
.logo-mark {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
}
.logo-mark span { color: var(--text); }

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; box-shadow: var(--shadow-sm); }
.stat-num { font-size: 1.6rem; font-weight: 800; }
.stat-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 2px; }

/* Document items */
.doc-item { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; transition: all 0.2s; }
.doc-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.doc-item.uploaded { border-color: rgba(5,150,105,0.3); background: var(--success-light); }
.doc-item.required { border-left: 3px solid var(--error); }
.doc-icon { font-size: 1.4rem; width: 36px; text-align: center; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 0.84rem; font-weight: 600; color: var(--text); }
.doc-desc { font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.doc-status { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; padding: 3px 10px; border-radius: 20px; flex-shrink: 0; }
.status-pending { background: var(--warning-light); color: var(--warning); }
.status-uploaded { background: var(--success-light); color: var(--success); }
.status-missing { background: var(--error-light); color: var(--error); }
.upload-btn { background: none; border: 1px solid var(--border); color: var(--primary); padding: 5px 14px; border-radius: var(--radius-sm); font-size: 0.74rem; cursor: pointer; font-weight: 600; flex-shrink: 0; transition: all 0.2s; }
.upload-btn:hover { border-color: var(--primary); background: var(--primary-light); }

/* Progress */
.progress { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.progress-bar { flex: 1; height: 8px; background: var(--border-light); border-radius: 4px; margin: 0 12px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }
.progress-text { font-size: 0.78rem; font-weight: 700; white-space: nowrap; }

/* Timeline */
.timeline-item { display: flex; gap: 12px; padding: 8px 0; font-size: 0.8rem; align-items: flex-start; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: var(--primary); }
.timeline-text { color: var(--muted); flex: 1; }
.timeline-time { color: var(--muted); font-size: 0.7rem; white-space: nowrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; padding: 10px 8px; border-bottom: 2px solid var(--border); }
td { padding: 12px 8px; border-bottom: 1px solid var(--border-light); font-size: 0.84rem; }
tr:hover { background: var(--surface-hover); }

/* Sections */
.section { margin-bottom: 20px; }
.section-title { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--primary); margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border-light); }
.critical { color: var(--error); font-size: 0.6rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; margin-left: 8px; background: var(--error-light); padding: 1px 6px; border-radius: 4px; }
.gate { padding: 16px; border-radius: var(--radius); text-align: center; margin-top: 16px; }
.add-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 12px; }
.sku-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.sku-row .remove { background: none; border: none; color: var(--error); cursor: pointer; font-size: 1.2rem; padding: 8px; }
.hidden { display: none; }

/* Responsive */
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .add-row { grid-template-columns: 1fr; }
  .shell { padding: 16px; }
  .header h1 { font-size: 1.3rem; }
}

/* ─── Skeleton Loading States ──────────────────────────────── */
.skeleton { animation: skeleton-shimmer 1.5s ease-in-out infinite; background: linear-gradient(90deg, var(--border-light) 25%, var(--border) 50%, var(--border-light) 75%); background-size: 200% 100%; border-radius: var(--radius-sm); }
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skeleton-row { display: flex; gap: 12px; margin-bottom: 10px; }
.skeleton-row .skeleton { flex: 1; height: 16px; }
.skeleton-card { height: 80px; border-radius: var(--radius); margin-bottom: 12px; }
@keyframes skeleton-shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ─── Live Status Indicators ──────────────────────────────── */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.status-dot.live { background: var(--success); animation: status-pulse 2s infinite; }
.status-dot.warning { background: var(--warning); animation: status-pulse 2s infinite; }
.status-dot.error { background: var(--error); animation: status-pulse 1.5s infinite; }
.status-dot.idle { background: var(--label); }
@keyframes status-pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.2); } }

.status-badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; }
.status-badge.success { background: var(--success-light); color: var(--success); }
.status-badge.warning { background: var(--warning-light); color: var(--warning); }
.status-badge.error { background: var(--error-light); color: var(--error); }
.status-badge.info { background: var(--primary-light); color: var(--primary); }
.status-badge.neutral { background: var(--bg-subtle); color: var(--muted); border: 1px solid var(--border); }

/* ─── Progress Bars ───────────────────────────────────────── */
.progress-track { width: 100%; height: 8px; background: var(--border-light); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease-out; background: var(--primary-gradient); }
.progress-fill.warning { background: linear-gradient(90deg, var(--warning), #b45309); }
.progress-fill.error { background: linear-gradient(90deg, var(--error), #991b1b); }

/* ─── Data Cards ──────────────────────────────────────────── */
.data-grid { display: grid; gap: 12px; margin: 16px 0; }
.data-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.data-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.data-grid.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
@media (max-width: 640px) { .data-grid.cols-3, .data-grid.cols-4 { grid-template-columns: 1fr 1fr; } }

.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-card .metric-value { font-size: 1.6rem; font-weight: 900; color: var(--text); line-height: 1; }
.metric-card .metric-label { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-top: 4px; }
.metric-card .metric-change { font-size: 0.72rem; font-weight: 700; margin-top: 4px; }
.metric-card .metric-change.up { color: var(--success); }
.metric-card .metric-change.down { color: var(--error); }

/* ─── Timestamp / Activity ────────────────────────────────── */
.timestamp { font-size: 0.68rem; color: var(--label); }
.activity-feed { display: flex; flex-direction: column; gap: 8px; }
.activity-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border-light); font-size: 0.78rem; }
.activity-item:last-child { border-bottom: none; }

/* ─── Toast Notifications ─────────────────────────────────── */
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 9998; padding: 12px 20px; border-radius: var(--radius); font-size: 0.82rem; font-weight: 600; box-shadow: var(--shadow-xl); animation: toast-in 0.3s ease-out; }
.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--error); color: white; }
.toast.warning { background: var(--warning); color: white; }
@keyframes toast-in { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ─── Premium Micro-Interactions ──────────────────────────── */

/* Page load fade-in */
.shell { animation: page-fade-in 0.3s ease-out; }
@keyframes page-fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Card hover lift */
.card { transition: box-shadow var(--transition), transform var(--transition); }
.card:hover { box-shadow: var(--shadow-lg); }

/* Input focus ring */
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5,150,105,0.12); transition: all var(--transition-fast); }

/* Button focus visible (accessibility) */
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Link hover */
a { transition: color var(--transition-fast); }

/* Tab smooth transition */
.tab-btn { transition: all var(--transition-fast); }

/* Metric card number count-up feel */
.metric-value { transition: color var(--transition); }

/* Badge subtle pulse on appear */
.header-badge { animation: badge-pop 0.4s ease-out; }
@keyframes badge-pop { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

/* Success checkmark bounce */
@keyframes check-bounce { 0% { transform: scale(0); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }

/* Smooth scroll */
html { scroll-behavior: smooth; }

/* ─── Mobile Responsive Fixes ─────────────────────────────── */
@media (max-width: 768px) {
  /* Stack all multi-column grids */
  .data-grid.cols-3, .data-grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .row { grid-template-columns: 1fr; }

  /* Contain table overflow */
  .doc-table, .cert-table, .param-table, .summary-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Enforce touch targets */
  .btn, select, input, textarea { min-height: 44px; }

  /* Nav adjustments */
  .shell { padding: 16px 14px; }
  .header h1 { font-size: 1.3rem; }
  .header p { font-size: 0.78rem; }

  /* Card spacing */
  .card { padding: 14px; }
  .metric-card { padding: 12px; }
  .metric-card .metric-value { font-size: 1.2rem; }

  /* Toast bottom-safe */
  .toast { bottom: max(20px, env(safe-area-inset-bottom)); right: 14px; left: 14px; }
}

@media (max-width: 480px) {
  .data-grid.cols-2, .data-grid.cols-3, .data-grid.cols-4 { grid-template-columns: 1fr; }
  .header h1 { font-size: 1.15rem; }
  .filter-bar { flex-direction: column; }
  .filter-bar select, .filter-bar input { width: 100%; }
}

/* Backward compatibility aliases for old var names */
:root {
  --red: var(--error);
  --red-dim: var(--error-light);
  --green: var(--success);
  --green-dim: var(--success-light);
  --amber: var(--warning);
  --amber-dim: var(--warning-light);
  --accent-dim: var(--primary-light);
  --text-bright: var(--text);
}

/* v5.2: Codex QA fixes — more dark mode overrides */
@media (prefers-color-scheme: dark) {
  .delta-card, .impact-card, .winner-banner,
  .hook-card, .upgrade-box, .success-card,
  .flow-col, .opp-form, .risk-form, .sub-form,
  .sc-input, .cmp-form, .sim-form {
    background: #1e293b !important;
    border-color: #334155 !important;
    color: #f1f5f9 !important;
  }
  .winner-banner.a, .winner-banner.b { background: rgba(5,150,105,0.12) !important; }
  .winner-banner.tie { background: rgba(217,119,6,0.12) !important; }
  .delta-card.before { background: rgba(220,38,38,0.1) !important; }
  .delta-card.after { background: rgba(5,150,105,0.1) !important; }
  .hook-card.grade { background: #1e293b !important; }

  /* Fix locked paywall overlay for dark mode */
  #th-paywall-overlay > div { background: rgba(15,23,42,0.98) !important; }
  #th-paywall-overlay h2 { color: #f1f5f9 !important; }
  #th-paywall-overlay p { color: #94a3b8 !important; }

  /* v5.3: Full nuclear dark mode sweep — kill ALL hardcoded whites */
  .btn-ghost { background: var(--surface) !important; color: var(--text-secondary) !important; }
  .btn-ghost:hover { background: var(--surface-hover) !important; color: var(--primary) !important; }

  /* Select dropdown icon visibility */
  select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E") !important;
  }

  /* Kill ALL inline background:white via attribute selectors */
  [style*="background:white"], [style*="background: white"],
  [style*="background:#fff"], [style*="background: #fff"],
  [style*="background:#ffffff"], [style*="background: #ffffff"],
  [style*="background-color:white"], [style*="background-color: white"],
  [style*="background-color:#fff"], [style*="background-color: #fff"] {
    background: var(--surface) !important;
    color: var(--text) !important;
  }

  /* Kill hardcoded dark text colors that become invisible */
  [style*="color:#333"], [style*="color: #333"],
  [style*="color:#222"], [style*="color: #222"],
  [style*="color:#111"], [style*="color: #111"],
  [style*="color:black"], [style*="color: black"] {
    color: var(--text) !important;
  }
  [style*="color:#666"], [style*="color: #666"],
  [style*="color:#555"], [style*="color: #555"],
  [style*="color:#6b7280"], [style*="color: #6b7280"],
  [style*="color:#4b5563"], [style*="color: #4b5563"] {
    color: var(--text-secondary) !important;
  }

  /* Tier cards, pricing cards, form cards — universal dark surface */
  .tier-card, .pricing-card, .card,
  .stat-card, .team-card, .step-card,
  .trust-card, .process-card, .faq-card,
  .market-option, .market-card,
  details, summary {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
  }

  /* Ensure all card inner text is readable */
  .tier-card h3, .tier-card h4, .tier-card p, .tier-card li,
  .card h3, .card h4, .card p, .card li,
  .stat-card h3, .stat-card p,
  .team-card h3, .team-card p,
  details p, details li {
    color: var(--text) !important;
  }

  /* Fix tier card selected state */
  .tier-card.selected, .tier-card.popular {
    background: rgba(5,150,105,0.08) !important;
    border-color: var(--primary) !important;
  }

  /* Testimonial cards */
  .testimonial { background: var(--surface) !important; border-color: var(--border) !important; }

  /* Table fixes */
  table, th, td, tr { border-color: var(--border) !important; }
  tr:nth-child(even) { background: var(--bg) !important; }
  tr:hover { background: var(--surface-hover) !important; }

  /* Input/form backgrounds */
  input, select, textarea {
    background: var(--bg) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
  }

  /* CRM and admin specific */
  .crm-card, .lead-card, .alert-card, .error-card,
  .review-card, .portal-card, .analytics-card {
    background: var(--surface) !important;
    border-color: var(--border) !important;
    color: var(--text) !important;
  }

  /* v5.4: Kill hardcoded semantic light backgrounds — use dark-safe rgba versions */
  [style*="background:#ecfdf5"], [style*="background: #ecfdf5"] {
    background: rgba(5,150,105,0.1) !important;
  }
  [style*="background:#fffbeb"], [style*="background: #fffbeb"] {
    background: rgba(217,119,6,0.1) !important;
  }
  [style*="background:#fff7ed"], [style*="background: #fff7ed"] {
    background: rgba(234,88,12,0.1) !important;
  }

  /* Status badges & banners in <style> blocks */
  .winner-banner.a, .winner-banner.b,
  .result-status.compliant, .overall-banner.ready,
  .overall-banner.status-ready, .status-pill.compliant,
  .status-pill.approved, .vs-badge.positive,
  .dossier-status.sealed, .product-status.compliant,
  .risk-badge.low, .alt-badge.lower, .job-completed,
  .badge-ready, .safe-result, .fix-suggestion,
  .upgrade-box.after, .flow-col.new, .endpoint-badge,
  .tip, #success-msg {
    background: rgba(5,150,105,0.1) !important;
    border-color: rgba(5,150,105,0.3) !important;
  }

  .winner-banner.tie, .result-status.needs_review,
  .overall-banner.partial, .overall-banner.status-partial,
  .status-pill.needs_review, .status-pill.pending,
  .dossier-status.pending, .product-status.needs_review,
  .risk-badge.medium, .alt-badge.higher,
  .badge-partial, .hazard-card, .next-step,
  .tier-badge.gold, .deadline, .finding-card.high,
  .finding-card.review {
    background: rgba(217,119,6,0.1) !important;
    border-color: rgba(217,119,6,0.3) !important;
  }

  .severity-pill.error, .severity-pill.warning,
  .risk-badge.high, .priority-badge.high,
  .change-tag.sec, .hazard-card.high {
    background: rgba(234,88,12,0.1) !important;
    border-color: rgba(234,88,12,0.3) !important;
  }

  /* Save badge in pricing table */
  .price-table .save {
    background: linear-gradient(to bottom, #D4AF37, #B8941F) !important;
    color: #1a1a1a !important;
  }
}
