/* ============================================================
   Hospital Management System — base theme
   Clean, responsive, intuitive. CSS variables for easy theming.
   ============================================================ */
:root {
    --primary: #0f766e;        /* teal */
    --primary-600: #0d655e;
    --primary-50: #ecfdf8;
    --accent: #2563eb;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --sidebar-w: 260px;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --font: 'Segoe UI', Roboto, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.content { padding: 24px; flex: 1; }

/* ---------- Sidebar ---------- */
.sidebar {
    width: var(--sidebar-w);
    background: #0b1324;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 18px; font-weight: 700; color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.06);
    text-decoration: none;
}
a.brand:hover { background: rgba(255,255,255,.04); }
.brand-mark {
    background: var(--primary); color: #fff; font-weight: 800;
    width: 34px; height: 34px; border-radius: 9px;
    display: grid; place-items: center; font-size: 16px;
}
.brand-mark span { color: #5eead4; }
.brand-text { font-size: 14px; line-height: 1.1; }

.nav { padding: 10px 8px; }
.nav-group { margin-bottom: 2px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px; color: #cbd5e1;
    cursor: pointer; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-ico {
    width: 18px; height: 18px; flex: none;
    display: inline-flex; align-items: center; justify-content: center;
    color: #94a3b8;
}
.nav-link:hover .nav-ico, .nav-group.open .nav-ico { color: #5eead4; }
.nav-ico svg { width: 18px; height: 18px; }
.nav-label { flex: 1; }
.nav-caret { transition: transform .2s; opacity: .6; }
.nav-group.open > .nav-link .nav-caret { transform: rotate(90deg); }
.nav-sub { display: none; padding: 4px 0 6px 40px; }
.nav-group.open .nav-sub { display: block; }
.nav-sublink {
    display: block; padding: 7px 10px; border-radius: 6px;
    color: #94a3b8; font-size: 13px;
}
.nav-sublink:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-link.active .nav-ico { color: #fff; }
.nav-sublink.active { color: #5eead4; font-weight: 600; }

/* ---------- Topbar ---------- */
.topbar {
    height: 60px; background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px; position: sticky; top: 0; z-index: 20;
}
.topbar-spacer { flex: 1; }
.icon-btn {
    background: none; border: none; cursor: pointer;
    font-size: 18px; color: var(--muted); padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; display: block; }
.brand-mark svg { width: 20px; height: 20px; }
.auth-brand .brand-mark svg { width: 26px; height: 26px; }
#menuToggle { display: inline-flex; }
body.sidebar-collapsed .sidebar { display: none; }
.sidebar-backdrop { display: none; }
.quick-links { display: flex; align-items: center; gap: 8px; margin-left: 6px; flex-wrap: wrap; min-width: 0; }
.quick-links .quick-label { font-size: 12px; }
.quick-link { font-size: 13px; padding: 4px 11px; border: 1px solid var(--border); border-radius: 999px; color: var(--text); text-decoration: none; background: #fff; white-space: nowrap; }
.quick-link:hover { background: var(--bg); border-color: var(--primary); }
@media (max-width: 760px) { .quick-links { display: none; } }

.lang-switch { display: flex; gap: 4px; }
.lang-link {
    padding: 4px 8px; border-radius: 6px; font-size: 12px;
    font-weight: 600; color: var(--muted);
}
.lang-link.active { background: var(--primary-50); color: var(--primary); }

.user-menu { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--primary); color: #fff; font-weight: 700;
    display: grid; place-items: center;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.1; }
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--muted); }

/* ---------- Page + cards ---------- */
.page-head { margin-bottom: 20px; }
.page-head h2 { margin: 0 0 4px; font-size: 22px; }
.card-grid {
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.stat-card .stat-label { color: var(--muted); font-size: 13px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; margin: 6px 0; }
.stat-card .stat-foot { font-size: 12px; }

/* ---------- Buttons / forms ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 8px; padding: 10px 16px; border-radius: 8px; border: 1px solid transparent;
    font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-block { width: 100%; }

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50);
}

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.alert-error   { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }
.alert-info    { background: #eff6ff; color: var(--accent); border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; color: var(--warning); border: 1px solid #fde68a; }

/* ---------- "What this form checks" help block ---------- */
.help-card { border-left: 4px solid var(--accent); padding: 14px 18px; }
.help-card > summary {
    cursor: pointer; font-weight: 700; font-size: 14px; color: var(--accent);
    list-style: none; display: flex; align-items: center; gap: 8px;
}
.help-card > summary::-webkit-details-marker { display: none; }
.help-card > summary::before { content: 'i'; flex: none;
    width: 18px; height: 18px; border-radius: 50%; background: var(--accent); color: #fff;
    font-size: 12px; font-style: italic; display: grid; place-items: center; }
.help-card[open] > summary { margin-bottom: 10px; }
.help-card p, .help-card li { font-size: 13px; color: var(--text); line-height: 1.55; }
.help-card p { margin: 0 0 10px; }
.help-card ul { margin: 0; padding-left: 18px; display: grid; gap: 6px; }
/* ---------- Duplicate patient guard (registration form) ---------- */
.dup-panel { background: #fffbeb; border: 1px solid #fde68a; border-left: 4px solid var(--warning); }
.dup-panel.is-blocking { background: #fef2f2; border-color: #fecaca; border-left-color: var(--danger); }
.dup-panel h3 { color: var(--warning); }
.dup-panel.is-blocking h3 { color: var(--danger); }
.dup-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.dup-item {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
    padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
.dup-item .dup-who { font-weight: 600; }
.dup-item .dup-meta { font-size: 12px; color: var(--muted); }
.dup-badge {
    display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px;
    border-radius: 999px; background: #f1f5f9; color: var(--muted); text-transform: uppercase;
}
.dup-confirm { display: flex; gap: 10px; align-items: flex-start; margin: 16px 0 0; font-size: 13px; }
.dup-confirm input { width: auto; margin-top: 2px; flex: none; }
.dup-notice {
    margin: 10px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px;
    background: #fff; border: 1px dashed var(--warning); color: var(--text);
}
.dup-item .dup-who + .dup-badge { margin-left: 8px; }
.dup-badge.block  { background: #fef2f2; color: var(--danger); }
.dup-badge.strong { background: #fffbeb; color: var(--warning); }

/* ---------- Guest / login ---------- */
.guest-body {
    background: linear-gradient(135deg, #0f766e, #0b1324);
    min-height: 100vh; display: grid; place-items: center; padding: 20px;
}
.auth-card {
    background: #fff; width: 100%; max-width: 380px;
    border-radius: 16px; padding: 32px; box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .brand-mark { margin: 0 auto 12px; width: 48px; height: 48px; font-size: 22px; }
.auth-brand h1 { font-size: 18px; margin: 0; }
.auth-form .btn { margin-top: 6px; }
.auth-lang { text-align: center; margin-top: 18px; display: flex; gap: 14px; justify-content: center; }
.auth-lang a { font-size: 12px; color: var(--muted); }
.auth-lang a.active { color: var(--primary); font-weight: 700; }

/* ---------- Error pages ---------- */
.error-page { text-align: center; padding: 60px 20px; }
.error-page h1 { font-size: 64px; margin: 0; color: var(--primary); }

/* ---------- Toolbar / page head ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Buttons (variants) ---------- */
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn:not(.btn-primary):not(.btn-danger) { background: #fff; color: var(--text); border-color: var(--border); }
.inline { display: inline; }

/* ---------- Tables ---------- */
.table-card { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.table thead th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }
.col-actions { white-space: nowrap; text-align: right; width: 1%; }
.col-actions .btn { margin-left: 4px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #15803d; }
.badge-muted { background: #f1f5f9; color: #64748b; }
.badge-info { background: #dbeafe; color: #1d4ed8; }
.badge-warning { background: #fef3c7; color: #b45309; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

/* Triage acuity row tints (doctor waiting list) */
tr.lvl-emergency > td { background: #fef2f2; }
tr.lvl-emergency > td:first-child { box-shadow: inset 4px 0 0 #dc2626; }
tr.lvl-urgent > td { background: #fff7ed; }
tr.lvl-urgent > td:first-child { box-shadow: inset 4px 0 0 #d97706; }
tr.lvl-standard > td { background: #eff6ff; }
tr.lvl-non_urgent > td { background: #f0fdf4; }

/* Acuity control: the badge itself opens a small panel for whoever may
   change the level (act:triage.set_level). Read-only users get a plain badge. */
details.acuity { display: inline-block; position: relative; }
details.acuity > summary { list-style: none; cursor: pointer; display: inline-block; }
details.acuity > summary::-webkit-details-marker { display: none; }
details.acuity > summary::after { content: ' BE'; color: #94a3b8; font-size: 10px; }
details.acuity > summary:hover .badge { filter: brightness(0.95); }
.acuity-pop {
    position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; min-width: 220px;
    background: #fff; border: 1px solid var(--border); border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, .14); padding: 12px; text-align: left;
}
.acuity-title { margin: 0 0 8px; font-size: 11px; font-weight: 600; color: #64748b; text-transform: uppercase; }
.acuity-opt { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; }
.acuity-opt input { width: auto; margin: 0; }
.acuity-reason { width: 100%; margin: 8px 0; font-size: 12px; padding: 6px 8px; }
/* Keep the panel on-screen for the last columns of a wide table. */
td:last-child .acuity-pop, th:last-child .acuity-pop { left: auto; right: 0; }
.badge-danger { background: #fee2e2; color: #b91c1c; }

/* ---------- Forms (grid) ---------- */
.form-card { max-width: 720px; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .field { margin-bottom: 0; }
.form-grid .col-span-2 { grid-column: 1 / -1; }
.form-grid .form-actions { grid-column: 1 / -1; display: flex; gap: 10px; margin-top: 6px; }
.field.checkbox { display: flex; align-items: center; gap: 8px; }
.field.checkbox input { width: auto; }
.field.checkbox span { margin: 0; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Checkbox grid (roles, etc.) ---------- */
.checkbox-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc;
}
.checkbox-grid .field { margin-bottom: 0; }

/* ---------- Settings ---------- */
.settings-section { margin-bottom: 24px; }
.settings-section h3 { margin: 0 0 12px; font-size: 15px; }

/* ---------- Numbers / filters / reports ---------- */
.num { text-align: right; white-space: nowrap; }
/* `.table th, .table td` sets text-align:left and outranks a bare `.num`,
   which left every numeric CELL aligned left under a right-aligned HEADING.
   Matching that specificity puts the figures back under their headers. */
.table th.num, .table td.num { text-align: right; }
th.num { text-align: right; }
.filter-bar { padding: 12px 16px; margin-bottom: 16px; }
.filter-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.filter-form select, .filter-form input {
    padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-family: inherit; font-size: 13px;
}
.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.report-total td, .report-total th { font-weight: 700; background: #f8fafc; }
.report-head { text-align: center; margin-bottom: 16px; }
.report-head h2 { margin: 0; }
.report-head .sub { color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .report-grid { grid-template-columns: 1fr; } }

/* ---------- Printable documents ---------- */
.print-doc { max-width: 800px; margin: 0 auto; }
.doc-head { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 14px; margin-bottom: 16px; }
.doc-brand { display: flex; gap: 14px; align-items: flex-start; }
.doc-logo { height: 60px; width: auto; max-width: 160px; object-fit: contain; }
.doc-contact { font-size: 12px; color: var(--muted); margin-top: 2px; }
.logo-preview img { height: 56px; width: auto; max-width: 200px; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; margin-bottom: 8px; display: block; }
.doc-hospital { font-size: 22px; margin: 0; color: var(--primary); }
.doc-type { text-transform: uppercase; letter-spacing: 1px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.doc-meta { font-size: 13px; text-align: right; }
.doc-meta div { margin-bottom: 3px; }
.doc-table tfoot th { background: #f8fafc; }
.doc-narration { font-size: 13px; margin-top: 14px; }
.doc-foot { margin-top: 30px; padding-top: 12px; border-top: 1px dashed var(--border); text-align: center; font-size: 12px; color: var(--muted); }

@media print {
    .sidebar, .topbar, .no-print, .alert { display: none !important; }
    .content { padding: 0; }
    .card { box-shadow: none; border: none; }
    body { background: #fff; }
}

/* ---------- Triage / body diagram ---------- */
.triage-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.body-card { text-align: center; }
.body-svg { width: 100%; max-width: 240px; height: auto; cursor: crosshair; touch-action: none; }
.body-actions { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
.small { font-size: 12px; }
@media (max-width: 820px) { .triage-layout { grid-template-columns: 1fr; } }

/* ---------- Doctor consultation ---------- */
.consult-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.consult-main, .consult-side { min-width: 0; }
.consult-main .table-scroll { overflow-x: auto; }
.consult-main .card { margin-bottom: 16px; }
.consult-main h3 { margin: 0 0 12px; font-size: 15px; }
.kv { list-style: none; padding: 0; margin: 0 0 8px; }
.kv li { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.kv li span { color: var(--muted); }
.hist-item { display: block; padding: 8px 6px; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; border-radius: 6px; transition: background .12s; }
a.hist-item:hover { background: #f1f5f9; }
.lab-search { width: 100%; max-width: 320px; padding: 8px 10px; margin-bottom: 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.consult-actions { position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.consult-actions .form-actions { margin: 0; }
.autosave-state { min-height: 18px; }
.lab-audit { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; }
.lab-audit-row td { background: #f8fafc; padding-top: 4px; padding-bottom: 4px; }
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.lab-nohit { grid-column: 1 / -1; margin: 4px 0; }
.patient-strip { display: flex; flex-wrap: wrap; gap: 10px 28px; align-items: center; }
.patient-strip > div { display: flex; flex-direction: column; line-height: 1.3; }
.patient-strip .muted { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
.patient-strip b { font-size: 14px; }
.lab-pick.lab-excluded { border-color: var(--warning); background: #fffbeb; }
.rx-excl { margin-top: 4px; }
.rx-stock { display: block; margin-top: 4px; }
.rx-stock-out { color: var(--danger); font-weight: 600; }
.lab-pick { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc; font-size: 13px; cursor: pointer; }
.lab-pick span { white-space: normal; word-break: break-word; }
.lab-pick input { margin-top: 2px; flex: none; }
.lab-pick.lab-ordered { justify-content: space-between; align-items: center; background: #eef2ff; border-color: #c7d2fe; }
.lab-pick.lab-ordered .badge { white-space: nowrap; }
.diag-cols { display: grid; grid-template-columns: 1fr; gap: 12px; }
.diag-block { border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.diag-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.diag-head h4 { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.diag-block .table td { padding: 6px 6px; border: none; }
@media (max-width: 900px) { .diag-cols { grid-template-columns: 1fr; } }
@media (max-width: 900px) { .consult-layout { grid-template-columns: 1fr; } }

/* ---------- Dashboard queue chips ---------- */
a.stat-card { display: block; transition: box-shadow .15s, transform .15s; }
a.stat-card:hover { box-shadow: 0 4px 14px rgba(15,23,42,.1); transform: translateY(-1px); }
.queue-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.queue-chip { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border: 1px solid var(--border); border-radius: 999px; background: #f8fafc; }
.queue-chip span { color: var(--muted); font-size: 13px; }
.queue-chip b { font-size: 18px; color: var(--primary); }

/* ---------- Sticky save bar (bulk edit) ---------- */
.save-bar {
    position: sticky; bottom: 0; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 12px 16px; margin-top: 12px;
    background: #fff; border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 -2px 10px rgba(15,23,42,.06);
}
td input.price-in { font-weight: 600; }

/* ---------- Bed board ---------- */
.bed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.bed-tile { border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: center; background: #fff; }
.bed-tile.bed-available { border-color: #bbf7d0; background: #f0fdf4; }
.bed-tile.bed-occupied { border-color: #fecaca; background: #fef2f2; }
.bed-tile.bed-maintenance { background: #f1f5f9; }
.bed-ward { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.bed-no { font-size: 20px; font-weight: 700; margin: 4px 0; }
.bed-patient { font-size: 13px; font-weight: 600; }
.bed-status { font-size: 12px; color: var(--success); }
.bed-link { font-size: 12px; color: var(--primary); display: inline-block; margin-top: 6px; }

/* ---------- Patient media + signature pad ---------- */
.media-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.media-col .field-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.media-preview { display: block; max-height: 120px; max-width: 160px; border: 1px solid var(--border); border-radius: 8px; padding: 4px; background: #fff; margin-bottom: 8px; object-fit: contain; }
.media-preview.sig { max-width: 280px; }
.sig-pad { border: 1px dashed var(--border); border-radius: 8px; background: #fff; touch-action: none; max-width: 100%; cursor: crosshair; }
@media (max-width: 640px) { .media-grid { grid-template-columns: 1fr; } }

/* ---------- Registration card (ID-card style) ---------- */
.card-print-body { background: #f1f5f9; padding: 24px; font-family: var(--font); }
.id-card { width: 560px; max-width: 100%; margin: 0 auto; background: #fff; border-radius: 14px; overflow: hidden; box-shadow: 0 10px 30px rgba(15,23,42,.12); border: 1px solid var(--border); }
.id-band { background: linear-gradient(135deg, var(--primary), #0b1324); color: #fff; display: flex; align-items: center; gap: 14px; padding: 16px 20px; }
.id-logo { height: 52px; width: auto; max-width: 120px; object-fit: contain; background: #fff; border-radius: 8px; padding: 4px; }
.id-hospital { font-size: 20px; font-weight: 800; line-height: 1.1; }
.id-contact { font-size: 12px; opacity: .9; margin-top: 2px; }
.id-title { background: #0b1324; color: #5eead4; text-transform: uppercase; letter-spacing: 3px; font-size: 11px; text-align: center; padding: 6px; }
.id-body { display: flex; gap: 18px; padding: 20px; }
.id-photo img, .id-nophoto { width: 120px; height: 140px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }
.id-nophoto { display: grid; place-items: center; color: var(--muted); background: #f8fafc; font-size: 12px; }
.id-info { flex: 1; }
.id-mrn { font-family: monospace; font-size: 22px; font-weight: 800; color: var(--primary); letter-spacing: 2px; }
.id-name { font-size: 18px; font-weight: 700; margin: 2px 0 10px; }
.id-kv { width: 100%; font-size: 13px; border-collapse: collapse; }
.id-kv td { padding: 4px 0; vertical-align: top; }
.id-kv td:first-child { color: var(--muted); width: 90px; }
.id-foot { display: flex; align-items: flex-end; justify-content: space-between; padding: 0 20px 14px; }
.id-sign img { height: 44px; display: block; }
.id-sign-line { border-top: 1px solid var(--text); font-size: 11px; color: var(--muted); padding-top: 2px; min-width: 160px; }
.id-issued { font-size: 12px; color: var(--muted); }
.id-brand { text-align: center; font-size: 11px; color: var(--muted); padding: 8px; border-top: 1px dashed var(--border); }
@media print { .card-print-body { background: #fff; padding: 0; } .id-card { box-shadow: none; border: none; } }

/* ---------- Price matrix ---------- */
.price-matrix th, .price-matrix td { white-space: nowrap; }
.price-matrix .sticky-col { position: sticky; left: 0; background: #fff; z-index: 1; min-width: 220px; white-space: normal; }
.price-matrix thead .sticky-col { background: #f8fafc; }
.price-matrix input.price-cell { width: 100px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.price-cell.cell-saving { border-color: var(--warning); }
.price-cell.cell-ok { border-color: var(--success); box-shadow: 0 0 0 2px #dcfce7; }
.price-cell.cell-err { border-color: var(--danger); box-shadow: 0 0 0 2px #fee2e2; }
.excl-cell-td { text-align: center; }
td.excl-cell-td.cell-saving { background: #fef9c3; }
td.excl-cell-td.cell-ok { background: #dcfce7; }
td.excl-cell-td.cell-err { background: #fee2e2; }
/* Purchase orders: cap breach on a line, and the signature block on the print */
.lpo-row.row-err input.num { border-color: var(--danger); box-shadow: 0 0 0 2px #fee2e2; }
.lpo-msg-row { display: none; }
.lpo-msg-row.is-shown { display: table-row; }
.lpo-msg { color: var(--danger); font-size: 12px; }
.doc-sign { display: flex; gap: 40px; margin-top: 36px; }
.doc-sign > div { flex: 1; font-size: 12px; color: var(--muted); }
.doc-sign .sign-line { display: block; border-top: 1px solid var(--text); margin-bottom: 4px; padding-top: 26px; }

/* Price List: per-row autosave feedback (Pharmacy -> Price List) */
.price-row input.num { transition: border-color .15s ease, box-shadow .15s ease; }
.price-row.row-saving input.num { border-color: var(--warning); }
.price-row.row-ok input.num { border-color: var(--success); box-shadow: 0 0 0 2px #dcfce7; }
.price-row.row-err input.num { border-color: var(--danger); box-shadow: 0 0 0 2px #fee2e2; }
.price-row .cell-msg { display: none; margin-top: 4px; font-size: 11px; line-height: 1.3; color: var(--danger); white-space: normal; text-align: right; }
.price-row.row-err .cell-msg { display: block; }
.autosave-hint:not(:empty) { color: var(--warning); font-weight: 600; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: center; margin-top: 14px; }
.perm-row { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.perm-row:hover { background: #f8fafc; }
.perm-row.cell-ok { background: #dcfce7; }
.perm-row.cell-err { background: #fee2e2; }
select.perm-eff.cell-ok { border-color: var(--success); }
select.perm-eff.cell-err { border-color: var(--danger); }

/* ---------- Documentation ---------- */
.docs-search-card { margin-bottom: 18px; }
.docs-search { display: flex; align-items: center; gap: 10px; position: relative; }
.docs-search-ico { color: var(--muted); display: flex; }
.docs-search input { flex: 1; padding: 11px 14px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 15px; font-family: inherit; background: #fff; }
.docs-search input:focus { outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-50); }

.docs-toc-grid { display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.docs-toc-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.docs-toc-head h3 { margin: 0 0 2px; font-size: 16px; }
.docs-toc-head p { margin: 0; font-size: 13px; }
.docs-toc-ico { flex: 0 0 38px; height: 38px; border-radius: 10px;
    display: grid; place-items: center; background: var(--primary-50); color: var(--primary); }
.docs-toc-list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.docs-toc-list li { border-bottom: 1px solid var(--border); }
.docs-toc-list a { display: block; padding: 9px 4px; font-size: 14px;
    color: var(--text); text-decoration: none; }
.docs-toc-list a:hover { color: var(--primary); padding-left: 8px; transition: padding .15s; }

.docs-result-list { list-style: none; margin: 0; padding: 0; }
.docs-result { display: block; padding: 12px; border: 1px solid var(--border);
    border-radius: 8px; margin-bottom: 10px; text-decoration: none; color: var(--text); }
.docs-result:hover { border-color: var(--primary); background: var(--primary-50); }
.docs-result strong { margin-right: 8px; }
.docs-snippet { display: block; margin-top: 5px; font-size: 13px; }
.docs-results-head { margin: 0 0 14px; font-size: 16px; }
.docs-back-link { margin: 14px 0 0; }

/* Article view */
.docs-layout { display: grid; grid-template-columns: 250px 1fr; gap: 18px; align-items: start; }
.docs-side { position: sticky; top: 16px; max-height: calc(100vh - 90px); overflow-y: auto; padding: 14px; }
.docs-side-group { margin-bottom: 16px; }
.docs-side-title { display: flex; align-items: center; gap: 7px; margin: 0 0 6px;
    font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
.docs-side-ico { display: flex; color: var(--muted); }
.docs-side-ico svg { width: 14px; height: 14px; }
.docs-side ul { list-style: none; margin: 0; padding: 0; }
.docs-side li a { display: block; padding: 6px 10px; font-size: 13px; border-radius: 7px;
    color: var(--text); text-decoration: none; }
.docs-side li a:hover { background: var(--bg); }
.docs-side li a.active { background: var(--primary); color: #fff; font-weight: 600; }

.docs-crumb a { color: var(--primary); text-decoration: none; font-weight: 600; }
.docs-article-head { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.docs-article-head h1 { margin: 10px 0 0; font-size: 24px; }

.docs-prose { font-size: 15px; line-height: 1.7; color: #1f2937; max-width: 760px; }
.docs-prose h2 { font-size: 18px; margin: 26px 0 10px; padding-top: 6px; }
.docs-prose h3 { font-size: 15px; margin: 20px 0 8px; }
.docs-prose p { margin: 0 0 12px; }
.docs-prose ul, .docs-prose ol { margin: 0 0 14px; padding-left: 22px; }
.docs-prose li { margin-bottom: 6px; }
.docs-prose code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px;
    font-size: 13px; font-family: ui-monospace, Consolas, monospace; }
.docs-prose strong { color: var(--text); }
.docs-prose .docs-note { border-left: 3px solid var(--primary); background: var(--primary-50);
    padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 0 0 14px; font-size: 14px; }
.docs-prose .docs-steps { counter-reset: step; list-style: none; padding-left: 0; }
.docs-prose .docs-steps li { position: relative; padding-left: 38px; margin-bottom: 12px; }
.docs-prose .docs-steps li::before { counter-increment: step; content: counter(step);
    position: absolute; left: 0; top: -2px; width: 26px; height: 26px; border-radius: 50%;
    background: var(--primary); color: #fff; font-size: 13px; font-weight: 700;
    display: grid; place-items: center; }

.docs-pager { display: flex; justify-content: space-between; gap: 12px;
    margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); }
.docs-pager-link { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px;
    border: 1px solid var(--border); border-radius: 8px; text-decoration: none;
    color: var(--text); max-width: 48%; }
.docs-pager-link:hover { border-color: var(--primary); background: var(--primary-50); }
.docs-pager-link.next { text-align: right; margin-left: auto; }
.docs-pager-link span { font-size: 12px; }

@media (max-width: 820px) {
    .docs-layout { grid-template-columns: 1fr; }
    .docs-side { position: static; max-height: none; order: 2; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .sidebar {
        position: fixed; left: 0; top: 0; z-index: 50;
        transform: translateX(-100%); transition: transform .25s;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    /* On mobile the toggle always slides the off-canvas panel, never collapses. */
    body.sidebar-collapsed .sidebar { display: flex; }
    /* Tap-anywhere backdrop to close the open panel. */
    body.sidebar-open .sidebar-backdrop {
        display: block; position: fixed; inset: 0;
        background: rgba(0, 0, 0, .45); z-index: 40;
    }
}
@media (max-width: 640px) {
    .content { padding: 14px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .page-head h2 { font-size: 19px; }
}

/* ---- NHIF verification panel ---- */
.nhif-panel { border-left: 4px solid var(--accent); }
.nhif-panel .text-danger { color: var(--danger); }
/* Bulk settlement: a line paying more than the claim's outstanding balance. */
.table tr.row-error td { background: #fef2f2; }
.table tr.row-error input { border-color: var(--danger); }
.nhif-panel .text-success { color: var(--success); }
.nhif-card-result { margin-top: 12px; }
.nhif-preview { display: block; max-width: 320px; max-height: 240px; margin-top: 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; object-fit: contain; }
.nhif-actions { justify-content: flex-start; flex-wrap: wrap; gap: 8px; }
.nhif-actions .btn { white-space: nowrap; }
.nhif-clear { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; }
.nhif-clear input { width: auto; }

/* ---------- Type-ahead multi-select with chips (assets/js/tag-select.js) ---------- */
.ts-box { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; min-height: 38px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: text; }
.ts-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-50); }
.ts-chip { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; padding: 2px 4px 2px 8px; border-radius: 999px; background: var(--primary-50); color: var(--primary-600); font-size: 12px; line-height: 1.6; }
.ts-x { border: 0; background: transparent; color: inherit; font-size: 15px; line-height: 1; padding: 0 4px; cursor: pointer; border-radius: 999px; }
.ts-x:hover, .ts-x:focus-visible { background: var(--primary); color: #fff; outline: none; }
.ts-input { flex: 1 1 90px; min-width: 90px; border: 0 !important; outline: none; box-shadow: none !important; padding: 4px 2px !important; background: transparent; }
.ts-list { position: absolute; z-index: 30; left: -1px; right: -1px; top: calc(100% + 2px); max-height: 240px; overflow: auto; margin: 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 23, 42, .12); }
.ts-opt { padding: 6px 10px; cursor: pointer; font-size: 13px; }
.ts-opt:hover, .ts-opt.is-active { background: var(--primary-50); color: var(--primary-600); }
.ts-none { padding: 6px 10px; font-size: 12px; color: var(--muted); }

/* Segmented control: a row of mutually exclusive buttons (dental chart view,
   eye drawing view and tool). The pressed one carries aria-pressed="true". */
.seg {
    display: inline-flex; border: 1px solid var(--border);
    border-radius: 999px; overflow: hidden; background: #fff;
}
.seg button {
    border: 0; background: transparent; cursor: pointer;
    padding: 6px 14px; font: inherit; font-size: 13px; color: var(--muted);
    border-right: 1px solid var(--border);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--bg); color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }

/* ---------- Pharmacy counter sale (POS) ---------- */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.pos-main, .pos-side { min-width: 0; }
.pos-side .card { margin-bottom: 16px; }
.pos-side h3 { margin: 0 0 10px; font-size: 15px; }
.pos-search-wrap { position: relative; margin-bottom: 12px; }
.pos-search { width: 100%; padding: 11px 12px; font-size: 15px; border: 2px solid var(--primary); border-radius: 10px; }
.pos-hits { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); max-height: 320px; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(15, 23, 42, .14); }
.pos-hit { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--border);
    background: none; text-align: left; font: inherit; cursor: pointer; }
.pos-hit:hover, .pos-hit.active { background: var(--primary-50); }
.pos-hit.out span:first-child { color: var(--danger); }
#basket input.num { width: 100%; }
#basket .pos-free { display: block; }
#basket tr.pos-short .pos-free { color: var(--danger); font-weight: 600; }
.pos-cust-chip { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; margin-bottom: 10px;
    background: var(--primary-50); border-radius: 8px; }
.pos-rx { margin-top: 6px; font-size: 13px; }
.pos-rx summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
.kv li.pos-total { font-size: 18px; border-bottom: 0; padding-top: 10px; }
.kv li.pos-total b { color: var(--primary); }
.pos-change { font-size: 15px; margin: 6px 0 12px; }
#payTable td { padding: 4px; }
#payTable select, #payTable input { width: 100%; }
@media (max-width: 900px) { .pos-layout { grid-template-columns: 1fr; } }

/* ---------- Stocktake ---------- */
#stTable input.stq { width: 100%; }
#stTable tr.st-done td:first-child { border-left: 3px solid var(--success); }
#rvTable tr.st-short td { background: #fef2f2; }
#rvTable tr.st-over td { background: #f0fdf4; }
@media print { #rvTable tr[hidden] { display: none; } }

/* ---------- Simple accounting screens ---------- */
.fin-bar { height: 12px; border-radius: 6px; min-width: 2px; }
.fin-bar-inc { background: var(--success); }
.fin-bar-exp { background: var(--warning); }
.fin-verdict { padding: 12px 16px; border-radius: 10px; font-size: 16px; margin: 12px 0; }
.fin-verdict.fin-profit { background: #dcfce7; color: #14532d; }
.fin-verdict.fin-loss { background: #fee2e2; color: #7f1d1d; }
@media print { .fin-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* ---- Info bar: what this screen is for and what happens next ------------- */
.info-bar { display: flex; gap: 12px; align-items: flex-start; background: #f0f9ff; border: 1px solid #bae6fd;
    border-left: 4px solid #0284c7; border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; color: #0c4a6e; }
.info-bar-icon { flex: 0 0 22px; height: 22px; border-radius: 50%; background: #0284c7; color: #fff; font-weight: 700;
    display: flex; align-items: center; justify-content: center; font-style: italic; font-family: Georgia, serif; }
.info-bar ul { margin: 4px 0 0 16px; padding: 0; }
.info-bar li { margin: 1px 0; }
.info-bar .info-next { margin-top: 6px; padding-top: 6px; border-top: 1px dashed #bae6fd; font-weight: 600; color: #075985; }
.info-bar .info-next a { color: inherit; }
@media print { .info-bar { display: none !important; } }

/* ---- Theatre -------------------------------------------------------------- */
.th-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.th-chip { font-size: 11px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--border); background: #fff; white-space: nowrap; }
.th-chip.ok { background: #dcfce7; border-color: #bbf7d0; color: #15803d; }
.th-chip.bad { background: #fee2e2; border-color: #fecaca; color: #b91c1c; }
.th-chip.na { color: var(--muted); }
.th-rooms { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.th-room h3 { margin: 0 0 10px; display: flex; justify-content: space-between; align-items: center; }
.th-case { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: #fff; display: block;
    color: inherit; text-decoration: none; }
.th-case:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.th-case.emergency { border-left: 4px solid var(--danger); }
.th-case.urgent { border-left: 4px solid var(--warning); }
.th-case .th-time { font-weight: 700; font-size: 15px; }
.th-case .th-next { font-size: 12px; color: #075985; margin-top: 6px; }
.th-steps > details { margin-bottom: 12px; }
.th-steps > details > summary { cursor: pointer; font-weight: 600; font-size: 15px; list-style: none; display: flex; gap: 10px; align-items: center; }
.th-steps > details > summary::-webkit-details-marker { display: none; }
.th-steps > details > summary::before { content: '▸'; color: var(--muted); }
.th-steps > details[open] > summary::before { content: '▾'; }
.th-steps > details[open] > summary { margin-bottom: 12px; }
.th-step-state { margin-left: auto; }
.th-proc-row { display: grid; grid-template-columns: 1fr 160px 36px; gap: 8px; margin-bottom: 8px; }
@media (max-width: 640px) { .th-proc-row { grid-template-columns: 1fr 110px 36px; } }
.th-check-table td { padding: 6px 8px; }
.th-check-table label { margin-right: 10px; white-space: nowrap; }
.th-consent-text { white-space: pre-line; line-height: 1.6; background: #fafafa; border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.th-sig-pad { border: 1px dashed var(--muted); border-radius: 8px; background: #fff; touch-action: none; max-width: 100%; }
.th-radio-cards { display: flex; flex-wrap: wrap; gap: 8px; }
.th-radio-cards label { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; cursor: pointer; background: #fff; }
.th-radio-cards input { margin-right: 6px; }
.th-radio-cards label:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.print-sign-row { display: grid; grid-template-columns: 1fr 1fr; gap: 30px; margin-top: 40px; }
.print-sign-row div { border-top: 1px solid #000; padding-top: 4px; font-size: 12px; }

/* ---- Row ⋯ menu (inpatient list) ----------------------------------------- */
.row-menu { position: relative; display: inline-block; }
.row-menu > summary { list-style: none; cursor: pointer; font-weight: 700; letter-spacing: 1px; }
.row-menu > summary::-webkit-details-marker { display: none; }
.row-menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 50; min-width: 220px; background: #fff;
    border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .15); padding: 6px; text-align: left; }
.row-menu-list a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; color: var(--text);
    text-decoration: none; white-space: nowrap; font-size: 14px; }
.row-menu-list a:hover { background: var(--bg); }
.row-menu-ico { width: 20px; text-align: center; }

/* ---- Ward charts (vitals / intake-output) --------------------------------- */
.obs-unit { color: var(--danger); font-style: normal; font-size: 12px; margin-left: 4px; }
.obs-summary { display: flex; flex-wrap: wrap; gap: 24px; align-items: center; }
.obs-news-big { font-size: 34px; font-weight: 800; padding: 4px 18px; border-radius: 12px; display: inline-block; margin-top: 2px; }
.obs-due { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.obs-due.overdue b { color: var(--danger); }
.obs-table td.obs-amber { background: #fef3c7; font-weight: 600; }
.obs-table td.obs-red { background: #fee2e2; color: #b91c1c; font-weight: 700; }
.obs-void td { color: var(--muted); text-decoration: line-through; }
.obs-void td .obs-void-note, .obs-void td form { text-decoration: none; display: inline-block; }
.obs-trends { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.obs-trends > div { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.obs-spark { max-width: 100%; height: auto; }
td.num, th.num { text-align: right; }
.nn-note { border-top: 1px solid var(--border); padding: 10px 0; }
.nn-note:first-of-type { border-top: 0; }
.nn-body { margin-top: 4px; line-height: 1.5; }
.nn-addendum { margin: 6px 0 0 18px; padding: 6px 10px; border-left: 3px solid var(--warning); background: #fffbeb; border-radius: 4px; }

/* ---- Medication administration grid -------------------------------------- */
.mar-slots { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.mar-slot { position: relative; }
.mar-slot > summary { list-style: none; cursor: pointer; }
.mar-slot > summary::-webkit-details-marker { display: none; }
.mar-slot .th-chip.due { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; font-weight: 700; }
.mar-pop { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 260px; background: #fff; border: 1px solid var(--border);
    border-radius: 10px; box-shadow: 0 10px 30px rgba(15, 23, 42, .15); padding: 10px; font-size: 13px; }
.mar-form input:not([type=radio]), .mar-form select { width: 100%; }
@media print { .mar-pop { display: none; } }

/* ---- MTUHA report ---------------------------------------------------------- */
.mt-wrap { overflow-x: auto; }
.mt-table th { text-align: center; font-size: 11px; letter-spacing: .03em; white-space: normal; }
.mt-table td { padding: 6px 8px; }
.mt-table .mt-desc { text-align: left; min-width: 240px; }
.mt-table .mt-band { border-left: 2px solid var(--border); }
.mt-table .mt-t { font-weight: 700; }
.mt-table .mt-name { color: #c2410c; }
.mt-table tr.mt-total td { background: #f1f5f9; font-weight: 700; }
.mt-table tr.mt-section td { background: #cffafe; font-weight: 700; color: #0e7490; }
.mt-n { display: inline-block; min-width: 26px; padding: 1px 6px; border-radius: 6px; text-decoration: none; font-weight: 600; }
.mt-n.m { background: #dbeafe; color: #1d4ed8; } .mt-n.f { background: #fee2e2; color: #be123c; }
.mt-n:not(.m):not(.f) { color: var(--text); }
.mt-zero { color: var(--muted); }
@media print { .mt-n { background: none !important; color: #000 !important; padding: 0; } }

/* ---------- Requisitions / store levels ---------- */
.text-danger { color: var(--danger); }
tr.row-warn > td { background: #fffbeb; }
.req-short td.num input { border-color: var(--warning); }

/* ---------- Reports → Cash Collection ---------- */
.cc-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 14px; align-items: end; margin-bottom: 16px; }
.cc-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; margin: 0; }
.cc-filters input, .cc-filters select { width: 100%; }
.cc-filters .cc-dt { display: flex; gap: 6px; }
.cc-filters .cc-dt input[type=time] { max-width: 110px; }
.cc-filters label.cc-check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.cc-filters label.cc-check input { width: auto; }
.cc-filters .cc-actions { display: flex; gap: 8px; }
.cc-filters .cc-own { grid-column: 1 / -1; margin: 0; }
.cc-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.cc-stats > div { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.cc-stats span { font-size: 12px; color: var(--muted); }
.cc-stats b { font-size: 20px; margin-top: 2px; }
.cc-stats small { font-size: 11px; color: var(--muted); }
.cc-table td { vertical-align: top; padding: 8px 10px; }
.cc-table tr.cc-refund > td { background: #fef2f2; }
.cc-h { margin: 18px 0 8px; font-size: 15px; }
.cc-sums { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 0 20px; }
.cc-sums .table td, .cc-sums .table th { padding: 6px 10px; }
@media print {
    .cc-doc { padding: 0; }
    .cc-table { font-size: 11px; }
    .cc-table td, .cc-table th { padding: 4px 6px; }
    .cc-table tr.cc-refund > td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .cc-stats > div { break-inside: avoid; }
    .cc-sums > div { break-inside: avoid; }
}

/* ---------- Fingerprint identity check (migration 087) ---------- */
.idv-panel { border-left: 4px solid var(--accent); }
.idv-msg { margin: 10px 0 0; font-size: 13px; }
.idv-msg.idv-ok { color: var(--success); font-weight: 600; }
.idv-msg.idv-error { color: var(--danger); font-weight: 600; }

/* ---------- Reports → Master Report ---------- */
.mr-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.mr-tools select { max-width: 220px; }
.mr-presets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; margin-bottom: 16px; }
.mr-preset-save { display: flex; gap: 6px; align-items: center; margin-right: 8px; }
.mr-preset-save input[type=text] { width: 220px; }
.mr-chip { display: inline-flex; align-items: center; gap: 4px; background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
.mr-chip form { display: inline; margin: 0; }
.mr-chip button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; padding: 0 4px; }
.mr-chip button:hover { color: var(--danger); }
.mr-detail-toggle > summary { cursor: pointer; margin: 14px 0 8px; font-weight: 600; color: var(--primary); }
.mr-table td { vertical-align: top; }

/* ---- Audit log (Admin → Audit log) ---- */
.audit-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.audit-tools form { margin: 0; }
.audit-table td { vertical-align: top; }
.audit-table .nowrap { white-space: nowrap; }
details.audit-changes > summary { cursor: pointer; }
details.audit-changes table { margin-top: 6px; font-size: 12px; }
details.audit-changes td { padding: 3px 8px; word-break: break-word; max-width: 360px; }
.audit-old { background: #fef2f2; color: #991b1b; }
.audit-new { background: #f0fdf4; color: #166534; }

/* ---------- Reports → Patient Visit Report ---------- */
.vr-head { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 18px; margin-bottom: 14px; }
.vr-head > div { display: flex; flex-direction: column; }
.vr-head span { font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.vr-head b { font-size: 14px; }
.vr-head small { font-size: 12px; color: var(--muted); }
.vr-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.vr-nav a { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #eff6ff; color: var(--primary); text-decoration: none; }
.vr-h { margin: 22px 0 8px; padding-bottom: 4px; border-bottom: 2px solid var(--border); font-size: 16px; }
.vr-sub { margin: 14px 0 6px; font-size: 14px; }
.vr-timeline td { padding: 5px 10px; }
.vr-timeline tr.vr-day td { background: #f8fafc; font-weight: 600; font-size: 12px; color: var(--muted); }
.vr-group td { background: #f8fafc; }
.vr-indent { padding-left: 26px !important; }
.vr-cancelled td { color: var(--muted); text-decoration: line-through; }
.vr-cancelled .badge { text-decoration: none; }
.vr-dl { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 4px 14px; margin: 0 0 10px; font-size: 13px; }
.vr-dl dt { color: var(--muted); font-weight: 600; }
.vr-dl dd { margin: 0; }
.vr-block { border-left: 3px solid var(--border); padding: 4px 10px; margin: 6px 0; font-size: 13px; }
.vr-fold > summary { cursor: pointer; color: var(--primary); font-size: 13px; margin: 4px 0; }
.vr-totals { max-width: 420px; margin-left: auto; margin-top: 10px; }
.vr-patient-visits td { padding: 6px 10px; }
@media (max-width: 640px) { .vr-dl { grid-template-columns: 1fr; } }
@media print {
    .vr-h { break-after: avoid; }
    .vr-block, .vr-dl { break-inside: avoid; }
    .vr-fold > summary { display: none; }
}
details.audit-history { margin-top: 16px; }
details.audit-history > summary { cursor: pointer; display: flex; gap: 8px; align-items: center; }
details.audit-history .audit-table { margin-top: 8px; }
table.audit-mini { margin-top: 4px; font-size: 11px; border-collapse: collapse; }
table.audit-mini td { padding: 1px 6px; word-break: break-word; max-width: 300px; }

/* ---------- Result turnaround (TAT) ---------- */
.tat-chip { display: inline-block; font-size: 11px; color: #0e7490; background: #ecfeff; border: 1px solid #a5f3fc; border-radius: 999px; padding: 0 7px; margin-left: 4px; white-space: nowrap; font-weight: 500; }
.tat-input { display: flex; gap: 6px; }
.tat-input input { max-width: 110px; }
.tat-input select { max-width: 120px; }
.tat-overdue { white-space: nowrap; }
.tat-expected { margin-top: 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: 8px; font-size: 13px; }
.tat-expected > div { margin-top: 3px; }

/* ---------- Patient history inside the consultation ---------- */
.ph-panel > summary.ph-summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; list-style: none; }
.ph-panel > summary.ph-summary::-webkit-details-marker { display: none; }
.ph-panel > summary.ph-summary::before { content: '▸'; color: var(--muted); }
.ph-panel[open] > summary.ph-summary::before { content: '▾'; }
.ph-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 12px 0 10px; flex-wrap: wrap; }
.ph-tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; cursor: pointer; font: inherit; color: var(--muted); }
.ph-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.ph-visit { border-bottom: 1px solid var(--border); }
.ph-row { display: grid; grid-template-columns: 82px auto 1fr auto auto; gap: 8px; align-items: center; width: 100%; background: none; border: 0; padding: 7px 4px; text-align: left; cursor: pointer; font: inherit; color: inherit; border-radius: 6px; }
.ph-row:hover, .ph-visit.open > .ph-row { background: #f1f5f9; }
.ph-date { font-weight: 600; font-size: 13px; }
.ph-dx { font-size: 13px; min-width: 0; }
.ph-badges { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.ph-body { padding: 8px 10px 12px 14px; border-left: 3px solid var(--primary-50, #dbeafe); margin: 0 0 8px 4px; }
.ph-detail p { margin: 0 0 6px; }
.ph-mini { font-size: 13px; }
.ph-mini td { padding: 4px 6px; }
.ph-abn td { background: #fef2f2; }
.ph-pt-abn { color: var(--danger); font-weight: 700; }
.ph-spark { color: var(--primary); vertical-align: middle; }
.ph-list { margin: 4px 0 8px 18px; padding: 0; }
@media (max-width: 760px) { .ph-row { grid-template-columns: 70px 1fr; } .ph-badges, .ph-doc { grid-column: 1 / -1; justify-content: flex-start; } }

/* ---- Old-system history (doctor/legacy_history) ---- */
.lh-visit > summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.lh-visit h4 { margin: 1rem 0 .3rem; font-size: .95rem; }
.lh-chip { display: inline-block; margin: 0 .6rem .2rem 0; }
.lh-note { border-left: 3px solid var(--border); padding: .2rem .7rem; margin: .4rem 0; }
.lh-dl { display: grid; grid-template-columns: minmax(8rem, 14rem) 1fr; gap: .15rem .8rem; margin: .3rem 0; }
.lh-dl dt { color: var(--muted); }
.lh-dl dd { margin: 0; }
.lh-pre { white-space: pre-wrap; font-size: .9rem; }
.lh-bill summary { cursor: pointer; margin-top: .6rem; }
@media (max-width: 640px) { .lh-dl { grid-template-columns: 1fr; } }
