/* ============================================================================
   jp-portal-mobile.css — Clinic Portal mobile layer — v1.7.17 (2026-06-11)
   ----------------------------------------------------------------------------
   Mobile Wave 1. Desktop is UNTOUCHED by design: every rule here lives behind
   a max-width media query (or styles elements that only exist on mobile, like
   the drawer toggle + scrim injected by jp-cp-mobile-nav.js).

   Loads AFTER the portal's inline styles and jp-portal-tokens.css, so its
   equal-specificity !important rules win over the inline ≤767px icon-rail
   block where they must.

   Contents:
     1 · Navigation drawer  — icon rail (closed) ⇄ full labeled drawer (open)
     2 · Touch targets      — 44px floors on interactive elements
     3 · Floating elements  — tour chip · sign-off queue · tour card
                              (bottom sheet) with safe-area insets, no overlap
     4 · Modals & panels    — dvh clamps + internal scroll (search · notif ·
                              detail panel · intake editor overlay)
     5 · Tables             — horizontal scroll + sticky first column
     6 · 390px small-phone pass for the v1.7.11–15 surfaces
   ========================================================================== */

/* Drawer chrome exists only on mobile — inert and hidden on desktop */
#jp-mnav-toggle { display: none; }
#jp-mnav-scrim  { display: none; }

@media (max-width: 767px) {

  /* ── 1 · Navigation drawer ─────────────────────────────────────────────
     Closed state = the existing 56px icon rail (unchanged, instantly
     familiar). Open state = the rail expands to a 268px labeled drawer that
     OVERLAYS content (#main keeps its 56px offset), under a scrim.        */
  #sidebar { transition: width .22s ease, min-width .22s ease;
             z-index: 9410; overflow-y: auto; overflow-x: hidden;
             -webkit-overflow-scrolling: touch; }
  #jp-mnav-toggle { display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 4px; width: 44px; height: 44px;
    margin: 8px auto 0; background: none; border: none; cursor: pointer;
    border-radius: 12px; }
  #jp-mnav-toggle span { display: block; width: 18px; height: 2px;
    border-radius: 2px; background: rgba(255,255,255,.85);
    transition: transform .2s ease, opacity .2s ease; }
  #jp-mnav-toggle:active { background: rgba(255,255,255,.08); }
  body.jp-drawer-open #jp-mnav-toggle span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  body.jp-drawer-open #jp-mnav-toggle span:nth-child(2) { opacity: 0; }
  body.jp-drawer-open #jp-mnav-toggle span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

  body.jp-drawer-open #sidebar { width: 268px !important; min-width: 268px !important;
    box-shadow: 24px 0 60px rgba(0, 0, 0, .45); }
  /* restore the labels/badges the inline icon-rail block hides
     (body-class selectors out-specify the inline #sidebar rules) */
  body.jp-drawer-open #sidebar .label,
  body.jp-drawer-open #sidebar .sb-label,
  body.jp-drawer-open #sidebar .sb-user-info { display: inline-block !important; }
  body.jp-drawer-open #sidebar .sb-badge { display: inline-flex !important; }
  body.jp-drawer-open #sidebar .sb-item { justify-content: flex-start !important;
    padding: 11px 14px !important; margin: 2px 8px !important; }
  body.jp-drawer-open #sidebar .sb-logo { justify-content: flex-start !important;
    padding: 14px 16px !important; }
  body.jp-drawer-open #sidebar .sb-user { justify-content: flex-start !important;
    padding: 10px 14px !important; }

  body.jp-drawer-open #jp-mnav-scrim { display: block; position: fixed; inset: 0;
    background: rgba(6, 18, 42, .52); z-index: 9405;
    backdrop-filter: blur(1.5px); -webkit-backdrop-filter: blur(1.5px); }

  /* ── v1.7.29 · rail discipline ─────────────────────────────────────────
     Device QA showed the rail in a half-expanded state with the wordmark
     image (72px tall, wide) cut to "JetPo" and bleeding over content.
     1) The closed rail is EXACTLY 56px — no in-between states.
     2) The wordmark never renders in the rail; a compact JP mark does.
        The full wordmark returns when the drawer opens. */
  /* v1.7.35 — design consolidation: the icon rail confused phones (three
     menus: rail + drawer + tab bar). On phones the rail is RETIRED — the
     tab bar is primary nav, the full drawer opens via the fixed hamburger.
     Desktop (>767px) untouched. */
  body:not(.jp-drawer-open) #sidebar { width: 0 !important;
    min-width: 0 !important; max-width: 0 !important;
    border: none !important; overflow: hidden !important; }
  /* body-prefixed: the page's inline `#main{margin-left:56px!important}`
     loads after this sheet — higher specificity required, not just order */
  body #main { margin-left: 0 !important; width: 100vw !important; }
  body #topbar { padding-left: 64px !important; }   /* room for the fixed toggle */
  #jp-mnav-toggle { position: fixed !important;
    top: calc(8px + env(safe-area-inset-top, 0px)) !important; left: 12px !important;
    z-index: 9412 !important; margin: 0 !important;
    background: rgba(10, 45, 110, .07) !important;
    border: 1px solid rgba(10, 45, 110, .16) !important; border-radius: 12px !important; }
  #jp-mnav-toggle span { background: #0A2D6E !important; }
  body.jp-drawer-open #jp-mnav-toggle {
    background: rgba(255, 255, 255, .10) !important;
    border-color: rgba(255, 255, 255, .25) !important; }
  body.jp-drawer-open #jp-mnav-toggle span { background: #fff !important; }
  body:not(.jp-drawer-open) #sidebar .sb-logo img { display: none !important; }
  body:not(.jp-drawer-open) #sidebar .sb-logo { justify-content: center !important;
    padding: 12px 0 !important; }
  body:not(.jp-drawer-open) #sidebar .sb-logo::before { content: "JP";
    display: grid; place-items: center; width: 34px; height: 34px;
    border-radius: 10px; background: linear-gradient(135deg, #00C9C0, #0A8FDF);
    color: #04102A; font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
  body.jp-drawer-open #sidebar .sb-logo img { display: block !important;
    height: 34px !important; width: auto !important; margin: 0 !important; }

  /* tour FAB clears the 56px rail and the bottom tab bar (its own injected
     <style> loads later, so !important is required here) */
  #jpt-fab { left: 16px !important;   /* v1.7.35: no rail to clear anymore */
    bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important; }
  body.jp-drawer-open { overflow: hidden; }   /* page doesn't scroll behind the drawer */

  /* ── 2 · Touch targets (44px HIG floor) ────────────────────────────────── */
  #sidebar .sb-item { min-height: 44px; }
  .cpv-btn, .ps-btn, .ai-tool-btn, .rk2-act, .cpw-next button,
  .jp-cp-aiwb-btn, .scb-h button, .cpw-accept button, .if-tpl button,
  .soq-chip, #jpt-fab { min-height: 44px; }
  .cpw-step { min-height: 72px; }
  .cpw-task { padding: 11px 4px; }
  .cpw-task .tick { width: 28px; height: 28px; }
  .scb-sum .tabs button, .pt-tab { min-height: 34px; }   /* secondary controls */
  .mc-row .cpv-btn { padding: 9px 13px; }

  /* ── 3 · Floating elements — deterministic, safe-area aware ───────────── */
  #jpt-fab { left: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    font-size: 10.5px; padding: 9px 14px; }
  .soq { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .soq-panel { width: min(330px, calc(100vw - 24px)); }
  /* tour card → full-width bottom sheet */
  #jpt-card { left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    width: auto; max-height: 62dvh; overflow-y: auto;
    border-radius: 18px 18px 14px 14px; }
  /* while the tour drives, lift the unrelated floaters out of the way */
  body:has(#jpt-ov.on) .soq, body:has(#jpt-ov.on) #jpt-fab { display: none; }

  /* ── 4 · Modals & panels — clamp + scroll, never a wall ────────────────── */
  .search-modal { width: min(560px, calc(100vw - 20px)) !important;
    max-height: 82dvh; overflow-y: auto; }
  .notif-panel { width: min(380px, calc(100vw - 20px)) !important;
    max-height: 80dvh; overflow-y: auto; }
  .detail-panel { width: 100% !important; max-width: 100vw !important; }
  #ife-ov > div, .ife-sheet { max-height: 88dvh !important; overflow-y: auto !important; }
  .sign-modal-content { max-height: 85dvh; overflow-y: auto; }

  /* ── 5 · Tables — scroll, don't squish ─────────────────────────────────── */
  .jp-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .jp-table thead, .jp-table tbody, .jp-table tr { white-space: nowrap; }
  .jp-table th:first-child, .jp-table td:first-child { position: sticky; left: 0;
    background: var(--surface, #fff); z-index: 1;
    box-shadow: 6px 0 8px -6px rgba(10, 45, 110, .12); }
  [data-theme="dark"] .jp-table th:first-child,
  [data-theme="dark"] .jp-table td:first-child { background: var(--surface, #102040); }
}

/* ── 7 · Wave 2 — phone-native flows (Message Hub drill-in · Dossiers) ──── */
.jp-mflow-back { display: none; }
@media (max-width: 767px) {
  /* Message Hub: three-pane grid → two stacked screens (list ⇄ conversation).
     jp-cp-mobile-flows.js toggles .jp-mh-detail on #page-messages.          */
  #page-messages .mh { display: block; height: auto; min-height: 72dvh; }
  #page-messages .mh-list { border-right: none; max-height: none; }
  #page-messages .mh-rail { display: none; }
  #page-messages.jp-mh-detail .mh-list { display: none; }
  #page-messages:not(.jp-mh-detail) .mh-conv { display: none; }
  #page-messages.jp-mh-detail .mh-conv { min-height: 72dvh; }
  .jp-mflow-back { display: flex; align-items: center; gap: 8px; width: 100%;
    font-family: var(--font, "Plus Jakarta Sans", sans-serif); font-size: 12px;
    font-weight: 800; color: var(--text, #0A2D6E); background: var(--bg, #F7F9FD);
    border: none; border-bottom: 1px solid var(--border, #D4DCF0);
    padding: 12px 14px; min-height: 44px; cursor: pointer; text-align: left;
    position: sticky; top: 0; z-index: 3; }
  .jp-mflow-back::before { content: "←"; font-size: 15px; color: var(--teal-dk, #00A8A0); }
  [data-theme="dark"] .jp-mflow-back { background: #0d1a36; color: var(--text, #E8EEF8); }
  /* conversation composer stays reachable above the tab bar */
  #page-messages .mh-conv { padding-bottom: 4px; }

  /* Dossiers: accordion already fits — fix the ergonomics around it */
  .cpd-qp-overlay { align-items: flex-end; padding: 0; }
  .cpd-qp-overlay > div { max-height: 90dvh; overflow-y: auto; width: 100%;
    border-radius: 18px 18px 0 0; }
  .cpd-actions { gap: 7px; }
  .cpd-actions .cpv-btn { flex: 1 1 46%; justify-content: center; }
  .cpd-grid { grid-template-columns: 1fr 1fr; }
  .cpd-form { grid-template-columns: 1fr; }
}

/* ── 8 · Wave 2 — bottom tab bar (thumb-zone nav, ≤767px only) ──────────── */
#jp-tabbar { display: none; }
@media (max-width: 767px) {
  #jp-tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0;
    z-index: 9300; background: var(--navy, #0A2D6E);
    border-top: 1px solid rgba(255, 255, 255, .10);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -8px 30px rgba(6, 18, 42, .25); }
  #jp-tabbar button { position: relative; flex: 1; display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; min-height: 48px; background: none; border: none; cursor: pointer;
    font-family: var(--font, "Plus Jakarta Sans", sans-serif);
    border-radius: 12px; color: rgba(255, 255, 255, .55); }
  #jp-tabbar button .ic { font-size: 17px; line-height: 1; }
  #jp-tabbar button .lb { font-size: 8.5px; font-weight: 800;
    letter-spacing: .04em; text-transform: uppercase; }
  #jp-tabbar button.on { color: var(--teal, #00C9C0);
    background: rgba(0, 201, 192, .10); }
  #jp-tabbar button .bdg { position: absolute; top: 3px; right: calc(50% - 19px);
    min-width: 15px; height: 15px; border-radius: 999px; background: #F43F5E;
    color: #fff; font-size: 8.5px; font-weight: 800; display: flex;
    align-items: center; justify-content: center; padding: 0 4px; }
  #jp-tabbar button .bdg:empty, #jp-tabbar button .bdg[data-n="0"] { display: none; }
  [data-theme="dark"] #jp-tabbar { background: #0a1730; }

  /* content + floats clear the bar */
  body.jp-has-tabbar #content,
  body.jp-has-tabbar #page-content, body.jp-has-tabbar .page-content
    { padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important; }
  body.jp-has-tabbar #jpt-fab,
  body.jp-has-tabbar .soq { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
  body.jp-has-tabbar #jpt-card { bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  body:has(#jpt-ov.on) #jp-tabbar { display: none; }   /* tour drives full-screen */
}

/* ── 6 · Small-phone pass (≤430px) for the v1.7.11–15 surfaces ──────────── */
@media (max-width: 430px) {
  .cpw-hd { gap: 7px; }
  .cpw-hd .who { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cpw-hd .sub { display: none; }                /* keep the header to two lines */
  .cpw-pw-hd .sub { margin-left: 0 !important; width: 100%; }
  .cpw-task .meta span { font-size: 9px; padding: 1px 6px; }
  .rk2-head { flex-direction: column; align-items: flex-start; gap: 4px; }
  .rk2-hero { padding: 12px 13px; }
  .rk2-hero .delta { width: 100%; }
  .rk2-iv { padding: 10px 11px; gap: 9px; }
  .rk2-iv .meta span { font-size: 9px; }
  .rk2-drv .n { flex-basis: 110px; font-size: 10.5px; }
  .rk2-drv .pts { flex-basis: 48px; font-size: 9.5px; }
  .rk2-cats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .scb-item { font-size: 11.5px; }
  .scb-tl { font-size: 10.5px; }
  .scb-meta { font-size: 10px; }
  .cpv-ctx select { min-width: 0; width: 100%; }
  .cpv-ctx { gap: 8px; }
  .cpv-score { font-size: 22px; }
  .mc-row { padding: 10px 12px; gap: 9px; }
  .mc-row .s { font-size: 11px; }
  .ps-grid { grid-template-columns: 1fr !important; }
  #jpt-card h4 { font-size: 14px; }
}
