/* =========================================================
   EcoID — Editorial data journalism dashboard
   Indonesia Macroeconomic Analysis 2026
   Created by INDIE Labs
   ========================================================= */

/* Fonts loaded via <link> in index.html: DM Serif Display + Inter + JetBrains Mono */

:root {
  /* ===== EcoID brand palette (editorial) ===== */
  --eco-red:        #C0392B;
  --eco-red-dark:   #9D2D22;
  --eco-red-soft:   #E5C4BF;
  --eco-red-tint:   #F5E7E4;

  --eco-teal:       #0F6E56;
  --eco-teal-dark:  #0A4E3C;
  --eco-teal-soft:  #BCD9D0;
  --eco-teal-tint:  #E4EFEB;

  --eco-amber:      #C48A00;
  --eco-amber-tint: #F5E9C6;

  --eco-paper:      #FAF9F6;
  --eco-paper-2:    #F2F0E9;
  --eco-paper-3:    #E8E5DA;

  --eco-ink:        #1A1A1A;
  --eco-ink-2:      #3A3A36;
  --eco-ink-3:      #6B6B64;
  --eco-ink-4:      #9A9890;
  --eco-rule:       #D8D4C7;
  --eco-rule-soft:  #E8E5DA;

  /* INDIE alignment (kept available) */
  --indie-orange-500: #F04000;
  --indie-navy-900:   #001933;

  /* Semantic */
  --bg:             var(--eco-paper);
  --bg-elev:        #FFFFFF;
  --bg-sunken:      var(--eco-paper-2);
  --bg-inverse:     var(--eco-ink);
  --fg-1:           var(--eco-ink);
  --fg-2:           var(--eco-ink-2);
  --fg-3:           var(--eco-ink-3);
  --fg-4:           var(--eco-ink-4);
  --border:         var(--eco-rule);
  --border-soft:    var(--eco-rule-soft);
  --danger:         var(--eco-red);
  --success:        var(--eco-teal);
  --warning:        var(--eco-amber);

  /* Type — DM Serif Display (headlines), Inter (body/UI), JetBrains Mono (numerals) */
  --font-display: "DM Serif Display", "Georgia", "Times New Roman", serif;
  --font-serif:   var(--font-display);
  --font-sans:    "Inter", -apple-system, BlinkMacSystemFont, system-ui, "Segoe UI", Helvetica, sans-serif;
  --font-mono:    "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;

  --fs-xs: 11px; --fs-sm: 13px; --fs-base: 15px; --fs-md: 17px;
  --fs-lg: 20px; --fs-xl: 26px; --fs-2xl: 34px; --fs-3xl: 48px;
  --fs-4xl: 64px; --fs-5xl: 88px; --fs-6xl: 128px;

  --lh-tight: 1.05; --lh-snug: 1.18; --lh-body: 1.55;

  /* Spacing */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;
  --sp-9: 96px; --sp-10: 128px;

  /* Radii — editorial = mostly sharp; small radii for chips */
  --r-0: 0;  --r-1: 2px;  --r-2: 4px;  --r-3: 8px;
  --r-pill: 999px;

  /* Shadows — quiet */
  --shadow-1: 0 1px 0 rgba(26,26,26,0.06), 0 1px 2px rgba(26,26,26,0.04);
  --shadow-2: 0 4px 16px rgba(26,26,26,0.06), 0 1px 2px rgba(26,26,26,0.04);
  --shadow-ink: 4px 4px 0 var(--eco-ink);
  --shadow-red: 4px 4px 0 var(--eco-red);
}

/* ===== Reset / base ===== */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100vw; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg-1);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "cv11", "tnum";
  text-rendering: optimizeLegibility;
}

/* Utility: scroll containers for wide tables/elements (mobile) */
.overflow-x-auto {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
h1,h2,h3,h4,h5 { margin: 0; font-weight: 600; line-height: var(--lh-snug); letter-spacing: -0.01em; }
h1.display, h2.display, h3.display, .display { line-height: var(--lh-tight); }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ===== Type primitives ===== */
.display { font-family: var(--font-display); font-weight: 800; line-height: var(--lh-tight); letter-spacing: -0.02em; }
.display-italic { font-family: var(--font-display); font-style: italic; font-weight: 500; }
.serif { font-family: var(--font-display); }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.tnum { font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }
.caps { text-transform: uppercase; letter-spacing: 0.14em; font-weight: 600; }
.caps-sm { text-transform: uppercase; letter-spacing: 0.18em; font-weight: 600; font-size: var(--fs-xs); }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-3);
}
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  font-weight: 700; color: var(--eco-red);
}
.kicker::before {
  content: ""; display: inline-block;
  width: 28px; height: 1px; background: var(--eco-red);
}

/* ===== Layout primitives ===== */
.shell { max-width: 1440px; margin: 0 auto; padding: 0 var(--sp-7); }
.grid { display: grid; gap: var(--sp-5); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }

/* ===== Top bar / nav ===== */
.topbar {
  position: sticky; top: 0; left: 0; z-index: 1000;
  width: 100%;
  background: rgba(250, 249, 246, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px var(--sp-7);
  gap: var(--sp-5);
}
.brand {
  display: flex; align-items: center; gap: 12px;
}
.brand-mark {
  width: 36px; height: 36px;
  background: var(--eco-ink); color: var(--eco-paper);
  display: grid; place-items: center;
  font-family: var(--font-display);
  font-weight: 900; font-size: 22px;
  font-style: italic;
  letter-spacing: -0.04em;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1;
}
.brand-sub {
  font-size: 11px; color: var(--fg-3);
  letter-spacing: 0.04em; line-height: 1.2;
  margin-top: 3px;
}

.navtabs { display: flex; gap: 2px; align-items: center; }
.navtab {
  background: transparent; border: 0; padding: 8px 14px;
  font-size: 13px; font-weight: 500; color: var(--fg-2);
  cursor: pointer; position: relative;
  letter-spacing: 0.02em;
  transition: color 160ms;
}
.navtab:hover { color: var(--fg-1); }
.navtab.active { color: var(--eco-red); font-weight: 600; }
.navtab.active::after {
  content: ""; position: absolute; left: 8px; right: 8px; bottom: -15px;
  height: 2px; background: var(--eco-red);
}
.navtab .num {
  display: inline-block; margin-right: 6px;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--fg-4);
}
.navtab.active .num { color: var(--eco-red); }

/* Mode toggle */
.mode-toggle {
  display: inline-flex; align-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  padding: 3px; gap: 0;
}
.mode-toggle button {
  background: transparent; border: 0;
  padding: 6px 14px;
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--fg-3);
  transition: all 160ms;
}
.mode-toggle button.on {
  background: var(--eco-ink); color: var(--eco-paper);
}
.mode-toggle .dot {
  display: inline-block;
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; margin-right: 8px;
  vertical-align: middle;
}

/* ===== Rule (hairline editorial divider) ===== */
.rule { border: 0; border-top: 1px solid var(--border); margin: 0; }
.rule-thick { border: 0; border-top: 3px solid var(--eco-ink); margin: 0; }
.rule-red { border: 0; border-top: 2px solid var(--eco-red); margin: 0; }

/* ===== Section ===== */
section.page { padding: var(--sp-8) 0; min-height: 100vh; }
section.page > .shell > header { margin-bottom: var(--sp-7); }
.sec-title {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.05;
  padding-bottom: 4px;
}
.sec-sub { color: var(--fg-3); font-size: var(--fs-md); max-width: 720px; line-height: 1.5; }

/* ===== KPI card ===== */
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 18px 20px;
  position: relative;
  transition: transform 200ms, box-shadow 200ms, border-color 200ms;
}
.kpi:hover { border-color: var(--eco-ink); }
.kpi .label {
  font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.16em; color: var(--fg-3);
  font-weight: 600;
}
.kpi .val {
  font-family: var(--font-display);
  font-size: 36px; font-weight: 700;
  line-height: 1.1; margin-top: 6px;
  letter-spacing: -0.02em;
  color: var(--fg-1);
  overflow-wrap: break-word;
}
.kpi .sub {
  margin-top: 6px;
  font-size: 12px; color: var(--fg-3);
}
.kpi .delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
  padding: 2px 8px;
  background: var(--eco-red-tint);
  color: var(--eco-red-dark);
  margin-top: 8px;
}
.kpi .delta.up { background: var(--eco-red-tint); color: var(--eco-red-dark); }
.kpi .delta.down { background: var(--eco-red-tint); color: var(--eco-red-dark); }
.kpi .delta.pos { background: var(--eco-teal-tint); color: var(--eco-teal-dark); }
.kpi .delta.neut { background: var(--eco-paper-2); color: var(--fg-3); }
.kpi .src {
  margin-top: 12px; font-size: 10px; color: var(--fg-4);
  font-family: var(--font-mono); letter-spacing: 0.02em;
}

/* Flag button (data accountability) */
.flag-btn {
  position: absolute; top: 10px; right: 10px;
  width: 24px; height: 24px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  display: grid; place-items: center;
  color: var(--fg-4);
  transition: all 160ms;
  font-size: 12px;
}
.flag-btn:hover { color: var(--eco-red); border-color: var(--eco-red); }
.flag-btn.flagged { color: var(--eco-red); border-color: var(--eco-red); background: var(--eco-red-tint); }

/* ===== Chart wrapper ===== */
.chart-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 24px;
  position: relative;
}
.chart-card .chart-header { display: flex; justify-content: space-between; align-items: start; margin-bottom: 16px; gap: 16px; }
.chart-card .chart-title {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700; letter-spacing: -0.01em;
  margin-bottom: 4px;
}
.chart-card .chart-desc { color: var(--fg-3); font-size: 13px; max-width: 540px; }
.chart-card .src-line {
  margin-top: 16px; padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 11px; color: var(--fg-3);
  display: flex; justify-content: space-between; gap: 16px;
}
.chart-card .src-line .src { font-family: var(--font-mono); font-size: 10px; color: var(--fg-4); letter-spacing: 0.02em; }

/* Tag */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; font-size: 10px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  background: var(--bg-sunken);
  color: var(--fg-2);
  border: 1px solid var(--border-soft);
}
.tag.red { background: var(--eco-red-tint); color: var(--eco-red-dark); border-color: var(--eco-red-soft); }
.tag.teal { background: var(--eco-teal-tint); color: var(--eco-teal-dark); border-color: var(--eco-teal-soft); }
.tag.amber { background: var(--eco-amber-tint); color: var(--eco-amber); border-color: var(--eco-amber); }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--eco-ink);
  background: var(--eco-ink); color: var(--eco-paper);
  letter-spacing: 0.04em;
  transition: all 160ms;
}
.btn:hover { background: var(--eco-red); border-color: var(--eco-red); }
.btn.outline { background: transparent; color: var(--eco-ink); }
.btn.outline:hover { background: var(--eco-ink); color: var(--eco-paper); }
.btn.red { background: var(--eco-red); border-color: var(--eco-red); }
.btn.red:hover { background: var(--eco-red-dark); border-color: var(--eco-red-dark); }
.btn.sm { padding: 6px 12px; font-size: 11px; }

/* ===== Tooltip ===== */
.tt {
  position: fixed; pointer-events: none;
  background: var(--eco-ink); color: var(--eco-paper);
  padding: 8px 12px; font-size: 12px;
  z-index: 99; max-width: 280px;
  box-shadow: var(--shadow-2);
  transform: translate(-50%, -120%);
  line-height: 1.4;
}
.tt .src { font-family: var(--font-mono); font-size: 10px; color: var(--eco-paper-3); margin-top: 4px; letter-spacing: 0.04em; }

/* ===== Sidebar (annotations) ===== */
.annot-backdrop {
  position: fixed; inset: 0;
  background: rgba(26, 26, 26, 0.32);
  z-index: 1099;
  opacity: 0; pointer-events: none;
  transition: opacity 220ms ease;
}
.annot-backdrop.open { opacity: 1; pointer-events: auto; }
.annot-sidebar {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: 420px; background: var(--bg-elev);
  border-left: 1px solid var(--border);
  z-index: 1100;
  box-shadow: -10px 0 40px rgba(26,26,26,0.08);
  transform: translateX(100%);
  transition: transform 280ms cubic-bezier(.22,.61,.36,1);
  display: flex; flex-direction: column;
}
.annot-sidebar.open { transform: translateX(0); }
.annot-sidebar header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.annot-sidebar .body { flex: 1; overflow-y: auto; padding: 16px 24px; }
.annot-sidebar .close { background: transparent; border: 0; font-size: 18px; color: var(--fg-3); }

.annot {
  padding: 14px 0;
  border-bottom: 1px solid var(--border-soft);
}
.annot .who { display: flex; gap: 10px; align-items: center; }
.annot .avatar {
  width: 32px; height: 32px; background: var(--eco-ink); color: var(--eco-paper);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
  font-family: var(--font-display);
}
.annot .name { font-size: 13px; font-weight: 600; }
.annot .role { font-size: 11px; color: var(--fg-3); letter-spacing: 0.02em; }
.annot .verified { color: var(--eco-teal); font-size: 11px; margin-left: 4px; }
.annot .quote { margin-top: 8px; font-size: 14px; color: var(--fg-2); line-height: 1.55; }
.annot .ref { margin-top: 6px; font-size: 11px; color: var(--fg-4); font-family: var(--font-mono); }

/* ===== Formula box (Policy mode) ===== */
.formula {
  background: var(--bg-sunken);
  border-left: 3px solid var(--eco-ink);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--fg-2);
  line-height: 1.6;
}
.formula .label {
  text-transform: uppercase; letter-spacing: 0.18em;
  font-size: 10px; color: var(--fg-3); font-weight: 700;
  margin-bottom: 4px;
}
.policy-only { display: none; }
.bayi-only { display: none; }
body[data-mode="policy"] .policy-only { display: block; }
body[data-mode="publik"] .publik-only { display: block; }
body[data-mode="policy"] .publik-only { display: none; }
body[data-mode="bayi"] .publik-only { display: none; }
body[data-mode="bayi"] .bayi-hide { display: none !important; }
/* Bayi-mode reveals: explicit display per element type so .bayi-only base
   rule properly hides them in publik/policy regardless of cascade order */
body[data-mode="bayi"] .bayi-only.bayi-card { display: flex; }
body[data-mode="bayi"] .bayi-only.bayi-hero { display: flex; }
body[data-mode="bayi"] .bayi-only:not(.bayi-card):not(.bayi-hero) { display: block; }

/* Gloss = brief explanation, shows in Publik + Policy, hidden in Bayi */
.gloss {
  display: block;
  background: var(--eco-paper-2);
  border-left: 3px solid var(--eco-ink-3);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--fg-2);
  line-height: 1.55;
  margin: 12px 0;
}
.gloss .gloss-label {
  font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase;
  font-weight: 700; color: var(--eco-red); margin-bottom: 4px; display: block;
}
.gloss strong { color: var(--eco-ink); }
.gloss em { color: var(--eco-teal-dark); font-style: normal; font-weight: 600; }
.gloss-inline {
  display: inline-block;
  border-bottom: 1px dotted var(--eco-ink-3);
  cursor: help;
  font-weight: 500;
}
body[data-mode="bayi"] .gloss { display: none; }


/* Bayi explainer card — friendly, illustrated. Display intentionally
   omitted from base rules so .bayi-only { display: none } correctly hides
   them outside Bayi mode (same-specificity cascade). */
.bayi-card {
  background: #FFFCF5;
  border: 1.5px solid var(--eco-ink);
  padding: 20px;
  gap: 20px;
  align-items: center;
  margin: 16px 0;
  box-shadow: var(--shadow-ink);
  position: relative;
}
.bayi-card::before {
  content: "👶 Bahasa Bayi";
  position: absolute;
  top: -12px; left: 16px;
  background: var(--eco-ink);
  color: var(--eco-paper);
  padding: 3px 10px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
}
.bayi-illus {
  flex-shrink: 0;
  width: 120px; height: 120px;
  background: var(--bg);
  border: 1.5px solid var(--eco-ink);
  display: grid; place-items: center;
}
.bayi-body { flex: 1; }
.bayi-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
  line-height: 1.15;
}
.bayi-text {
  font-size: 15px;
  color: var(--fg-2);
  line-height: 1.6;
}
.bayi-text.big { font-size: 17px; }
.bayi-text strong { color: var(--eco-red); font-weight: 700; }
.bayi-text em { color: var(--eco-teal-dark); font-style: normal; font-weight: 600; }

/* Bayi hero — bigger explainer at section start (display set in mode rule) */
.bayi-hero {
  background: var(--eco-ink);
  color: var(--eco-paper);
  padding: 28px 32px;
  gap: 28px;
  align-items: center;
  margin: 24px 0 32px;
  border: 1.5px solid var(--eco-ink);
}
.bayi-hero-illus {
  flex-shrink: 0;
  background: var(--bg);
  width: 160px; height: 160px;
  display: grid; place-items: center;
}
.bayi-hero-headline {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -0.02em;
}
.bayi-hero-sub {
  font-size: 16px;
  color: var(--eco-paper-3, #E8E5DA);
  margin-top: 8px;
  line-height: 1.55;
}

/* In Bayi mode: simplify some heavy charts (optional via .bayi-hide) */
body[data-mode="bayi"] .src-line,
body[data-mode="bayi"] .formula,
body[data-mode="bayi"] .kpi .src {
  display: none;
}
body[data-mode="bayi"] .kpi { background: #FFFCF5; }

/* ===== Table ===== */
.table {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.table th {
  text-align: left; padding: 12px 14px;
  font-weight: 600; font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-3); border-bottom: 1px solid var(--eco-ink);
  background: var(--bg-elev);
}
.table td {
  padding: 14px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
.table tr:hover td { background: var(--eco-paper-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

/* ===== Big editorial number ===== */
.big-num {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(72px, 13vw, 200px);
  line-height: 0.88;
  letter-spacing: -0.04em;
  color: var(--eco-ink);
}
.big-num .unit { font-size: 0.32em; font-weight: 600; color: var(--fg-3); letter-spacing: 0.02em; vertical-align: middle; margin-left: 12px; }

/* ===== Hover lift on chart elements ===== */
.svg-bar { transition: opacity 180ms; }
.svg-bar:hover { opacity: 0.85; cursor: pointer; }

/* ===== Slider ===== */
input[type="range"].eco-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px;
  background: var(--border);
  outline: none;
}
input[type="range"].eco-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px;
  background: var(--eco-red);
  border: 2px solid var(--eco-paper);
  box-shadow: 0 0 0 1px var(--eco-red);
  cursor: pointer;
}
input[type="range"].eco-slider::-moz-range-thumb {
  width: 20px; height: 20px;
  background: var(--eco-red);
  border: 2px solid var(--eco-paper);
  box-shadow: 0 0 0 1px var(--eco-red);
  cursor: pointer;
  border-radius: 0;
}

/* ===== Misc utilities ===== */
.muted { color: var(--fg-3); }
.tiny { font-size: 11px; }
.red-text { color: var(--eco-red); }
.teal-text { color: var(--eco-teal); }
.ink { color: var(--eco-ink); }
.inverse { background: var(--eco-ink); color: var(--eco-paper); }
.inverse-soft { background: #15140f; color: var(--eco-paper); }

/* anim */
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }
.blink { animation: blink 1.4s ease-in-out infinite; }

@keyframes ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
.ticker-track {
  display: inline-flex; gap: 48px; white-space: nowrap;
  animation: ticker 60s linear infinite;
}

/* =========================================================
   Responsive — Tablet + Mobile
   ========================================================= */

/* Tablet & narrow desktop */
@media (max-width: 1100px) {
  .shell { padding: 0 24px; }
  .topbar-inner { padding: 12px 24px; gap: 12px; flex-wrap: wrap; }
  .navtabs { order: 3; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .big-num { font-size: clamp(60px, 14vw, 120px); }

  /* Force inline-style grids with these patterns to single/two columns */
  [style*="gridTemplateColumns"][style*="1.5fr 1.1fr"],
  [style*="grid-template-columns"][style*="1.5fr 1.1fr"],
  [style*="1.4fr 1fr"],
  [style*="1.2fr 1fr"],
  [style*="1.15fr"][style*="1fr"],
  [style*="1fr 2fr"] {
    grid-template-columns: 1fr !important;
    gap: 32px !important;
  }
  [style*="repeat(10,"] { grid-template-columns: repeat(5, 1fr) !important; }
}

/* Mobile breakpoint — grid + nav-tabs + tables safety net */
@media (max-width: 768px) {
  .kpi-grid, .grid-2, .grid-3 {
    grid-template-columns: 1fr !important;
  }
  .nav-tabs {
    overflow-x: auto;
    scrollbar-width: none;
    flex-wrap: nowrap;
  }
  .nav-tabs::-webkit-scrollbar { display: none; }
  table { font-size: 12px; }
}

/* Mobile */
@media (max-width: 760px) {
  .shell { padding: 0 16px; }
  .page { padding: 32px 0 !important; }

  /* Top bar — stack and shrink */
  .topbar-inner { padding: 10px 16px; gap: 8px; }
  .topbar-inner .brand-mark,
  .brand-mark { width: 36px !important; height: 36px !important; font-size: 18px !important; }
  .navtabs { font-size: 11px; gap: 4px; }
  .navtabs button, .navtabs a { padding: 6px 10px !important; white-space: nowrap; }
  .ticker-track { gap: 24px; font-size: 12px; }

  /* Typography scale-down */
  h1, h2, h3 { letter-spacing: -0.015em; }
  h1.display { font-size: clamp(36px, 11vw, 56px) !important; line-height: 1.02 !important; }
  .sec-title { font-size: clamp(28px, 8vw, 40px) !important; }
  .sec-sub { font-size: 15px !important; }
  .big-num { font-size: clamp(56px, 18vw, 96px) !important; line-height: 0.95 !important; }
  .kicker, .eyebrow, .caps-sm { font-size: 10px !important; }

  /* Collapse ALL inline-style multi-col grids */
  [style*="gridTemplateColumns"],
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  /* But preserve KPI-style 2-col tile rows for compactness */
  [style*="repeat(4, 1fr)"],
  [style*="repeat(4,1fr)"],
  [style*="repeat(3, 1fr)"],
  [style*="repeat(3,1fr)"],
  [style*="repeat(2, 1fr)"],
  [style*="repeat(2,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1px !important;
  }
  /* Risk-chain & 10-col bars stay horizontal but smaller */
  [style*="repeat(10,"] {
    grid-template-columns: repeat(10, 1fr) !important;
    gap: 2px !important;
  }

  /* Hero adjustments */
  .hero-meta-row,
  [style*="justifyContent: 'space-between'"][style*="alignItems: 'baseline'"] {
    flex-wrap: wrap; gap: 6px;
  }

  /* Chart cards — let SVGs scale */
  .chart-card { padding: 16px !important; }
  .chart-card svg { width: 100% !important; height: auto !important; max-width: 100%; }
  .chart-header { flex-wrap: wrap; gap: 8px; }

  /* Buttons — stack full width when grouped */
  .btn { padding: 10px 14px !important; font-size: 13px !important; }
  [style*="flexWrap: 'wrap'"][style*="gap: 10"] .btn,
  [style*="flexWrap: 'wrap'"][style*="gap: 12"] .btn { flex: 1 1 auto; min-width: 140px; }

  /* Tables / scrollable rows */
  table { font-size: 12px; }

  /* Pullquote — smaller */
  .pullquote, blockquote { font-size: 18px !important; line-height: 1.35 !important; }

  /* Disclaimer band — stack label above text */
  aside[style*="auto 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* Bayi cards — stack image on top, text below */
  .bayi-hero, .bayi-card {
    flex-direction: column !important;
    align-items: stretch !important;
    grid-template-columns: 1fr !important;
    padding: 20px !important;
    gap: 16px !important;
  }
  .bayi-illus, .bayi-hero-illus {
    margin: 0 auto !important;
    width: 140px !important;
    height: 140px !important;
  }
  .bayi-body, .bayi-hero > div:not(.bayi-hero-illus) {
    width: 100%;
    flex: 1 1 auto;
  }
  .bayi-text { line-height: 1.75; }
  .bayi-hero img, .bayi-card img { max-width: 120px; }

  /* Tweaks panel & annotation panel — full width */
  .tweaks-panel, .annot-panel {
    width: calc(100vw - 24px) !important;
    max-width: 420px;
    right: 12px !important;
    left: 12px !important;
  }

  /* Headline mini-chart row — wrap into 2x2 */
  [style*="repeat(4, 1fr)"][style*="borderTop"][style*="borderBottom"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* Hide ticker on tiny viewports — too noisy */
  .ticker { display: none; }

  /* Generous spacing reset for nested flex toolbars */
  [style*="gap: 56"], [style*="gap: 48"] { gap: 24px !important; }
  [style*="gap: 32"] { gap: 20px !important; }
  [style*="marginTop: 56"], [style*="marginTop: 48"] { margin-top: 32px !important; }
  [style*="marginBottom: 56"], [style*="marginBottom: 48"] { margin-bottom: 32px !important; }
  [style*="padding: 24"] { padding: 16px !important; }
}

/* Very small mobile */
@media (max-width: 420px) {
  .shell { padding: 0 12px; }
  .navtabs { font-size: 10px; }
  .big-num { font-size: clamp(48px, 20vw, 80px) !important; }
  h1.display { font-size: clamp(30px, 11vw, 44px) !important; }
}

/* === MOBILE OVERFLOW NUCLEAR FIX === */
/* Prevent horizontal scroll without breaking sticky nav:
   overflow-x:clip does NOT create a scroll container / BFC,
   so position:sticky on .topbar keeps working on mobile.
   Supported: iOS Safari 16+, Chrome Android 90+. */
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}

/* Clamp main containers WITHOUT affecting .topbar (sticky) */
body > *:not(.topbar),
#root > *:not(.topbar),
.app > *:not(.topbar),
.site > *:not(.topbar) {
  max-width: 100%;
  overflow-x: clip;
}

/* Tables — always scroll within container, never push layout */
table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
  white-space: nowrap;
}

/* Charts and canvas */
canvas, svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Chart wrapper divs */
[class*="chart"], [class*="Chart"],
[style*="height:"], [style*="height :"] {
  max-width: 100% !important;
  overflow: hidden !important;
}

/* Any inline-style width on divs */
div[style*="width:"] {
  max-width: 100% !important;
}

/* Grid and flex containers */
.grid, [class*="grid"],
.flex, [class*="flex"] {
  max-width: 100%;
}

/* Mobile breakpoint — aggressive */
@media (max-width: 768px) {
  * {
    max-width: 100vw;
    box-sizing: border-box;
  }

  /* Sticky nav guard — must NOT be clipped/overridden by * rule above */
  .topbar {
    position: sticky !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 1000 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow: visible !important;
  }

  table {
    font-size: 11px;
    min-width: unset !important;
    width: 100%;
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  th, td {
    white-space: nowrap;
    padding: 6px 8px !important;
  }

  canvas {
    max-width: 100% !important;
  }

  svg {
    max-width: 100% !important;
    overflow: hidden;
  }

  /* Nav tabs — horizontal scroll only inside tab bar */
  .nav-tabs, [class*="nav-tab"], [class*="tabs"] {
    overflow-x: auto !important;
    overflow-y: visible !important;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .nav-tabs::-webkit-scrollbar,
  [class*="nav-tab"]::-webkit-scrollbar {
    display: none;
  }

  /* Metric/KPI grids — single column */
  [class*="kpi"], [class*="metric"],
  [class*="grid"], [class*="card-row"] {
    grid-template-columns: 1fr !important;
  }

  /* Simulators and sliders */
  [class*="sim-row"], [class*="slider"] {
    flex-wrap: wrap !important;
  }

  /* Waterfall and stacked charts */
  [class*="waterfall"], [class*="stacked"] {
    overflow-x: auto !important;
  }
}

/* END MOBILE OVERFLOW NUCLEAR FIX */
