/* ═══════════════════════════════════════════════════════════════════════
   MYHEARTCARE — BLOG MOBILE APP SYSTEM
   Every rule is scoped inside @media (max-width: 768px), so DESKTOP
   (≥769px) renders byte-for-byte identical whether or not this file loads.
   Loaded only on /blog/ and article pages. Behaviors/enhancements that
   need JS live in assets/blog-mobile.js (also mobile-gated).
   ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

  /* ── Native polish (blog pages only) ── */
  body {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    overscroll-behavior-y: auto;
  }
  /* Disable accidental selection on app chrome (keep text selectable in article body) */
  .main-nav, .blog-appbar, .blog-fab, .blog-fab-actions, .blog-chips,
  .reading-progress, .back-to-top, .toc-drawer {
    -webkit-user-select: none;
    user-select: none;
  }
  .article-content, .article-content * { -webkit-user-select: text; user-select: text; }

  /* Momentum scrolling for horizontal rails */
  .blog-carousel, .blog-chips, .related-rail {
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
  }

  /* ═══ HEADER: left as the STANDARD site header (logo + hamburger), identical
     to every other page on the site. We intentionally do NOT restyle .main-nav
     or hide .top-bar here, so the blog header matches the rest of the site.
     The only header-adjacent addition is a slim reading-progress line (articles),
     pinned to the very top edge — it does not alter the header's identity. ═══ */

  /* Reading progress bar — thin line at the very top edge of the viewport */
  .reading-progress {
    position: fixed;
    top: 0;
    left: 0; right: 0;
    height: 3px;
    background: transparent;
    z-index: 1001;            /* sits above the sticky header */
    pointer-events: none;
  }

  /* Inline share row at the top of the article body (replaces the old header share) */
  .article-share {
    display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
    margin: 4px 0 18px;
    padding: 10px 14px;
    background: var(--primary-light, #E3F0FA);
    border-radius: 12px;
  }
  .article-share > span {
    flex: 1 0 100%;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary-dark, #003A73);
  }
  .article-share button {
    flex: 1 1 0;
    min-width: 0;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; cursor: pointer;
    background: var(--primary, #004C97); color: #fff;
    padding: 9px 12px; border-radius: 999px;
    font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 0.85rem;
    min-height: 40px;
  }
  .article-share button span { flex: 0 1 auto; color: inherit; min-width: 0; }
  .article-share button:active { transform: scale(0.96); }
  .article-share button svg { width: 17px; height: 17px; }
  .article-share button.ghost {
    background: #fff;
    color: var(--primary, #004C97);
    box-shadow: inset 0 0 0 1.5px var(--primary, #004C97);
  }
  .reading-progress::after {
    content: '';
    display: block;
    height: 100%;
    width: var(--progress, 0%);
    background: linear-gradient(90deg, var(--accent, #009739), #19c37d);
    border-radius: 0 3px 3px 0;
    transition: width .1s linear;
  }

  /* ═══ LISTING — hero, carousel, chips, feed ═══ */
  .insights-hero { padding: calc(28px + env(safe-area-inset-top)) 0 18px !important; }
  .insights-hero h1 { font-size: 1.7rem !important; }
  .insights-hero-sub { font-size: 0.98rem !important; }
  .insights-section { padding: 18px 0 96px !important; }

  /* Section labels */
  .rail-label {
    font-family: 'Outfit', sans-serif;
    font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-muted, #888);
    padding: 0 4px; margin: 14px 0 10px;
  }

  /* Category chips — horizontal scroll */
  .blog-chips {
    display: flex; gap: 8px;
    overflow-x: auto;
    padding: 4px 16px 12px;
    margin: 0 -16px;
    scrollbar-width: none;
  }
  .blog-chips::-webkit-scrollbar { display: none; }
  .blog-chips .chip {
    flex: 0 0 auto;
    appearance: none; -webkit-appearance: none;
    border: 1px solid var(--border, #E0E5EB);
    background: #fff;
    color: var(--text-body, #666);
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem; font-weight: 600;
    padding: 8px 14px;
    border-radius: 999px;
    scroll-snap-align: start;
    transition: background .2s ease, color .2s ease, border-color .2s ease;
  }
  .blog-chips .chip:active { transform: scale(0.96); }
  .blog-chips .chip[aria-pressed="true"] {
    background: var(--primary, #004C97);
    border-color: var(--primary, #004C97);
    color: #fff;
  }

  /* Featured carousel */
  .blog-carousel {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 2px 16px 14px;
    margin: 0 -16px;
    scrollbar-width: none;
  }
  .blog-carousel::-webkit-scrollbar { display: none; }
  .blog-carousel .blog-card {
    flex: 0 0 78%;
    max-width: 300px;
    scroll-snap-align: center;
  }

  /* Feed grid → single column with app gutters */
  .insights-grid {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
    padding: 0 16px;
  }

  /* Card — compact app feed, image-on-top, no CLS */
  a.blog-card {
    border-radius: 16px;
    box-shadow: 0 2px 10px rgba(0,76,151,0.06);
    transition: transform .18s ease, box-shadow .18s ease;
  }
  a.blog-card:active {
    transform: scale(0.985);
    box-shadow: 0 1px 6px rgba(0,76,151,0.10);
  }
  .blog-card-img {
    aspect-ratio: 16 / 9 !important;
    background: #eef2f7;
    background-image: linear-gradient(90deg, #eaeef3 25%, #f3f6fa 37%, #eaeef3 63%);
    background-size: 400% 100%;
    animation: blogShimmer 1.4s ease infinite;
  }
  .blog-card-img.is-loaded { animation: none; background-image: none; }
  .blog-card-img img { opacity: 0; transition: opacity .35s ease; }
  .blog-card-img.is-loaded img { opacity: 1; }
  .blog-card-body { padding: 14px 16px 16px !important; }
  /* category chip injected by JS */
  .blog-card-chip {
    display: inline-block;
    align-self: flex-start;
    font-family: 'Outfit', sans-serif;
    font-size: 0.66rem; font-weight: 700; letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--accent-dark, #007934);
    background: rgba(0,151,57,0.10);
    padding: 3px 8px; border-radius: 999px;
    margin-bottom: 8px;
  }
  .blog-card-title {
    font-size: 1.06rem !important;
    line-height: 1.32 !important;
    margin-bottom: 6px !important;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .blog-card-excerpt {
    font-size: 0.86rem !important;
    line-height: 1.5 !important;
    margin-bottom: 12px !important;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .blog-card-meta { font-size: 0.7rem !important; margin-bottom: 0 !important; }
  .blog-card-readmore { display: none !important; }   /* whole card is tappable */

  /* Skeleton placeholders */
  .skeleton-card {
    border: 1px solid var(--border-light, #EEF0F4);
    border-radius: 16px;
    overflow: hidden;
    background: #fff;
  }
  .skeleton-card .sk-img { aspect-ratio: 16/9; background: #eef2f7; }
  .skeleton-card .sk-line { height: 12px; margin: 12px 16px 0; border-radius: 6px; background: #eef2f7; }
  .skeleton-card .sk-line.short { width: 55%; }
  .skeleton-card .sk-line.last { height: 10px; width: 35%; margin-bottom: 16px; }

  /* ═══ ARTICLE — reader experience ═══ */
  .article-hero { padding: calc(20px + env(safe-area-inset-top)) 0 8px !important; }
  .article-hero::before { opacity: 0.5; }
  .article-hero-grid { gap: 16px !important; }
  .article-hero-media { order: 1 !important; }     /* image first (full-width) */
  .article-hero-media,
  .article-hero-media img {
    border-radius: 16px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    width: 100%;
  }
  .article-hero-card { padding: 8px 4px 0 !important; background: none !important; box-shadow: none !important; }
  .article-pill {
    font-size: 0.66rem !important; padding: 4px 10px !important;
  }
  .article-meta { font-size: 0.76rem !important; }
  .article-hero-card h1 { font-size: 1.55rem !important; line-height: 1.25 !important; }
  .article-hero-excerpt { font-size: 0.95rem !important; }

  .article-body { padding: 24px 0 110px !important; }
  .article-body-grid { gap: 0 !important; }
  .article-sidebar { display: none !important; }    /* moved to Related rail at bottom */
  .article-overview { display: none !important; }   /* desktop-only summary card */

  /* Reader typography */
  .article-content { font-size: 1.0625rem; line-height: 1.72; color: #2a2f36; }
  .article-content p { margin: 0 0 1.15em; }
  .article-content h2 { font-size: 1.4rem !important; margin: 1.5em 0 0.5em; line-height: 1.25; }
  .article-content h3 { font-size: 1.16rem !important; margin: 1.3em 0 0.4em; }
  .article-content ul, .article-content ol { margin: 0 0 1.15em; padding-left: 1.25em; }
  .article-content li { margin: 0.35em 0; }
  .article-content blockquote {
    margin: 1.3em 0; padding: 14px 16px;
    background: rgba(0,76,151,0.05);
    border-left: 4px solid var(--primary, #004C97);
    border-radius: 0 10px 10px 0;
    font-size: 1rem; color: #34404c;
  }
  .article-content a { color: var(--primary, #004C97); }

  /* In-content images → neat rounded cards, centered, no CLS */
  .article-content img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 14px;
    margin: 1.2em auto;
    box-shadow: 0 2px 12px rgba(0,76,151,0.08);
    cursor: zoom-in;
  }
  .article-content figure { margin: 1.4em 0; }
  .article-content figure img { margin: 0 auto; }
  .article-content figcaption,
  .article-content .img-caption {
    text-align: center; font-size: 0.8rem; color: var(--text-muted, #888);
    margin: -0.6em auto 1.2em; padding: 0 8px;
  }

  /* Article end CTA → app banner */
  .article-cta {
    margin: 8px 0 0 !important;
    padding: 22px 18px !important;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--primary, #004C97), var(--secondary, #0057B8));
    color: #fff;
    box-shadow: 0 8px 24px rgba(0,76,151,0.22);
  }
  .article-cta h3, .article-cta p { color: #fff !important; }
  .article-cta h3 { font-size: 1.3rem !important; }
  .article-cta .article-cta-btn, .article-cta a {
    display: inline-block;
    background: var(--accent, #009739) !important;
    color: #fff !important;
    padding: 12px 22px; border-radius: 999px; font-weight: 700;
  }

  /* Related posts → horizontal snap rail */
  .more-insights { padding: 36px 0 110px !important; }
  .more-insights h2, .related-title { font-size: 1.25rem !important; margin-bottom: 14px; padding: 0 4px; }
  .related-rail, #more-insights-grid {
    display: flex !important;
    grid-template-columns: none !important;
    gap: 14px !important;
    overflow-x: auto;
    padding: 4px 16px 8px;
    margin: 0 -16px;
    scrollbar-width: none;
  }
  #more-insights-grid::-webkit-scrollbar,
  .related-rail::-webkit-scrollbar { display: none; }
  #more-insights-grid .blog-card,
  .related-rail .blog-card {
    flex: 0 0 70%;
    max-width: 260px;
    scroll-snap-align: start;
  }

  /* Hide the site-wide sticky CTA bar on blog (replaced by floating CTA) */
  .sticky-cta { display: none !important; }

  /* ═══ FLOATING CTA (speed-dial) ═══ */
  .blog-fab-wrap {
    position: fixed;
    left: 16px;                                   /* bottom-LEFT: the live-chat widget owns bottom-right */
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: 50px; height: 50px;                    /* only the FAB occupies layout space */
    z-index: 1001;
    pointer-events: none;                         /* the wrap area itself lets taps pass through */
  }
  .blog-fab {
    width: 50px; height: 50px; border-radius: 50%;
    border: none; cursor: pointer;
    background: var(--accent, #009739); color: #fff;
    box-shadow: 0 6px 18px rgba(0,151,57,0.40);
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
    pointer-events: auto;                         /* only the visible button captures taps */
  }
  .blog-fab svg { width: 22px; height: 22px; transition: transform .25s ease; }
  .blog-fab:active { transform: scale(0.94); }
  .blog-fab-wrap.open .blog-fab svg { transform: rotate(135deg); }
  .blog-fab-actions {
    position: absolute;                           /* out of flow so the FAB sits flush at the bottom */
    left: 0; bottom: calc(100% + 12px);
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
    pointer-events: none;
  }
  .blog-fab-wrap.open .blog-fab-actions { pointer-events: auto; }
  .blog-fab-action {
    display: flex; align-items: center; gap: 10px;
    background: #fff; color: var(--primary, #004C97);
    padding: 10px 14px; border-radius: 999px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.16);
    font-family: 'Outfit', sans-serif; font-weight: 700; font-size: 0.86rem;
    text-decoration: none;
    opacity: 0; transform: translateY(10px) scale(0.9);
    transition: opacity .2s ease, transform .2s ease;
  }
  .blog-fab-action svg { width: 18px; height: 18px; }
  .blog-fab-action.call svg { color: var(--accent, #009739); }
  .blog-fab-wrap.open .blog-fab-action { opacity: 1; transform: translateY(0) scale(1); }
  .blog-fab-wrap.open .blog-fab-action:nth-child(1) { transition-delay: .02s; }
  .blog-fab-wrap.open .blog-fab-action:nth-child(2) { transition-delay: .06s; }
  /* dim backdrop when open */
  .blog-fab-backdrop {
    position: fixed; inset: 0; background: rgba(0,18,40,0.35);
    opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s;
    z-index: 1000;
    pointer-events: none;
  }
  .blog-fab-backdrop.open { opacity: 1; visibility: visible; pointer-events: auto; }

  /* ═══ LIGHTBOX ═══ */
  .img-lightbox {
    position: fixed; inset: 0; z-index: 2000;
    background: rgba(8,16,28,0.92);
    display: flex; align-items: center; justify-content: center;
    padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
    opacity: 0; visibility: hidden;
    transition: opacity .25s ease, visibility .25s;
    pointer-events: none;
  }
  .img-lightbox.open { opacity: 1; visibility: visible; pointer-events: auto; }
  .img-lightbox img {
    max-width: 100%; max-height: 100%; border-radius: 8px;
    transform: scale(0.96); transition: transform .25s ease;
  }
  .img-lightbox.open img { transform: scale(1); }
  .img-lightbox-close {
    position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px;
    width: 44px; height: 44px; border-radius: 50%; border: none;
    background: rgba(255,255,255,0.16); color: #fff; font-size: 1.4rem;
    display: inline-flex; align-items: center; justify-content: center;
  }

  /* ═══ BACK TO TOP ═══ */
  .back-to-top {
    position: fixed; left: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    width: 38px; height: 38px; border-radius: 50%;
    border: none; background: #fff; color: var(--primary, #004C97);
    box-shadow: 0 4px 14px rgba(0,0,0,0.16);
    display: inline-flex; align-items: center; justify-content: center;
    opacity: 0; visibility: hidden; transform: translateY(8px);
    transition: opacity .2s ease, visibility .2s, transform .2s ease;
    z-index: 1000;
  }
  .back-to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
  .back-to-top svg { width: 18px; height: 18px; }

  /* ═══ TOC drawer (long posts) — opened from the inline Contents button ═══ */
  .toc-drawer {
    position: fixed; top: 0; bottom: 0; right: 0;
    width: min(82vw, 340px);
    background: #fff;
    z-index: 2001;
    transform: translateX(100%);
    transition: transform .28s ease;
    padding: calc(20px + env(safe-area-inset-top)) 20px env(safe-area-inset-bottom);
    box-shadow: -8px 0 30px rgba(0,0,0,0.18);
    overflow-y: auto;
  }
  .toc-drawer.open { transform: translateX(0); }
  .toc-drawer h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted,#888); margin-bottom: 12px; }
  .toc-drawer a { display: block; padding: 10px 8px; color: var(--text-dark,#333); border-bottom: 1px solid var(--border-light,#EEF0F4); font-size: 0.95rem; }
  .toc-drawer a:active { background: var(--primary-light,#E3F0FA); }
  .toc-backdrop { position: fixed; inset: 0; background: rgba(0,18,40,0.4); z-index: 2000; opacity: 0; visibility: hidden; transition: opacity .2s, visibility .2s; pointer-events: none; }
  .toc-backdrop.open { opacity: 1; visibility: visible; pointer-events: auto; }

  /* keep content above fixed bars */
  .article-body, .insights-section, .more-insights { padding-bottom: 120px; }

  @keyframes blogShimmer {
    0% { background-position: 100% 0; }
    100% { background-position: 0 0; }
  }
}

/* ═══ Reduced motion ═══ */
@media (max-width: 768px) and (prefers-reduced-motion: reduce) {
  a.blog-card, .blog-card-img, .blog-card-img img, .blog-fab, .blog-fab-action,
  .back-to-top, .img-lightbox img, .toc-drawer {
    transition: none !important;
    animation: none !important;
  }
  .blog-card-img img { opacity: 1 !important; }
}
