/* ═══════════════════════════════════════════════════════════════
   Watchmaking Supply Chain Intelligence — Premium Design System
   Inspired by Linear · Vercel · Stripe · Tailwind UI
   ═══════════════════════════════════════════════════════════════

   Table of Contents:
   §1  Variables — Light (default) + Dark theme
   §2  Base & Reset
   §3  Typography & Font Features
   §4  Scrollbar
   §5  Animations & Keyframes
   §6  Auth Overlay
   §7  Loading Screen
   §8  App Header
   §9  Navigation (Main + Micro + Meso tabs)
   §10 Views & Layout
   §11 Cards & Shadows
   §12 Section Titles
   §13 KPI Cards
   §14 Segment Cards
   §15 Chart Cards
   §16 Alert Banners
   §17 Correlation Cards
   §18 Prediction Cards
   §19 Meso Controls & Entity Banner
   §20 Risk Gauge & Insight Cards
   §21 Reorder Cards
   §22 Timeline
   §23 Badges & Status Pills
   §24 Data Tables
   §25 Nano View
   §26 What-If Simulator
   §27 Buttons & Interactive Elements
   §28 Skeleton Loading
   §29 Responsive Breakpoints
   ═══════════════════════════════════════════════════════════════ */


/* ── §1 Variables ─────────────────────────────────────────────── */

:root {
  /* Backgrounds — Light default (Slate scale) */
  --bg-primary:    #f1f5f9;
  --bg-card:       #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-input:      #ffffff;
  --bg-chart:      #f8fafc;
  --bg-header:     linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  --bg-glass:      rgba(255, 255, 255, 0.82);
  --bg-toggle:     #f1f5f9;

  /* Borders */
  --border:        #e2e8f0;
  --border-light:  #f1f5f9;

  /* Text — Slate scale */
  --text-primary:   #0f172a;
  --text-secondary: #334155;
  --text-muted:     #64748b;
  --text-faint:     #94a3b8;

  /* Accent */
  --accent:        #3b82f6;
  --accent-bg:     rgba(59, 130, 246, 0.10);
  --accent-ring:   rgba(59, 130, 246, 0.15);

  /* Brand */
  --gold:          #c9a84c;
  --gold-bg:       rgba(201, 168, 76, 0.10);
  --gold-border:   rgba(201, 168, 76, 0.20);

  /* Semantic */
  --green:         #22c55e;
  --green-bg:      #dcfce7;
  --green-text:    #166534;
  --red:           #ef4444;
  --red-bg:        #fee2e2;
  --red-text:      #b91c1c;
  --amber:         #f59e0b;
  --amber-bg:      #fef3c7;
  --amber-text:    #92400e;
  --blue:          #3b82f6;
  --blue-bg:       #dbeafe;
  --blue-text:     #1e40af;
  --purple:        #a855f7;
  --teal:          #2dd4bf;
  --indigo:        #6366f1;
  --pink:          #ec4899;

  /* Chart palette */
  --chart-1: #3b82f6;
  --chart-2: #22c55e;
  --chart-3: #6366f1;
  --chart-4: #a855f7;
  --chart-5: #ec4899;
  --chart-6: #f59e0b;
  --chart-7: #2dd4bf;
  --chart-8: #f97316;
  --chart-9: #60a5fa;
  --chart-10: #fb7185;

  /* Shadows — Slate 900 tinted */
  --sh-0: none;
  --sh-1: 0 2px 8px -2px rgba(15, 23, 42, 0.03);
  --sh-2: 0 4px 12px -2px rgba(15, 23, 42, 0.04);
  --sh-3: 0 8px 20px -4px rgba(15, 23, 42, 0.10);
  --sh-4: 0 8px 24px -4px rgba(15, 23, 42, 0.10);
  --sh-5: 0 12px 32px rgba(15, 23, 42, 0.12);
  --sh-6: 0 20px 25px rgba(0, 0, 0, 0.10);

  /* Radii */
  --r-xs:  6px;
  --r-sm:  8px;
  --r-md:  10px;
  --r-lg:  12px;
  --r-xl:  14px;
  --r-2xl: 16px;
  --r-3xl: 20px;
  --r-pill: 9999px;

  /* Transitions */
  --t-fast:   0.2s ease;
  --t-med:    0.3s ease;
  --t-slow:   0.4s ease-out;
}

/* ── Dark Mode ────────────────────────────────────────────────── */

body.dark {
  --bg-primary:    #0f172a;
  --bg-card:       #1e293b;
  --bg-card-hover: #334155;
  --bg-input:      #1e293b;
  --bg-chart:      #0f172a;
  --bg-header:     linear-gradient(135deg, #020617 0%, #0f172a 100%);
  --bg-glass:      rgba(15, 23, 42, 0.82);
  --bg-toggle:     rgba(255, 255, 255, 0.08);

  --border:        #334155;
  --border-light:  rgba(255, 255, 255, 0.06);

  --text-primary:   #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted:     #94a3b8;
  --text-faint:     #64748b;

  --accent-bg:     rgba(59, 130, 246, 0.15);
  --accent-ring:   rgba(59, 130, 246, 0.25);

  --gold-bg:       rgba(201, 168, 76, 0.12);
  --gold-border:   rgba(201, 168, 76, 0.25);

  --green-bg:      rgba(34, 197, 94, 0.12);
  --green-text:    #4ade80;
  --red-bg:        rgba(239, 68, 68, 0.12);
  --red-text:      #fca5a5;
  --amber-bg:      rgba(245, 158, 11, 0.12);
  --amber-text:    #fbbf24;
  --blue-bg:       rgba(59, 130, 246, 0.12);
  --blue-text:     #93c5fd;

  --sh-1: 0 2px 8px -2px rgba(0, 0, 0, 0.20);
  --sh-2: 0 4px 12px -2px rgba(0, 0, 0, 0.25);
  --sh-3: 0 8px 20px -4px rgba(0, 0, 0, 0.30);
  --sh-4: 0 8px 24px -4px rgba(0, 0, 0, 0.30);
  --sh-5: 0 12px 32px rgba(0, 0, 0, 0.35);
  --sh-6: 0 20px 25px rgba(0, 0, 0, 0.40);
}


/* ── §2 Base & Reset ──────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 13px;
  line-height: 1.55;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--accent-bg);
  color: var(--text-primary);
}


/* ── §3 Typography & Font Features ────────────────────────────── */

.tnum, .kpi-val, .data-table .amt-col, .whatif-impact-value,
.risk-gauge-score, .nano-stat strong, .info-pill-count {
  font-feature-settings: "tnum";
}


/* ── §4 Scrollbar ─────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--r-md); }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }


/* ── §5 Animations & Keyframes ────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(5px); }
}

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

@keyframes pulse-badge {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.9); }
  to   { opacity: 1; transform: scale(1); }
}

.shake { animation: shake 0.35s ease; }


/* ── §6 Auth Overlay ──────────────────────────────────────────── */

#auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease, visibility 0.4s;
}

#auth-overlay.fade-out {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-box {
  background: #ffffff;
  padding: 32px 40px;
  border-radius: var(--r-2xl);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  text-align: center;
  width: 92%;
  max-width: 400px;
  animation: modalPop 0.4s ease-out;
}

.auth-icon {
  font-size: 34px;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 10px rgba(201, 168, 76, 0.25));
}

.auth-title {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.3px;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: #94a3b8;
  margin-bottom: 28px;
}

#auth-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: #ffffff;
  color: #0f172a;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

#auth-input::placeholder { color: #94a3b8; }

#auth-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.auth-error {
  color: #ef4444;
  font-size: 12px;
  font-weight: 500;
  margin-top: 10px;
  min-height: 18px;
  opacity: 0;
  transition: opacity var(--t-fast);
}

.auth-error:not(:empty) { opacity: 1; }


/* ── §7 Loading Screen ────────────────────────────────────────── */

#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-wrap { text-align: center; }

.loader-ring {
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.06);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

.loader-text {
  font-size: 13px;
  font-weight: 500;
  color: #cbd5e1;
  margin-bottom: 18px;
  letter-spacing: 0.3px;
}

.loader-bar {
  width: 200px;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  margin: 0 auto;
}

.loader-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #93c5fd);
  border-radius: 2px;
  transition: width 0.3s;
}


/* ── §8 App Header ────────────────────────────────────────────── */

#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 54px;
  background: var(--bg-header);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.hdr-left { display: flex; align-items: center; gap: 10px; }

.hdr-icon { font-size: 20px; color: #cbd5e1; }

.hdr-title {
  font-size: 15px;
  font-weight: 700;
  color: #f1f5f9;
  letter-spacing: -0.3px;
}

.hdr-badge {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 3px 8px;
  border-radius: var(--r-xs);
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
  animation: pulse-badge 2s ease-in-out infinite;
}

.hdr-right { display: flex; align-items: center; gap: 14px; }

.hdr-time { font-size: 11px; color: #94a3b8; }

.theme-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--r-md);
  cursor: pointer;
  color: #cbd5e1;
  font-size: 16px;
  line-height: 1;
  transition: all var(--t-fast);
}

.theme-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.2);
  transform: scale(1.08);
}


/* ── §9 Navigation ────────────────────────────────────────────── */

/* Main nav — sits below the dark header */
#main-nav {
  display: flex;
  gap: 0;
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  position: sticky;
  top: 54px;
  z-index: 99;
}

.nav-btn {
  position: relative;
  padding: 12px 24px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: color var(--t-fast);
  letter-spacing: 0.2px;
}

.nav-btn:hover { color: var(--text-primary); }

.nav-btn.active { color: var(--accent); }

.nav-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 12px;
  right: 12px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
}

/* Micro sub-nav */
.micro-nav {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.micro-tab {
  padding: 10px 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-fast);
}

.micro-tab:hover { color: var(--text-primary); }
.micro-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.micro-panel { display: none; animation: fadeUp 0.25s ease; }
.micro-panel.active { display: block; }

/* Meso analytics tabs */
.analytics-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.a-tab {
  padding: 10px 22px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--t-fast);
}

.a-tab:hover { color: var(--text-primary); }
.a-tab.active { color: var(--accent); border-bottom-color: var(--accent); }


/* ── §10 Views & Layout ───────────────────────────────────────── */

.view {
  display: none;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.view.active { display: block; }


/* ── §11 Cards & Shadows ──────────────────────────────────────── */

/* Card base style applied to most containers */
.chart-card,
.corr-card,
.pred-card,
.entity-banner,
.risk-gauge-wrap,
.insight-card,
.reorder-card,
.tl-item,
.whatif-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-3xl);
  box-shadow: var(--sh-2);
  opacity: 0;
  transform: translateY(12px);
  animation: fadeIn 0.4s ease-out forwards;
  transition: box-shadow var(--t-med), transform var(--t-med), border-color var(--t-med);
}

/* Hover lift for interactive cards */
.segment-card:hover,
.corr-card:hover,
.pred-card:hover,
.chart-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-3);
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-3);
}


/* ── §12 Section Titles ───────────────────────────────────────── */

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 28px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}


/* ── §13 KPI Cards ────────────────────────────────────────────── */

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

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-2xl);
  padding: 20px;
  box-shadow: var(--sh-2);
  position: relative;
  overflow: hidden;
  transition: all var(--t-med);
  opacity: 0;
  transform: translateY(12px);
  animation: fadeIn 0.4s ease-out forwards;
}

/* Accent left border strip (§26) */
.kpi-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--r-2xl) 0 0 var(--r-2xl);
  background: var(--accent);
}

.kpi-card.s-ok::before    { background: var(--green); }
.kpi-card.s-warn::before  { background: var(--amber); }
.kpi-card.s-crit::before  { background: var(--red); }

.kpi-val {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  font-feature-settings: "tnum";
}

.kpi-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 6px;
}

.kpi-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-faint);
  margin-top: 3px;
}

.kpi-sub .up   { color: var(--green); font-weight: 600; }
.kpi-sub .down { color: var(--red); font-weight: 600; }


/* ── §14 Segment Cards ────────────────────────────────────────── */

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

.segment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-3xl);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--sh-2);
  position: relative;
  overflow: hidden;
  transition: all var(--t-med);
  opacity: 0;
  transform: translateY(12px);
  animation: fadeIn 0.4s ease-out forwards;
}

.segment-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent);
  opacity: 0;
  transition: opacity var(--t-med);
}

.segment-card:hover::before { opacity: 1; }

.seg-icon { font-size: 24px; margin-bottom: 10px; }

.seg-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.seg-stats { display: flex; flex-direction: column; gap: 4px; }

.seg-stat { font-size: 12px; color: var(--text-secondary); }
.seg-stat strong { color: var(--text-primary); font-weight: 600; }


/* ── §15 Chart Cards ──────────────────────────────────────────── */

.chart-grid { display: grid; gap: 16px; margin-bottom: 24px; }
.chart-grid.g2 { grid-template-columns: repeat(2, 1fr); }
.chart-grid.g3 { grid-template-columns: repeat(3, 1fr); }

.chart-card {
  padding: 20px;
}

.cc-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.cc-body {
  position: relative;
  height: 260px;
  background: var(--bg-chart);
  border: 1px solid var(--border-light);
  border-radius: var(--r-xl);
  padding: 12px;
}


/* ── §16 Alert Banners ────────────────────────────────────────── */

.alert-banner {
  background: linear-gradient(135deg, #fef2f2, #fff1f2);
  border: 1px solid #fecdd3;
  border-radius: var(--r-xl);
  padding: 14px 18px;
  margin-bottom: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  animation: fadeIn 0.4s ease-out forwards;
}

.alert-banner strong {
  display: block;
  margin-bottom: 6px;
  color: var(--red-text);
  font-size: 13px;
}

.alert-banner ul { padding-left: 18px; margin-top: 6px; }
.alert-banner li { color: var(--text-secondary); margin-bottom: 3px; font-size: 12px; }

.alert-banner.alert-error {
  background: var(--red-bg);
  border-color: #fecaca;
  color: var(--red-text);
}

body.dark .alert-banner {
  background: linear-gradient(135deg, #450a0a, #4c0519);
  border-color: #881337;
  color: #fecdd3;
}

body.dark .alert-banner strong { color: #fca5a5; }
body.dark .alert-banner li { color: #fecdd3; }


/* ── §17 Correlation Cards ────────────────────────────────────── */

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

.corr-card {
  padding: 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.corr-pct {
  min-width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  flex-shrink: 0;
  font-feature-settings: "tnum";
}

.corr-title { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.corr-desc { font-size: 11px; color: var(--text-secondary); margin-bottom: 8px; line-height: 1.55; }
.corr-tags { display: flex; gap: 5px; flex-wrap: wrap; }

.corr-tag {
  font-size: 9px;
  padding: 3px 8px;
  border-radius: var(--r-pill);
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}


/* ── §18 Prediction Cards ─────────────────────────────────────── */

.pred-summary {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.pred-card { padding: 18px; }

.pred-card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.pred-field { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.pred-field strong { color: var(--text-primary); }
.pred-action { font-size: 12px; color: var(--accent); margin-top: 8px; font-weight: 500; }
.pred-cost { font-size: 11px; color: var(--text-faint); margin-top: 4px; }


/* ── §19 Meso Controls & Entity Banner ────────────────────────── */

.meso-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.meso-type-btns {
  display: flex;
  gap: 2px;
  background: var(--bg-toggle);
  border-radius: var(--r-md);
  padding: 3px;
}

.meso-type {
  padding: 8px 18px;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--r-sm);
  transition: all var(--t-fast);
}

.meso-type:hover {
  color: var(--text-primary);
}

.meso-type.active {
  color: var(--text-primary);
  background: var(--bg-card);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.meso-select {
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  cursor: pointer;
  min-width: 260px;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2364748b' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.meso-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

/* Meso Content */
.meso-content { min-height: 300px; }
.meso-placeholder { text-align: center; padding: 80px 20px; color: var(--text-faint); font-size: 14px; }

/* Entity Banner */
.entity-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 18px 20px;
}

.entity-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--r-lg);
  background: var(--accent-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.entity-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.entity-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.entity-meta span { margin-right: 14px; }


/* ── §20 Risk Gauge & Insight Cards ───────────────────────────── */

.risk-gauge-wrap {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 20px;
  padding: 20px;
}

.risk-gauge-score {
  font-size: 36px;
  font-weight: 700;
  min-width: 70px;
  text-align: center;
  font-feature-settings: "tnum";
}

.risk-gauge-info { flex: 1; }
.risk-gauge-label { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }

.risk-gauge-bar {
  flex: 1;
  height: 10px;
  background: var(--bg-primary);
  border-radius: var(--r-pill);
  overflow: hidden;
}

.risk-gauge-fill {
  height: 100%;
  border-radius: var(--r-pill);
  transition: width 0.6s ease;
}

/* Insights & Factors */
.insight-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.insight-card {
  padding: 16px;
  border-left: 4px solid var(--accent);
  border-radius: var(--r-xl);
}

.insight-card.sev-critical { border-left-color: var(--red); }
.insight-card.sev-high     { border-left-color: var(--amber); }
.insight-card.sev-medium   { border-left-color: var(--gold); }
.insight-card.sev-low      { border-left-color: var(--blue); }
.insight-title { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.insight-desc  { font-size: 12px; color: var(--text-secondary); line-height: 1.55; }
.insight-value { font-size: 11px; color: var(--text-faint); margin-top: 6px; }


/* ── §21 Reorder Cards ────────────────────────────────────────── */

.reorder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.reorder-card {
  padding: 16px;
  border-left: 4px solid var(--border);
  border-radius: var(--r-xl);
}

.reorder-card.urg-critical { border-left-color: var(--red); }
.reorder-card.urg-high     { border-left-color: var(--amber); }
.reorder-card.urg-medium   { border-left-color: var(--gold); }
.reorder-hdr { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.reorder-details { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.reorder-notes   { font-size: 12px; color: var(--text-faint); font-style: italic; }


/* ── §22 Timeline ─────────────────────────────────────────────── */

.timeline { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.tl-item {
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  border-left: 4px solid var(--border);
  border-radius: var(--r-xl);
}

.tl-item.sev-critical { border-left-color: var(--red); }
.tl-item.sev-high     { border-left-color: var(--amber); }
.tl-item.sev-medium   { border-left-color: var(--gold); }
.tl-item.sev-low      { border-left-color: var(--blue); }
.tl-date   { font-size: 11px; color: var(--text-faint); min-width: 82px; font-weight: 500; }
.tl-body   { flex: 1; }
.tl-header { font-size: 12px; font-weight: 600; color: var(--text-primary); margin-bottom: 3px; }
.tl-desc   { font-size: 11px; color: var(--text-secondary); margin-bottom: 4px; line-height: 1.5; }
.tl-resolution         { font-size: 11px; color: var(--green); font-weight: 500; }
.tl-resolution.pending { color: var(--amber); }


/* ── §23 Badges & Status Pills ────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--r-pill);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Tinted background + darkened foreground (Tailwind UI pattern) */
.badge-critical  { background: var(--red-bg); color: var(--red-text); }
.badge-high      { background: var(--amber-bg); color: var(--amber-text); }
.badge-medium    { background: var(--blue-bg); color: var(--blue-text); }
.badge-low       { background: var(--green-bg); color: var(--green-text); }
.badge-ok        { background: var(--green-bg); color: var(--green-text); }
.badge-scheduled { background: var(--blue-bg); color: var(--blue-text); }


/* ── §24 Data Tables ──────────────────────────────────────────── */

.table-wrap {
  overflow: auto;
  border-radius: var(--r-3xl);
  border: 1px solid var(--border);
  max-height: 400px;
  box-shadow: var(--sh-1);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--bg-card);
}

.data-table thead th {
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: -1px;
  z-index: 1;
}

.data-table tbody td {
  padding: 8px 14px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.data-table tbody tr {
  cursor: default;
  transition: background 0.15s;
}

.data-table tbody tr:hover { background: var(--accent-bg); }

/* Numeric alignment */
.data-table .amt-col  { text-align: right; font-feature-settings: "tnum"; }
.data-table .qty-col,
.data-table .rate-col { text-align: center; font-feature-settings: "tnum"; }


/* ── §25 Nano View ────────────────────────────────────────────── */

.nano-header { margin-bottom: 20px; }

.nano-title { font-size: 20px; font-weight: 700; color: var(--text-primary); }

.nano-subtitle { font-size: 11px; font-weight: 400; color: var(--text-faint); margin-top: 4px; }

.nano-controls { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }

.nano-select,
.nano-search-input {
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), width var(--t-fast);
}

.nano-select { min-width: 230px; cursor: pointer; }

.nano-search-input {
  width: 200px;
  padding-left: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' fill='none' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7' stroke='%2394a3b8' stroke-width='2'/%3E%3Cpath d='M21 21l-4.35-4.35' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 10px center;
  background-size: 14px;
}

.nano-select:focus,
.nano-search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.nano-search-input:focus { width: 280px; }

.nano-count { font-size: 11px; color: var(--text-faint); font-weight: 500; }

#nano-table-wrap {
  max-height: 72vh;
  overflow: auto;
  border-radius: var(--r-3xl);
  border: 1px solid var(--border);
  box-shadow: var(--sh-2);
}

.nano-stats { margin-top: 14px; display: flex; gap: 18px; flex-wrap: wrap; }
.nano-stat  { font-size: 12px; color: var(--text-muted); }
.nano-stat strong { color: var(--accent); font-weight: 600; }
.no-data        { text-align: center; padding: 50px 20px; color: var(--text-faint); font-size: 14px; }
.data-truncated { text-align: center; padding: 10px; font-size: 11px; color: var(--text-faint); }


/* ── §26 What-If Simulator ────────────────────────────────────── */

.whatif-wrap { margin-bottom: 24px; }
.whatif-select-wrap { margin-bottom: 16px; }

.whatif-select-wrap select {
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  min-width: 340px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.whatif-select-wrap select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.whatif-result { padding: 22px; }

.whatif-result h4 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.whatif-desc { font-size: 12px; color: var(--text-secondary); margin-bottom: 16px; }

.whatif-impacts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.whatif-impact {
  background: var(--bg-chart);
  border: 1px solid var(--border-light);
  border-radius: var(--r-lg);
  padding: 14px;
}

.whatif-impact-label {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.whatif-impact-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 4px;
  font-feature-settings: "tnum";
}

.whatif-rec {
  background: var(--green-bg);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  font-size: 12px;
  color: var(--text-secondary);
}

body.dark .whatif-rec {
  background: rgba(34, 197, 94, 0.08);
  border-color: rgba(34, 197, 94, 0.15);
}

.whatif-placeholder { text-align: center; padding: 40px; color: var(--text-faint); font-size: 13px; }


/* ── §27 Buttons & Interactive Elements ───────────────────────── */

select:focus, input:focus { outline: none; }

.export-btn {
  padding: 6px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--t-fast);
}

.export-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}


/* ── §28 Skeleton Loading ─────────────────────────────────────── */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--border);
  border-radius: var(--r-sm);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  width: 200%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: shimmer 1.5s infinite;
}

body.dark .skeleton { background: #334155; }

body.dark .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.08), transparent);
}

.skeleton-card { height: 120px; border-radius: var(--r-2xl); }
.skeleton-bar  { height: 280px; border-radius: var(--r-xl); }
.skeleton-row  { height: 18px; width: 80%; border-radius: var(--r-sm); }


/* ── §30 Combobox (searchable single-select) ──────────────────── */

.cbx {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 36px 0 12px;
  height: 40px;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  color: var(--text-muted);
}

.cbx:focus-within,
.cbx.open {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

.cbx-search-icon {
  color: var(--text-faint);
  flex-shrink: 0;
}

.cbx-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  padding: 0;
}

.cbx-input::placeholder { color: var(--text-faint); }

.cbx-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  width: 24px;
  height: 24px;
  border-radius: var(--r-xs);
  cursor: pointer;
  display: none;
  transition: background var(--t-fast), color var(--t-fast);
}

.cbx.has-value .cbx-clear { display: inline-flex; align-items: center; justify-content: center; }
.cbx-clear:hover { background: var(--bg-card-hover); color: var(--text-primary); }

.cbx-panel {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 340px;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-4);
  z-index: 50;
  padding: 4px;
}

.cbx-group {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 10px 10px 6px;
}

.cbx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background var(--t-fast);
}

.cbx-item:hover,
.cbx-item.active {
  background: var(--accent-bg);
}

.cbx-chip {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-card-hover);
  border: 1px solid var(--border);
  border-radius: var(--r-xs);
  padding: 2px 6px;
  flex-shrink: 0;
}

.cbx-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cbx-hint  { color: var(--text-faint); font-size: 11px; flex-shrink: 0; }

.cbx-empty {
  padding: 14px 10px;
  text-align: center;
  color: var(--text-faint);
  font-size: 12px;
}


/* ── §31 Section Nav (sticky, inside Overview) ────────────────── */

.section-nav {
  position: sticky;
  top: 94px;            /* header (54) + main-nav (~40) */
  z-index: 20;
  display: flex;
  gap: 4px;
  margin: 0 -24px 20px;
  padding: 8px 24px;
  background: var(--bg-glass);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.section-nav::-webkit-scrollbar { display: none; }

.snav {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  border-radius: var(--r-pill);
  transition: all var(--t-fast);
  white-space: nowrap;
}

.snav:hover { color: var(--text-primary); background: var(--bg-card-hover); }

.snav.active {
  color: var(--accent);
  background: var(--accent-bg);
}


/* ── §32 Deep Sections (merged Micro content in Overview) ─────── */

.deep-section {
  margin-top: 48px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  scroll-margin-top: 150px;  /* keeps heading below sticky nav on anchor jump */
}

.deep-section-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
}

.deep-section-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.2px;
}

.deep-skeleton {
  padding: 32px;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
}

#sec-top { scroll-margin-top: 150px; }


/* ── §33 Meso & Nano — combobox wrappers ──────────────────────── */

.meso-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}

.meso-cbx { max-width: 520px; }

.meso-hint {
  font-size: 11px;
  color: var(--text-faint);
  padding-left: 4px;
}

.nano-cbx {
  min-width: 280px;
  flex: 0 1 320px;
}


/* ── §29 Responsive Breakpoints ───────────────────────────────── */

@media (max-width: 1024px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .chart-grid.g2, .chart-grid.g3 { grid-template-columns: 1fr; }
  .corr-grid, .pred-summary { grid-template-columns: 1fr; }
  .segment-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .view { padding: 16px; }
  #app-header { padding: 0 16px; }
  #main-nav { padding: 0 12px; overflow-x: auto; }

  .kpi-row { grid-template-columns: 1fr; }
  .segment-grid { grid-template-columns: 1fr; }
  .chart-grid.g2, .chart-grid.g3 { grid-template-columns: 1fr; }
  .corr-grid, .insight-grid, .pred-summary, .reorder-grid { grid-template-columns: 1fr; }

  .meso-cbx { max-width: 100%; }
  .entity-banner { flex-direction: column; text-align: center; }
  .risk-gauge-wrap { flex-direction: column; text-align: center; }

  .nano-search-input,
  .nano-search-input:focus { width: 100%; }
  .nano-cbx { min-width: 100%; flex: 1 1 100%; }

  .section-nav { top: 94px; padding: 6px 16px; margin: 0 -16px 16px; }
}

@media (max-width: 480px) {
  .hdr-title { font-size: 13px; }
  .hdr-badge { display: none; }
  .nav-btn { padding: 10px 14px; font-size: 11px; }
  .nano-controls { flex-direction: column; }
}
