/* ===== EMR section styles (scoped under .emr-section) ===== */
.emr-section { --emr-ink:#1f2733; --emr-muted:#6b7785; --emr-line:#dde3ea; --emr-primary:#2a5298; --emr-primary-dark:#1f3a5f; --emr-accent:#0a7c7c; --emr-warn:#c47f17; --emr-alert:#b42318; --emr-ok:#1a7f4b;
  color:var(--emr-ink); font-size:14px; }
.emr-section .emr-loading, .emr-section .emr-empty { color:var(--emr-muted); padding:24px; text-align:center; }

.emr-section .emr-bar { display:flex; gap:8px; align-items:center; margin-bottom:10px; }
.emr-section .emr-res-select { padding:8px 10px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; min-width:220px; }
.emr-section .emr-add-res { padding:8px 12px; border:1px solid var(--emr-line); background:#fff; border-radius:8px; cursor:pointer; }

.emr-section .emr-rh { display:flex; flex-wrap:wrap; gap:14px; align-items:center; background:#fff; border:1px solid var(--emr-line); border-radius:12px; padding:12px 14px; margin-bottom:12px; }
.emr-section .emr-rh-name { font-size:18px; font-weight:700; }
.emr-section .emr-rh-meta { color:var(--emr-muted); font-size:13px; }
.emr-section .emr-chip { display:inline-flex; align-items:center; gap:6px; padding:3px 10px; border-radius:20px; font-size:12px; font-weight:600; }
.emr-section .emr-chip-allergy { background:#fdeaea; color:var(--emr-alert); border:1px solid #f3c2c2; }
.emr-section .emr-chip-code { background:#eef4fb; color:var(--emr-primary); border:1px solid #cfe0f3; }
.emr-section .emr-rh-note { margin-left:auto; display:flex; align-items:center; gap:8px; background:#fffbe9; border:1px solid #f0e3b8; border-radius:8px; padding:6px 10px; }
.emr-section .emr-rh-note label { font-size:11px; color:var(--emr-warn); font-weight:700; }
.emr-section .emr-rh-note input { border:none; background:transparent; font-size:13px; min-width:200px; outline:none; color:var(--emr-ink); }

.emr-section .emr-body { display:flex; gap:14px; align-items:flex-start; }
.emr-section .emr-nav { width:180px; flex:0 0 180px; display:flex; flex-direction:column; gap:2px; }
.emr-section .emr-nav-item { display:flex; align-items:center; gap:8px; padding:9px 11px; border:none; background:transparent; border-radius:8px; cursor:pointer; font-size:13px; text-align:left; color:var(--emr-ink); }
.emr-section .emr-nav-item:hover { background:#eef2f7; }
.emr-section .emr-nav-item.active { background:var(--emr-primary); color:#fff; }
.emr-section .emr-nav-cat { font-size:10px; text-transform:uppercase; letter-spacing:.06em; color:#94a3b3; font-weight:700; padding:10px 11px 4px; }
.emr-section .emr-nav-cat:first-child { padding-top:2px; }
.emr-section .a-cfield-row { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.emr-section .a-cfield-row input, .emr-section .a-cfield-row select { padding:7px 9px; border:1px solid var(--emr-line); border-radius:6px; font-size:13px; }
/* Assessment search (used on Assessments page + Orders attach) */
.emr-section .emr-tpl-search-input { width:100%; padding:9px 11px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; }
.emr-section .emr-tpl-search-results { border:1px solid var(--emr-line); border-radius:8px; margin-top:4px; max-height:240px; overflow-y:auto; background:#fff; }
.emr-section .emr-tpl-search-item { padding:8px 10px; cursor:pointer; border-bottom:1px solid #eef1f5; font-size:13px; }
.emr-section .emr-tpl-search-item:last-child { border-bottom:none; }
.emr-section .emr-tpl-search-item:hover { background:#eef2f7; }
.emr-section .emr-tpl-cat { color:#6b7785; font-size:11px; }
.emr-section .emr-tpl-search-empty { padding:8px 10px; color:#6b7785; font-size:13px; }
.emr-section .emr-content { flex:1; min-width:0; }

.emr-section .emr-card { background:#fff; border:1px solid var(--emr-line); border-radius:12px; padding:14px; margin-bottom:14px; }
.emr-section .emr-card h3 { margin:0 0 10px; font-size:15px; }

.emr-section .emr-board { display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:14px; }
.emr-section .emr-widget { background:#fff; border:1px solid var(--emr-line); border-radius:12px; padding:14px; }
.emr-section .emr-widget-head h3 { margin:0 0 10px; font-size:13px; text-transform:uppercase; letter-spacing:.03em; color:var(--emr-muted); }
.emr-section .emr-due-big { font-size:22px; font-weight:700; margin-bottom:6px; }
.emr-section .emr-due-row { display:flex; align-items:center; justify-content:space-between; padding:7px 0; border-bottom:1px solid #eef1f5; }
.emr-section .emr-due-row:last-child { border-bottom:none; }
.emr-section .emr-due-time { font-weight:700; color:var(--emr-primary); min-width:52px; display:inline-block; }
.emr-section .emr-due-late { color:var(--emr-alert); }
.emr-section .emr-due-soon { color:var(--emr-warn); }

/* Ordered-assessment due states */
.emr-section .emr-as-row { padding-left:10px; border-left:3px solid transparent; }
.emr-section .emr-as-row.emr-as-overdue { border-left-color:var(--emr-alert); }
.emr-section .emr-as-row.emr-as-due { border-left-color:var(--emr-warn); }
.emr-section .emr-as-row.emr-as-upcoming { border-left-color:var(--emr-line); }
.emr-section .emr-as-row.emr-as-complete { border-left-color:#34a853; }
.emr-section .emr-as-row.emr-as-prn { border-left-color:#4285f4; }
.emr-section .emr-as-label { display:flex; align-items:baseline; gap:6px; flex-wrap:wrap; }
.emr-section .emr-as-dot { font-size:13px; }
.emr-section .emr-as-overdue .emr-as-dot { color:var(--emr-alert); }
.emr-section .emr-as-due .emr-as-dot { color:var(--emr-warn); }
.emr-section .emr-as-complete .emr-as-dot { color:#34a853; }
.emr-section .emr-as-meta { font-size:11px; color:var(--emr-muted); font-style:normal; }
/* Unresolved items */
.emr-section .emr-unres-count { display:inline-block; background:var(--emr-alert); color:#fff; border-radius:11px; font-size:12px; font-weight:700; padding:0 7px; vertical-align:middle; }
.emr-section .emr-unres-row { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; padding:10px 0; border-bottom:1px solid #eef1f5; }
.emr-section .emr-unres-row:last-child { border-bottom:none; }
.emr-section .emr-unres-info { min-width:0; flex:1 1 200px; }
.emr-section .emr-unres-name { font-weight:600; }
.emr-section .emr-unres-meta { font-size:12px; color:var(--emr-muted); margin-top:2px; }
.emr-section .emr-unres-actions { display:flex; align-items:center; gap:6px; flex-wrap:wrap; }

/* Patient photo / avatar */
.emr-section .emr-avatar { display:inline-block; border-radius:50%; object-fit:cover; vertical-align:middle; background:#eef2f7; border:1px solid var(--emr-line); }
.emr-section .emr-avatar-ph { text-align:center; color:#64748b; font-weight:700; text-transform:uppercase; }
.emr-section .emr-avatar-btn { cursor:pointer; padding:0; }
.emr-section .emr-avatar-btn:hover { box-shadow:0 0 0 3px rgba(37,99,235,0.18); }
.emr-section .emr-ov-banner { display:flex; align-items:center; gap:16px; margin-bottom:14px; }
.emr-section .emr-ov-banner .emr-ov-bname { font-size:20px; font-weight:700; }
.emr-section .emr-ov-banner .emr-ov-bmeta { color:var(--emr-muted); font-size:13px; }
.emr-section .emr-fac-thumb { margin-right:8px; }

/* Facility refill box */
.emr-section .emr-fac-refill { font-size:14px; padding:8px 12px; border-radius:8px; background:#eef4fb; border:1px solid #cfe0f3; }
.emr-section .emr-fac-refill-bad { background:#fdecec; border-color:#f3bcbc; color:var(--emr-alert); font-weight:600; }

/* Medication list */
.emr-section .emr-ml-badge { display:inline-block; padding:2px 8px; border-radius:12px; font-size:11px; font-weight:600; }
.emr-section .emr-ml-ordered { background:#eef4fb; color:var(--emr-primary); border:1px solid #cfe0f3; }
.emr-section .emr-ml-manual { background:#f1f5f9; color:#475569; border:1px solid #dde3ea; }
.emr-section .emr-ml-reorder { color:var(--emr-alert); font-weight:700; }
.emr-section .emr-ml-soon { color:var(--emr-warn); font-weight:600; }
.emr-section .emr-ml-row-reorder { background:#fdecec; }

/* Next Due Assessments — fixed-height scroll worklist */
.emr-section .emr-nextdue-scroll { max-height:230px; overflow-y:auto; padding-right:4px; }
.emr-section .emr-nextdue-scroll .emr-as-row:last-child { border-bottom:none; }
.emr-section .emr-as-overdue .emr-as-meta { color:var(--emr-alert); font-weight:600; }
.emr-section .o-set-preview { background:#f8fafc; border:1px solid var(--emr-line); border-radius:8px; padding:10px 12px; }

/* Undoable charted entries — click to void with a reason */
.emr-section .emr-undoable { cursor:pointer; }
.emr-section tr.emr-undoable:hover { background:#f1f5f9; }
.emr-section .emr-due-row.emr-undoable:hover { background:#f1f5f9; }
.emr-section .emr-mar-slot.emr-undoable:hover { outline:2px solid var(--emr-accent,#2563eb); outline-offset:1px; }
.emr-section .emr-voided { text-decoration:line-through; color:#9aa3af; }

/* MAR slots — per-med today status */
.emr-section .emr-mar-slots { display:flex; flex-wrap:wrap; gap:6px; }
.emr-section .emr-mar-slot { display:inline-flex; align-items:center; gap:5px; padding:4px 9px; border-radius:14px; font-size:12px; border:1px solid var(--emr-line); white-space:nowrap; }
.emr-section .emr-mar-slot em { font-style:normal; color:#6b7785; font-size:11px; }
.emr-section .emr-mar-given { background:#e9f7ef; border-color:#bfe6cf; color:#1a7f4b; }
.emr-section .emr-mar-held { background:#fff4e5; border-color:#f3d6a6; color:#9a6400; }
.emr-section .emr-mar-duebox { background:#fdecec; border-color:#f3bcbc; }
.emr-section .emr-mar-duebox.emr-due-soon { background:#fff4e5; border-color:#f3d6a6; }
.emr-section .emr-mar-duebox .emr-btn-sm { padding:3px 8px; }
.emr-section select.emr-mar-give { padding:3px 6px; max-width:130px; }
.emr-section tr.mar-sum-row { cursor:pointer; }
.emr-section tr.mar-sum-row:hover { background:#f1f5f9; }
.emr-modal .mar-hist-day { margin-bottom:12px; }
.emr-modal .mar-hist-date { font-size:12px; font-weight:700; color:var(--emr-primary,#2a5298); text-transform:uppercase; letter-spacing:.03em; padding:4px 0; border-bottom:1px solid #eef1f5; margin-bottom:2px; }
.emr-modal .mar-hist-day .emr-res-given { color:#1a7f4b; font-weight:600; }
.emr-modal .mar-hist-day .emr-res-held { color:#9a6400; font-weight:600; }
.emr-section .emr-res-given { color:#1a7f4b; font-weight:600; }
.emr-section .emr-res-held { color:#9a6400; font-weight:600; }

/* Order frequency builder — wraps on narrow screens */
.emr-section .emr-freq-row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.emr-section .emr-freq-row select, .emr-section .emr-freq-row input { padding:9px 10px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; }
.emr-section .emr-freq-row .o-fn { width:80px; }
.emr-section .emr-freq-row .o-ftimes { flex:1; min-width:160px; }
.emr-section .o-fhint { font-size:12px; color:var(--emr-muted); margin-top:6px; }
.emr-section .o-dc { color:var(--emr-alert); border-color:var(--emr-alert); }
@media (max-width:560px) {
  .emr-section .emr-freq-row select, .emr-section .emr-freq-row input { flex:1 1 100%; min-width:0; }
  .emr-section .emr-freq-row .o-fn { flex:0 0 90px; }
}

/* AI charting confirmation overlay (modal is appended to body, so unscoped) */
.emr-modal.emr-confirm { border-top:4px solid var(--emr-accent, #2563eb); }
.emr-modal .emr-confirm-head { display:flex; align-items:center; gap:8px; margin-bottom:10px; }
.emr-modal .emr-confirm-icon { font-size:20px; }
.emr-modal .emr-confirm-body { font-size:15px; line-height:1.45; color:#1f2733; background:#f4f7fb; border:1px solid #e3e9f1; border-radius:8px; padding:12px 14px; }
.emr-modal .emr-confirm-sub { font-size:12px; color:#6b7785; margin:10px 0 4px; }
.emr-section .emr-pill-btn, .emr-section .emr-btn-sm { border:1px solid var(--emr-line); background:#f8fafc; border-radius:6px; padding:5px 10px; cursor:pointer; font-size:12px; }
.emr-section .emr-pill-btn:hover, .emr-section .emr-btn-sm:hover { background:#eef2f7; }

.emr-section .emr-table { width:100%; border-collapse:collapse; }
.emr-section .emr-table th, .emr-section .emr-table td { border:1px solid var(--emr-line); padding:7px 9px; text-align:left; font-size:13px; overflow-wrap:anywhere; }
.emr-section .emr-table th { background:#f1f5f9; }

.emr-section .emr-field { display:block; margin-bottom:12px; }
.emr-section .emr-field > span { display:block; font-size:12px; font-weight:600; color:var(--emr-muted); margin-bottom:4px; }
.emr-section .emr-field input, .emr-section .emr-field select, .emr-section .emr-field textarea { width:100%; padding:9px 10px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; }
.emr-section .emr-btn-primary { background:var(--emr-accent); color:#fff; border:none; padding:9px 16px; border-radius:8px; cursor:pointer; font-weight:600; }
.emr-section .emr-btn-primary:hover { filter:brightness(1.08); }

.emr-section .emr-order-form, .emr-section .emr-vital-form { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:10px; align-items:end; }
.emr-section .emr-vitals-grid { display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr)); gap:12px; margin-bottom:14px; }
.emr-section .emr-vitals-grid .emr-field { margin:0; }
.emr-section .emr-vital-form .emr-btn-primary, .emr-section .emr-order-form .emr-btn-primary { height:40px; }

.emr-section .emr-cp-item { border:1px solid var(--emr-line); border-radius:10px; padding:12px; margin-bottom:10px; }
.emr-section .emr-cp-problem { font-weight:700; color:var(--emr-alert); margin-bottom:4px; }
.emr-section .emr-cp-goal { font-size:13px; margin-bottom:4px; }
.emr-section .emr-cp-item ul { margin:6px 0; padding-left:20px; font-size:13px; }
.emr-display-note { color:#6b7785; font-style:italic; padding:10px; }
/* Chart overview quick-nav */
.emr-section .emr-ov-quicknav { display:flex; flex-wrap:wrap; gap:8px; margin-bottom:14px; }
.emr-section .emr-ov-nav { display:inline-flex; align-items:center; gap:6px; padding:8px 12px; border:1px solid var(--emr-line); background:#fff; border-radius:20px; cursor:pointer; font-size:13px; color:var(--emr-ink); }
.emr-section .emr-ov-nav:hover { background:#eef2f7; border-color:#cfe0f3; }
.emr-section .emr-widget-head { display:flex; align-items:center; justify-content:space-between; }
.emr-section .emr-widget-head .emr-btn-sm { padding:3px 9px; font-size:11px; white-space:nowrap; }
/* Clickable header chips (code status / allergies) */
.emr-section .emr-chip-btn { cursor:pointer; font-family:inherit; }
.emr-section .emr-chip-btn:hover { filter:brightness(0.96); box-shadow:0 0 0 2px rgba(37,99,235,0.18); }
/* Chart-overview clickable charted items */
.emr-section .emr-ov-item { display:flex; align-items:center; justify-content:space-between; gap:8px; width:100%; text-align:left; padding:8px 6px; border:none; border-bottom:1px solid #eef1f5; background:transparent; cursor:pointer; font:inherit; color:var(--emr-ink); border-radius:6px; }
.emr-section .emr-ov-item:hover { background:#f1f5f9; }
.emr-section .emr-ov-item .emr-ov-when { color:#6b7785; font-size:11px; white-space:nowrap; }
.emr-section .emr-ov-empty { color:#6b7785; font-size:13px; padding:4px 0; }
.emr-section .emr-view .emr-table th { background:#f8fafc; font-weight:600; width:38%; }
/* Facility board */
.emr-section .emr-fac-overview { display:flex; gap:16px; flex-wrap:wrap; align-items:stretch; }
.emr-section .emr-fac-overview > * { flex:1 1 300px; min-width:0; }
.emr-section .emr-fac-stats { display:flex; gap:8px; flex-wrap:wrap; flex:1 1 320px; }
.emr-section .emr-fac-stat { flex:1 1 100px; min-width:96px; max-width:180px; background:#f1f5f9; border-radius:10px; padding:10px 12px; text-align:center; }
.emr-section .emr-fac-stat-bad { background:#fdeaea; }
.emr-section .emr-fac-num { font-size:26px; font-weight:800; }
.emr-section .emr-fac-stat-bad .emr-fac-num { color:var(--emr-alert); }
.emr-section .emr-fac-lbl { font-size:11px; text-transform:uppercase; letter-spacing:.04em; color:#6b7785; }
.emr-section .emr-fac-notes { flex:1; min-width:240px; }
.emr-section .emr-fac-notes-head { font-size:12px; text-transform:uppercase; letter-spacing:.04em; color:#6b7785; font-weight:700; margin-bottom:6px; }
.emr-section .emr-fac-note-single { cursor:pointer; border:1px solid var(--emr-line); border-radius:8px; padding:9px 11px; min-height:38px; background:#fff; font-size:13px; line-height:1.4; }
.emr-section .emr-fac-note-single:hover { border-color:#cfe0f3; background:#f8fbff; }
.emr-section .emr-fac-note-add { display:flex; gap:8px; margin-bottom:8px; }
.emr-section .emr-fac-note-add input { flex:1; padding:8px 10px; border:1px solid var(--emr-line); border-radius:8px; font-size:13px; }
.emr-section .emr-fac-note-row { display:flex; justify-content:space-between; gap:10px; padding:5px 0; border-bottom:1px solid #eef1f5; font-size:13px; }
.emr-section .emr-fac-note-meta { color:#6b7785; font-size:11px; white-space:nowrap; }
.emr-section .emr-fac-addnote { border:1px solid var(--emr-line); background:#f8fafc; border-radius:6px; padding:2px 8px; cursor:pointer; font-size:11px; white-space:nowrap; }
.emr-section .emr-fac-addnote:hover { background:#eef2f7; }
.emr-section .emr-fac-wrap { overflow-x:auto; }
/* Facility board — resident cards (fills space; never side-scrolls) */
.emr-section .emr-fcards { display:grid; grid-template-columns:repeat(auto-fill,minmax(300px,1fr)); gap:12px; }
.emr-section .emr-fcard { background:#fff; border:1px solid var(--emr-line); border-radius:12px; padding:12px 14px; }
.emr-section .emr-fcard-head { display:flex; align-items:center; gap:10px; margin-bottom:10px; padding-bottom:8px; border-bottom:1px solid #eef1f5; }
.emr-section .emr-fcard-name { display:flex; align-items:center; gap:10px; text-decoration:none; color:inherit; flex:1; min-width:0; }
.emr-section .emr-fcard-namewrap { display:flex; flex-direction:column; min-width:0; }
.emr-section .emr-fcard-nm { font-weight:700; color:var(--emr-primary); font-size:15px; overflow:hidden; text-overflow:ellipsis; }
.emr-section .emr-fcard-sub { font-size:11px; color:var(--emr-muted); }
.emr-section .emr-fcard-badge { font-size:11px; font-weight:600; white-space:nowrap; background:#fdeaea; border:1px solid #f3c2c2; border-radius:10px; padding:2px 8px; }
.emr-section .emr-fcard-grid { display:grid; grid-template-columns:1fr 1fr; gap:10px 14px; }
.emr-section .emr-fcard-col { min-width:0; }
.emr-section .emr-fcard-lbl { font-size:10px; text-transform:uppercase; letter-spacing:.04em; color:#94a3b3; font-weight:700; margin-bottom:3px; }
.emr-section .emr-fcard-col .emr-fac-due { font-size:12px; padding:1px 0; }
@media (max-width:430px) { .emr-section .emr-fcard-grid { grid-template-columns:1fr; } }
.emr-section .emr-fac-note-view { cursor:pointer; display:inline-block; max-width:240px; }
.emr-section .emr-fac-note-view:hover { text-decoration:underline; color:var(--emr-primary); }
.emr-section .emr-fac-note-empty { color:#6b7785; font-size:11px; border:1px dashed var(--emr-line); border-radius:6px; padding:2px 8px; }
.emr-section .emr-fac-table th, .emr-section .emr-fac-table td { vertical-align:top; }
.emr-section .emr-fac-name { font-weight:700; color:var(--emr-primary); text-decoration:none; }
.emr-section .emr-fac-name:hover { text-decoration:underline; }
.emr-section .emr-fac-room { font-size:11px; color:#6b7785; font-weight:400; }
.emr-section .emr-fac-due-cell { min-width:170px; }
.emr-section .emr-fac-due { font-size:12px; padding:1px 0; }
.emr-section .emr-fac-due.emr-due-late { color:var(--emr-alert); }
.emr-section .emr-fac-due.emr-due-soon { color:var(--emr-warn); }
.emr-section .emr-fac-note { max-width:220px; color:#1f2733; font-size:12px; }
.emr-section .emr-doc-group { margin-bottom:14px; }
.emr-section .emr-doc-group h4 { margin:0 0 6px; font-size:13px; text-transform:uppercase; letter-spacing:.03em; color:#6b7785; }
.emr-section .emr-doc-unassigned h4 { color:#c47f17; }
.emr-section .emr-doc-row { display:flex; align-items:center; gap:10px; padding:7px 0; border-bottom:1px solid #eef1f5; }
.emr-section .emr-doc-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.emr-section .emr-doc-date { color:#6b7785; font-size:12px; }
.emr-section .emr-doc-type { padding:5px 8px; border:1px solid #dde3ea; border-radius:6px; font-size:12px; }
.emr-section .emr-report-wrap { position:relative; }
.emr-section .emr-report-btn { border:1px solid var(--emr-line); background:#fff; color:var(--emr-ink); border-radius:8px; padding:7px 12px; cursor:pointer; font-weight:600; font-size:13px; }
.emr-section .emr-report-btn:hover { background:#eef2f7; }
.emr-section .emr-report-menu { position:absolute; right:0; top:calc(100% + 4px); background:#fff; border:1px solid var(--emr-line); border-radius:10px; box-shadow:0 6px 20px rgba(0,0,0,.12); z-index:30; min-width:200px; overflow:hidden; }
.emr-section .emr-report-menu button { display:block; width:100%; text-align:left; padding:10px 14px; border:none; background:transparent; cursor:pointer; font-size:13px; color:var(--emr-ink); }
.emr-section .emr-report-menu button:hover { background:#eef4fb; }
.emr-section .emr-report-menu button + button { border-top:1px solid #eef1f5; }
.emr-dc-btn { border:1px solid #f3c2c2; background:#fdeaea; color:#b42318; border-radius:8px; padding:7px 12px; cursor:pointer; font-weight:600; font-size:13px; }
.emr-dc-btn:hover { background:#f9dada; }
.emr-section .emr-import-res { border:1px solid #cfe0f3; background:#eef4fb; color:#2a5298; border-radius:8px; padding:8px 12px; cursor:pointer; font-weight:600; }
.emr-section .emr-import-res:hover { background:#dfeaf7; }
.emr-section .emr-transfer-btn { border:1px solid #cfe0f3; background:#eef4fb; color:#2a5298; border-radius:8px; padding:7px 12px; cursor:pointer; font-weight:600; font-size:13px; }
.emr-section .emr-transfer-btn:hover { background:#dfeaf7; }

/* EMR modals — UNSCOPED (modals are appended to document.body, outside .emr-section),
   so they get their own full styling here including their inner controls. */
.emr-modal-overlay { position:fixed; inset:0; background:rgba(15,25,40,.5); display:flex; align-items:center; justify-content:center; z-index:5000;
  font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif; color:#1f2733; }
.emr-modal { background:#fff; border-radius:16px; padding:24px; width:480px; max-width:94vw; box-shadow:0 24px 60px rgba(15,30,50,.35); animation:emrModalIn .16s ease both; }
@keyframes emrModalIn { from { opacity:0; transform:translateY(8px) scale(.98); } to { opacity:1; transform:none; } }
.emr-modal h3 { margin:0; font-size:18px; font-weight:700; }
.emr-modal .emr-field { display:block; margin:14px 0; }
.emr-modal .emr-field > span { display:block; font-size:12px; font-weight:600; color:#6b7785; margin-bottom:6px; }
.emr-modal textarea, .emr-modal input[type="text"], .emr-modal input:not([type]), .emr-modal select {
  width:100%; padding:10px 12px; border:1px solid #dde3ea; border-radius:10px; font-size:14px;
  font-family:inherit; box-sizing:border-box; background:#fff; color:#1f2733; }
.emr-modal textarea { resize:vertical; min-height:90px; line-height:1.45; }
.emr-modal textarea:focus, .emr-modal input:focus, .emr-modal select:focus { outline:none; border-color:#2a5298; box-shadow:0 0 0 3px rgba(42,82,152,.12); }
.emr-modal-actions { display:flex; justify-content:flex-end; gap:10px; margin-top:18px; }
.emr-modal .emr-btn-primary { background:#0a7c7c; color:#fff; border:none; padding:10px 18px; border-radius:10px; cursor:pointer; font-weight:600; font-size:14px; }
.emr-modal .emr-btn-primary:hover { filter:brightness(1.08); }
.emr-modal .emr-btn-sm { padding:9px 14px; border:1px solid #dde3ea; background:#fff; border-radius:10px; cursor:pointer; font-size:13px; color:#1f2733; }
.emr-modal .emr-btn-sm:hover { background:#f1f5f9; }
.emr-modal .emr-btn-ghost { color:#5f7285; }
.emr-match-pick { border:1px solid #dde3ea !important; background:#f8fafc; border-radius:10px !important; }
.emr-match-pick:hover { background:#eef2f7; }

@media (max-width:760px) {
  /* On mobile the host section forces a dark background; give the EMR its own
     clean light surface so cards, nav, and text all read correctly. */
  .emr-section { background:#eef1f5; border-radius:12px; padding:10px; }
  /* Stack the chart: nav becomes a horizontal scrollable pill strip on top. */
  .emr-section .emr-body { flex-direction:column; }
  .emr-section .emr-nav { width:100%; flex:none; flex-direction:row; flex-wrap:wrap; gap:6px; padding-bottom:8px; margin-bottom:10px; border-bottom:1px solid var(--emr-line); }
  .emr-section .emr-nav-cat { display:none; }
  .emr-section .emr-nav-item { white-space:nowrap; flex:0 0 auto; border:1px solid var(--emr-line); background:#fff; }
  .emr-section .emr-nav-item.active { border-color:var(--emr-primary); }
  /* Resident bar + header wrap cleanly. */
  .emr-section .emr-bar { flex-wrap:wrap; }
  .emr-section .emr-res-select { min-width:0; flex:1 1 100%; }
  .emr-section .emr-rh { gap:8px; }
  .emr-section .emr-rh-note { margin-left:0; width:100%; }
  .emr-section .emr-rh-note input { min-width:0; flex:1; }
  .emr-section .emr-dc-btn, .emr-section .emr-transfer-btn { margin-left:0; }
  /* Forms + grids collapse to a single column. */
  .emr-section .emr-order-form, .emr-section .emr-vital-form, .emr-section .emr-vitals-grid { grid-template-columns:1fr; }
  /* (Table reflow is handled by container queries below — based on the chart
     column's actual width, so tables never side-scroll at any viewport.) */
  /* Facility overview: stats stack above the refill/note column, full-width. */
  .emr-section .emr-fac-overview { flex-direction:column; gap:12px; }
  .emr-section .emr-fac-stats { flex:1 1 auto; width:100%; }
  .emr-section .emr-fac-num { font-size:22px; }
  .emr-section .emr-fac-notes { width:100%; min-width:0; }
  .emr-section .emr-ov-banner .emr-avatar { width:64px !important; height:64px !important; }
}
@media (max-width:420px) {
  /* Very small phones: single-column stats, tighter cards. */
  .emr-section .emr-fac-stats { grid-template-columns:1fr 1fr; }
  .emr-section .emr-card { padding:12px; }
  .emr-section .emr-ov-quicknav { gap:6px; }
  .emr-section .emr-ov-nav { padding:7px 10px; font-size:12px; }
}

/* ===== Fit the viewport (no whole-section side-scroll) ===== */
/* Sections are absolutely positioned at their fixed BUILD width. The EMR is a
   full-screen app, so in user mode we free it from that fixed size and let it
   fill the viewport — it then condenses to fit any screen (iPad, laptop) instead
   of overflowing at its build width. Build mode keeps the absolute size so it can
   still be positioned/resized. */
.canvas.user-mode .section:has(.emr-section) {
  position: relative !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
}
.canvas.user-mode:has(.emr-section) { overflow-x: hidden; }

/* ===== No-side-scroll ===== */
/* Every table is fixed-layout + full width, so columns SHARE the available space
   and content wraps. The table always fits its column — it never side-scrolls, on
   desktop OR mobile. (Desktop = condensed rows; mobile = reflowed to cards.) */
.emr-section .emr-table { table-layout:fixed; }
.emr-section .emr-table th, .emr-section .emr-table td { overflow-wrap:anywhere; word-break:break-word; }
/* Facility board: condensed patient ROWS on desktop, cards on phones. */
.emr-section .emr-fac-mobile { display:none; }

@media (max-width:760px) {
  /* The host turns the section into a flex box on mobile, which can shrink our
     content to a narrow strip — force the EMR to fill the full viewport width. */
  .section.mobile-active:has(.emr-section) { display:block !important; width:100% !important; }
  .section.mobile-active:has(.emr-section) .section-content { width:100% !important; }

  /* Facility board: hide the desktop table, show the resident cards. */
  .emr-section .emr-fac-desktop { display:none; }
  .emr-section .emr-fac-mobile { display:block; }

  /* Other labelled tables (MAR, vitals, orders, med list, assessments) → stacked,
     fully-labelled cards so nothing is cramped or hidden. */
  .emr-section table.emr-stack, .emr-section .emr-stack tbody, .emr-section .emr-stack tr, .emr-section .emr-stack td { display:block; width:auto; }
  .emr-section .emr-stack tr:first-child { display:none; }
  .emr-section .emr-stack tr { border:1px solid var(--emr-line); border-radius:10px; background:#fff; margin-bottom:10px; padding:8px 12px; }
  .emr-section .emr-stack td { border:none !important; padding:5px 0; display:flex; gap:12px; justify-content:space-between; align-items:flex-start; flex-wrap:wrap; }
  .emr-section .emr-stack td + td { border-top:1px solid #f1f4f8 !important; }
  .emr-section .emr-stack td::before { content:attr(data-label); font-weight:600; color:var(--emr-muted); flex:0 0 36%; font-size:12px; }
  .emr-section .emr-stack td:not([data-label])::before, .emr-section .emr-stack td[data-label=""]::before { content:none; }
  .emr-section .emr-stack td[data-label=""] { justify-content:flex-start; }
  .emr-section .emr-stack td.emr-card-title { display:block; font-size:15px; font-weight:700; border-bottom:1px solid #eef1f5 !important; margin-bottom:6px; padding-bottom:8px; }
  .emr-section .emr-stack td.emr-card-title + td { border-top:none !important; }
  .emr-section .emr-stack td.emr-stack-wide { flex-direction:column; gap:3px; }
  .emr-section .emr-stack td.emr-stack-wide::before { flex-basis:auto; }
}

/* ===== Face Sheet ===== */
.emr-section .emr-fsheet-group { border:1px solid var(--emr-line); border-radius:10px; padding:10px 12px; margin-bottom:10px; background:#fafbfc; }
.emr-section .emr-fsheet-gh { font-size:12px; font-weight:700; letter-spacing:.03em; text-transform:uppercase; color:var(--emr-primary); margin-bottom:8px; }
.emr-section .emr-fsheet-grid { display:grid; grid-template-columns:repeat(3,1fr); gap:8px 12px; }
@media (max-width:760px){ .emr-section .emr-fsheet-grid { grid-template-columns:1fr; } }

/* ===== Flowsheets ===== */
.emr-section .emr-fs-ordered { display:inline-block; font-size:11px; font-weight:600; color:var(--emr-accent); background:#e6f4f4; border:1px solid #bfe2e2; border-radius:12px; padding:1px 8px; margin-left:6px; }
.emr-section .a-cfield-row { display:grid; grid-template-columns:2fr 1fr auto; gap:8px; align-items:center; margin-bottom:6px; }
@media (max-width:760px){ .emr-section .a-cfield-row { grid-template-columns:1fr; } }

/* ===== Connections ===== */
.emr-section .emr-conn-build { display:flex; gap:10px; align-items:stretch; flex-wrap:wrap; }
.emr-section .emr-conn-side { flex:1 1 220px; min-width:200px; display:flex; flex-direction:column; gap:6px; }
.emr-section .emr-conn-sh { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.03em; color:var(--emr-muted); }
.emr-section .emr-conn-side select { padding:8px 10px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; width:100%; }
.emr-section .emr-conn-arrow { align-self:center; font-size:22px; color:var(--emr-primary); font-weight:700; padding:0 2px; }
.emr-section .emr-conn-row { display:grid; grid-template-columns:1fr auto 1fr auto; gap:8px; align-items:center; margin-bottom:6px; }
.emr-section .emr-conn-row select { padding:7px 9px; border:1px solid var(--emr-line); border-radius:8px; font-size:13px; min-width:0; }
.emr-section .emr-conn-rowarrow { color:var(--emr-primary); font-weight:700; }
.emr-section .emr-fs-srcchip { display:inline-flex; align-items:center; gap:3px; font-size:11px; font-weight:600; color:var(--emr-accent); background:#e6f4f4; border:1px solid #bfe2e2; border-radius:12px; padding:1px 7px; margin-left:6px; cursor:pointer; }
@media (max-width:760px){
  .emr-section .emr-conn-arrow { display:none; }
  .emr-section .emr-conn-row { grid-template-columns:1fr auto; }
  .emr-section .emr-conn-rowarrow { display:none; }
}

/* ===== Charting time (back-charting) ===== */
.emr-section .emr-when-field .emr-when-row { display:flex; gap:8px; }
.emr-section .emr-when-field input { padding:7px 9px; border:1px solid var(--emr-line); border-radius:8px; font-size:14px; }
.emr-section .emr-when-modal { margin-top:10px; }
.emr-section .emr-when-card { padding:10px 12px; }
.emr-section .emr-when-bar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.emr-section .emr-when-lbl { font-size:13px; font-weight:600; color:var(--emr-muted); }
.emr-section .emr-when-bar input { padding:6px 8px; border:1px solid var(--emr-line); border-radius:8px; font-size:13px; }
.emr-section .emr-when-flag { font-size:12px; font-weight:700; color:var(--emr-warn); }
.emr-section .emr-when-bar.emr-when-active { background:#fff7e6; border-radius:8px; padding:6px 8px; }
.emr-section .emr-when-help { font-size:11px; color:var(--emr-muted); margin-top:6px; }

/* ===== Clickable due rows / cells (navigate to charting) ===== */
.emr-section .emr-due-nav { cursor:pointer; border-radius:6px; transition:background .12s; display:flex; align-items:center; justify-content:space-between; gap:6px; }
.emr-section .emr-due-nav:hover { background:#eef4fb; }
.emr-section .emr-due-arrow { color:var(--emr-primary); font-weight:700; opacity:0; transition:opacity .12s; }
.emr-section .emr-due-nav:hover .emr-due-arrow { opacity:1; }
.emr-section a.emr-fac-go { cursor:pointer; display:block; }
.emr-section a.emr-fac-go:hover { background:#eef4fb; border-radius:6px; }

/* ===== Due-action dropdowns (Record/Chart + Not done) ===== */
.emr-section select.emr-btn-sm { padding:4px 8px; border:1px solid var(--emr-line); border-radius:8px; font-size:12px; background:#fff; cursor:pointer; max-width:140px; }
.emr-section select.a-charge-sel, .emr-section select.a-fsrec-sel, .emr-section select.fs-recdue-sel { border-color:#cfe0f3; color:var(--emr-primary); font-weight:600; }
.emr-section .er-reason { border:1px solid var(--emr-line); border-radius:8px; padding:8px; font-size:14px; margin-top:8px; font-family:inherit; }

/* ===== EMR Settings (permissions) ===== */
.emr-section .emr-set-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:12px; }
@media (max-width:760px){ .emr-section .emr-set-grid { grid-template-columns:1fr; } }
.emr-section .emr-set-fn { border:1px solid var(--emr-line); border-radius:10px; padding:10px 12px; background:#fafbfc; }
.emr-section .emr-set-fh { font-size:13px; margin-bottom:6px; }
.emr-section .emr-set-count { font-size:11px; font-weight:600; color:var(--emr-primary); background:#eef4fb; border:1px solid #cfe0f3; border-radius:12px; padding:1px 8px; }
.emr-section .emr-set-all { font-size:11px; color:var(--emr-ok); }
.emr-section .emr-set-emails { width:100%; box-sizing:border-box; border:1px solid var(--emr-line); border-radius:8px; padding:7px; font-size:13px; font-family:inherit; resize:vertical; }
.emr-section .emr-set-actions { margin-top:12px; display:flex; align-items:center; gap:12px; }

/* ===== My Board (configurable dashboard) ===== */
.emr-section .emr-dash-bar { display:flex; align-items:center; gap:8px; }
.emr-section .emr-dash-barsp { flex:1; }
.emr-section .emr-dash-grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(300px,1fr)); gap:12px; }
.emr-section .emr-dash-card { border:1px solid var(--emr-line); border-radius:12px; background:#fff; overflow:hidden; }
.emr-section .emr-dash-card.emr-dash-dragging { opacity:.5; outline:2px dashed var(--emr-primary); }
.emr-section .emr-dash-head { display:flex; align-items:center; gap:6px; padding:8px 10px; background:#f6f8fb; border-bottom:1px solid var(--emr-line); font-size:14px; }
.emr-section .emr-dash-grip { cursor:grab; color:#9aa6b2; }
.emr-section .emr-dash-scope { font-size:11px; font-weight:600; color:var(--emr-primary); background:#eef4fb; border:1px solid #cfe0f3; border-radius:12px; padding:1px 8px; }
.emr-section .emr-dash-tools { margin-left:auto; display:flex; gap:2px; }
.emr-section .emr-dash-tools button { border:1px solid var(--emr-line); background:#fff; border-radius:6px; cursor:pointer; font-size:11px; padding:1px 6px; color:#6b7785; }
.emr-section .emr-dash-rm:hover { color:var(--emr-alert); border-color:#f3c2c2; }
.emr-section .emr-dash-body { padding:10px; }
.emr-section .emr-dash-line { display:block; padding:3px 4px; border-radius:6px; font-size:13px; color:inherit; text-decoration:none; }
.emr-section a.emr-dash-line:hover { background:#eef4fb; }
.emr-section .emr-dash-stats { display:flex; flex-wrap:wrap; gap:8px; }
.emr-section .emr-dash-stat { flex:1 1 80px; text-align:center; border:1px solid var(--emr-line); border-radius:8px; padding:8px 4px; }
.emr-section .emr-dash-stat .n { font-size:20px; font-weight:700; }
.emr-section .emr-dash-stat.bad .n { color:var(--emr-alert); }
.emr-section .emr-dash-stat .l { font-size:11px; color:#6b7785; }

/* ===== Face Sheet (read-only document) ===== */
.emr-section .emr-fsgrid { columns:2; column-gap:18px; }
@media (max-width:760px){ .emr-section .emr-fsgrid { columns:1; } }
.emr-section .emr-fsblock { break-inside:avoid; border:1px solid var(--emr-line); border-radius:10px; padding:8px 12px; margin-bottom:12px; background:#fafbfc; }
.emr-section .emr-fsbh { font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.03em; color:var(--emr-primary); margin-bottom:6px; }
.emr-section .emr-fsrow { display:flex; justify-content:space-between; gap:12px; padding:2px 0; font-size:13px; border-bottom:1px dotted #e4e9ef; }
.emr-section .emr-fsrow:last-child { border-bottom:none; }
.emr-section .emr-fslbl { color:var(--emr-muted); }
.emr-section .emr-fsval { font-weight:600; text-align:right; }

/* ===== Overview: safety banner, counts, trends ===== */
.emr-section .emr-ov-chips { display:flex; flex-wrap:wrap; gap:6px; margin-top:6px; }
.emr-section .emr-chip-ok { background:#e8f5ee; color:var(--emr-ok); border:1px solid #bfe3cf; }
.emr-section .emr-chip-soft { background:#eef1f5; color:#41506a; border:1px solid #d8dee7; }
.emr-section .emr-ov-conflict { margin-top:8px; background:#fdeaea; color:var(--emr-alert); border:1px solid #f3c2c2; border-radius:8px; padding:8px 12px; font-weight:600; font-size:13px; }
.emr-section .emr-avatar-btn.emr-avatar-od { box-shadow:0 0 0 3px #fdeaea, 0 0 0 4px var(--emr-alert); border-radius:50%; }
.emr-section .emr-avatar-btn.emr-avatar-ok { box-shadow:0 0 0 3px #e8f5ee, 0 0 0 4px var(--emr-ok); border-radius:50%; }
.emr-section .emr-ov-count { font-size:12px; font-weight:600; color:var(--emr-primary); }
.emr-section .emr-ov-od { color:var(--emr-alert); }
.emr-section .emr-spark-row { display:flex; align-items:center; gap:8px; padding:4px 2px; border-bottom:1px dotted #e4e9ef; }
.emr-section .emr-spark-row:last-child { border-bottom:none; }
.emr-section .emr-spark-lbl { font-size:12px; color:var(--emr-muted); width:64px; }
.emr-section .emr-spark { flex:1; height:24px; }
.emr-section .emr-spark-last { font-size:13px; font-weight:700; min-width:36px; text-align:right; }

/* ===== Toast (transient save confirmation) ===== */
.emr-toast { position:fixed; left:50%; bottom:26px; transform:translateX(-50%) translateY(12px); background:#1a7f4b; color:#fff; padding:11px 20px; border-radius:24px; font-size:14px; font-weight:600; box-shadow:0 6px 20px rgba(0,0,0,.22); z-index:99999; opacity:0; transition:opacity .25s, transform .25s; pointer-events:none; max-width:90vw; }
.emr-toast.show { opacity:1; transform:translateX(-50%) translateY(0); }
.emr-toast.emr-toast-err { background:#b42318; }
