/* =========================================================
   Bệnh án chuyên khoa – bộ màu và khung giao diện
   Màu chủ đạo: xanh teal. Mọi màu lấy từ biến, không viết cứng trong trang.
   ========================================================= */
:root {
    --c-bg: #f3f6f6;
    --c-surface: #ffffff;
    --c-surface-2: #eaf1f1;
    --c-ink: #0f2628;
    --c-ink-2: #44585a;
    --c-muted: #6b7f81;
    --c-line: #d3dfdf;
    --c-accent: #0e7c86;
    --c-accent-600: #0a636c;
    --c-accent-50: #e3f5f4;
    --c-accent-ink: #083f45;
    --c-ok: #1f7a4d;
    --c-ok-bg: #e3f4ea;
    --c-warn: #9a5b00;
    --c-warn-bg: #fdf1dc;
    --c-bad: #b3261e;
    --c-bad-bg: #fbe5e3;
    --c-control-border: #7f9799;

    --sidebar-w: 52px;
    --sidebar-w-open: 208px;
    --topbar-h: 52px;

    --bs-body-bg: var(--c-bg);
    --bs-body-color: var(--c-ink);
    --bs-body-font-family: "Be Vietnam Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
    --bs-body-font-size: 0.9375rem;
    --bs-link-color: var(--c-accent);
    --bs-link-color-rgb: 14, 124, 134;
    --bs-link-hover-color: var(--c-accent-600);
    --bs-link-hover-color-rgb: 10, 99, 108;
    --bs-border-color: var(--c-line);
    --bs-primary: var(--c-accent);
    --bs-primary-rgb: 14, 124, 134;
}

html, body {
    height: 100%;
}

.skip-link {
    position: absolute;
    z-index: 100;
    background: var(--c-surface);
    padding: 8px 12px;
}

/* ---------- Khung ứng dụng ---------- */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100%;
}

.sidebar-open .app-shell {
    grid-template-columns: var(--sidebar-w-open) minmax(0, 1fr);
}

.app-sidebar {
    background: var(--c-surface);
    border-right: 1px solid var(--c-line);
    padding: 6px 0;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow: hidden auto;
}

.sidebar-toggle,
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 17px;
    white-space: nowrap;
    color: var(--c-ink-2);
    text-decoration: none;
    font-size: 0.875rem;
    border: 0;
    background: transparent;
}

.sidebar-toggle {
    color: var(--c-accent);
    font-weight: 700;
    cursor: pointer;
}

.app-sidebar svg {
    width: 18px;
    height: 18px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-label {
    display: none;
}

.sidebar-open .sidebar-label {
    display: inline;
}

a.sidebar-item:hover {
    background: var(--c-surface-2);
    color: var(--c-accent-ink);
}

.sidebar-item.active {
    background: var(--c-accent-50);
    color: var(--c-accent-ink);
    font-weight: 600;
    box-shadow: inset 3px 0 0 var(--c-accent);
}

.sidebar-item.disabled {
    opacity: 0.45;
    cursor: default;
}

.sidebar-separator {
    border-top: 1px solid var(--c-line);
    margin: 6px 10px;
}

.sidebar-toggle:focus-visible,
.sidebar-item:focus-visible,
.quick-search input:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: -2px;
}

.app-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: var(--topbar-h);
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-line);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    flex-wrap: wrap;
}

.quick-search {
    flex: 1 1 220px;
    max-width: 560px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--c-line);
    border-radius: 6px;
    background: var(--c-bg);
    padding: 0 10px;
    margin: 0;
}

.quick-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    padding: 6px 0;
    font-size: 0.875rem;
    color: var(--c-ink);
}

kbd {
    font-size: 0.6875rem;
    background: var(--c-surface);
    color: var(--c-ink-2);
    border: 1px solid var(--c-line);
    border-radius: 3px;
    padding: 0 5px;
    white-space: nowrap;
}

.topbar-chip {
    border: 1px solid var(--c-accent);
    color: var(--c-accent-ink);
    background: var(--c-accent-50);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}

.topbar-user {
    font-size: 0.8125rem;
    color: var(--c-ink-2);
    white-space: nowrap;
}

.app-content {
    padding: 16px;
    flex: 1;
}

/* ---------- Thành phần dùng chung ---------- */
.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin: 0 0 12px;
}

.panel {
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: 6px;
    margin-bottom: 12px;
}

.panel-header {
    padding: 8px 14px;
    border-bottom: 1px solid var(--c-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-weight: 600;
    font-size: 0.875rem;
}

.panel-body {
    padding: 12px 14px;
}

.status-pill {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 1px 9px;
    border-radius: 99px;
    white-space: nowrap;
}

.status-ok { background: var(--c-ok-bg); color: var(--c-ok); }
.status-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.status-bad { background: var(--c-bad-bg); color: var(--c-bad); }

.kv {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 6px 16px;
    margin: 0;
    font-size: 0.875rem;
}

.kv dt { color: var(--c-ink-2); font-weight: 500; }
.kv dd { margin: 0; }

.btn-primary {
    --bs-btn-bg: var(--c-accent);
    --bs-btn-border-color: var(--c-accent-600);
    --bs-btn-hover-bg: var(--c-accent-600);
    --bs-btn-hover-border-color: var(--c-accent-600);
    --bs-btn-active-bg: var(--c-accent-600);
    --bs-btn-active-border-color: var(--c-accent-600);
}

/* ---------- Thanh trên: người dùng ---------- */
a.topbar-chip { text-decoration: none; }
a.topbar-chip:hover { background: var(--c-accent); color: #fff; }

button.topbar-user {
    border: 0;
    background: transparent;
    padding: 4px 6px;
    border-radius: 6px;
}

button.topbar-user:hover { background: var(--c-surface-2); }

/* ---------- Trang đăng nhập ---------- */
.auth-shell {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: 10px;
    padding: 28px;
}

.auth-brand {
    color: var(--c-accent);
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.auth-title { font-size: 1.375rem; font-weight: 700; margin: 0 0 16px; }
.auth-hint { font-size: 0.8125rem; color: var(--c-muted); margin: 16px 0 0; text-align: center; }

.auth-divider {
    text-align: center;
    font-size: 0.8125rem;
    color: var(--c-muted);
    margin: 14px 0;
}

.code-input { font-size: 1.25rem; letter-spacing: 0.3em; text-align: center; }

.qr-box {
    display: flex;
    gap: 14px;
    align-items: center;
    flex-wrap: wrap;
    border: 1px solid var(--c-line);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 16px;
    background: #fff;
    color: #111;
}

.setup-key { font-size: 0.9375rem; word-break: break-all; color: #111; }

.choice-list { display: grid; gap: 8px; }

.choice {
    text-align: left;
    border: 1px solid var(--c-line);
    border-radius: 8px;
    background: var(--c-bg);
    padding: 10px 14px;
    display: grid;
    gap: 2px;
    color: var(--c-ink);
}

.choice span { font-size: 0.8125rem; color: var(--c-ink-2); }
.choice:hover, .choice.active { border-color: var(--c-accent); background: var(--c-accent-50); }

/* ---------- Bảng và form quản trị ---------- */
.page-tabs { margin-bottom: 12px; }
.page-tabs .nav-link { color: var(--c-ink-2); font-size: 0.875rem; }
.page-tabs .nav-link.active { color: var(--c-accent-ink); font-weight: 600; border-top: 2px solid var(--c-accent); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .form-control, .toolbar .form-select { width: auto; min-width: 180px; }
.input-code { max-width: 140px; min-width: 100px !important; }
.input-scope { min-width: 150px !important; }

.data-table { margin: 0; font-size: 0.875rem; }
.data-table th { background: var(--c-surface-2); color: var(--c-ink-2); font-size: 0.8125rem; font-weight: 600; white-space: nowrap; }
.data-table td, .data-table th { padding: 7px 12px; vertical-align: middle; }
.data-table.matrix th:not(:first-child), .data-table.matrix td:not(:first-child) { text-align: center; }
.data-table .group-row th { background: var(--c-surface); color: var(--c-accent); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }
.th-note { font-weight: 400; font-size: 0.6875rem; color: var(--c-muted); }
.row-denied td { background: var(--c-bad-bg); }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.form-actions-left { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.temp-password { font-size: 1.125rem; user-select: all; }
.pager { display: flex; gap: 16px; align-items: center; font-size: 0.875rem; }

/* ---------- Ô nhập liệu: phải nhìn ra ngay là bấm được, gõ được ---------- */
.form-control,
.form-select {
    background-color: var(--c-surface);
    border-color: var(--c-control-border);
    color: var(--c-ink);
}

.form-control:hover:not(:disabled):not([readonly]),
.form-select:hover:not(:disabled) {
    border-color: var(--c-accent);
}

.form-control:focus,
.form-select:focus {
    background-color: var(--c-surface);
    border-color: var(--c-accent);
    box-shadow: 0 0 0 0.2rem rgba(14, 124, 134, 0.2);
}

/* Ô chỉ đọc hoặc bị khoá mới có nền xám. */
.form-control[readonly],
.form-control:disabled,
.form-select:disabled {
    background-color: var(--c-surface-2);
    border-color: var(--c-line);
    color: var(--c-ink-2);
}

.form-check-input {
    width: 1.2em;
    height: 1.2em;
    margin-top: 0.15em;
    background-color: var(--c-surface);
    border: 2px solid var(--c-control-border);
    cursor: pointer;
}

.form-check-input:hover:not(:disabled) {
    border-color: var(--c-accent);
    box-shadow: 0 0 0 3px var(--c-accent-50);
}

.form-check-input:focus {
    border-color: var(--c-accent);
    box-shadow: 0 0 0 0.2rem rgba(14, 124, 134, 0.25);
}

.form-check-input:checked {
    background-color: var(--c-accent);
    border-color: var(--c-accent);
}

.form-check-input:disabled {
    background-color: var(--c-surface-2);
    border-color: var(--c-line);
    cursor: not-allowed;
}

.form-check-label { cursor: pointer; }

/* Bảng ma trận: cả ô là vùng bấm, rê chuột vào thì sáng lên. */
.data-table.matrix td.cell-toggle { cursor: pointer; }
.data-table.matrix td.cell-toggle:hover { background: var(--c-accent-50); }
.data-table.matrix td.cell-toggle.is-checked { background: var(--c-accent-50); }
.data-table.matrix tbody tr:hover td:first-child { color: var(--c-accent-ink); font-weight: 600; }
.btn-outline-primary {
    --bs-btn-color: var(--c-accent);
    --bs-btn-border-color: var(--c-accent);
    --bs-btn-hover-bg: var(--c-accent);
    --bs-btn-hover-border-color: var(--c-accent);
    --bs-btn-active-bg: var(--c-accent-600);
    --bs-btn-active-border-color: var(--c-accent-600);
}

@media (max-width: 720px) {
    .app-shell,
    .sidebar-open .app-shell {
        grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    }

    .sidebar-open .sidebar-label { display: none; }
    .kv { grid-template-columns: 1fr; }
}

/* ---------- Danh mục ---------- */
.row-inactive td { color: var(--c-muted); }
.unit { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.8125rem; white-space: nowrap; }
.input-num { max-width: 110px; min-width: 80px !important; }
.pre-line { white-space: pre-line; }

/* Mã (chỉ số, tên đăng nhập) dùng màu chủ đạo thay cho màu hồng mặc định của Bootstrap. */
code { color: var(--c-accent-ink); }

/* ---------- Bệnh nhân ---------- */
.req { color: var(--c-bad); }
.search-wide { min-width: 300px !important; }
.row-link { color: var(--c-ink); text-decoration: none; font-weight: 500; }
.row-link:hover { color: var(--c-accent); text-decoration: underline; }
.stack { display: grid; gap: 8px; }

.hidden-match {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 14px;
    background: var(--c-warn-bg);
    color: var(--c-warn);
    border-bottom: 1px solid var(--c-line);
    font-size: 0.875rem;
}

.patient-bar {
    display: flex;
    gap: 6px 16px;
    align-items: center;
    flex-wrap: wrap;
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: 6px;
    padding: 9px 14px;
    margin-bottom: 12px;
    font-size: 0.875rem;
    color: var(--c-ink-2);
}

.patient-bar strong { font-size: 1.0625rem; color: var(--c-ink); }

.panel-danger { border-color: var(--c-bad); }
.panel-danger > .panel-header { color: var(--c-bad); }

.request-card {
    display: grid;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-line);
    font-size: 0.875rem;
}

.request-card:last-child { border-bottom: 0; }
.request-reason { margin-top: 2px; color: var(--c-ink-2); }

/* ---------- Ô tìm nhanh ---------- */
.quick-search-wrap { position: relative; flex: 1 1 220px; max-width: 560px; }
.quick-search-wrap .quick-search { max-width: none; }
.topbar-spacer { flex: 1 1 220px; }
.quick-search:focus-within { border-color: var(--c-accent); background: var(--c-surface); }
.quick-search input:focus-visible { outline: none; }

.quick-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: var(--c-surface);
    border: 1px solid var(--c-line);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 38, 40, 0.14);
    max-height: 420px;
    overflow-y: auto;
    z-index: 30;
}

.quick-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 2px 10px;
    padding: 8px 12px;
    text-decoration: none;
    color: var(--c-ink);
    border-bottom: 1px solid var(--c-line);
    font-size: 0.875rem;
}

.quick-item:last-child { border-bottom: 0; }
.quick-item small { grid-column: 2; color: var(--c-ink-2); }
.quick-item.active, .quick-item:hover { background: var(--c-accent-50); }
.quick-item.locked { background: var(--c-warn-bg); color: var(--c-warn); }
.quick-empty { padding: 10px 12px; font-size: 0.875rem; color: var(--c-muted); }

.plain-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 0.875rem; }

/* ---------- Số điện thoại nhiều dòng ---------- */
.phone-rows { display: grid; gap: 6px; }

.phone-row {
    display: grid;
    grid-template-columns: minmax(150px, 200px) minmax(150px, 190px) minmax(0, 1fr);
    gap: 8px;
}

.status-neutral { background: var(--c-surface-2); color: var(--c-ink-2); }

/* ---------- Ô chọn có tìm kiếm ---------- */
.combo { position: relative; }

.combo-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    background: var(--c-surface);
    border: 1px solid var(--c-control-border);
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 38, 40, 0.14);
    max-height: 260px;
    overflow-y: auto;
    z-index: 20;
    font-size: 0.875rem;
}

.combo-option { padding: 6px 10px; cursor: pointer; }
.combo-option.active, .combo-option:hover { background: var(--c-accent-50); color: var(--c-accent-ink); }
.combo-empty { padding: 8px 10px; color: var(--c-muted); }
.combo.is-chosen input[role=combobox] { border-color: var(--c-ok); }

@media (max-width: 720px) {
    .phone-row { grid-template-columns: 1fr; }
}

/* ---------- Form theo mẫu bệnh án ---------- */
.encounter-layout { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 1rem; align-items: start; }
.section-nav { position: sticky; top: 4.5rem; display: flex; flex-direction: column; gap: .125rem; font-size: .875rem; }
.section-nav a { padding: .35rem .6rem; border-radius: .375rem; color: var(--c-ink-2); text-decoration: none; border-left: 3px solid transparent; }
.section-nav a:hover { background: var(--c-accent-50); color: var(--c-accent-600); border-left-color: var(--c-accent); }
@media (max-width: 991.98px) {
    .encounter-layout { grid-template-columns: minmax(0, 1fr); }
    .section-nav { position: static; flex-direction: row; flex-wrap: wrap; }
}
.encounter-head { display: flex; flex-wrap: wrap; gap: 1rem 2rem; align-items: flex-end; }
.encounter-head > div:first-child { min-width: 180px; }
.save-state { margin-left: auto; font-size: .85rem; color: var(--c-muted); }
.save-state.is-dirty { color: var(--c-warn); }
.save-state.is-saving { color: var(--c-accent); }
.save-state.is-saved { color: var(--c-ok); }
.save-state.is-error { color: var(--c-bad); font-weight: 600; }
.form-section { scroll-margin-top: 4.5rem; }
.form-item .form-label { font-weight: 500; margin-bottom: .25rem; }
.field-error { color: var(--c-bad); font-size: .8rem; }
.field-error:empty { display: none; }
.field-previous { font-size: .78rem; color: var(--c-muted); margin-top: .15rem; }
.flag { font-size: .75rem; font-weight: 600; margin-left: .25rem; white-space: nowrap; }
.flag-none { display: none; }
.flag-abnormal { color: var(--c-warn); }
.flag-critical { color: var(--c-bad); }
.yes-no .btn { min-width: 3.5rem; }
.choice-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.choice-chips .btn { border-radius: 999px; }
.input-group .unit-select { flex: 0 0 auto; width: auto; max-width: 9rem; }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.calc-value { display: flex; align-items: baseline; gap: .35rem; min-height: 31px; padding: .25rem .5rem; border: 1px dashed var(--c-line); border-radius: .375rem; background: var(--c-surface-2); }
.calc-value output { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 2.5rem; }
.calc-unit, .calc-note { font-size: .8rem; color: var(--c-muted); }
.calc-note { margin-left: auto; font-style: italic; }
.form-matrix th, .form-matrix td, .form-group-table th, .form-group-table td { vertical-align: top; }
.form-matrix tbody th { font-weight: 500; white-space: nowrap; }
.form-matrix input { min-width: 5rem; }
.form-group-table .row-no { width: 2.5rem; color: var(--c-muted); }
.sticky-actions { position: sticky; bottom: 0; z-index: 5; background: var(--c-bg); padding: .75rem 0; border-top: 1px solid var(--c-line); }
.form-readonly dd .table { width: auto; }
.new-encounter { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; }
.encounter-list .key-value { display: inline-block; margin-right: .75rem; font-size: .85rem; }
.back-link { text-decoration: none; font-size: 1.1rem; }

/* Trình soạn mẫu */
.designer-section { border: 1px solid var(--c-line); border-radius: .5rem; margin-bottom: 1rem; background: var(--c-surface); }
.designer-section > header { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; padding: .75rem; background: var(--c-surface-2); border-bottom: 1px solid var(--c-line); border-radius: .5rem .5rem 0 0; }
.designer-item { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: .5rem; padding: .6rem .75rem; border-bottom: 1px dashed var(--c-line); }
.designer-item:last-child { border-bottom: 0; }
.designer-item .span-2 { grid-column: span 2; }
.designer-item .span-3 { grid-column: span 3; }
.designer-item .span-4 { grid-column: span 4; }
.designer-item .span-6 { grid-column: span 6; }
.designer-item .span-12 { grid-column: span 12; }
.designer-item .form-label { font-size: .75rem; margin-bottom: .1rem; color: var(--c-ink-2); }
.designer-flags { display: flex; flex-wrap: wrap; gap: .25rem 1rem; align-items: center; }
.designer-tools { display: flex; gap: .25rem; justify-content: flex-end; align-items: flex-end; }
@media (max-width: 991.98px) {
    .designer-item .span-2, .designer-item .span-3, .designer-item .span-4 { grid-column: span 6; }
    .designer-item .span-6 { grid-column: span 12; }
}
.json-editor { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; min-height: 28rem; }
/* Trình soạn: chỉ hiện các ô hợp với loại mục */
.designer-item .when-indicator, .designer-item .when-rows, .designer-item .when-matrix, .designer-item .when-group, .designer-item .when-calc { display: none; }
.designer-item[data-type="Field"] .when-indicator, .designer-item[data-type="Calculated"] .when-indicator,
.designer-item[data-type="Matrix"] .when-rows, .designer-item[data-type="Group"] .when-rows,
.designer-item[data-type="Matrix"] .when-matrix, .designer-item[data-type="Group"] .when-group,
.designer-item[data-type="Calculated"] .when-calc { display: block; }

/* Có / Không: hai lựa chọn tách bạch, lựa chọn đang chọn tô đậm, có dấu ✓ */
.seg { display: inline-flex; border: 1px solid var(--c-control-border); border-radius: .5rem; overflow: hidden; background: var(--c-surface); }
.seg-opt { position: relative; margin: 0; cursor: pointer; }
.seg-opt + .seg-opt { border-left: 1px solid var(--c-control-border); }
.seg-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.seg-opt span { display: block; padding: .3rem .95rem; font-size: .9rem; color: var(--c-ink-2); user-select: none; }
.seg-opt:hover span { background: var(--c-accent-50); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--c-accent); outline-offset: -2px; }
.seg-yes input:checked + span { background: var(--c-accent); color: #fff; font-weight: 600; }
.seg-no input:checked + span { background: var(--c-ink-2); color: #fff; font-weight: 600; }
.seg-yes input:checked + span::before, .seg-no input:checked + span::before { content: "✓ "; }
.seg-clear span { color: var(--c-muted); font-size: .8rem; padding: .35rem .7rem; }
.seg-clear input:checked + span { background: var(--c-surface-2); color: var(--c-ink-2); }

/* Chọn nhiều: lưới ô đánh dấu, ô đã chọn tô nền */
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .35rem .5rem; }
.check-opt { display: flex; align-items: flex-start; gap: .5rem; margin: 0; padding: .35rem .6rem; border: 1px solid var(--c-line); border-radius: .4rem; cursor: pointer; background: var(--c-surface); font-size: .9rem; }
.check-opt:hover { border-color: var(--c-accent); }
.check-opt .form-check-input { margin-top: .15rem; flex: 0 0 auto; }
.check-opt:has(input:checked) { background: var(--c-accent-50); border-color: var(--c-accent); color: var(--c-accent-ink); font-weight: 500; }
.check-opt.is-none { font-style: italic; }

/* Ô chọn có tìm kiếm, cho thêm mới */
.tag-combo { position: relative; }
.tag-box { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; min-height: 31px; padding: .2rem .35rem; border: 1px solid var(--c-control-border); border-radius: .375rem; background: var(--c-surface); cursor: text; }
.tag-box:focus-within { border-color: var(--c-accent); box-shadow: 0 0 0 .2rem var(--c-accent-50); }
.tag { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .2rem .1rem .55rem; border-radius: 999px; background: var(--c-accent-50); color: var(--c-accent-ink); font-size: .85rem; border: 1px solid var(--c-accent); }
.tag.is-new { background: var(--c-warn-bg); border-color: var(--c-warn); color: var(--c-warn); }
.tag-x { border: 0; background: transparent; color: inherit; font-size: 1rem; line-height: 1; padding: 0 .3rem; cursor: pointer; }
.tag-input { flex: 1 1 8rem; min-width: 8rem; border: 0; outline: 0; background: transparent; font-size: .875rem; padding: .15rem; }
.tag-combo .combo-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; max-height: 16rem; overflow-y: auto; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: .375rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.tag-combo .combo-option { padding: .4rem .65rem; cursor: pointer; font-size: .9rem; }
.tag-combo .combo-option.active, .tag-combo .combo-option:hover { background: var(--c-accent-50); }
.tag-combo .combo-option.is-new { color: var(--c-accent-600); font-weight: 600; border-top: 1px dashed var(--c-line); }
.tag-combo .combo-empty { padding: .4rem .65rem; color: var(--c-muted); font-size: .85rem; }

/* Chi tiết trong cửa sổ bật lên */
.detail-dialog { width: min(560px, calc(100vw - 32px)); border: 0; border-radius: .6rem; padding: 1rem 1.1rem; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); color: var(--c-ink); background: var(--c-surface); }
.detail-dialog::backdrop { background: rgba(15, 38, 40, .35); }
.dlg-head { font-weight: 600; margin-bottom: .75rem; }
.dlg-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }
.popup-summary { margin-top: .35rem; font-size: .85rem; padding: .3rem .5rem; border-left: 3px solid var(--c-accent); background: var(--c-accent-50); border-radius: 0 .3rem .3rem 0; }
.popup-summary.is-empty { color: var(--c-muted); font-style: italic; border-left-color: var(--c-warn); background: var(--c-warn-bg); }

/* Bảng theo dõi */
.followup-table th, .followup-table td { white-space: nowrap; font-size: .85rem; }
.followup-table thead th { position: sticky; top: 0; background: var(--c-surface-2); z-index: 1; }
.followup-table .fu-label { position: sticky; left: 0; background: var(--c-surface); z-index: 1; white-space: normal; min-width: 200px; }
.followup-table .fu-group td { background: var(--c-surface-2); font-weight: 600; color: var(--c-ink-2); }
.followup-table .trend { font-size: .75rem; margin-left: .15rem; color: var(--c-muted); }
.followup-scroll { max-height: 70vh; overflow: auto; }

.form-item > .form-label { display: block; }

/* ---------- Màn hình theo dõi (thiết kế đã duyệt, màn hình 4) ---------- */
:root { --c-series-1: #7a4fb0; --c-series-2: #c2410c; --c-series-3: #2563eb; --c-series-4: #15803d; --c-series-5: #a16207; }
.dx-line { display: flex; flex-wrap: wrap; gap: .25rem 1.25rem; margin: 0 0 .6rem; font-size: .9rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem; margin-bottom: .6rem; }
.kpi { background: var(--c-surface); border: 1px solid var(--c-line); border-radius: .4rem; padding: .5rem .65rem; min-width: 0; }
.kpi small { display: block; font-size: .68rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi strong { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .72rem; }
.kpi.alert { border-color: var(--c-bad); background: var(--c-bad-bg); }
.kpi.alert small, .kpi.alert strong { color: var(--c-bad); }
.flagrow { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin: 0 0 .75rem; }
.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: .05rem .55rem; border-radius: 99px; white-space: nowrap; }
.p-ok { background: var(--c-ok-bg); color: var(--c-ok); }
.p-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.p-bad { background: var(--c-bad-bg); color: var(--c-bad); }
.p-info { background: var(--c-accent-50); color: var(--c-accent-ink); }
.p-mute { background: var(--c-surface-2); color: var(--c-ink-2); border: 1px solid var(--c-line); }
.pending { display: inline-block; border: 1px dashed var(--c-warn); background: var(--c-warn-bg); color: var(--c-warn); font-size: .72rem; padding: .05rem .5rem; border-radius: .25rem; white-space: nowrap; }
.box { background: var(--c-surface); border: 1px solid var(--c-line); border-top: 3px solid var(--c-accent); border-radius: .3rem; margin-bottom: .75rem; min-width: 0; }
.box-h { padding: .5rem .75rem; border-bottom: 1px solid var(--c-line); display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; }
.box-h h5 { margin: 0; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; }
.box-b { padding: .6rem .75rem; }
.fu-split { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: .75rem; }
@media (max-width: 1099.98px) { .fu-split { grid-template-columns: minmax(0, 1fr); } }
.legend { display: flex; flex-wrap: wrap; gap: .25rem .75rem; font-size: .75rem; }
.legend .lg.s0 { color: var(--c-accent); } .legend .lg.s1 { color: var(--c-series-1); } .legend .lg.s2 { color: var(--c-series-2); }
.legend .lg.s3 { color: var(--c-series-3); } .legend .lg.s4 { color: var(--c-series-4); } .legend .lg.s5 { color: var(--c-series-5); }
.chart-wrap { overflow-x: auto; }
.trend { min-width: 420px; display: block; }
.trend .grid { stroke: var(--c-line); stroke-width: 1; }
.trend .axis { fill: var(--c-muted); font-size: 11px; }
.trend .limit { stroke: var(--c-bad); stroke-width: 1.2; stroke-dasharray: 5 4; }
.trend .limit-text { fill: var(--c-bad); font-size: 10.5px; }
.trend .line { fill: none; stroke-width: 2.5; }
.trend .dot { fill: var(--c-surface); stroke-width: 2; }
.trend .val { font-size: 11px; font-weight: 600; }
.trend .s0 { stroke: var(--c-accent); } .trend .val.s0, .trend .dot.last.s0 { fill: var(--c-accent); }
.trend .s1 { stroke: var(--c-series-1); } .trend .val.s1, .trend .dot.last.s1 { fill: var(--c-series-1); }
.trend .s2 { stroke: var(--c-series-2); } .trend .val.s2, .trend .dot.last.s2 { fill: var(--c-series-2); }
.trend .s3 { stroke: var(--c-series-3); } .trend .val.s3, .trend .dot.last.s3 { fill: var(--c-series-3); }
.trend .s4 { stroke: var(--c-series-4); } .trend .val.s4, .trend .dot.last.s4 { fill: var(--c-series-4); }
.trend .s5 { stroke: var(--c-series-5); } .trend .val.s5, .trend .dot.last.s5 { fill: var(--c-series-5); }
.trend .val { stroke: none; }
.chart-pick summary { cursor: pointer; font-size: .8rem; color: var(--c-accent-600); margin-top: .35rem; }
.tl { list-style: none; padding: 0; margin: 0; }
.tl li { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: .6rem; padding: .5rem 0; border-bottom: 1px dashed var(--c-line); }
.tl li:last-child { border-bottom: 0; }
.tl .d { font-size: .78rem; color: var(--c-ink-2); font-variant-numeric: tabular-nums; }
.tl .t { font-size: .85rem; }
.tl .tags { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-top: .25rem; }
.delta { font-size: .72rem; color: var(--c-ink-2); margin-left: .1rem; }
.hl-bad { color: var(--c-bad); font-weight: 600; }
.followup-table td.num, .followup-table th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Tab hồ sơ: biểu tượng + phím tắt gợi ý */
.record-tabs .nav-link { display: inline-flex; align-items: center; gap: .4rem; }
.tab-icon, .back-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.tab-kbd { font-family: ui-monospace, Consolas, monospace; font-size: .62rem; padding: .05rem .3rem; border-radius: .25rem; border: 1px solid var(--c-line); background: var(--c-surface-2); color: var(--c-muted); box-shadow: none; }
.record-tabs .nav-link.active .tab-kbd { border-color: var(--c-accent); color: var(--c-accent-600); }
@media (max-width: 767.98px) { .tab-kbd { display: none; } }

/* Nút quay về hồ sơ ở trang khám */
.back-btn { display: inline-flex; align-items: center; gap: .35rem; font-weight: 600; }

/* Chẩn đoán: "Chẩn đoán chính: Mã - Tên (ghi chú)" mỗi loại một dòng */
.dx-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: .2rem .6rem; margin: 0; }
.dx-list dt { font-weight: 500; color: var(--c-ink-2); }
.dx-list dd { margin: 0; font-weight: 600; }
.dx-box { background: var(--c-surface); border: 1px solid var(--c-line); border-left: 4px solid var(--c-accent); border-radius: .4rem; padding: .5rem .75rem; margin-bottom: .6rem; }

/* Vùng thao tác nguy hiểm (xoá lượt khám) */
.danger-zone { margin-top: 1rem; border: 1px solid var(--c-bad); border-radius: .4rem; padding: .5rem .75rem; background: var(--c-surface); }
.danger-zone summary { cursor: pointer; color: var(--c-bad); font-weight: 600; font-size: .9rem; }

/* Kê toa */
.rx-item { border: 1px solid var(--c-line); border-radius: .5rem; padding: .6rem .75rem; margin-bottom: .6rem; background: var(--c-surface); }
.rx-head { display: flex; gap: .5rem; align-items: center; }
.rx-no { font-weight: 700; color: var(--c-accent); min-width: 1.6rem; }
.rx-search { position: relative; flex: 1 1 auto; }
.rx-search .combo-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; max-height: 18rem; overflow-y: auto; background: var(--c-surface); border: 1px solid var(--c-line); border-radius: .375rem; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.rx-search .combo-option { padding: .4rem .65rem; cursor: pointer; font-size: .88rem; border-bottom: 1px dashed var(--c-line); }
.rx-search .combo-option:hover { background: var(--c-accent-50); }
.rx-search .combo-option.is-new { color: var(--c-accent-600); font-weight: 600; }
.rx-preview { margin-top: .4rem; font-style: italic; color: var(--c-ink-2); min-height: 1.2em; }
.rx-item .form-label.small { font-size: .75rem; margin-bottom: .1rem; color: var(--c-ink-2); }

/* Cột bên của lượt khám: Tự tính, Gợi ý, Còn thiếu */
.insights { display: flex; flex-direction: column; gap: .75rem; font-size: .875rem; }
.ins-box { border: 1px solid var(--c-line); border-radius: .5rem; background: var(--c-surface); padding: .6rem .75rem; }
.ins-box h6 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); margin: 0 0 .4rem; }
.ins-box ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.ins-box li { padding: .3rem .5rem; border-radius: .375rem; font-weight: 600; }
.ins-box li small { display: block; font-weight: 400; color: var(--c-ink-2); }
.ins-box li.sg-bad { background: var(--c-bad-bg); color: var(--c-bad); }
.ins-box li.sg-warn { background: var(--c-warn-bg); color: var(--c-warn); }
.ins-box li.sg-info { background: var(--c-accent-50); color: var(--c-accent-600); }
.ins-box li.ins-missing { background: var(--c-surface-2); font-weight: 500; }
.ins-note { margin: .4rem 0 0; font-size: .75rem; color: var(--c-muted); }
.ins-calc { border-bottom: 1px dashed var(--c-line); }
.ins-calc:last-child { border-bottom: 0; }
.ins-calc summary { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; cursor: pointer; list-style: none; }
.ins-calc summary::-webkit-details-marker { display: none; }
.ins-calc summary b { white-space: nowrap; }
.ins-calc summary b.ins-abnormal { color: var(--c-warn); }
.ins-calc summary b.ins-critical { color: var(--c-bad); }
.ins-detail { font-size: .78rem; color: var(--c-ink-2); padding: 0 0 .4rem; }
.ins-source { margin-top: .2rem; color: var(--c-accent-ink); }
@media (min-width: 1200px) {
    .encounter-layout { grid-template-columns: 190px minmax(0, 1fr) 250px; }
    .insights { position: sticky; top: 4.5rem; max-height: calc(100vh - 6rem); overflow-y: auto; }
}
@media (max-width: 1199.98px) {
    .insights { order: -1; }
    .encounter-layout > .section-nav { order: -2; }
}

/* Sửa quy tắc gợi ý */
.rule-criterion { border: 1px solid var(--c-line); border-radius: .5rem; padding: .5rem .75rem .6rem; margin-bottom: .6rem; }
.rule-criterion legend { float: none; width: auto; font-size: .95rem; font-weight: 600; padding: 0 .3rem; margin: 0; }
.rule-condition { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .2rem 0; }
.rule-condition .rule-value { width: 6rem; }

/* Đọc file cận lâm sàng: tải file, màn hình đối chiếu */
.upload-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.upload-row .form-control { flex: 1 1 18rem; }
.steps { list-style: none; display: flex; gap: .5rem; padding: 0; margin: 0 0 .75rem; font-size: .85rem; }
.steps li { padding: .25rem .75rem; border-radius: 999px; background: var(--c-surface-2); color: var(--c-muted); }
.steps li.done { background: var(--c-ok-bg); color: var(--c-ok); }
.steps li.done::before { content: "✓ "; }
.steps li.current { background: var(--c-accent); color: var(--c-surface); font-weight: 600; }
.review-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: 1rem; align-items: start; }
@media (max-width: 1199.98px) { .review-layout { grid-template-columns: minmax(0, 1fr); } }
.review-source { position: sticky; top: 4.5rem; }
@media (max-width: 1199.98px) { .review-source { position: static; } }
.source-text { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; line-height: 1.5; tab-size: 4;
    max-height: 70vh; overflow: auto; border: 1px solid var(--c-line); border-radius: .375rem; padding: .5rem .6rem; background: var(--c-bg); }
.source-text > div { padding: 0 .25rem; border-radius: .2rem; white-space: pre-wrap; min-height: 1.5em; }
.src-matched { background: var(--c-warn-bg); }
.src-unmatched { background: var(--c-bad-bg); }
.src-key { padding: 0 .35rem; border-radius: .2rem; }
.review-lines th { font-size: .78rem; white-space: nowrap; }
.review-lines td { vertical-align: top; }
.review-lines .rv-check { width: 2.5rem; text-align: center; }
.review-lines tr.rv-unmatched td { background: var(--c-bad-bg); }
.review-lines tr.rv-suggested td { background: var(--c-warn-bg); }
.review-lines tr.rv-blank td { background: var(--c-surface-2); }
.rv-value { display: flex; gap: .25rem; min-width: 9.5rem; }
.rv-value .rv-unit { width: 5rem; flex: 0 0 5rem; }
.rv-remember { display: inline-flex; gap: .3rem; align-items: center; font-size: .78rem; margin-top: .2rem; color: var(--c-ink-2); }
.review-checks { border-top: 1px solid var(--c-line); }
.check-list { list-style: none; padding: 0; margin: .75rem 0 0; display: flex; flex-direction: column; gap: .25rem; font-size: .875rem; }
.check-list li::before { display: inline-block; width: 1.2rem; font-weight: 700; }
.check-list li.ok::before { content: "✓"; color: var(--c-ok); }
.check-list li.warn::before { content: "!"; color: var(--c-warn); }
.check-list li.bad { color: var(--c-bad); font-weight: 600; }
.check-list li.bad::before { content: "✗"; }

/* Hội chẩn */
.invite-list { display: flex; flex-direction: column; gap: .6rem; }
.invite-card { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
    border: 1px solid var(--c-line); border-left: 4px solid var(--c-accent); border-radius: .5rem; padding: .6rem .85rem; background: var(--c-surface); }
.invite-card.is-urgent { border-left-color: var(--c-bad); background: var(--c-bad-bg); }
.invitee-table td:last-child { width: 12rem; }
.session-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 1099.98px) { .session-layout { grid-template-columns: minmax(0, 1fr); } }
.session-side { display: flex; flex-direction: column; gap: .75rem; position: sticky; top: 4.5rem; }
@media (max-width: 1099.98px) { .session-side { position: static; order: -1; } }
.session-side summary { cursor: pointer; font-weight: 600; }
.session-side .check-opt { font-size: .875rem; }
.opinions { margin-top: 1rem; }
.opinions h6 { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--c-muted); }
.opinion { border-left: 3px solid var(--c-accent); padding: .3rem .7rem; margin-bottom: .5rem; background: var(--c-accent-50); border-radius: 0 .375rem .375rem 0; }
.opinion-h { font-size: .8rem; }
.opinion-b, .pre-line { white-space: pre-line; }

/* Chuông thông báo */
.topbar-bell { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; color: var(--c-ink-2); }
.topbar-bell:hover { background: var(--c-surface-2); color: var(--c-accent-600); }
.topbar-bell svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.topbar-bell.has-unread { color: var(--c-accent-600); }
.bell-count { position: absolute; top: -.1rem; right: -.2rem; min-width: 1.1rem; height: 1.1rem; padding: 0 .25rem; border-radius: 999px;
    background: var(--c-bad); color: var(--c-surface); font-size: .68rem; font-weight: 700; line-height: 1.1rem; text-align: center; }
.notice-list { list-style: none; margin: 0; padding: 0; }
.notice-list li { border-bottom: 1px solid var(--c-line); }
.notice-list li:last-child { border-bottom: 0; }
.notice-list li.is-unread { background: var(--c-accent-50); }
.notice-open { display: flex; flex-direction: column; gap: .15rem; width: 100%; text-align: left; border: 0; background: transparent; padding: .6rem .9rem; color: inherit; }
.notice-open:hover { background: var(--c-surface-2); }
.notice-open small { color: var(--c-muted); }

/* Dải cảnh báo khi đang làm việc dưới góc nhìn người dùng khác */
.acting-bar { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap;
    background: var(--c-bad); color: var(--c-surface); padding: .45rem 1rem; font-size: .875rem; position: sticky; top: 0; z-index: 30; }
.acting-bar form { margin: 0; }
