/* ============================================================================
   responsive.css — shared mobile/responsive layer for index.html + client.html
   ----------------------------------------------------------------------------
   Mirrors the engine.js shared-asset pattern: ONE file, linked by both pages,
   loaded LAST in <head> so it wins the cascade. It is purely additive and lives
   almost entirely inside @media queries, so it cannot affect the desktop layout.

   Why !important here is justified (and scoped): the app is a desktop-first,
   inline-style-heavy single-file app. Overriding its grids/типography from an
   external sheet — especially inline style="" attributes — requires !important.
   It is confined to mobile/tablet breakpoints, so desktop specificity is intact.

   Benchmarks targeted (UI/UX Pro Max):
   · no horizontal scroll on mobile      · 44px minimum touch targets
   · readable body text (≥15px mobile)   · visible focus states
   · reflow at 375 / 768 / 1024 / 1440   · prefers-reduced-motion respected
   ========================================================================== */

/* ---- breakpoint scale (documentation only; CSS can't use custom-prop in @media) ----
   --bp-mobile: 640px   --bp-tablet: 960px   --bp-desktop: 1200px            */

/* ── Global safety (all viewports): never let content exceed the viewport ── */
html, body { max-width: 100%; }
body { overflow-x: hidden; }                 /* belt-and-braces vs stray wide children */
img, canvas, svg, video { max-width: 100%; height: auto; }

/* Keyboard focus visibility (a11y) — applies everywhere, harmless on desktop */
a:focus-visible, button:focus-visible, select:focus-visible,
input:focus-visible, [tabindex]:focus-visible, .tab-btn:focus-visible {
  outline: 2px solid var(--coral, #B86B52);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Tablet (≤ 960px): drop the sidebar, thin the densest heat grids ── */
@media (max-width: 960px) {
  .main-grid     { grid-template-columns: 1fr !important; }
  .hero-heatmap  { grid-template-columns: repeat(6, 1fr) !important; }
  .house-lens-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .container     { padding-left: 14px; padding-right: 14px; }
}

/* ── Mobile (≤ 640px): the real work ───────────────────────────────────── */
@media (max-width: 640px) {

  /* Typography uplift — lift the page toward the readable floor without
     destroying data density. Body to 15px; the named small-text classes to a
     12–13px floor. (The deeper px→rem fluid-type refactor lands separately.) */
  body { font-size: 15px !important; line-height: 1.6 !important; }
  .subtitle, .abu-body, .abu-card .abu-body, .voter-expand-body,
  .cc-narrative, .voter-detail, .detail-note, .footer, .label {
    font-size: 12px !important;
    line-height: 1.55 !important;
  }
  h1 { font-size: 20px !important; line-height: 1.25 !important; }
  h2 { font-size: 17px !important; }
  h3 { font-size: 15px !important; }

  /* Tighten the page frame */
  .container { padding: 12px 12px 32px !important; }
  .header-top { flex-direction: column; align-items: flex-start !important; gap: 10px; }
  .header-top > div[style*="text-align:right"],
  .header-top > div:last-child { text-align: left !important; }

  /* Tab bar → horizontal scroll strip (no ugly wrap), 44px touch targets */
  .tab-bar {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
  }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex: 0 0 auto !important;
    min-height: 44px;
    padding: 10px 16px !important;
    font-size: 12px !important;
    white-space: nowrap;
    scroll-snap-align: start;
  }

  /* Collapse every multi-column grid to 1–2 columns */
  .main-grid, .planet-grid, .voter-grid, .upcoming-grid,
  .dob-row, .dob-row-time { grid-template-columns: 1fr !important; }
  .kpi-strip, .house-lens-grid { grid-template-columns: repeat(2, 1fr) !important; }
  /* Heat grids stay multi-cell but shrink so they don't overflow */
  .heatmap-grid, .hero-heatmap { grid-template-columns: repeat(6, 1fr) !important; }

  /* Wide fixed-column rows / tables / charts → scroll instead of overflowing */
  .sr-planet-row { grid-template-columns: repeat(7, minmax(40px, 1fr)) !important; }
  table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .chart-wrap, .chart-container, canvas { max-width: 100% !important; }

  /* Touch targets for the remaining interactive controls */
  .period-mode-btn, .house-tab-btn, .btn-reset, select, button,
  input[type="date"], input[type="text"], input[type="number"] { min-height: 44px; }
  select, input { font-size: 16px !important; }   /* ≥16px stops iOS auto-zoom on focus */
  /* Form controls must never exceed the column — a <select> with a long option
     (e.g. chartZodiac "Tropical (default — AstroSeek standard)") otherwise sizes
     to its intrinsic content width and pushes a horizontal scrollbar. */
  select, input, textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  select { width: 100% !important; text-overflow: ellipsis; }

  /* Micro-label readability floor (mobile only) — the app is desktop-first and
     data-dense, so hundreds of labels are hard-coded to 5–8px INLINE. clamp()
     is the wrong tool here (it shrinks text as the viewport shrinks); the right
     move is to LIFT sub-floor inline sizes on small screens while leaving the
     desktop density byte-for-byte intact. Substring selectors are anchored with
     the unit so "font-size:8px" can't match "font-size:80px". Both spaced and
     unspaced inline forms are covered. */
  [style*="font-size:4.5px"], [style*="font-size: 4.5px"],
  [style*="font-size:5px"],   [style*="font-size: 5px"],
  [style*="font-size:5.5px"], [style*="font-size: 5.5px"],
  [style*="font-size:6px"],   [style*="font-size: 6px"],
  [style*="font-size:6.5px"], [style*="font-size: 6.5px"],
  [style*="font-size:7px"],   [style*="font-size: 7px"],
  [style*="font-size:7.5px"], [style*="font-size: 7.5px"],
  [style*="font-size:8px"],   [style*="font-size: 8px"],
  [style*="font-size:8.5px"], [style*="font-size: 8.5px"] {
    font-size: 10px !important;
    line-height: 1.4 !important;
  }

  /* Modal fills the small screen comfortably */
  .modal-content { width: 94% !important; max-width: 94% !important; padding: 16px !important; }

  /* Misc fixed widths that would otherwise overflow */
  .cc-narrative { max-width: 100% !important; }
}

/* ── Very small phones (≤ 380px): one more density step down ── */
@media (max-width: 380px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr) !important; }
  .heatmap-grid, .hero-heatmap { grid-template-columns: repeat(4, 1fr) !important; }
  .house-lens-grid { grid-template-columns: 1fr !important; }
}

/* ── D5 — density toggle: collapse tab bar on very narrow (≤ 480px) ── */
@media (max-width: 480px) {
  .tab-nav-row { flex-wrap: wrap; }
  .density-btn { align-self: flex-end; }
}

/* ── D5 — Print stylesheet ──────────────────────────────────────────────── */
@media print {
  /* Hide all interactive chrome */
  .tab-nav-row .density-btn,
  .tab-bar,
  #appDrawer,
  #monthDetailModal,
  .footer,
  .btn-reset,
  .how-to-btn,
  .period-controls,
  .print-hide { display: none !important; }

  /* Only the active tab content */
  .tab-content { display: none !important; }
  .tab-content.active { display: block !important; }

  /* Clean page */
  body { background: #fff !important; color: #1a1a1a !important; font-size: 12px !important; }
  .container { padding: 12px !important; max-width: 100% !important; box-shadow: none !important; }

  /* Flat cards */
  .card, .info-card, .voter-chart-card, .command-center,
  .consensus-card, .l0-strip { box-shadow: none !important; border-color: #ccc !important; }

  /* Avoid page breaks inside key components */
  .card, .info-card, .voter-chart-card, .l0-strip { break-inside: avoid; }
  h1, h2, h3 { break-after: avoid; }

  /* Canvas respects column width */
  canvas { max-width: 100% !important; break-inside: avoid; }

  /* Tables readable in B&W */
  table { border-collapse: collapse; }
  td, th { border: 1px solid #ccc !important; }
}
