/* ═══════════════════════════════════════════════════════════
   DMEHelper — Mobile Optimization CSS
   Target: 375px (iPhone SE) minimum viewport
   Context: Caregivers in hospital waiting rooms — one-handed use
   ═══════════════════════════════════════════════════════════ */

/* ── Global: Prevent horizontal scroll ──────────────────────────────── */
/* iOS Safari ignores overflow-x:hidden on html/body — use clip instead */
html { overflow-x: clip; }
body { overflow-x: clip; max-width: 100vw; }
* { max-width: 100%; box-sizing: border-box; }
/* Allow overflow-x on explicit scroll containers */
.overflow-x-auto, .scrollbar-hide { max-width: initial; }

/* ── Role selector & wizard cards: contain on mobile ─────────────────── */
@media (max-width: 768px) {
  #role-selector,
  #who-are-you-wizard,
  #patient-wizard,
  #caregiver-wizard {
    overflow-x: hidden;
    max-width: 100%;
  }
  /* Ensure wizard cards don't push wider than container */
  .wiz-care-card,
  #role-selector button,
  #role-selector a {
    max-width: 100%;
    overflow: hidden;
  }
  /* The 2-col grid for prescriber/health plan cards: collapse on narrow phones */
  #role-selector .grid.grid-cols-2 {
    grid-template-columns: 1fr !important;
  }
}
@media (min-width: 481px) and (max-width: 768px) {
  /* Restore 2-col grid on larger phones/small tablets */
  #role-selector .grid.grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

/* ── Typography floor: readable without zooming ─────────────────────── */
/* body already 1rem/16px via SHARED_STYLES — enforce on mobile */
@media (max-width: 768px) {
  p, li, td { font-size: 0.9375rem; line-height: 1.65; } /* 15px baseline */
  /* Secondary / helper text floored at 13px */
  .text-xs { font-size: 0.8125rem !important; }
  /* Scale headings down so they don't blow out 375px */
  h1, .text-4xl { font-size: 2rem !important; }
  .text-5xl { font-size: 2.25rem !important; }
  h2, .text-3xl { font-size: 1.5rem !important; }
  h3, .text-2xl { font-size: 1.25rem !important; }
}
@media (max-width: 480px) {
  h1, .text-4xl { font-size: 1.75rem !important; }
  .text-5xl { font-size: 2rem !important; }
  h2, .text-3xl { font-size: 1.375rem !important; }
}

/* ── Touch targets: minimum 48×48px on all interactive elements ──────── */
/* PageSpeed Accessibility recommendation: 48×48px with 8px spacing between */
@media (max-width: 768px) {
  /* Anchor tags that are standalone CTAs */
  a.rounded-2xl,
  a.rounded-xl,
  a.rounded-lg,
  a.rounded-full,
  .dme-touch-target {
    min-height: 48px;
    display: block;
  }
  /* All buttons: 48px minimum for mobile tap target compliance */
  button { min-height: 48px; }
  /* Nav links and interactive elements */
  nav a { min-height: 48px; display: inline-flex; align-items: center; }
}

/* ── Container horizontal padding on small screens ──────────────────── */
@media (max-width: 480px) {
  /* Ensure content doesn't kiss edges on iPhone SE */
  .max-w-3xl { padding-left: 1rem !important; padding-right: 1rem !important; }
  .max-w-4xl { padding-left: 1rem !important; padding-right: 1rem !important; }
  .max-w-5xl { padding-left: 1rem !important; padding-right: 1rem !important; }
  .max-w-6xl { padding-left: 1rem !important; padding-right: 1rem !important; }
  .max-w-7xl { padding-left: 1rem !important; padding-right: 1rem !important; }
}

/* ── Section overflow containment ─────────────────────────────────────── */
@media (max-width: 768px) {
  /* Prevent any section from causing horizontal overflow */
  section {
    overflow-x: hidden;
    max-width: 100vw;
  }
  /* Main content area: belt-and-suspenders overflow prevention */
  main, #main-content, [role="main"] {
    overflow-x: hidden;
    max-width: 100vw;
  }
}

/* ── Images: always fit container, stack vertically ─────────────────── */
@media (max-width: 640px) {
  img:not([class*="w-"]):not([class*="h-"]) {
    width: 100%;
    height: auto;
  }
  /* Two-column grids collapse on small screens */
  .grid.grid-cols-2:not(.keep-2col) {
    grid-template-columns: 1fr !important;
  }
}

/* ── Section padding: tighter on small screens ──────────────────────── */
@media (max-width: 480px) {
  .py-14 { padding-top: 2.5rem !important; padding-bottom: 2.5rem !important; }
  .py-20 { padding-top: 3rem !important; padding-bottom: 3rem !important; }
  section.mb-12 { margin-bottom: 2rem !important; }
}

/* ── Forms: mobile-friendly, prevent iOS zoom (font-size ≥ 16px) ───── */
@media (max-width: 768px) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  input[type="password"],
  textarea,
  select {
    font-size: 16px !important;   /* critical: prevents iOS Safari auto-zoom */
    min-height: 48px;
    padding: 12px 16px !important;
    border-radius: 10px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }
  /* Submit buttons: full-width on mobile */
  input[type="submit"],
  button[type="submit"] {
    width: 100%;
    min-height: 52px;
    font-size: 1rem;
    border-radius: 12px;
  }
}

/* ── Prose / guide tables: horizontal scroll instead of overflow ─────── */
@media (max-width: 640px) {
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }
}

/* ══════════════════════════════════════════════════════════
   STICKY MOBILE CTA BAR
   Always-visible "Find a Provider" + "Talk to Someone"
   Stays above Dottie FAB. Hidden on desktop.
   ══════════════════════════════════════════════════════════ */

#dme-mobile-cta-bar {
  display: none; /* hidden by default — shown via media query */
}

@media (max-width: 768px) {
  #dme-mobile-cta-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9995;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)) 14px;
    background: rgba(250, 248, 244, 0.97);
    border-top: 1.5px solid rgba(42, 138, 150, 0.12);
    box-shadow: 0 -4px 20px rgba(22, 74, 82, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  #dme-mobile-cta-bar .dme-cta-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: none;
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-size: 0.8125rem;   /* 13px */
    font-weight: 700;
    line-height: 1.2;
    padding: 12px 10px;
    min-height: 48px;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
    transition: background 0.15s, transform 0.1s;
  }
  #dme-mobile-cta-bar .dme-cta-btn:active {
    transform: scale(0.97);
  }
  #dme-mobile-cta-bar .dme-cta-find {
    /* PageSpeed Accessibility: deep-teal (#1a6068) has 6.77:1 contrast on white text (was #2a8a96 = 3.9:1, failed WCAG AA) */
    background: #1a6068;
    color: #fff;
  }
  #dme-mobile-cta-bar .dme-cta-find:hover { background: #164a52; }
  #dme-mobile-cta-bar .dme-cta-talk {
    /* PageSpeed Accessibility: warm sienna (#8b5a2e) has 4.86:1 contrast on white text (was #c88b62 gold = 2.47:1, failed WCAG AA) */
    background: #8b5a2e;
    color: #fff;
  }
  #dme-mobile-cta-bar .dme-cta-talk:hover { background: #7a5028; }

  /* Push body content up so nothing hides behind sticky bar
     CTA bar is ~72px + safe area inset */
  body {
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }

  /* Dottie FAB: lift above sticky CTA bar so it doesn't overlap */
  #dottie-fab {
    bottom: calc(82px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Back to top: also lift above sticky CTA bar */
  #dme-back-top {
    bottom: calc(90px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* ── Hide sticky bar on pages where Dottie is the whole app (app.html) ── */
body.dme-app-page #dme-mobile-cta-bar {
  display: none !important;
}

/* ══════════════════════════════════════════════════════════
   MOBILE ACCORDION — Collapsible Sections
   Applied by mobile-enhancements.js at runtime.
   Section heads become tap toggles on mobile.
   ══════════════════════════════════════════════════════════ */

.dme-collapsible-header {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dme-collapsible-header .dme-chevron {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(42, 138, 150, 0.1);
  color: #2a8a96;
  transition: transform 0.25s ease, background 0.15s;
  margin-left: auto;
}
.dme-collapsible-header[aria-expanded="true"] .dme-chevron {
  transform: rotate(180deg);
  background: rgba(42, 138, 150, 0.18);
}

.dme-collapsible-body {
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.dme-collapsible-body.dme-collapsed {
  max-height: 0 !important;
}
.dme-collapsible-body:not(.dme-collapsed) {
  max-height: 4000px; /* large enough for any content */
}

/* ══════════════════════════════════════════════════════════
   SHARE / SAVE BUTTON (replaces print on mobile)
   ══════════════════════════════════════════════════════════ */

.dme-print-btn {
  display: inline-flex; /* shown on desktop */
}
.dme-share-btn {
  display: none; /* hidden on desktop */
}

@media (max-width: 768px) {
  .dme-print-btn { display: none !important; }
  .dme-share-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f0fafb;
    border: 1.5px solid rgba(42, 138, 150, 0.25);
    color: #1a6068;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 600;
    min-height: 44px;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
  }
  .dme-share-btn:active { background: #e8f4f6; }
}

/* ══════════════════════════════════════════════════════════
   PROVIDER CARDS — better mobile layout
   ══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  /* Provider card main flex: don't squish address/actions */
  article.bg-white .flex.items-start.justify-between.gap-3 {
    flex-wrap: wrap;
  }
  /* Directory listing buttons: full width on mobile */
  article.bg-white .flex.gap-2 a,
  article.bg-white .flex.gap-2 button {
    flex: 1;
    justify-content: center;
  }
}

/* ══════════════════════════════════════════════════════════
   DOTTIE CHAT WIDGET — mobile responsiveness
   ══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  /* FAB: ensure it doesn't overflow right edge */
  #dottie-fab {
    right: 14px !important;
    max-width: calc(100vw - 28px) !important;
  }

  /* Teaser: cap width so it doesn't overflow left edge on narrow phones */
  #dottie-teaser {
    max-width: calc(100vw - 100px) !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }

  /* Chat window: full-width bottom sheet with safe-area insets */
  #dottie-window {
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    border-radius: 20px 20px 0 0 !important;
  }

  /* Message bubbles: constrain to viewport */
  .dottie-msg-bubble {
    max-width: calc(100vw - 80px) !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
  }

  /* Stack option buttons vertically for easier one-thumb tapping */
  #dottie-options {
    flex-direction: column !important;
    max-height: 40vh !important;
  }
  #dottie-options .dottie-opt {
    width: 100% !important;
    text-align: left !important;
    white-space: normal !important;
    min-height: 44px !important;
    padding: 10px 14px !important;
    border-radius: 12px !important;
  }

  /* Input row: respect safe areas */
  #dottie-input-row {
    max-width: 100vw !important;
  }

  /* Provider/plan cards inside Dottie */
  .dottie-provider-card,
  .dottie-plan-card,
  .dottie-vision-card {
    max-width: 100% !important;
    overflow: hidden !important;
  }
}

/* ══════════════════════════════════════════════════════════
   CARE PATHWAYS / HOME HEALTH / HOSPICE — hub page cards
   ══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  /* Ensure pathway/condition cards stack single column */
  .grid.sm\:grid-cols-2,
  .grid.sm\:grid-cols-3 {
    grid-template-columns: 1fr !important;
  }
  /* Side-by-side flex layouts: stack on mobile */
  .flex.gap-4:not(.keep-row),
  .flex.gap-6:not(.keep-row) {
    flex-wrap: wrap;
  }
  /* Icon + text combos: keep side-by-side only if small icons */
  .flex.items-start.gap-3 img,
  .flex.items-start.gap-4 img {
    max-width: 60px;
  }
}

/* ══════════════════════════════════════════════════════════
   BLOG POSTS — long-form readable content
   ══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  /* Blog/guide main content area: remove sidebar gap on mobile */
  .lg\:grid.lg\:grid-cols-3 {
    display: block !important;
  }
  /* Sidebar elements: render as stacked after content on mobile */
  .lg\:w-64,
  .lg\:block.w-64 {
    width: 100% !important;
    display: block !important;
    margin-top: 2rem;
  }
  /* Pull-quote blocks: full width */
  blockquote {
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding-left: 1rem;
    border-left: 3px solid #2a8a96;
  }
}

/* ══════════════════════════════════════════════════════════
   SEARCH RESULTS PAGE
   ══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  /* Filter chips: scrollable horizontally */
  .dme-filter-row {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 8px;
    padding-bottom: 4px;
    flex-wrap: nowrap;
  }
  .dme-filter-row .dme-filter-chip {
    flex-shrink: 0;
    min-height: 36px;
    padding: 8px 14px;
    border-radius: 20px;
    white-space: nowrap;
  }
  /* Pagination: center and larger tap targets */
  .dme-pagination {
    display: flex;
    justify-content: center;
    gap: 4px;
  }
  .dme-pagination a,
  .dme-pagination button {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ══════════════════════════════════════════════════════════
   CAREGIVER WIZARD (Dottie onboarding flow)
   Already handled by Dottie widget CSS above.
   Additional: wizard role selection chips
   ══════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
  /* Wizard multi-select equipment options: 2 per row on mobile */
  .dottie-ms-container {
    max-height: 45vh !important;
  }
  .dottie-ms-opt {
    white-space: normal !important;
    flex: 0 0 calc(50% - 4px) !important;
    text-align: center !important;
    padding: 8px 6px !important;
    font-size: 11.5px !important;
  }
}

/* ══════════════════════════════════════════════════════════
   CRISIS PATHWAY — emergency page emphasis on mobile
   ══════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
  /* Crisis phone numbers: large, tappable */
  a[href^="tel"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    font-size: 1.125rem;
    font-weight: 700;
  }
  /* Emergency info boxes: prominent on mobile */
  .dme-crisis-box {
    padding: 1.25rem !important;
    border-radius: 16px !important;
  }
}

/* ══════════════════════════════════════════════════════════
   ACCESSIBILITY — focus ring for keyboard users on mobile
   ══════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
  :focus-visible {
    outline: 3px solid #2a8a96;
    outline-offset: 2px;
    border-radius: 4px;
  }
}

/* ══════════════════════════════════════════════════════════
   PRINT: override sticky bar and padding
   ══════════════════════════════════════════════════════════ */
@media print {
  #dme-mobile-cta-bar { display: none !important; }
  body { padding-bottom: 0 !important; }
}
