/* ═══════════════════════════════════════════════════════════════════════════
 * HIKMA — Platform-wide Responsive Layer
 *
 * 2026-06-08 — Single responsive CSS that applies across every dashboard
 * page. Loaded AFTER hikma-design-system.css + hikma-design-system-v3.css so
 * its breakpoints win.
 *
 * Breakpoints:
 *   ≤768px (phone / portrait tablet) — single-column, hamburger-friendly,
 *                                      tables collapse to card view
 *   ≤1024px (landscape tablet)        — 2-column grids, full table preserved
 *   >1024px                           — original desktop layout, untouched
 *
 * Touch-friendly defaults:
 *   - Buttons + inputs: min-height 44px (Apple HIG / Material standard)
 *   - Inputs: font-size 16px on mobile to prevent iOS auto-zoom
 *   - Touch targets: spaced ≥8px apart
 *
 * Selectors are deliberately generic (matching common class patterns from
 * billing-review.html, intake.html, discharge.html, executive.html, etc.) so
 * adding this stylesheet to a page gives it baseline responsive behavior with
 * zero per-page work. Page-specific overrides go in the page's own <style>.
 * ═══════════════════════════════════════════════════════════════════════════ */

/* ── Touch-friendly minimums everywhere (small screens get strict) ─────── */
@media (max-width: 1024px) {
  button, .btn, .btn-action, .btn-approve, .btn-reject,
  .btn-topbar, .btn-refresh, .btn-revise-cancel, .btn-revise-submit,
  .tab, a.btn, input[type="submit"], input[type="button"] {
    min-height: 40px;
  }
}

@media (max-width: 768px) {
  /* Inputs at 16px prevent iOS Safari auto-zoom on focus */
  input[type="text"], input[type="number"], input[type="email"],
  input[type="password"], input[type="tel"], input[type="search"],
  input[type="datetime-local"], input[type="date"], input[type="time"],
  select, textarea {
    min-height: 44px !important;
    font-size: 16px !important;
  }
  button, .btn, .btn-action, .btn-approve, .btn-reject,
  .btn-topbar, .btn-refresh, .btn-revise-cancel, .btn-revise-submit,
  .tab, a.btn, input[type="submit"], input[type="button"] {
    min-height: 44px !important;
    font-size: 14px !important;
  }
}

/* ── Layout reflow on tablet ───────────────────────────────────────────── */
@media (max-width: 1024px) {
  /* KPI strips reflow */
  .kpi-strip, .kpis, .kpi-row, .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)) !important;
  }
  /* Common 3-column grids drop to 2 */
  .intel-grid, .grid-3, .three-col {
    grid-template-columns: 1fr 1fr !important;
  }
  /* Page padding tightens */
  .page, main.page, .content, .main-content {
    padding: 16px !important;
  }
  /* Section card headers wrap their action row */
  .section-card-header, .card-header {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
}

/* ── Phone-sized layout ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header: hide subtitle chip, tighten brand */
  .topbar-sub, .header-sub {
    display: none !important;
  }
  .topbar-name, .header-brand {
    font-size: 14px !important;
    letter-spacing: 1px !important;
  }
  header, .header {
    padding: 0 14px !important;
  }

  /* Single-column everywhere */
  .intel-grid, .grid-3, .three-col,
  .grid-2, .two-col, .kpi-strip, .kpis, .kpi-row, .kpi-grid,
  .workspaces-grid, .tile-grid, .workspace-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  /* Cards full-width with breathing room */
  .intel-card, .section-card, .card, .workspace-tile, .tile {
    max-width: 100% !important;
    width: 100% !important;
  }

  /* Page padding tightens further */
  .page, main.page, .content, .main-content {
    padding: 10px !important;
  }

  /* Filter pills wrap nicely */
  .filter-pills {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .filter-pill {
    min-height: 38px !important;
    padding: 8px 12px !important;
    font-size: 13px !important;
  }

  /* ── Tables: collapse to card view ───────────────────────────────── */
  /* Generic pattern: tables with `data-label` attribute on td stack
     cleanly. We also handle plain tables but the data-label pattern
     gives the best UX. */
  table.q-table, table.responsive-table, .stack-table table,
  .table-responsive table {
    border: none !important;
  }
  table.q-table thead,
  table.responsive-table thead,
  .stack-table table thead,
  .table-responsive table thead {
    display: none !important;
  }
  table.q-table, table.q-table tbody, table.q-table tr,
  table.responsive-table, table.responsive-table tbody, table.responsive-table tr,
  .stack-table table, .stack-table table tbody, .stack-table table tr,
  .table-responsive table, .table-responsive table tbody, .table-responsive table tr {
    display: block !important;
    width: 100% !important;
  }
  table.q-table tr,
  table.responsive-table tr,
  .stack-table table tr,
  .table-responsive table tr {
    border: 1px solid var(--border, #e5e7eb) !important;
    border-radius: 8px !important;
    margin-bottom: 12px !important;
    background: #fff !important;
    padding: 10px !important;
  }
  table.q-table td,
  table.responsive-table td,
  .stack-table table td,
  .table-responsive table td {
    display: block !important;
    width: 100% !important;
    padding: 6px 0 !important;
    border: none !important;
  }
  /* When the td has a data-label attribute, render the label above */
  table.q-table td[data-label]::before,
  table.responsive-table td[data-label]::before,
  .stack-table table td[data-label]::before,
  .table-responsive table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted, #6b7280);
    text-transform: uppercase;
    margin-bottom: 2px;
    letter-spacing: 0.05em;
  }

  /* Modals: full-screen on phone */
  .hikma-modal-content, .modal-content, .revise-modal {
    max-width: 95vw !important;
    width: 95vw !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }

  /* Two-col forms become single-col */
  .form-row, .form-grid-2 {
    grid-template-columns: 1fr !important;
  }
}

/* ── Sidebar collapse on phone (left-side nav) ────────────────────────── */
@media (max-width: 768px) {
  /* The hikma-nav.js sidebar — give it room to be tucked off-canvas */
  .hk-sidebar, .sidebar, aside.nav, aside.sidebar {
    position: fixed !important;
    top: 0; bottom: 0; left: 0;
    z-index: 200;
    width: 84vw; max-width: 320px;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  .hk-sidebar.open, .sidebar.open, aside.nav.open, aside.sidebar.open {
    transform: translateX(0);
  }
  /* When sidebar is open, content shifts behind it (overlay) */
  body.has-sidebar-open {
    overflow: hidden;
  }
  /* If a page has main-content sibling to sidebar, drop the offset */
  .main-content, main.content, main.main {
    margin-left: 0 !important;
  }
}

/* ── Hover-only affordances become always-visible on touch devices ───── */
@media (hover: none) {
  .show-on-hover, .row-actions {
    opacity: 1 !important;
    visibility: visible !important;
  }
}

/* ── RTL adjustments for Arabic ──────────────────────────────────────── */
html[dir="rtl"] @media (max-width: 768px) {
  /* Sidebar slides in from the right on RTL */
  .hk-sidebar, .sidebar, aside.nav, aside.sidebar {
    left: auto; right: 0;
    transform: translateX(100%);
  }
  .hk-sidebar.open, .sidebar.open, aside.nav.open, aside.sidebar.open {
    transform: translateX(0);
  }
}
