/*
 * Nomad Trader — Mobile Responsive Layer
 * Version: 1.1.0
 *
 * ADDITIVE ONLY — every rule here lives inside a @media block.
 * Zero desktop changes.
 *
 * v1.1 fixes:
 *   - Nav dropdown z-index (menu hidden behind ticker) → z-index:1002
 *   - Portfolio counter 84px font → clamped for mobile
 *   - Chart header bar overflow (flex nowrap)
 *   - Product pages: hamburger injected via main.js + styled here
 *   - Tightened inline grid overrides
 */


/* ─────────────────────────────────────────────
   FIX 1: NAV DROPDOWN Z-INDEX
   .live-ticker z-index:999 was intercepting clicks
   on the open .primary-nav dropdown.
───────────────────────────────────────────── */

@media (max-width: 900px) {
  .primary-nav {
    display: none;
    position: absolute;
    top: var(--nav-h);
    left: 0;
    right: 0;
    background: var(--bg2);
    border-bottom: 1px solid var(--b1);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 10px 16px 16px;
    z-index: 1002;
    box-shadow: 0 8px 32px rgba(0,0,0,.5);
  }
  .primary-nav.is-open { display: flex; }
  .primary-nav a { padding: 10px 12px !important; border-radius: 6px; }
  .primary-nav .nav-cta > a,
  .primary-nav .nav-cta a {
    margin-left: 0 !important;
    margin-top: 6px;
    text-align: center;
    display: block !important;
  }
  .nav-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
  }
}


/* ─────────────────────────────────────────────
   FIX 2: PORTFOLIO COUNTER + CHART HEADER
───────────────────────────────────────────── */

@media (max-width: 900px) {
  /* Chart header bar: allow wrapping */
  .hero-section [style*="justify-content:space-between"][style*="flex"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  /* Hide overflow text on mobile */
  .hero-section [style*="justify-content:space-between"] > span:last-child {
    display: none !important;
  }
}

@media (max-width: 600px) {
  /* Portfolio total counter */
  #portfolio-counter {
    font-size: clamp(48px, 15vw, 72px) !important;
    line-height: 1 !important;
  }
  /* Reduce chart height */
  .hero-section [style*="height:240px"] {
    height: 180px !important;
  }
  /* Stack chart header pills */
  .hero-section [style*="justify-content:space-between"][style*="flex"] {
    flex-direction: column !important;
    align-items: flex-start !important;
    padding: 10px 16px !important;
  }
  .hero-section [style*="display:flex;align-items:center;gap:14px"] {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
}


/* ─────────────────────────────────────────────
   1. FRONT-PAGE SPECIFIC CLASSES
───────────────────────────────────────────── */

@media (max-width: 1100px) {
  .fp-hero-main       { grid-template-columns: 1fr 280px !important; }
  .fp-ea-strip        { grid-template-columns: repeat(3, 1fr) !important; }
  .fp-blog-main       { grid-template-columns: 1fr !important; }
  .fp-indicators-grid { grid-template-columns: 1fr !important; gap: 32px !important; }
}

@media (max-width: 900px) {
  .fp-hero-main { grid-template-columns: 1fr !important; }
  .fp-hero-circles  { display: none !important; }
  .fp-hero-contact {
    border-right: none !important;
    border-top: 1px solid rgba(255,255,255,.07) !important;
    padding: 32px 28px !important;
  }
  .fp-ea-strip { grid-template-columns: repeat(2, 1fr) !important; }
  .fp-ea-strip > div:nth-child(2) { border-right: none !important; }
  .fp-ea-strip > div:nth-child(4) { border-right: none !important; }
  .fp-product-cards   { grid-template-columns: 1fr 1fr !important; }
  .fp-install-guides  { grid-template-columns: 1fr 1fr !important; }
  .fp-blog-minis      { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 600px) {
  .fp-hero-headline {
    padding: 28px 20px !important;
    border-right: none !important;
    border-bottom: 1px solid rgba(255,255,255,.07) !important;
  }
  .fp-ea-strip { grid-template-columns: repeat(2, 1fr) !important; }
  .fp-ea-strip > div:nth-child(odd)  { border-right: 1px solid rgba(255,255,255,.07) !important; }
  .fp-ea-strip > div:nth-child(even) { border-right: none !important; }
  .fp-product-cards   { grid-template-columns: 1fr !important; }
  .fp-install-guides  { grid-template-columns: 1fr !important; }
  .fp-blog-minis      { grid-template-columns: 1fr !important; }
  .fp-blog-header,
  .fp-guides-header,
  .fp-section-header  { flex-direction: column !important; align-items: flex-start !important; gap: 12px !important; }
}


/* ─────────────────────────────────────────────
   2. SHARED PRODUCT PAGE PATTERNS
───────────────────────────────────────────── */

@media (max-width: 600px) {
  .hero-grid { grid-template-columns: 1fr !important; gap: 28px !important; padding: 0 18px !important; }
  .buy-card  { max-width: 100% !important; margin: 0 !important; }
  .hero-title { font-size: clamp(36px, 9vw, 64px) !important; line-height: .95 !important; }

  .hero-stats { display: grid !important; grid-template-columns: 1fr 1fr !important; }
  .hero-stat  { border-right: none !important; border-bottom: 1px solid rgba(255,255,255,.05) !important; min-width: 0 !important; }
  .hero-stat:nth-child(odd) { border-right: 1px solid rgba(255,255,255,.05) !important; }

  .hero-actions { flex-direction: column !important; }
  .hero-actions .btn-primary,
  .hero-actions .btn-secondary,
  .hero-actions .btn-ghost { width: 100%; justify-content: center; }

  .perf-grid, .perf-layout { grid-template-columns: 1fr !important; gap: 24px !important; }
  .pair-imgs { grid-template-columns: 1fr !important; }
  .pair-imgs img:first-child { border-right: none !important; border-bottom: 1px solid rgba(255,255,255,.07) !important; }
  .features-grid, .fg { grid-template-columns: 1fr !important; }
  .param-row { grid-template-columns: 1fr !important; }
  .param-row > div:first-child { padding-bottom: 0 !important; border-bottom: none !important; opacity: .6; font-size: 9px !important; }
  .perf-metrics { grid-template-columns: 1fr !important; }
  .nav-links    { display: none !important; }
  .params-grid, .steps-grid, .ea-showroom-grid { grid-template-columns: 1fr !important; }
}

@media (max-width: 400px) {
  .hero-title { font-size: 32px !important; }
  .hero-stats { grid-template-columns: 1fr !important; }
  .hero-stat  { border-right: none !important; }
  .hero-stat:nth-child(odd) { border-right: none !important; }
}


/* ─────────────────────────────────────────────
   3. INLINE-STYLE GRID OVERRIDES
───────────────────────────────────────────── */

@media (max-width: 900px) {
  .order-strategy-box { grid-template-columns: 1fr !important; gap: 24px !important; padding: 28px 22px !important; }
}

@media (max-width: 600px) {
  [style*="repeat(4,1fr)"]   { grid-template-columns: repeat(2, 1fr) !important; }
  [style*="repeat(3,1fr)"]   { grid-template-columns: 1fr 1fr !important; }
  [style*="repeat(5,1fr)"]   { grid-template-columns: repeat(2, 1fr) !important; }
  [style*="300px 195px"]     { grid-template-columns: 1fr !important; }
  [style*="grid-template-columns:1fr 1fr"][style*="gap:60px"] { grid-template-columns: 1fr !important; gap: 28px !important; }
  [style*="grid-template-columns:1fr 1fr"][style*="gap:56px"] { grid-template-columns: 1fr !important; gap: 28px !important; }
  [style*="grid-template-columns:1fr 1fr"][style*="gap:80px"] { grid-template-columns: 1fr !important; gap: 28px !important; }
  [style*="420px"]           { grid-template-columns: 1fr !important; }
  [style*="380px"]           { grid-template-columns: 1fr !important; }
  [style*="1.5fr 1fr"]       { grid-template-columns: 1fr !important; }
  [style*="240px 1fr"]       { grid-template-columns: 1fr !important; }
  [style*="200px 1fr"]       { grid-template-columns: 1fr !important; }
  [style*="2fr 1fr 1fr 1fr"] { grid-template-columns: 1fr 1fr !important; }
}

@media (max-width: 400px) {
  [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
  [style*="repeat(3,1fr)"]                 { grid-template-columns: 1fr !important; }
}


/* ─────────────────────────────────────────────
   4. GLOBAL UTILITY FIXES
───────────────────────────────────────────── */

@media (max-width: 900px) {
  .live-ticker { height: 30px !important; }
  .ticker-item { padding: 0 14px !important; font-size: 10px !important; }
  .stats-strip__inner { border-left: none !important; }
  .stat-block { padding: 16px 18px !important; }
  .section { padding: 56px 0 !important; }
  .container { padding: 0 20px !important; }
  .product-page-layout { grid-template-columns: 1fr !important; }
  .product-sidebar { position: static !important; }
  .post-body .container { grid-template-columns: 1fr !important; }
  .post-sidebar { position: static !important; }
  .footer-grid { grid-template-columns: 1fr 1fr !important; gap: 28px !important; }
}

@media (max-width: 600px) {
  .nav-inner { padding: 0 16px !important; }
  .section   { padding: 44px 0 !important; }
  .container { padding: 0 16px !important; }

  .stats-strip__inner { grid-template-columns: repeat(2, 1fr) !important; }
  .stat-block { border-right: 1px solid rgba(255,255,255,.07) !important; }
  .stat-block:nth-child(even) { border-right: none !important; }
  .stat-block__val { font-size: 20px !important; }

  .footer-grid { grid-template-columns: 1fr !important; gap: 24px !important; }
  .footer-brand p { max-width: 100% !important; }
  .footer-bottom { flex-direction: column !important; gap: 10px !important; }
  .blog-grid { grid-template-columns: 1fr !important; }
  .factsheet-grid { grid-template-columns: 1fr !important; }
  .purchase-box__btn { width: 100% !important; text-align: center !important; }
  .product-page-header { padding: 40px 0 32px !important; }
  .product-page-header .product-price-large { font-size: 28px !important; }
  .factsheet-card { padding: 20px !important; }
  .factsheet-card__perf { font-size: 26px !important; }
  .factsheet-card__name { padding-right: 40px !important; }
  .entry-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .entry-content { max-width: 100% !important; }
  .pill-tag { white-space: normal !important; }
  .no-risk-tags { flex-wrap: wrap !important; }
}

@media (max-width: 400px) {
  .container { padding: 0 14px !important; }
  .section { padding: 36px 0 !important; }
  .logo-sub { display: none !important; }
  .footer-social { flex-wrap: wrap !important; }
}


/* ─────────────────────────────────────────────
   5. PAGE-SPECIFIC
───────────────────────────────────────────── */

@media (max-width: 600px) {
  /* Tools */
  .grades-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .proof-grid  { grid-template-columns: 1fr !important; }
  /* Order */
  .process-steps  { grid-template-columns: 1fr !important; }
  .plat-grid      { grid-template-columns: repeat(2, 1fr) !important; }
  .dev-card-stats { grid-template-columns: 1fr 1fr !important; }
  /* Prop */
  .the5ers-facts, .ea-cards-grid, .videos-grid, .rules-grid { grid-template-columns: 1fr !important; }
  /* Knowledge hub */
  .ti-hero-grid, .ti-main { grid-template-columns: 1fr !important; }
  .ti-feat-title { font-size: 18px !important; }
  /* Spectrum */
  .spec-hero-grid, .spec-tabs-content { grid-template-columns: 1fr !important; }
  /* Dashboard */
  .dash-hero-grid, .dash-features { grid-template-columns: 1fr !important; }
  /* Affiliate */
  .aff-hero-grid, .aff-tiers { grid-template-columns: 1fr !important; }
  /* Partners */
  .partners-grid { grid-template-columns: 1fr !important; }
}


/* ─────────────────────────────────────────────
   6. PRODUCT PAGE STANDALONE NAV MOBILE
   Product pages have their own <nav> with .nav-links.
   .nav-links hidden at 700px but no hamburger exists.
   main.js injects .product-nav-toggle + .product-nav-panel.
───────────────────────────────────────────── */

@media (max-width: 700px) {
  .nav-links { display: none !important; }

  /* Injected hamburger button */
  .product-nav-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid rgba(255,255,255,.13);
    border-radius: 5px;
    padding: 6px 10px;
    cursor: pointer;
    color: rgba(255,255,255,.7);
    font-size: 18px;
    line-height: 1;
    margin-left: auto;
  }

  /* Injected mobile nav panel */
  .product-nav-panel {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    background: #0c0f17;
    border-bottom: 1px solid rgba(255,255,255,.07);
    z-index: 9999;
    flex-direction: column;
    padding: 10px 16px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.6);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .product-nav-panel.is-open { display: flex; }
  .product-nav-panel a {
    display: block;
    color: rgba(255,255,255,.8) !important;
    font-size: 14px !important;
    font-weight: 500;
    text-decoration: none !important;
    padding: 11px 12px !important;
    border-radius: 6px;
    border: none !important;
    transition: background .15s;
  }
  .product-nav-panel a:hover { background: rgba(255,255,255,.05); }
  .product-nav-panel a.nav-cta-mobile {
    background: #0ea5e9 !important;
    color: #000 !important;
    font-weight: 700 !important;
    text-align: center;
    margin-top: 8px;
    border-radius: 6px !important;
  }
}


/* ─────────────────────────────────────────────
   7. OVERFLOW SAFETY NET
───────────────────────────────────────────── */

@media (max-width: 600px) {
  body   { overflow-x: hidden !important; }
  table  { max-width: 100% !important; }
  iframe { max-width: 100% !important; }
  [style*="height:220px"] img,
  [style*="height:180px"] img { width: 100% !important; height: 100% !important; object-fit: cover !important; }
}
