/* ============================================================
   Figment EMR — stylesheet (Epic-style layout, Figment skin)
   ============================================================ */
:root {
    --emr-bg: #eef1f6;
    --emr-ink: #1e2433;
    --emr-muted: #5b6475;
    --emr-line: #d7dde7;
    --emr-card: #ffffff;
    --emr-primary: #1f5fae;       /* Figment clinical blue */
    --emr-primary-dark: #16467f;
    --emr-accent: #0e9f6e;
    --emr-warn: #b45309;
    --emr-danger: #c0392b;
    --emr-nav: linear-gradient(90deg, #16467f 0%, #1f5fae 100%);
    --emr-radius: 8px;
    --emr-shadow: 0 4px 14px rgba(30,40,60,.08);
    --emr-flag-h: #c0392b;
    --emr-flag-l: #2563eb;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--emr-bg); color: var(--emr-ink); line-height: 1.5; }
a { color: var(--emr-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
.emr-nav { background: var(--emr-nav); color: #fff; box-shadow: var(--emr-shadow); }
.emr-nav-inner { max-width: 1200px; margin: 0 auto; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; min-height: 56px; gap: 14px; }
.emr-brand { display: flex; align-items: center; gap: 10px; line-height: 1; color: #fff; }
.emr-brand:hover { text-decoration: none; }
.emr-brand-logo { height: 30px; width: auto; display: block; }
.emr-brand-txt { font-size: 1.15rem; font-weight: 700; color: #fff; letter-spacing: .01em; }
.emr-brand-top { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.emr-brand-bottom { font-size: 1.25rem; font-weight: 700; }
.emr-nav-links { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.emr-nav-link { color: rgba(255,255,255,.85); padding: 7px 12px; border-radius: 6px; font-size: .9rem; font-weight: 500; }
.emr-nav-link:hover { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.emr-nav-link.is-active { background: rgba(255,255,255,.2); color: #fff; }
.emr-nav-user { margin-left: 8px; padding: 4px 11px; border-radius: 20px; background: rgba(255,255,255,.16); font-size: .8rem; font-weight: 600; }

/* Layout */
.emr-main { max-width: 1200px; margin: 0 auto; padding: 24px 18px 60px; }
.emr-page-head { margin-bottom: 18px; }
.emr-page-head h1 { font-size: 1.5rem; margin: 0 0 4px; }
.emr-page-head p { color: var(--emr-muted); margin: 0; font-size: .92rem; }

/* Cards / sections */
.emr-card { background: var(--emr-card); border: 1px solid var(--emr-line); border-radius: var(--emr-radius); box-shadow: var(--emr-shadow); padding: 18px 20px; margin-bottom: 16px; }
.emr-card h2 { font-size: 1.05rem; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 1px solid var(--emr-line); }
.emr-card h3 { font-size: .92rem; margin: 14px 0 6px; color: var(--emr-primary-dark); }

/* Buttons */
.emr-btn { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; padding: 9px 16px; border-radius: 6px; border: 1px solid var(--emr-line); background: #fff; color: var(--emr-ink); font-size: .9rem; font-weight: 600; font-family: inherit; text-decoration: none; }
.emr-btn:hover { background: #f1f4f9; text-decoration: none; }
.emr-btn-primary { background: var(--emr-primary); border-color: var(--emr-primary); color: #fff; }
.emr-btn-primary:hover { background: var(--emr-primary-dark); }
.emr-btn-sm { padding: 6px 11px; font-size: .82rem; }
.emr-btn[disabled] { opacity: .55; cursor: default; }

/* Forms */
.emr-field { margin-bottom: 14px; }
.emr-field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 4px; }
.emr-input, textarea.emr-input, select.emr-input { width: 100%; padding: 10px 12px; border: 1px solid var(--emr-line); border-radius: 6px; font-family: inherit; font-size: .92rem; resize: vertical; }
.emr-input:focus { outline: none; border-color: var(--emr-primary); }

/* Tables */
.emr-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.emr-table th, .emr-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--emr-line); vertical-align: top; }
.emr-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--emr-muted); }
.emr-flag-H, .flag-H, .flag-HH { color: var(--emr-flag-h); font-weight: 700; }
.emr-flag-L, .flag-L, .flag-LL { color: var(--emr-flag-l); font-weight: 700; }

/* Setting badge */
.emr-badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 9px; border-radius: 20px; letter-spacing: .02em; }
.emr-badge-inpatient { background: #e0ecfb; color: #16467f; }
.emr-badge-ambulatory { background: #e7f8f0; color: #0e7a52; }
.emr-badge-ed { background: #fde9e7; color: #b3382b; }
.emr-badge-draft { background: #eef0f4; color: #5b6475; }

/* Chart preview (authoring) — mini patient banner + sections */
.emr-preview { display: grid; grid-template-columns: 230px 1fr; gap: 16px; }
@media (max-width: 800px) { .emr-preview { grid-template-columns: 1fr; } }
.emr-banner { background: var(--emr-primary-dark); color: #fff; border-radius: var(--emr-radius); padding: 16px; align-self: start; }
.emr-banner .emr-avatar { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: rgba(255,255,255,.2); display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: 700; margin-bottom: 10px; }
.emr-banner .emr-pt-name { font-size: 1.1rem; font-weight: 700; }
.emr-banner .emr-pt-line { font-size: .8rem; opacity: .9; margin-top: 2px; }
.emr-banner .emr-pt-field { margin-top: 10px; font-size: .78rem; }
.emr-banner .emr-pt-field b { display: block; opacity: .7; text-transform: uppercase; font-size: .66rem; letter-spacing: .04em; }
.emr-banner .emr-alert { color: #ffd0c8; font-weight: 600; }

/* ── Chart shell: activity tabs ───────────────────────── */
.emr-chart { display: grid; grid-template-columns: 240px 1fr; gap: 16px; align-items: start; }
@media (max-width: 820px) { .emr-chart { grid-template-columns: 1fr; } }
.emr-tabbar { display: flex; gap: 2px; flex-wrap: wrap; background: var(--emr-card); border: 1px solid var(--emr-line); border-radius: var(--emr-radius) var(--emr-radius) 0 0; padding: 4px 4px 0; }
.emr-tab { padding: 9px 15px; font-size: .86rem; font-weight: 600; color: var(--emr-muted); border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; cursor: pointer; background: none; font-family: inherit; }
.emr-tab:hover { color: var(--emr-primary); background: #f3f6fb; }
.emr-tab.is-active { color: var(--emr-primary-dark); background: #fff; border-color: var(--emr-line); position: relative; top: 1px; }
.emr-tab .emr-tab-count { font-size: .7rem; color: var(--emr-muted); font-weight: 600; }
.emr-tabwrap { background: var(--emr-card); border: 1px solid var(--emr-line); border-top: none; border-radius: 0 0 var(--emr-radius) var(--emr-radius); box-shadow: var(--emr-shadow); padding: 18px 20px; min-height: 320px; }
.emr-panel { display: none; }
.emr-panel.is-active { display: block; }
.emr-panel h3 { margin: 0 0 12px; font-size: 1rem; color: var(--emr-primary-dark); }
.emr-panel-empty { color: var(--emr-muted); padding: 30px 0; text-align: center; }

/* ── Notes (interactive) ──────────────────────────────── */
.emr-notes-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.emr-note-card { border: 1px solid var(--emr-line); border-radius: 7px; margin-bottom: 10px; overflow: hidden; }
.emr-note-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; background: #f6f8fc; cursor: pointer; }
.emr-note-bar:hover { background: #eef3fb; }
.emr-note-meta { font-size: .82rem; }
.emr-note-meta .emr-note-title { font-weight: 700; }
.emr-note-meta .emr-note-sub { color: var(--emr-muted); font-size: .76rem; margin-top: 1px; }
.emr-note-type { font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 12px; background: #e0ecfb; color: #16467f; white-space: nowrap; }
.emr-note-body { display: none; padding: 14px 16px; font-size: .9rem; line-height: 1.6; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; border-top: 1px solid var(--emr-line); }
.emr-note-body.is-open { display: block; }
.emr-note-body .emr-h { font-weight: 700; font-family: 'Inter', sans-serif; color: var(--emr-primary-dark); display: block; margin-top: 10px; }
.emr-note-body .emr-h:first-child { margin-top: 0; }
.emr-note-actions { padding: 0 16px 12px; display: none; gap: 12px; font-size: .82rem; }
.emr-note-actions.is-open { display: flex; }
.emr-note-actions a { cursor: pointer; }

/* Runtime inline action rows */
.emr-runrow { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.emr-runrow .emr-input { flex: 1; min-width: 140px; }
.emr-result-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--emr-line); font-size: .9rem; }
.emr-result-icon { width: 22px; text-align: center; font-weight: 700; }
.emr-result-met { color: var(--emr-accent); }
.emr-result-missed { color: var(--emr-danger); }
.emr-result-manual { color: var(--emr-muted); }
.emr-score { font-size: 2rem; font-weight: 800; color: var(--emr-primary-dark); }

/* Note editor modal */
.emr-modal-bg { position: fixed; inset: 0; background: rgba(20,30,50,.5); z-index: 1000; display: none; align-items: center; justify-content: center; padding: 16px; }
.emr-modal-bg.is-open { display: flex; }
.emr-modal { background: #fff; border-radius: 12px; width: 100%; max-width: 720px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden; }
.emr-modal-head { padding: 14px 18px; border-bottom: 1px solid var(--emr-line); display: flex; justify-content: space-between; align-items: center; }
.emr-modal-head h3 { margin: 0; font-size: 1.05rem; }
.emr-modal-body { padding: 16px 18px; overflow-y: auto; }
.emr-modal-foot { padding: 12px 18px; border-top: 1px solid var(--emr-line); display: flex; justify-content: flex-end; gap: 8px; }
.emr-modal textarea { min-height: 320px; font-family: ui-monospace, Menlo, monospace; font-size: .88rem; line-height: 1.55; }
.emr-modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--emr-muted); }

/* Flash */
.emr-flash-wrap { max-width: 1200px; margin: 14px auto 0; padding: 0 18px; }
.emr-flash { padding: 11px 15px; border-radius: 6px; margin-bottom: 9px; font-size: .9rem; }
.emr-flash-success { background: #e7f8f0; color: #065f46; }
.emr-flash-error { background: #fdeaea; color: #9b1c1c; }
.emr-flash-info { background: #e8effb; color: #16467f; }

/* Empty */
.emr-empty { text-align: center; color: var(--emr-muted); padding: 56px 20px; }

/* Generate status */
.emr-status { font-size: .85rem; color: var(--emr-muted); margin-top: 8px; }

/* Gate */
.emr-gate { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--emr-nav); padding: 20px; }
.emr-gate-card { background: #fff; border-radius: 14px; padding: 34px 32px; max-width: 460px; box-shadow: 0 18px 44px rgba(0,0,0,.3); }
.emr-gate-brand { font-size: 1.25rem; font-weight: 700; margin-bottom: 16px; }
.emr-gate-brand span { color: var(--emr-primary); }
.emr-gate-card h1 { font-size: 1.35rem; margin: 0 0 10px; }
.emr-gate-card p { color: var(--emr-muted); font-size: .94rem; margin-bottom: 18px; }

/* Case editor */
.emr-esec { padding: 14px 16px; }
.emr-esechead { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--emr-line); }
.emr-esechead h2 { margin: 0; padding: 0; border: none; }
.emr-esec-actions { display: flex; gap: 8px; }
.emr-erows { display: flex; flex-direction: column; gap: 8px; }
.emr-erow { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end;
    padding: 10px; border: 1px solid var(--emr-line); border-radius: 6px; background: #fafbfd; }
.emr-erow-wrap { background: transparent; border: none; padding: 0; }
.emr-ecell { display: flex; flex-direction: column; flex: 1 1 140px; min-width: 120px; }
.emr-ecell-chk { flex: 0 0 auto; justify-content: center; padding-bottom: 8px; }
.emr-elbl { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; color: var(--emr-muted);
    font-weight: 600; margin-bottom: 3px; }
.emr-erow .emr-input { padding: 7px 9px; font-size: .88rem; }
.emr-echk { display: inline-flex; align-items: center; gap: 6px; font-size: .85rem; font-weight: 600;
    color: var(--emr-ink); white-space: nowrap; }
.emr-echk input { width: 16px; height: 16px; }
.emr-edel { flex: 0 0 auto; align-self: center; color: var(--emr-danger); line-height: 1;
    padding: 6px 9px; font-size: 1rem; }
.emr-eempty { padding: 10px; }

/* Footer */
.emr-footer { margin-top: 36px; padding: 16px 18px; background: #1c2433; }
.emr-footer-inner { max-width: 1200px; margin: 0 auto; text-align: center; color: rgba(255,255,255,.5); font-size: .76rem; }

/* ── Scanned outside records on external notes ─────────────────────────────
   The note body is monospace + pre-wrap for typed text; a document viewer
   needs neither, so reset both inside the wrapper. */
.emr-note-doc { white-space: normal; font-family: 'Inter', sans-serif; margin: -2px 0 0; }
.emr-note-doc-bar { display: flex; align-items: center; justify-content: space-between;
    gap: 10px; flex-wrap: wrap; padding: 0 0 10px; }
.emr-note-doc-name { font-size: .85rem; color: var(--emr-ink, #23324a); font-weight: 600; }
.emr-note-pdf { display: block; width: 100%; height: 70vh; min-height: 420px;
    border: 1px solid var(--emr-line, #dfe4ec); border-radius: 6px; background: #f4f6fa; }
.emr-note-doc-fallback { padding: 22px; text-align: center; font-size: .9rem;
    color: var(--emr-muted, #6b7688); }
.emr-note-doc-text { white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace;
    font-size: .88rem; margin-top: 12px; padding-top: 12px;
    border-top: 1px dashed var(--emr-line, #dfe4ec); }
@media (max-width: 700px) { .emr-note-pdf { height: 55vh; min-height: 300px; } }

/* Editor: the attach-PDF control on an external note row */
.emr-epdf { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.emr-epdf-name { font-size: .78rem; color: var(--emr-muted, #6b7688);
    max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.emr-epdf[data-has="1"] .emr-epdf-name { color: var(--emr-primary-dark, #1b3a63); font-weight: 600; }
.emr-ehint { margin: 0 0 10px; font-size: .82rem; color: var(--emr-muted, #6b7688); }

/* ── Chart Review timeline (admin/case-timeline.php) ───────────────────────── */
.emr-tl-issues{margin:.2rem 0 0;padding-left:1.1rem;}
.emr-tl-issues li{margin:.3rem 0;font-size:.9rem;line-height:1.5;}
.emr-tl-issue-where{display:inline-block;font-weight:700;font-size:.78rem;background:#fff4e5;
  color:#8a5300;border-radius:4px;padding:1px 6px;margin-right:6px;}
.emr-tl-enc{margin-bottom:14px;}
.emr-tl-head{display:flex;justify-content:space-between;align-items:flex-start;gap:12px;
  flex-wrap:wrap;margin-bottom:.35rem;}
.emr-tl-enc-title{font-weight:700;font-size:1.02rem;}
.emr-tl-table{width:100%;border-collapse:collapse;font-size:.88rem;}
.emr-tl-table td{padding:6px 8px;border-top:1px solid #eef0f4;vertical-align:top;}
.emr-tl-table tr:first-child td{border-top:none;}
.emr-tl-when{white-space:nowrap;color:#6b7280;font-variant-numeric:tabular-nums;width:1%;}
.emr-tl-kind{width:1%;white-space:nowrap;}
.emr-tl-chip{display:inline-block;font-size:.72rem;font-weight:700;letter-spacing:.02em;
  padding:2px 7px;border-radius:999px;background:#eef2f7;color:#42506b;}
.emr-tl-vital{background:#e8f4ff;color:#12558f;}
.emr-tl-lab{background:#eefbf3;color:#0e7a52;}
.emr-tl-imaging{background:#f3ecff;color:#5b3ba8;}
.emr-tl-note{background:#fff4e5;color:#8a5300;}
.emr-tl-order{background:#fdeef0;color:#9b2233;}
.emr-tl-by{color:#6b7280;}
.emr-tl-detail{color:#6b7280;font-size:.83rem;margin-top:2px;}

/* ── Per-row tools in the chart editor ────────────────────────────────────── */
.emr-erow-tools{display:flex;gap:4px;align-items:flex-start;flex:none;}
.emr-erow-new{animation:emrRowIn .9s ease;}
@keyframes emrRowIn{from{background:#eefbf3;}to{background:transparent;}}
.emr-field-changed{animation:emrFieldIn 2.4s ease;}
@keyframes emrFieldIn{0%{background:#fff4c2;}70%{background:#fff4c2;}100%{background:transparent;}}
