  /* ---------- Modal ---------- */
  .modal-bg{
    position:fixed;inset:0;background:rgba(15,23,42,.55);
    backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);
    display:none;align-items:flex-end;justify-content:center;
    z-index:100;padding:24px 0 0;
    padding-top:max(24px, env(safe-area-inset-top));
  }
  .modal-bg.open{display:flex}
  @media (min-width:640px){.modal-bg{align-items:center;padding:24px}}
  .modal{
    background:var(--card);border-radius:20px 20px 0 0;
    width:100%;max-width:520px;overflow:auto;
    /* dvh tracks the visible viewport on mobile; vh fallback for older browsers */
    max-height:calc(100vh - 24px);
    max-height:calc(100dvh - 24px);
    overscroll-behavior:contain;
    padding-bottom:env(safe-area-inset-bottom);
    box-shadow:var(--shadow-3);
    animation:slideUp .25s ease-out;
  }
  @media (min-width:640px){.modal{
    border-radius:18px;animation:fadeUp .2s ease-out;padding-bottom:0;
    max-height:calc(100vh - 48px);
    max-height:calc(100dvh - 48px);
  }}
  /* Modals injected as a bare .modal-card (no modal-head/body/foot structure) */
  .modal-card{padding:18px 20px;max-width:100%!important}
  .modal-card>h3{font-size:15.5px;font-weight:700;margin:0 0 8px}
  @keyframes slideUp{from{transform:translateY(20px);opacity:0}to{transform:translateY(0);opacity:1}}
  @keyframes fadeUp{from{transform:translateY(8px);opacity:0}to{transform:translateY(0);opacity:1}}
  .modal-head{
    padding:16px 20px;border-bottom:1px solid var(--hairline);
    display:flex;align-items:center;gap:12px;
  }
  .modal-head .grow{flex:1}
  .modal-head h3{font-size:15px;font-weight:700}
  .modal-head .small{margin-top:2px}
  .modal-body{padding:18px 20px}
  .modal-foot{padding:14px 20px;border-top:1px solid var(--hairline);display:flex;justify-content:flex-end;gap:8px}
  .field{margin-bottom:12px}
  .field label{display:block;font-size:11.5px;color:var(--muted);font-weight:600;text-transform:uppercase;letter-spacing:.05em;margin-bottom:4px}
  .field input,.field textarea,.field select{
    width:100%;padding:9px 11px;font-size:14px;
    background:var(--bg-soft);border:1px solid var(--border);border-radius:8px;outline:none;
  }
  .field input:focus,.field textarea:focus,.field select:focus{border-color:var(--brand);background:var(--card);box-shadow:0 0 0 3px var(--brand-ring)}
  .source-line{
    margin-top:10px;padding:10px 12px;background:var(--bg-soft);
    border-radius:8px;font-size:11.5px;color:var(--muted);line-height:1.5;
  }
  .source-line b{color:var(--ink-2);font-weight:600}

  .record-camera-card{
    display:flex;align-items:center;gap:14px;padding:20px;border:1px solid var(--border);
    border-radius:12px;background:var(--card)
  }
  .record-camera-icon{
    width:44px;height:44px;border-radius:11px;background:var(--ok-soft);color:var(--ok);
    border:1px solid var(--ok-border);display:flex;align-items:center;justify-content:center;flex-shrink:0
  }
  .record-camera-icon svg{width:21px;height:21px}
  @media (max-width:560px){
    .record-camera-card{align-items:flex-start;flex-wrap:wrap}
    .record-camera-card .btn{width:100%;justify-content:center}
  }

  /* Draft auto-save. The status line stands where the Save button used to, so
     the place the clinician looked for confirmation still answers them — it
     just reports rather than asks. */
  .draft-save-row{margin-top:12px;display:flex;align-items:center;gap:10px;flex-wrap:wrap}
  .draft-save-state{
    display:inline-flex;align-items:center;gap:7px;flex:1 1 auto;min-width:0;
    font-size:12px;color:var(--muted);line-height:1.4
  }
  .draft-save-state[data-state="error"]{color:var(--crit)}
  .draft-save-state[data-state="empty"]{color:var(--warn)}
  .draft-save-dot{width:7px;height:7px;border-radius:50%;flex:0 0 auto;background:var(--muted)}
  .draft-save-dot.ok{background:var(--ok)}
  .draft-save-dot.warn{background:var(--warn)}
  .draft-save-dot.crit{background:var(--crit)}
  /* Mid-save the dot pulses; a reader who prefers no motion still gets the
     wording, which carries the same state on its own. */
  .draft-save-state[data-state="saving"] .draft-save-dot{animation:draftSavePulse 1.1s ease-in-out infinite}
  @keyframes draftSavePulse{0%,100%{opacity:.35}50%{opacity:1}}
  @media (prefers-reduced-motion:reduce){
    .draft-save-state[data-state="saving"] .draft-save-dot{animation:none}
  }

  .upload-row{display:flex;align-items:center;gap:10px;padding:7px 0;border-top:1px solid var(--border)}
  .upload-row-name{font-weight:600;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

  /* Bed-assignment sheet: high-frequency bedside confirmation flow. */
  .bed-sheet{padding:20px;max-width:560px}
  .modal:has(.bed-sheet){max-width:560px}
  .bed-sheet-kicker{
    font-size:11px;color:var(--muted);letter-spacing:.08em;text-transform:uppercase;
    font-weight:800;margin-bottom:6px;
  }
  .bed-sheet-title{display:flex;align-items:flex-start;justify-content:space-between;gap:14px;margin-bottom:10px}
  .bed-sheet-title h3{font-size:19px;line-height:1.2;font-weight:800;letter-spacing:0;margin:0;color:var(--ink)}
  .bed-sheet-bed{
    display:inline-flex;align-items:center;justify-content:center;min-width:74px;
    padding:7px 11px;border-radius:8px;background:var(--brand-soft);
    border:1px solid var(--brand-ring);color:var(--brand-2);font-weight:800;
    font-size:13px;line-height:1;white-space:nowrap;
  }
  .bed-sheet-source{
    display:flex;align-items:center;gap:9px;padding:10px 12px;margin-bottom:14px;
    border:1px solid var(--border);background:var(--card-2);border-radius:10px;
    color:var(--muted);font-size:12.5px;line-height:1.35;
  }
  .bed-sheet-source b{color:var(--ink-2);font-weight:700}
  .bed-sheet-source-dot{width:8px;height:8px;border-radius:50%;background:var(--brand);box-shadow:0 0 0 3px var(--brand-ring);flex-shrink:0}
  .bed-sheet-warning{
    background:var(--crit-soft);border:1px solid var(--crit-border);color:var(--crit);
    padding:11px 12px;border-radius:10px;margin-bottom:14px;font-size:13px;line-height:1.45;
  }
  .bed-choice{
    border:1px solid var(--border);border-radius:12px;background:var(--card);
    margin-bottom:10px;overflow:hidden;box-shadow:var(--shadow-1);
  }
  .bed-choice.confirm{
    border-color:var(--ok-border);background:linear-gradient(180deg,var(--ok-soft),var(--card) 72%);
  }
  .bed-choice.reject{border-color:var(--crit-border)}
  .bed-choice-head{
    display:flex;align-items:center;gap:11px;padding:13px 14px;color:var(--ink);
    font-weight:750;line-height:1.25;
  }
  .bed-choice-icon{
    width:30px;height:30px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;
    color:#fff;font-weight:800;font-size:14px;flex-shrink:0;
  }
  .bed-choice.confirm .bed-choice-icon{background:var(--ok)}
  .bed-choice.remap .bed-choice-icon{background:var(--brand)}
  .bed-choice.reject .bed-choice-icon{background:var(--crit)}
  .bed-choice-sub{display:block;margin-top:2px;color:var(--muted);font-size:12px;font-weight:500}
  .bed-choice-body{padding:0 14px 14px 55px}
  .bed-field-row{display:grid;grid-template-columns:70px minmax(0,1fr);gap:10px;align-items:center;margin-bottom:10px}
  .bed-field-row label{
    color:var(--muted);font-size:11px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;
  }
  .bed-field-row input{
    width:100%;min-width:0;padding:9px 10px;border:1px solid var(--border);
    border-radius:8px;background:var(--surface-input);outline:none;color:var(--ink);
  }
  .bed-field-row input:focus{border-color:var(--brand);box-shadow:0 0 0 3px var(--brand-ring);background:var(--card)}
  .bed-choice summary{list-style:none;cursor:pointer}
  .bed-choice summary::-webkit-details-marker{display:none}
  .bed-choice summary::after{
    content:"";width:8px;height:8px;border-right:1.5px solid var(--muted);border-bottom:1.5px solid var(--muted);
    transform:rotate(45deg);margin-left:auto;transition:transform .15s;flex-shrink:0;
  }
  .bed-choice[open] summary::after{transform:rotate(225deg)}
  .bed-choice.reject .bed-choice-head{color:var(--crit)}
  .bed-sheet-actions{display:flex;justify-content:flex-end;margin-top:14px}
  @media (max-width:520px){
    .bed-sheet{padding:18px 16px}
    .bed-sheet-title{flex-direction:column;gap:8px}
    .bed-sheet-bed{align-self:flex-start}
    .bed-choice-body{padding-left:14px}
    .bed-field-row{grid-template-columns:1fr;gap:5px}
    .bed-sheet-actions .btn{width:100%;justify-content:center}
  }

  /* ---------- Toast ---------- */
  .toast-wrap{
    position:fixed;bottom:24px;left:50%;transform:translateX(-50%);
    z-index:200;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none;
  }
  .toast{
    background:var(--ink);color:#fff;padding:10px 16px;border-radius:10px;
    font-size:13px;font-weight:500;box-shadow:var(--shadow-3);
    display:inline-flex;align-items:center;gap:8px;
    animation:toastIn .25s ease-out;
  }
  .toast svg{width:14px;height:14px}
  .toast.ok{background:var(--ok)}
  /* A toast carrying an action must be clickable, so it opts back into pointer
     events that .toast-wrap disables for the passive ones. */
  .toast.has-action{pointer-events:auto;padding-right:6px}
  .toast-action{
    margin-left:4px;padding:5px 11px;border-radius:7px;border:1px solid rgba(255,255,255,.45);
    background:rgba(255,255,255,.14);color:inherit;font:inherit;font-weight:750;cursor:pointer;
    display:inline-flex;align-items:center;gap:5px;
  }
  .toast-action:hover{background:rgba(255,255,255,.28)}
  .toast-action svg{width:13px;height:13px}
  @keyframes toastIn{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:translateY(0)}}

  /* ---------- Misc ---------- */
  .empty-state{
    padding:48px 20px;text-align:center;color:var(--muted);font-size:14.5px;
  }
  /* Load failure — the one presentation of "this screen's data didn't arrive".
     Styled as a warning surface rather than a plain card so it can't be mistaken
     for content, and sized to the message rather than the container. */
  .load-failure{
    display:flex;align-items:flex-start;gap:14px;
    max-width:720px;padding:16px 18px;margin-bottom:14px;
    background:var(--crit-soft);border:1px solid var(--crit-border);
    border-radius:var(--radius-2);
  }
  .load-failure-icon{flex:none;display:flex;color:var(--crit)}
  .load-failure-icon svg{width:20px;height:20px}
  .load-failure-body{flex:1;min-width:0}
  .load-failure-title{
    font-size:15px;font-weight:700;color:var(--ink);
    letter-spacing:-.01em;line-height:1.3;margin:0;
  }
  .load-failure-detail{font-size:13px;color:var(--ink-2);margin:6px 0 0;line-height:1.45}
  .load-failure-hint{font-size:12.5px;color:var(--muted);margin:6px 0 0;line-height:1.45}
  .load-failure .btn{flex:none;align-self:center}
  /* One region of an otherwise-working page: same language, less weight. */
  .load-failure.compact{
    flex-wrap:wrap;gap:10px;padding:12px 14px;margin-bottom:0;
  }
  .load-failure.compact .load-failure-icon svg{width:16px;height:16px}
  .load-failure.compact .load-failure-title{font-size:13px}
  .load-failure.compact .load-failure-detail{font-size:12px}
  @media (max-width:600px){
    .load-failure{flex-wrap:wrap}
    .load-failure .btn{width:100%;justify-content:center}
  }
  .source-tag{
    display:inline-flex;align-items:center;gap:4px;
    font-size:10px;color:var(--muted);
    background:var(--bg-soft);padding:2px 6px;border-radius:4px;
    border:1px solid var(--border);font-weight:500;
  }
  .source-tag.auto{color:var(--indigo);background:#eef2ff;border-color:#c7d2fe}
  .source-tag.touch{color:#a16207;background:#fef3c7;border-color:#fde68a}
  .source-tag svg{width:10px;height:10px}

  /* ---------- Responsive tightening ---------- */
  @media (max-width:760px){
    .container{padding:14px 12px 60px}
    .topbar-inner{padding:10px 12px;gap:8px}
    .topbar-meta{font-size:12px;gap:8px}
    .acct-trigger .av{width:22px;height:22px}
    .h1{font-size:20px}
    .wf-bar-inner{padding:8px 12px;gap:8px}
    .wf-pat .nm{font-size:13px}
    .wf-pat .mt{font-size:11px}
    .wf-pat .avatar{width:28px;height:28px;font-size:11px}
    .ppanel-head{padding:14px}
    .ppanel-name{font-size:16px}
    .pfact{padding:0 10px}
    .ppanel-id .avatar{width:42px;height:42px;border-radius:12px;font-size:14px}
    .vital{padding:8px 10px}
    .vital-val{font-size:16px}
    .ppanel-body{padding:12px;gap:12px}
    .priority-grid{grid-template-columns:1fr}
    .pri-card{min-height:auto}
    .tile-grid{grid-template-columns:repeat(2,1fr);gap:8px}
    .tile{padding:12px 10px;min-height:96px}
    .tile-icon{width:30px;height:30px}
    .tile-icon svg{width:16px;height:16px}
    .tile-name{font-size:12px}
    .tile-sub{font-size:10.5px}
    .lab-controls,.io-controls,.mon-toolbar{padding:10px 12px;gap:8px}
    .btn{padding:7px 11px;font-size:12.5px;min-height:34px}
    .btn-group .btn{padding:5px 10px;min-height:28px}
    .lab-table th,.lab-table td{padding:8px 10px}
    .lab-table th.col-test,.lab-table td.cell-test{min-width:140px}
    .mon-table th,.mon-table td{padding:6px 8px}
    .mon-table th.col-row,.mon-table td.cell-row{min-width:120px}
    .io-grid th,.io-grid td{padding:5px 6px;font-size:11.5px}
    .io-grid thead tr:nth-child(2) th{top:28px}
    .io-summary-panel{position:static;top:auto}
    .form-section{padding:14px}
    .check-grid{grid-template-columns:repeat(auto-fill,minmax(150px,1fr))}
    .narrative{min-height:80px}
    .modal-foot{flex-wrap:wrap;gap:6px}
    .modal-foot .btn{flex:1 1 auto}
    .pcard{padding:13px 12px}
    .select-head .sh-nurse{margin-left:0;width:100%}
    .roster-sticky{top:0}
    .start-shift-bar .btn{padding:9px 14px}
    .rx-table th,.rx-table td{padding:8px 10px;font-size:12px}
    .rx-admin{max-width:140px}
    .rx-admin-pill{padding:2px 5px;font-size:10px}
    .order-row{padding:7px 8px}
    .bundle-grid{grid-template-columns:1fr}
    .insight{padding:12px}
    .insight-icon{width:32px;height:32px}
    .culture-head{padding:12px}
    .sens-table th,.sens-table td{padding:6px 8px;font-size:11.5px}
  }
  @media (min-width:761px) and (max-width:1023px){
    .home-grid{grid-template-columns:1fr}
    .priority-grid{grid-template-columns:1fr 1fr}
    .tile-grid{grid-template-columns:repeat(3,1fr)}
    .io-summary-panel{position:static}
  }
  @media (max-width:520px){
    .tile-grid{grid-template-columns:1fr 1fr}
    .home-grid.two{grid-template-columns:1fr}
    .vitals-strip{grid-template-columns:repeat(2,1fr)}
  }

  /* Scrollbars */
  ::-webkit-scrollbar{height:10px;width:10px}
  ::-webkit-scrollbar-track{background:transparent}
  ::-webkit-scrollbar-thumb{background:var(--border-2);border-radius:10px;border:2px solid var(--bg)}
  ::-webkit-scrollbar-thumb:hover{background:#94a3b8}

  /* Print */
  @media print{
    .topbar,.wf-bar,.btn,.modal-bg,.patient-chat-global{display:none!important}
    :root,:root[data-theme="dark"]{
      --bg:#fff;--bg-soft:#f8fafc;--card:#fff;--card-2:#fcfdff;--card-3:#f1f5f9;
      --border:#d1d5db;--border-2:#9ca3af;--ink:#111;--ink-2:#222;--muted:#555;
      --faint:#777;--hairline:#e5e7eb;--surface-header:#f8fafc;--surface-sticky:#fff;
      --crit:#b91c1c;--crit-soft:#fef2f2;--crit-border:#fecaca;
      --warn:#b45309;--warn-soft:#fffbeb;--warn-border:#fde68a;
      --ok:#15803d;--ok-soft:#f0fdf4;--ok-border:#bbf7d0;
      --info:#0e7490;--info-soft:#ecfeff;
      color-scheme:light;
    }
    body{background:#fff;color:#111}
    .card,.lab-section,.mon-wrap,.io-wrap{box-shadow:none;border:1px solid #ccc}
  }

  /* ---------- Touch targets on coarse-pointer devices (bedside tablets) ----------
     Mouse/desktop (fine pointer) keeps the compact layout; touch input gets
     >=44px tap targets (Apple HIG). Last in the cascade so it wins over the
     width-based rules above when a touch device is also narrow. */
  @media (pointer: coarse){
    .btn, .back-btn{ min-height:44px; }
    .btn.icon{ min-width:44px; }
    .btn-group .btn{ min-height:44px; }
    .form-section input, .form-section select, .form-section textarea,
    .field input, .field select, .field textarea,
    .sl-combobox-input, .sl-combobox-opt,
    .sl-quickpick .btn, .score-opt{ min-height:44px; }
    .sl-preset-chip, .nrv-chip{ min-height:44px; display:inline-flex; align-items:center; justify-content:center; }
    .now-jump{ min-height:44px; padding-left:14px; padding-right:11px; }
    .rx-give, .rx-tray-btn, .rx-tray-sign, .rx-tray-round, .rx-tray-input{ min-height:44px; }
    .o-edit{ min-height:44px; display:inline-flex; align-items:center; justify-content:center; }
    .o-x{ min-width:44px; min-height:44px; display:inline-flex; align-items:center; justify-content:center; }
    .rx-rate-tap, .rx-rate-stepper button{ min-height:40px; }
  }

  /* ---------- Unified dropdowns ----------
     One consistent chevron + sizing across every native <select> in the app.
     Placed last so the custom chevron wins over each control's own
     `background:` shorthand; per-control focus rings and colours are untouched.
     Chevron uses a slate tone that reads on both light and dark grounds. */
  .roster-tool-select,
  .monitoring-toolbar select,
  .dnotes-select,
  .order-row .order-prio,
  .order-row .order-freq,
  .field select,
  select.ipn-input{
    -webkit-appearance:none;-moz-appearance:none;appearance:none;
    background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat:no-repeat;background-position:right 9px center;background-size:14px;
    padding-right:30px;cursor:pointer;
  }
  /* Order-row selects are compact; give the chevron a little less room. */
  .order-row .order-prio,.order-row .order-freq{background-position:right 7px center;background-size:13px;padding-right:26px}
