/* ============================================================
   Responsive — mobile-first media queries
   ============================================================ */

/* ── Utility classes (used via class composition) ───────── */
@media (min-width: 640px) {
  .sm\:grid-2 { grid-template-columns: repeat(2, 1fr); }
  .sm\:grid-3 { grid-template-columns: repeat(3, 1fr); }
  .sm\:hidden { display: none !important; }
  .sm\:block  { display: block !important; }
  .sm\:flex   { display: flex !important; }
}
@media (min-width: 768px) {
  .md\:grid-2 { grid-template-columns: repeat(2, 1fr); }
  .md\:grid-3 { grid-template-columns: repeat(3, 1fr); }
  .md\:grid-4 { grid-template-columns: repeat(4, 1fr); }
  .md\:hidden { display: none !important; }
  .md\:block  { display: block !important; }
  .md\:flex   { display: flex !important; }
  .md\:text-left { text-align: left; }
}
@media (min-width: 1024px) {
  .lg\:grid-3 { grid-template-columns: repeat(3, 1fr); }
  .lg\:grid-4 { grid-template-columns: repeat(4, 1fr); }
  .lg\:hidden { display: none !important; }
  .lg\:block  { display: block !important; }
  .lg\:flex   { display: flex !important; }
}

/* ===========================================================
   Mobile polish — ≤ 768px
   Reduces crowded layouts, stacks grids, shrinks type, makes
   tap targets comfortable.
   =========================================================== */
@media (max-width: 768px) {
  /* Containers get tighter padding */
  .container { padding-left: var(--s-4); padding-right: var(--s-4); }

  /* Sections breathe less on phones */
  .section      { padding: var(--s-10) 0; }
  .section--sm  { padding: var(--s-6) 0; }
  .section--lg  { padding: var(--s-12) 0; }
  .section-header { margin-bottom: var(--s-5); }
  .section-title { font-size: clamp(1.5rem, 7vw, 2rem); line-height: 1.2; }

  /* Hero */
  .hero { padding: var(--s-6) 0 var(--s-8); }
  .hero h1 { font-size: clamp(1.9rem, 8vw, 2.6rem) !important; line-height: 1.15; }
  .hero-content { padding: var(--s-6) var(--s-4); }
  .hero-clinic-name { font-size: clamp(1.4rem, 7vw, 2rem); }
  .hero-tagline { font-size: var(--text-base); }
  .hero-cta { justify-content: center; }
  .hero-cta .btn { flex: 1 1 auto; min-width: 140px; }
  .hero-visual { padding: var(--s-4) var(--s-4) var(--s-8); }

  /* Page header (inside portals and public pages) */
  .page-header { margin-bottom: var(--s-4); }
  .page-title  { font-size: clamp(1.4rem, 6vw, 1.8rem); }
  .page-header-label { font-size: 10px; }
  .page-subtitle { font-size: var(--text-base); }

  /* Any grid-2 should stack on mobile by default */
  .grid-2 { grid-template-columns: 1fr !important; }

  /* Stat grids pack 2-up on mobile (3 is too narrow) */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; gap: var(--s-3); }
  .stat-card  { padding: var(--s-4); }
  .stat-number { font-size: 1.8rem; }
  .stat-label { font-size: 11px; }

  /* Cards */
  .card          { padding: var(--s-4); }
  .card--pad-lg  { padding: var(--s-5); }
  .card-title    { font-size: 1rem; }

  /* Modals: fill the screen less aggressively */
  .modal {
    width: calc(100vw - 1rem) !important;
    max-width: 100% !important;
    margin: 0.5rem !important;
    max-height: calc(100vh - 1rem);
    overflow-y: auto;
  }
  .modal--xl, .modal--lg, .modal--md { width: calc(100vw - 1rem) !important; }
  .modal-body { padding: var(--s-4); }

  /* Buttons — larger tap targets */
  .btn { min-height: 40px; }
  .btn--sm { min-height: 32px; }
  .btn--lg { font-size: var(--text-base); padding: 0.7rem 1.2rem; }

  /* Form fields — prevent iOS zoom by keeping font-size ≥ 16px */
  .field-input,
  .field-input--boxed,
  input.field-input,
  textarea.field-input,
  select.field-input {
    font-size: 16px !important;
  }

  /* Tables convert to stacked cards */
  .table--responsive thead { display: none; }
  .table--responsive tr {
    display: block;
    margin-bottom: var(--s-3);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: var(--s-3);
    background: #fff;
  }
  .table--responsive td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: none !important;
    padding: 4px 0 !important;
    text-align: right;
    gap: var(--s-3);
  }
  .table--responsive td::before {
    content: attr(data-label);
    font-weight: 500;
    color: var(--stone);
    font-size: var(--text-xs);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: left;
    flex-shrink: 0;
  }

  /* Field grids collapse */
  .field-grid,
  .field-grid--2,
  .field-grid--3,
  .field-grid--4 {
    grid-template-columns: 1fr !important;
  }

  /* Any generic auto-fit grid tightens gaps */
  .grid-auto { gap: var(--s-3); }

  /* Landing "How It Works" cards stack one-per-row cleanly */
  .hiw-grid { grid-template-columns: 1fr !important; max-width: 420px; margin-left: auto; margin-right: auto; }

  /* Shop grid packs 2-up */
  .product-card { padding: var(--s-3); }

  /* Filter chips scroll horizontally on tiny screens */
  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap !important;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-chip { flex-shrink: 0; }

  /* Footer tightens */
  .footer-grid { gap: var(--s-5); }
  .footer { padding: var(--s-8) var(--s-4) var(--s-4); }

  /* Alert / info blocks */
  .alert { padding: var(--s-3); }

  /* Toast container above the bottom nav */
  .toast-container { bottom: 5rem !important; padding: 0 var(--s-4); right: 0 !important; left: 0 !important; }
  .toast { max-width: 100%; }
}

/* ===========================================================
   Tiny screens — ≤ 420px (iPhone SE / Mini)
   =========================================================== */
@media (max-width: 420px) {
  .container { padding-left: var(--s-3); padding-right: var(--s-3); }
  .section { padding: var(--s-8) 0; }
  .hero h1 { font-size: 1.75rem !important; }
  .section-title { font-size: 1.4rem !important; }

  /* Stack stats 1-up on really small phones */
  .stats-grid { grid-template-columns: 1fr !important; }

  /* Shop preview 1-up */
  #shop-preview-grid { grid-template-columns: 1fr !important; }
  #sh-grid .grid-auto { grid-template-columns: 1fr !important; }
}

/* ===========================================================
   Print styles
   =========================================================== */
@media print {
  .nav, .sidebar, .footer, .btn, .toast-container, .modal-backdrop {
    display: none !important;
  }
  body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
  }
  .main { padding: 0; }
  .card, .alert {
    border: 1px solid #ccc !important;
    box-shadow: none !important;
    break-inside: avoid;
  }
  a { color: black !important; text-decoration: underline; }
  h1, h2, h3 { page-break-after: avoid; }
}
