/* =========================================================
   IUW — Responsive overrides for inline-styled React layouts
   Targets common patterns produced by camelCased React inline
   styles (which serialize as `style="prop-name: value;"`).
   Loaded site-wide via <link> in every HTML page.
   ========================================================= */

html, body { max-width: 100%; }
body { overflow-x: hidden; }
/* Mobile-only captions inside the Trade Live comparison — hidden by default */
.tlvs-cap { display: none; }
img, svg, video { max-width: 100%; height: auto; }
section, header, footer { max-width: 100vw; }

/* ── Tablet (≤1024) ───────────────────────────────────────
   Collapse the “hero + secondary panel” style two-column
   layouts that don't fit comfortably below ~1024.
   ───────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  [style*="grid-template-columns: 1.25fr 1fr"],
  [style*="grid-template-columns: 1.15fr 1fr"],
  [style*="grid-template-columns: 1.1fr 1fr"],
  [style*="grid-template-columns: 1.2fr 1fr"],
  [style*="grid-template-columns: 1.4fr 1fr"],
  [style*="grid-template-columns: 1.5fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"],
  [style*="grid-template-columns: 1fr 1.15fr"],
  [style*="grid-template-columns: 1fr 1.25fr"],
  [style*="grid-template-columns: 1fr 1.5fr"],
  [style*="grid-template-columns: 1fr 2fr"],
  [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 40px !important;
  }
  /* 4-col footers/strips → 2x2 */
  [style*="grid-template-columns: 1.4fr 1fr 1fr 1fr"],
  [style*="grid-template-columns: repeat(4,1fr)"],
  [style*="grid-template-columns: repeat(4, 1fr)"] {
    grid-template-columns: repeat(2, minmax(0,1fr)) !important;
    gap: 32px !important;
  }
  /* 3-col card grids → 2-up on tablet */
  [style*="grid-template-columns: repeat(3,1fr)"],
  [style*="grid-template-columns: repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, minmax(0,1fr)) !important;
  }
  /* Maxwidth caps off */
  [style*="max-width: 1440"],
  [style*="max-width: 1360"],
  [style*="max-width: 1280"] {
    max-width: 100% !important;
  }
  /* Reduce huge horizontal padding */
  [style*="padding: 100px 40px"],
  [style*="padding: 120px 40px"],
  [style*="padding: 140px 40px"],
  [style*="padding: 80px 40px"],
  [style*="padding: 96px 40px"],
  [style*="padding: 72px 60px"],
  [style*="padding: 80px 60px"],
  /* Any 3-value shorthand using 40px as the horizontal padding */
  [style*="px 40px "] {
    padding-left: 28px !important;
    padding-right: 28px !important;
  }
}

/* ── Mobile (≤720) ────────────────────────────────────────
   Stack everything. Reduce padding and big type.
   ───────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  /* Collapse every multi-column grid to a single column */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
    gap: 20px !important;
  }
  /* Rows with leading icon column (e.g. "56px 1fr ...") need a slim 2-col fallback */
  [style*="grid-template-columns: 56px 1fr"],
  [style*="grid-template-columns: 60px 1fr"],
  [style*="grid-template-columns: 32px 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Tighter section padding on phones */
  [style*="padding: 100px 40px"],
  [style*="padding: 120px 40px"],
  [style*="padding: 140px 40px"],
  [style*="padding: 80px 40px"],
  [style*="padding: 96px 40px"],
  [style*="padding: 60px 40px"],
  [style*="padding: 56px 40px"],
  [style*="padding: 48px 40px"],
  [style*="padding: 40px 40px"],
  [style*="padding: 72px 60px"],
  [style*="padding: 80px 60px"],
  /* Any 3-value shorthand using 40px as the horizontal padding */
  [style*="px 40px "] {
    padding-left: 18px !important;
    padding-right: 18px !important;
  }
  /* Footer / hero with rounded corners look pinched on phones */
  [style*="border-radius: 0px 0px 32px 32px"],
  [style*="border-radius: 32px 32px 0px 0px"] {
    border-radius: 0 !important;
  }
  /* Big inline font sizes -> scale down */
  [style*="font-size: 96px"]      { font-size: 56px !important; line-height: 1 !important; }
  [style*="font-size: 80px"]      { font-size: 48px !important; line-height: 1.05 !important; }
  [style*="font-size: 72px"]      { font-size: 44px !important; }
  [style*="font-size: 64px"]      { font-size: 40px !important; }
  [style*="font-size: 56px"]      { font-size: 36px !important; }
  [style*="font-size: 48px"]      { font-size: 32px !important; }
  [style*="font-size: 44px"]      { font-size: 30px !important; }
  [style*="font-size: 36px"]      { font-size: 26px !important; }
  [style*="font-size: 32px"]      { font-size: 24px !important; }
  [style*="font-size: 28px"]      { font-size: 22px !important; }
  /* Tables / wide bordered cells loose their rigid border-right when stacked */
  [style*="border-right: 1px solid"] {
    border-right: none !important;
  }
  /* Flex rows force-wrap on phones */
  [style*="display: flex"] {
    flex-wrap: wrap;
  }
  /* Don't wrap things that explicitly shouldn't (e.g. compact pills) */
  [style*="white-space: nowrap"] {
    flex-wrap: nowrap;
  }
  /* Cap container widths and remove huge gaps */
  [style*="max-width"] { max-width: 100% !important; }
  [style*="gap: 80px"] { gap: 32px !important; }
  [style*="gap: 64px"] { gap: 28px !important; }
  [style*="gap: 56px"] { gap: 24px !important; }
  [style*="gap: 48px"] { gap: 24px !important; }
  /* Quote / CTA inside blocks have giant inner padding */
  [style*="padding: 72px 60px"] { padding: 36px 22px !important; }
  [style*="padding: 80px 60px"] { padding: 36px 22px !important; }
  [style*="padding: 60px 56px"] { padding: 32px 22px !important; }
  /* Min-heights collapse */
  [style*="min-height: 560"],
  [style*="min-height: 480"],
  [style*="min-height: 420"] {
    min-height: 0 !important;
  }
  /* Sparkline / panels overflow safely */
  [style*="aspect-ratio: 4 / 5"],
  [style*="aspect-ratio: 4/5"] {
    aspect-ratio: 3 / 4 !important;
    max-width: 100%;
  }
  /* Inline-block strip cells: drop left/right padding */
  [style*="padding-right: 32px"] { padding-right: 0 !important; }
  [style*="padding-left: 32px"]  { padding-left: 0 !important; }

  /* === Nav: hide desktop links, show inline menu button === */
  /* Nav.jsx renders the menu button itself; this is a safety net for any
     unmodified page during transition. */
  header[data-iuw-nav] nav.iuw-desktop-links { display: none !important; }
  header[data-iuw-nav] .iuw-cta-login { display: none !important; }
  header[data-iuw-nav] .iuw-cta-signup { display: none !important; }
  header[data-iuw-nav] [style*="padding: 18px 40px"] { padding: 14px 18px !important; gap: 12px !important; }
}

/* ── Very narrow (≤420) ────────────────────────────────── */
@media (max-width: 420px) {
  [style*="padding: 80px 40px"],
  [style*="padding: 100px 40px"],
  [style*="padding: 120px 40px"],
  [style*="padding: 56px 40px"],
  [style*="padding: 60px 40px"],
  [style*="padding: 72px 60px"],
  [style*="padding: 80px 60px"],
  [style*="px 40px "] {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }
  [style*="font-size: 96px"] { font-size: 44px !important; }
  [style*="font-size: 80px"] { font-size: 40px !important; }
  [style*="font-size: 72px"] { font-size: 36px !important; }
  [style*="font-size: 64px"] { font-size: 32px !important; }
}

/* === Homepage hero — explicit mobile treatment ================
   The hero uses a 3-value padding and a clamp() headline that the
   generic substring rules above don't catch, so it gets its own
   deterministic block via stable class hooks (see hero.jsx).
   ============================================================== */
@media (max-width: 720px) {
  .iuw-hero {
    padding: 56px 20px 60px !important;
    border-radius: 0 !important;
  }
  .iuw-hero-inner { gap: 32px !important; align-items: stretch !important; }
  .iuw-hero-h1 { font-size: 46px !important; line-height: 0.96 !important; }
  .iuw-hero-panel { padding: 22px !important; border-radius: 20px !important; }
  .iuw-hero-bignum { font-size: 60px !important; }
}
@media (max-width: 420px) {
  .iuw-hero { padding: 48px 16px 52px !important; }
  .iuw-hero-h1 { font-size: 38px !important; }
  .iuw-hero-panel { padding: 18px !important; }
  .iuw-hero-bignum { font-size: 52px !important; }
}

/* === Mobile nav drawer (cooperates with nav.jsx) ============= */
.iuw-mobile-toggle { display: none; }
.iuw-mobile-drawer { display: none; }
@media (max-width: 720px) {
  .iuw-mobile-toggle {
    display: inline-flex !important;
    align-items: center; justify-content: center;
    width: 40px; height: 40px;
    border: 1px solid var(--line, rgba(29,16,60,0.25));
    border-radius: 999px;
    background: transparent;
    color: var(--ink, #1D103C);
    cursor: pointer;
  }
  .iuw-mobile-toggle svg { width: 18px; height: 18px; }

  .iuw-mobile-drawer {
    display: flex !important;
    flex-direction: column;
    position: fixed; inset: 0;
    background: var(--paper, #FBF8F2);
    color: var(--ink, #1D103C);
    z-index: 100;
    padding: 18px;
    transform: translateY(-101%);
    transition: transform .28s cubic-bezier(.2,.7,.2,1);
  }
  .iuw-mobile-drawer.open { transform: translateY(0); }
  .iuw-mobile-drawer .iuw-drawer-top {
    display: flex; justify-content: space-between; align-items: center;
    padding: 4px 4px 24px;
  }
  .iuw-mobile-drawer .iuw-drawer-links {
    display: flex; flex-direction: column; gap: 4px;
    padding: 8px 0; border-top: 1px solid var(--line, rgba(29,16,60,0.12));
  }
  .iuw-mobile-drawer .iuw-drawer-links a {
    font-size: 28px; font-weight: 600; letter-spacing: -0.02em;
    padding: 18px 4px; border-bottom: 1px solid var(--line, rgba(29,16,60,0.12));
    display: flex; justify-content: space-between; align-items: center;
  }
  .iuw-mobile-drawer .iuw-drawer-links a::after {
    content: ""; width: 16px; height: 16px;
    background: currentColor;
    -webkit-mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="none" stroke="black" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" d="M2 8h11M9 4l4 4-4 4"/></svg>') no-repeat center / contain;
            mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="none" stroke="black" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" d="M2 8h11M9 4l4 4-4 4"/></svg>') no-repeat center / contain;
    opacity: 0.6;
  }
  .iuw-mobile-drawer .iuw-drawer-cta {
    margin-top: auto;
    display: flex; flex-direction: column; gap: 10px;
  }
}

/* === Overrides that must beat the generic grid-collapse rules ===
   The catch-all `[style*="grid-template-columns"]` at ≤720 collapses
   EVERY grid to 1fr. Two grids must not collapse: the hero sparkline
   (32 vertical bars) and the homepage stats strip (wanted 2x2).
   These come last so they win at equal specificity.
   ============================================================== */
@media (max-width: 720px) {
  /* Keep the sparkline as 32 thin vertical bars, never stacked rows */
  .iuw-sparkline {
    grid-template-columns: repeat(32, 1fr) !important;
    gap: 2px !important;
    height: 48px !important;
    overflow: hidden !important;
  }
  /* Homepage count-up stats → 2x2 on phones */
  .iuw-stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 36px 24px !important;
  }
  .iuw-stats-grid .iuw-stat-n { font-size: 48px !important; }
  .iuw-stats-grid .iuw-stat-suffix { font-size: 22px !important; }

  /* Expanded product cards must NOT span 2 cols/rows once the grid is
     forced to a single column — the span creates a phantom column and
     throws every following card out of alignment. */
  .iuw-product-card {
    grid-column: auto !important;
    grid-row: auto !important;
  }

  /* Trade Live promo band: shrink the oversized panel padding and let
     the "LIVE ·…" eyebrow wrap instead of forcing horizontal overflow. */
  .iuw-tlpromo-panel {
    padding: 32px 22px !important;
    border-radius: 22px !important;
  }
  .iuw-tlpromo-eyebrow {
    white-space: normal !important;
    line-height: 1.4 !important;
    font-size: 11px !important;
    letter-spacing: 0.08em !important;
    text-align: left;
  }

  /* === All 4-up stat strips → 2x2 on phones ====================
     Two repeating signatures across the site, both 4-col grids the
     generic catch-all would otherwise collapse to one column:
       A) product-page hero strips  (padding-top:36 + top border)
       B) page stat strips          (top + bottom var(--line) border)
     Compound selectors out-specify the single-attr catch-all.
     Cell border-right / padding-right are already stripped on mobile
     by earlier rules, so the 2x2 lands clean. ==================== */
  [style*="grid-template-columns: repeat(4, 1fr)"][style*="padding-top: 36px"],
  [style*="grid-template-columns: repeat(4,1fr)"][style*="padding-top: 36px"],
  [style*="grid-template-columns: repeat(4, 1fr)"][style*="border-bottom: 1px solid var(--line)"],
  [style*="grid-template-columns: repeat(4,1fr)"][style*="border-bottom: 1px solid var(--line)"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 30px 20px !important;
  }
  /* Page stat strip cells carry a chunky 40x32 padding — drop it so
     numbers aren't squeezed once they sit two-up (scoped to the grid
     so it can't touch the unrelated why-cta block). */
  [style*="grid-template-columns: repeat(4, 1fr)"][style*="border-bottom: 1px solid var(--line)"] > [style*="padding: 40px 32px"],
  [style*="grid-template-columns: repeat(4,1fr)"][style*="border-bottom: 1px solid var(--line)"] > [style*="padding: 40px 32px"] {
    padding: 4px 0 !important;
  }

  /* === Trade Live "Why" comparison → stacked labelled cards ====
     The 3-col table (row | traditional | trade live) collapses to a
     single column on phones, which leaves bare values with no context
     and an empty header band. Hide the header, reduce the dark card
     padding, and turn each row into a labelled block with mobile-only
     "Traditional broking" / "With Trade Live" captions. =========== */
  .tlvs-inner { padding: 30px 18px !important; border-radius: 22px !important; }
  .tlvs-thead { display: none !important; }
  .tlvs-table { border-radius: 14px !important; }
  .tlvs-row { padding: 18px 16px !important; }
  .tlvs-td { padding: 0 !important; border-left: none !important; }
  .tlvs-label { font-size: 17px !important; margin-bottom: 12px !important; }
  .tlvs-trad { margin-bottom: 12px !important; }
  .tlvs-cap {
    display: block !important;
    font-family: "JetBrains Mono", monospace;
    font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
    color: rgba(255,255,255,0.4); margin-bottom: 4px;
  }
  .tlvs-cap-live { color: var(--lime); }
  .tlvs-live { flex-wrap: wrap !important; align-items: center !important; }
  .tlvs-live .tlvs-cap { flex-basis: 100% !important; width: 100% !important; }

  /* === Instant Broking "Classes placed" tabs ==================
     Each tab's inner 3-col grid (index | label | arrow) was being
     collapsed to one column, stacking those three vertically and
     making every tab a tall block. Keep the row intact and trim the
     oversized detail-panel padding. ============================ */
  .ib-class-tab {
    grid-template-columns: 32px 1fr 16px !important;
    padding: 18px 20px !important;
  }
  .ib-class-panel { padding: 32px 22px !important; }
}
