/* Marketing site — shared mobile layout (source file).
   Appended to the end of navigation.css so rules cascade after per-page inline styles. */

@media (max-width: 768px) {
  /* ── Typography: readable headings (not one-word-per-line) ── */
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
    hyphens: manual;
  }

  p,
  li,
  td,
  th,
  dd,
  blockquote {
    overflow-wrap: anywhere;
    word-break: normal;
  }

  /* ── Resource article body (.content on formula / tool pages) ── */
  article.content,
  .content {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    padding-top: 2rem !important;
    padding-bottom: 3.5rem !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }

  .content h2 {
    font-size: clamp(1.3rem, 5.2vw, 1.65rem);
    line-height: 1.25;
    margin: 2.25rem 0 0.85rem;
    padding-bottom: 0.65rem;
  }

  .content h2:first-of-type {
    margin-top: 1.5rem;
  }

  .content h2::after {
    width: 48px;
    height: 3px;
  }

  .content h3 {
    font-size: clamp(1.1rem, 4.2vw, 1.35rem);
    line-height: 1.3;
    margin: 1.75rem 0 0.65rem;
  }

  .content h4 {
    font-size: 1rem;
    line-height: 1.35;
    margin: 1.25rem 0 0.5rem;
  }

  .content p,
  .content li {
    font-size: 0.95rem;
    line-height: 1.62;
    max-width: 100%;
  }

  .content ul,
  .content ol {
    padding-left: 1.25rem;
    margin-bottom: 1.25rem;
  }

  /* ── Callout / info boxes: no decorative underline bleed ── */
  .key-takeaways h2,
  .key-takeaways h3,
  .key-takeaways h4,
  .warning-box h2,
  .warning-box h3,
  .warning-box h4,
  .danger-box h2,
  .danger-box h3,
  .danger-box h4,
  .highlight-box h2,
  .highlight-box h3,
  .highlight-box h4,
  .info-box h2,
  .info-box h3,
  .info-box h4,
  .data-box h2,
  .data-box h3,
  .data-box h4,
  .example-card h2,
  .example-card h3,
  .example-card h4,
  .tip-box h2,
  .tip-box h3,
  .tip-box h4,
  .checklist h2,
  .checklist h3,
  .checklist h4 {
    overflow-wrap: normal;
    word-break: normal;
    text-wrap: balance;
    padding-bottom: 0;
  }

  .key-takeaways h2::after,
  .key-takeaways h3::after,
  .key-takeaways h4::after,
  .warning-box h2::after,
  .warning-box h3::after,
  .warning-box h4::after,
  .danger-box h2::after,
  .danger-box h3::after,
  .danger-box h4::after,
  .highlight-box h2::after,
  .highlight-box h3::after,
  .highlight-box h4::after,
  .info-box h2::after,
  .info-box h3::after,
  .info-box h4::after,
  .data-box h2::after,
  .data-box h3::after,
  .data-box h4::after,
  .example-card h2::after,
  .example-card h3::after,
  .example-card h4::after,
  .tip-box h2::after,
  .tip-box h3::after,
  .tip-box h4::after,
  .checklist h2::after,
  .checklist h3::after,
  .checklist h4::after,
  .cta-section h2::after,
  .faq-item h2::after,
  .faq-item h3::after {
    display: none;
  }

  .warning-box,
  .danger-box,
  .highlight-box,
  .info-box,
  .data-box,
  .example-card,
  .tip-box {
    padding: 1rem 0.95rem !important;
    margin: 1.5rem 0 !important;
    border-radius: 12px;
  }

  .warning-box p,
  .danger-box p,
  .highlight-box p,
  .info-box p,
  .data-box p,
  .example-card p,
  .tip-box p {
    font-size: 0.92rem;
    line-height: 1.55;
  }

  /* ── Grids → single column ── */
  .feature-grid,
  .related-pages,
  .related-links-grid,
  .steps,
  .steps-grid,
  .stat-grid,
  .audience-grid,
  .passive-cards,
  .comparison-cards,
  .card-grid,
  .benefits-grid,
  .metrics-grid,
  .hub-grid,
  .risk-grid,
  .risk-hub-grid,
  .resource-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  .feature-grid {
    display: grid;
  }

  /* ── Related links (cards + row links) ── */
  .related-links {
    padding: 2rem 1rem !important;
  }

  .related-links h3 {
    font-size: 1.1rem;
    margin-bottom: 0.85rem;
  }

  .related-link,
  .related-link-card {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0.85rem 1rem !important;
    font-size: 0.9rem !important;
    line-height: 1.4;
    box-sizing: border-box;
  }

  .related-pages {
    display: grid;
    padding-left: 1rem;
    padding-right: 1rem;
    gap: 0.65rem;
  }

  .related-pages .related-link {
    width: 100%;
  }

  /* ── Steps / numbered sections ── */
  .steps .step,
  .steps-grid .step {
    padding: 1rem !important;
  }

  /* ── CTA bands ── */
  .cta-section {
    padding: 2.75rem 1rem !important;
    box-sizing: border-box;
  }

  .cta-section h2 {
    font-size: clamp(1.35rem, 5vw, 1.75rem) !important;
    line-height: 1.2 !important;
    margin-bottom: 0.75rem !important;
  }

  .cta-section p {
    font-size: 0.95rem !important;
    line-height: 1.55 !important;
    margin-bottom: 1.25rem !important;
    max-width: 100%;
  }

  .cta-section-inner {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    align-items: stretch;
    text-align: center;
  }

  .cta-section-actions {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
  }

  .cta-button-large,
  .cta-section .cta-button,
  .cta-section a.cta-button-large,
  article.content .cta-button-large {
    display: block !important;
    width: 100% !important;
    max-width: min(320px, 100%) !important;
    margin-left: auto !important;
    margin-right: auto !important;
    text-align: center !important;
    font-size: 0.9rem !important;
    padding: 0.75rem 1.25rem !important;
    box-sizing: border-box !important;
  }

  /* ── FAQ blocks (legacy + comparison) ── */
  .faq-section {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }

  .faq-item {
    padding: 1rem !important;
    margin-bottom: 0.75rem;
  }

  .faq-question,
  .faq-item h3 {
    font-size: 1rem !important;
    line-height: 1.35 !important;
  }

  .faq-answer,
  .faq-item p {
    font-size: 0.92rem !important;
    line-height: 1.55 !important;
  }

  /* ── Tables: horizontal scroll inside wrapper ── */
  .table-scroll,
  .table-wrapper,
  .comparison-table-wrap,
  .metrics-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    touch-action: pan-x pan-y;
    margin: 1.25rem 0;
  }

  .table-scroll > table,
  .table-wrapper > table,
  .table-scroll .metrics-table,
  .table-scroll .comparison-table {
    display: table;
    width: auto;
    min-width: 640px;
  }

  /* Two-column metric tables (direct in .content): stack as cards, no sideways scroll */
  .content > .metrics-table,
  article.content > .metrics-table {
    display: table;
    width: 100%;
    margin: 1.25rem 0;
    border-collapse: separate;
    border-spacing: 0;
    border: none;
    overflow: visible;
  }

  .content > .metrics-table thead,
  article.content > .metrics-table thead {
    display: none;
  }

  .content > .metrics-table tbody tr,
  article.content > .metrics-table tbody tr {
    display: block;
    margin-bottom: 0.65rem;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #fff;
  }

  .content > .metrics-table td,
  article.content > .metrics-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border-bottom: none;
    white-space: normal;
  }

  .content > .metrics-table td:first-child,
  article.content > .metrics-table td:first-child {
    background: #f8fafc;
    border-bottom: 1px solid #f1f5f9;
    padding: 0.65rem 0.85rem 0.45rem;
  }

  .content > .metrics-table td:last-child,
  article.content > .metrics-table td:last-child {
    padding: 0.55rem 0.85rem 0.75rem;
    font-size: 0.9rem;
    line-height: 1.55;
    color: #4b5563;
  }

  .content > .metrics-table tr:nth-child(even) td,
  article.content > .metrics-table tr:nth-child(even) td {
    background: inherit;
  }

  .content > .metrics-table td:first-child strong,
  article.content > .metrics-table td:first-child strong {
    font-size: 0.88rem;
    color: #111827;
  }

  /* ── Code / formula blocks ── */
  pre,
  .formula-block,
  .code-block {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    font-size: 0.82rem;
    line-height: 1.45;
    padding: 0.85rem 0.9rem;
    border-radius: 10px;
  }

  /* ── Sidebars stack below content ── */
  .content-with-sidebar,
  .page-with-sidebar,
  .layout-with-sidebar {
    display: flex !important;
    flex-direction: column !important;
    gap: 1.5rem;
  }

  aside.sidebar,
  .content-sidebar {
    width: 100% !important;
    max-width: 100% !important;
    position: static !important;
  }

  /* ── Comparison / risk shells ── */
  .cmp-shell,
  .risk-shell {
    padding-left: 0.95rem !important;
    padding-right: 0.95rem !important;
    box-sizing: border-box;
  }

  .cmp-shell .article-content,
  .risk-shell .article-content,
  .risk-shell .content {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* ── Homepage hero: fix excessive side padding from minified nav block ── */
  .home-page .hero .container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    gap: 24px !important;
  }

  .home-page .hero h1,
  .home-page .hero h1 .h1-line {
    font-size: clamp(1.45rem, 6.4vw, 2rem) !important;
    line-height: 1.16 !important;
  }

  .home-page .hero .subtitle,
  .home-page .hero .subtitle a {
    font-size: 0.92rem !important;
    line-height: 1.55 !important;
  }

  .home-page .hero-cta-btn {
    width: 100%;
    max-width: min(320px, 100%);
    box-sizing: border-box;
  }

  /* ── Legacy simple footer (pre site-footer injection) ── */
  body > footer:not(.site-footer) {
    padding: 1.5rem 1rem !important;
    font-size: 0.85rem;
    line-height: 1.5;
  }

  body > footer:not(.site-footer) p {
    overflow-wrap: anywhere;
  }

  /* ── Utility: safe horizontal padding on common wrappers ── */
  .container {
    max-width: 100%;
    box-sizing: border-box;
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }
}

@media (max-width: 480px) {
  article.content,
  .content {
    padding-top: 1.5rem !important;
    padding-bottom: 2.75rem !important;
  }

  .content h2 {
    margin-top: 1.85rem;
  }

  .cta-section {
    padding: 2.25rem 0.85rem !important;
  }

  .related-link,
  .related-link-card {
    font-size: 0.87rem !important;
    padding: 0.75rem 0.85rem !important;
  }
}

/* ── Pass 2: additional mobile fixes (append to navigation.css tail) ── */
@media (max-width: 768px) {
  .table-scroll-hint {
    display: block;
    font-size: 0.82rem;
    color: #64748b;
    margin: 0 0 0.6rem;
    line-height: 1.45;
  }

  /* Unwrapped comparison tables in .content */
  .content > table.comparison-table,
  article.content > table.comparison-table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    margin: 1.25rem 0;
    border-collapse: collapse;
  }

  .content > table.comparison-table thead,
  .content > table.comparison-table tbody,
  .content > table.comparison-table tr {
    display: table;
    width: 100%;
    min-width: 0;
    table-layout: auto;
  }

  /* Wide tables (3+ columns) need horizontal scroll on phones */
  .content > table.comparison-table:has(thead th:nth-child(3)) thead,
  .content > table.comparison-table:has(thead th:nth-child(3)) tbody,
  .content > table.comparison-table:has(thead th:nth-child(3)) tr,
  .table-scroll table thead,
  .table-scroll table tbody,
  .table-scroll table tr {
    min-width: 580px;
  }

  .content > table.comparison-table:has(thead th:nth-child(3))::before {
    content: "Swipe to compare all columns on mobile.";
    display: block;
    font-size: 0.82rem;
    color: #64748b;
    margin-bottom: 0.6rem;
    line-height: 1.45;
  }

  .content > .table-scroll-hint + table.comparison-table::before {
    content: none;
    display: none;
  }

  .content > table.comparison-table th,
  .content > table.comparison-table td {
    font-size: 0.84rem;
    padding: 0.55rem 0.65rem;
    line-height: 1.4;
    white-space: normal;
  }

  /* Step cards: stack number above body on phones */
  .step-card {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0.65rem !important;
    padding: 1rem 0.95rem !important;
  }

  .step-number {
    width: 2rem !important;
    height: 2rem !important;
    font-size: 0.82rem !important;
  }

  /* Page intro band (portfolio-monitoring pattern) */
  .page-intro {
    padding-left: max(1rem, env(safe-area-inset-left, 0px)) !important;
    padding-right: max(1rem, env(safe-area-inset-right, 0px)) !important;
  }

  .page-intro-points {
    grid-template-columns: 1fr !important;
  }

  .monitor-grid {
    grid-template-columns: 1fr !important;
  }

  /* Key takeaways: tighter on small screens */
  .key-takeaways {
    padding: 1rem 0.9rem !important;
    margin-bottom: 1.75rem !important;
  }

  .key-takeaways h2,
  .key-takeaways h3 {
    font-size: 1.02rem !important;
    line-height: 1.32 !important;
  }

  .key-takeaways li {
    font-size: 0.9rem !important;
    line-height: 1.52 !important;
  }

  /* Collapsible further-reading */
  details.further-reading {
    padding: 1.15rem 1rem !important;
    margin: 2rem 0 !important;
  }

  details.further-reading summary {
    font-size: 0.95rem;
    cursor: pointer;
  }

  details.further-reading .further-reading-list {
    margin-top: 0.85rem;
  }

  details.further-reading li {
    font-size: 0.88rem;
    line-height: 1.48;
  }

  /* FAQ details elements */
  .faq-section details.faq-item,
  details.faq-item {
    padding: 0 !important;
  }

  .faq-section details.faq-item summary,
  details.faq-item summary {
    padding: 0.95rem 0 !important;
    font-size: 0.95rem !important;
    line-height: 1.4 !important;
  }

  /* Methodology / trust strip */
  .methodology-trust {
    padding-left: max(1rem, env(safe-area-inset-left, 0px)) !important;
    padding-right: max(1rem, env(safe-area-inset-right, 0px)) !important;
    font-size: 0.88rem !important;
  }
}

/* ── Pass 3: FAQ details, overflow wrappers, flex rows ── */
@media (max-width: 768px) {
  /* Inline overflow wrappers (etf-overlap-checker, portfolio-at-risk, etc.) */
  .content div[style*="overflow-x: auto"],
  .content div[style*="overflow-x:auto"] {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    max-width: 100%;
  }

  .content > div[style*="overflow-x: auto"]:has(table)::before,
  .content > div[style*="overflow-x:auto"]:has(table)::before {
    content: "Swipe to compare all columns on mobile.";
    display: block;
    font-size: 0.82rem;
    color: #64748b;
    margin-bottom: 0.6rem;
    line-height: 1.45;
  }

  /* Unstyled FAQ details in article body (portfolio-diversification, etc.) */
  .content details:not(.faq-item):not(.further-reading) {
    border-bottom: 1px solid #e5e7eb;
    padding: 0.95rem 0 !important;
  }

  .content details:not(.faq-item):not(.further-reading) summary {
    font-weight: 600 !important;
    font-size: 0.95rem !important;
    line-height: 1.4 !important;
    color: #1f2937 !important;
    cursor: pointer;
    list-style: none;
  }

  .content details:not(.faq-item):not(.further-reading) summary::-webkit-details-marker {
    display: none;
  }

  .content details:not(.faq-item):not(.further-reading) p {
    margin-top: 0.75rem !important;
    font-size: 0.92rem !important;
    line-height: 1.62 !important;
    color: #4b5563 !important;
  }

  /* Horizontal stat / meta rows */
  .stat-row,
  .stats-row,
  .hero-meta,
  .founder-stats {
    flex-wrap: wrap !important;
    gap: 0.75rem !important;
    justify-content: center !important;
  }

  /* Chip / quick-link rows */
  .pill-row,
  .tag-row,
  .quick-links,
  .broker-logos {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
    justify-content: center !important;
  }

  /* Feature cards with side-by-side icon + text */
  .feature-card,
  .benefit-card,
  .capability-card {
    flex-direction: column !important;
    align-items: flex-start !important;
    text-align: left !important;
  }
}
