/* LVH Data — giao diện nhập liệu nghiên cứu ICAS-LVO */
:root {
  --bg: #f4f2ed;
  --panel: #ffffff;
  --panel-2: #faf8f4;
  --ink: #1c2a30;
  --ink-2: #33444b;
  --muted: #64737a;
  --line: #e4dfd5;
  --line-2: #efebe3;
  --brand: #0e5c63;
  --brand-2: #13757e;
  --brand-soft: #e3f0f0;
  --accent: #b8692a;
  --accent-soft: #f8ecdf;
  --ok: #1f7a3a;
  --ok-soft: #e4f3e8;
  --warn: #a8670f;
  --warn-soft: #fbf0dc;
  --bad: #b42318;
  --bad-soft: #fbe6e3;
  --info: #2563a8;
  --info-soft: #e5eef9;
  --shadow: 0 1px 2px rgba(20, 30, 35, .06), 0 4px 16px rgba(20, 30, 35, .05);
  --radius: 12px;
  --radius-sm: 8px;
  --side: 252px;
  --font: "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", "Consolas", ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1417; --panel: #141c20; --panel-2: #172126; --ink: #e4ebed; --ink-2: #c7d2d5; --muted: #93a3a9;
    --line: #25333a; --line-2: #1d292f; --brand: #3aa9b0; --brand-2: #4fc0c7; --brand-soft: #16302f;
    --accent: #e09a5c; --accent-soft: #3a2a1c; --ok: #4cc177; --ok-soft: #14301f; --warn: #e3ad4e; --warn-soft: #3a2d14;
    --bad: #f07a6c; --bad-soft: #3a1b18; --info: #6aa7ec; --info-soft: #172a40; --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1417; --panel: #141c20; --panel-2: #172126; --ink: #e4ebed; --ink-2: #c7d2d5; --muted: #93a3a9;
  --line: #25333a; --line-2: #1d292f; --brand: #3aa9b0; --brand-2: #4fc0c7; --brand-soft: #16302f;
  --accent: #e09a5c; --accent-soft: #3a2a1c; --ok: #4cc177; --ok-soft: #14301f; --warn: #e3ad4e; --warn-soft: #3a2d14;
  --bad: #f07a6c; --bad-soft: #3a1b18; --info: #6aa7ec; --info-soft: #172a40; --shadow: 0 1px 2px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; color: var(--ink); }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 .7em; }
small, .small { font-size: 12.5px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
[hidden] { display: none !important; }
svg.ico { width: 18px; height: 18px; flex: none; vertical-align: -3px; }
.tree svg.ico, .il-head svg.ico, .callout svg.ico { width: 16px; height: 16px; }
select { max-width: 100%; }

/* ------------------------------------------------------------------ khung */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 14px; border-bottom: 1px solid var(--line-2); }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: var(--brand); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 24px; height: 24px; }
.brand-title { font-weight: 700; font-size: 15.5px; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { padding: 10px 10px 20px; display: flex; flex-direction: column; gap: 2px; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink-2);
  font-weight: 500; text-decoration: none; }
.nav a:hover { background: var(--panel-2); }
.nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav a .num { width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; font-size: 11.5px;
  background: var(--line-2); color: var(--muted); font-weight: 700; flex: none; }
.nav a.active .num { background: var(--brand); color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.sidebar-foot { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; min-height: 56px; }
.topbar .title { font-weight: 650; font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; position: relative; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; display: grid;
  place-items: center; font-weight: 700; font-size: 12px; }
.dropdown { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 200px; padding: 6px; z-index: 30; }
.dropdown button, .dropdown a { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px;
  background: none; border: 0; color: var(--ink); font: inherit; cursor: pointer; }
.dropdown button:hover, .dropdown a:hover { background: var(--panel-2); text-decoration: none; }
.view { padding: 22px 24px 60px; max-width: 1480px; width: 100%; }

/* ------------------------------------------------------------------ thẻ, lưới */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; min-width: 0; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; flex: 1; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: minmax(0, 1fr) 360px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .lead { flex: 1; min-width: 260px; }
.page-head p { color: var(--muted); margin: 4px 0 0; max-width: 820px; }

.kpi { padding: 16px 18px; }
.kpi .k-label { color: var(--muted); font-size: 12.5px; }
.kpi .k-val { font-size: 28px; font-weight: 700; letter-spacing: -.5px; margin-top: 2px; }
.kpi .k-sub { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ nút, nhập liệu */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: 500 13.5px var(--font); cursor: pointer;
  white-space: nowrap; text-decoration: none; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.btn svg { width: 16px; height: 16px; }
.btn.icon { padding: 6px; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); min-width: 0; }
label.field > span { font-weight: 500; }
input[type=text], input[type=password], input[type=search], input[type=number], input[type=date], input[type=datetime-local],
input[type=time], input[type=email], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink); font: 14px var(--font); outline: none; min-width: 0; }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13.5px; }
.input-code { font: 600 26px var(--mono) !important; letter-spacing: 8px; text-align: center; }

/* ------------------------------------------------------------------ nhãn trạng thái */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: currentColor; }

.bar { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

.dossier { display: inline-flex; gap: 3px; }
.dossier i { width: 14px; height: 14px; border-radius: 4px; display: inline-block; background: var(--line); }
.dossier i.du, .dossier i.khong_ap_dung { background: var(--ok); }
.dossier i.chua_duyet, .dossier i.can_cap_nhat { background: var(--warn); }
.dossier i.mot_phan { background: var(--accent); }
.dossier i.thieu { background: color-mix(in srgb, var(--bad) 75%, var(--panel)); }

/* ------------------------------------------------------------------ bảng */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
.tbl th { position: sticky; top: 0; background: var(--panel-2); font-weight: 600; color: var(--ink-2); z-index: 1;
  white-space: nowrap; font-size: 12.5px; }
.tbl tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl.compact th, .tbl.compact td { padding: 5px 8px; }
.tbl tr.click { cursor: pointer; }
.data-grid { max-height: calc(100vh - 250px); }
.data-grid td { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.data-grid th .sub { display: block; font-weight: 400; color: var(--muted); font-size: 11px; max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; }
.data-grid td:first-child, .data-grid th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 2; font-weight: 600; }
.data-grid th:first-child { z-index: 3; background: var(--panel-2); }

/* ------------------------------------------------------------------ tab */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: 500 13.5px var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; margin-bottom: -1px; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.tabs button .pill { margin-left: 6px; }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.subtabs button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px;
  font: 500 12.5px var(--font); color: var(--ink-2); cursor: pointer; }
.subtabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ------------------------------------------------------------------ tải lên */
.dropzone { border: 2px dashed color-mix(in srgb, var(--brand) 35%, var(--line)); border-radius: var(--radius);
  background: color-mix(in srgb, var(--brand-soft) 40%, var(--panel)); padding: 26px; text-align: center; cursor: pointer;
  transition: background .15s, border-color .15s; }
.dropzone.drag { background: var(--brand-soft); border-color: var(--brand); }
.dropzone .dz-icon { width: 42px; height: 42px; margin: 0 auto 8px; color: var(--brand); }
.dropzone .dz-title { font-weight: 600; font-size: 15px; }
.dropzone .dz-hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-top: 14px; }
.thumb { position: relative; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--panel-2);
  aspect-ratio: 3/4; display: flex; align-items: center; justify-content: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .t-name { position: absolute; left: 0; right: 0; bottom: 0; font-size: 10.5px; padding: 3px 6px;
  background: rgba(0,0,0,.55); color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .t-x { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 13px; line-height: 22px; padding: 0; }
.thumb .t-prog { position: absolute; left: 0; top: 0; height: 3px; background: var(--brand); }
.thumb .t-file { font-size: 28px; color: var(--muted); }
.thumb .t-badge { position: absolute; top: 4px; left: 4px; }

/* ------------------------------------------------------------------ tiến trình */
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: flex; gap: 10px; padding: 6px 0; align-items: flex-start; }
.steps li .s-ic { width: 20px; height: 20px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: var(--ok); color: #fff; font-size: 12px; margin-top: 1px; }
.steps li.error .s-ic { background: var(--bad); }
.steps li.run .s-ic { background: var(--brand); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.progress { height: 10px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .4s; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ danh sách vấn đề */
.issue-list { list-style: none; padding: 0; margin: 0; }
.issue-list li { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line-2); margin-bottom: 6px; background: var(--panel-2); }
.issue-list li .il-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.issue-list li .il-body { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.sec-chip { font: 700 11px var(--mono); padding: 1px 6px; border-radius: 5px; background: var(--brand-soft); color: var(--brand); }
.callout { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); }
.callout.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, var(--line)); }
.callout.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 25%, var(--line)); }
.callout.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 25%, var(--line)); }
.callout.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 25%, var(--line)); }

/* ------------------------------------------------------------------ biểu mẫu bệnh án */
.crf-sections { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 18px; align-items: start; }
.crf-nav { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 2px; }
.crf-nav button { text-align: left; background: none; border: 0; padding: 7px 10px; border-radius: 7px; cursor: pointer;
  font: 13px var(--font); color: var(--ink-2); display: flex; gap: 8px; align-items: center; }
.crf-nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.crf-nav button .bar { flex: 1; height: 5px; min-width: 30px; }
.crf-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px 16px; }
.fv { border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; background: var(--panel); position: relative; }
.fv.core { border-left: 3px solid var(--brand); }
.fv.na { opacity: .55; }
.fv.ai { background: color-mix(in srgb, var(--accent-soft) 55%, var(--panel)); }
.fv.ok { background: color-mix(in srgb, var(--ok-soft) 45%, var(--panel)); }
.fv.conflict { background: var(--bad-soft); }
.fv .fv-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); display: flex; gap: 6px; align-items: flex-start; }
.fv .fv-label .nm { font: 11px var(--mono); color: var(--muted); font-weight: 400; margin-left: auto; white-space: nowrap; }
.fv .fv-input { margin-top: 6px; }
.fv .fv-meta { margin-top: 5px; font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.fv .fv-meta .ev { font-style: italic; }
.fv .multi { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.fv .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.fv .seg button { border: 0; background: var(--panel); padding: 5px 12px; cursor: pointer; font: 13px var(--font); color: var(--ink-2); }
.fv .seg button + button { border-left: 1px solid var(--line); }
.fv .seg button.on { background: var(--brand); color: #fff; }
.fv .dirty { position: absolute; top: 6px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.save-bar { position: sticky; bottom: 0; z-index: 10; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 -4px 20px rgba(0,0,0,.08); padding: 10px 14px; display: flex; gap: 10px;
  align-items: center; margin-top: 16px; }

/* ------------------------------------------------------------------ hộp thoại, thông báo */
.modal-back { position: fixed; inset: 0; background: rgba(10, 18, 22, .5); z-index: 100; display: grid; place-items: center;
  padding: 20px; }
.modal { background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); width: min(720px, 100%);
  max-height: calc(100vh - 40px); overflow: auto; padding: 20px; border: 1px solid var(--line); }
.modal.wide { width: min(1200px, 100%); }
.modal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.modal-head h2 { flex: 1; margin: 0; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { background: var(--ink); color: var(--panel); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: 13.5px; animation: tin .2s ease-out; }
.toast.bad { background: var(--bad); color: #fff; } .toast.ok { background: var(--ok); color: #fff; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ------------------------------------------------------------------ đăng nhập */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: linear-gradient(150deg, #0b4a50, #0e5c63 45%, #1b7b72); color: #eef6f5; padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art h1 { color: #fff; font-size: 30px; margin-top: 30px; }
.auth-art p { color: #cfe6e3; max-width: 460px; font-size: 15px; }
.auth-art svg.vessel { position: absolute; right: -60px; bottom: -40px; width: 520px; opacity: .22; }
.auth-panel { display: grid; place-items: center; padding: 32px; background: var(--bg); }
.auth-card { width: min(400px, 100%); }
.auth-card h2 { font-size: 21px; }
.qr-box { background: #fff; border-radius: 12px; padding: 10px; width: 220px; margin: 10px auto; border: 1px solid var(--line); }
.qr-box svg { width: 100%; height: auto; display: block; }
.secret { font: 600 13px var(--mono); letter-spacing: 1.5px; background: var(--panel-2); border: 1px dashed var(--line);
  padding: 8px; border-radius: 8px; text-align: center; word-break: break-all; }

/* ------------------------------------------------------------------ phòng ảnh */
.studio { display: grid; grid-template-columns: 64px minmax(0, 1fr) 330px; gap: 0; height: calc(100vh - 56px);
  margin: -22px -24px -60px; }
.studio .tools { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column;
  gap: 4px; padding: 10px 8px; overflow-y: auto; }
.studio .tools button { width: 46px; height: 42px; border-radius: 9px; border: 1px solid transparent; background: none;
  color: var(--ink-2); cursor: pointer; display: grid; place-items: center; position: relative; }
.studio .tools button:hover { background: var(--panel-2); }
.studio .tools button.on { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 30%, transparent); }
.studio .tools button svg { width: 21px; height: 21px; }
.studio .tools .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.studio .stage { position: relative; background: #0b0f11; overflow: hidden; }
.studio .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.studio .stage .empty { position: absolute; inset: 0; display: grid; place-items: center; color: #9fb0b5; text-align: center; padding: 30px; }
.studio .stage .hud { position: absolute; left: 10px; bottom: 10px; font: 12px var(--mono); color: #cfe; background: rgba(0,0,0,.45);
  padding: 4px 8px; border-radius: 6px; pointer-events: none; }
.studio .stage .framebar { position: absolute; left: 10px; right: 10px; top: 10px; display: flex; gap: 8px; align-items: center;
  background: rgba(0,0,0,.5); padding: 6px 10px; border-radius: 8px; color: #dfe; font-size: 12px; }
.studio .stage .framebar input[type=range] { flex: 1; }
.studio .side { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.studio .side h3 { font-size: 13.5px; margin: 14px 0 8px; }
.studio .side h3:first-child { margin-top: 0; }
.slider-row { display: grid; grid-template-columns: 82px 1fr 42px; gap: 8px; align-items: center; font-size: 12.5px; margin-bottom: 6px; }
.slider-row input { width: 100%; }
.aspects-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.aspects-grid button { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 6px 0; cursor: pointer;
  font: 600 12.5px var(--font); color: var(--ink-2); }
.aspects-grid button.hit { background: var(--bad); border-color: var(--bad); color: #fff; }
.measure-list { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.measure-list li { display: flex; gap: 6px; align-items: center; padding: 4px 0; border-bottom: 1px dashed var(--line-2); }
.swatches { display: flex; gap: 5px; }
.swatches button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--panel); outline: 1px solid var(--line); cursor: pointer; }
.swatches button.on { outline: 2px solid var(--brand); }

/* ------------------------------------------------------------------ cây thư mục */
.tree { list-style: none; margin: 0; padding-left: 0; font-size: 13px; }
.tree ul { list-style: none; padding-left: 18px; margin: 0; }
.tree li > .node { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 6px; cursor: pointer; }
.tree li > .node:hover { background: var(--panel-2); }
.tree .node .sz { margin-left: auto; color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.preview { border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); min-height: 300px; display: grid; place-items: center; overflow: hidden; }
.preview img, .preview video { max-width: 100%; max-height: 70vh; }
.preview iframe { width: 100%; height: 70vh; border: 0; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-state svg { width: 48px; height: 48px; opacity: .5; margin-bottom: 8px; }
.kbd { font: 11.5px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: var(--panel-2); }

/* ------------------------------------------------------------------ màn hình nhỏ */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-side { grid-template-columns: 1fr; }
  .studio { grid-template-columns: 56px minmax(0, 1fr); height: auto; }
  .studio .stage { height: 70vh; }
  .studio .side { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .menu-btn { display: inline-flex; }
  .view { padding: 16px 16px 60px; }
  .topbar { padding: 8px 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .crf-sections { grid-template-columns: 1fr; }
  .crf-nav { position: static; flex-direction: row; overflow-x: auto; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .studio { margin: -16px -16px -60px; }
}

/* ---- nút Trang chủ, máy tin cậy, cài đặt, bản nháp */
.home-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; flex: none; }
.home-btn svg.ico { width: 18px; height: 18px; }
.trust-box { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); display: grid; gap: 4px; }
.trust-box .check { align-items: flex-start; }
.prov-row { padding: 12px 0; border-top: 1px solid var(--line-2); display: grid; gap: 6px; }
.prov-row:first-of-type { border-top: 0; }
.chain-box { padding: 12px 0; border-top: 1px solid var(--line-2); }
.chain-row { gap: 6px; flex-wrap: wrap; }
.chain-row input, .chain-row select { min-width: 0; }
.chain-n { width: 22px; height: 22px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center;
  font: 700 11px var(--mono); flex: none; }
.copy-box { white-space: pre-wrap; word-break: break-all; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin: 4px 0; max-height: 140px; overflow: auto; }
.spinner.sm { width: 13px; height: 13px; border-width: 2px; display: inline-block; vertical-align: -2px; }
.draft-note { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.xu-home { position: fixed; right: 14px; bottom: 14px; z-index: 9999; }
@media (max-width: 720px) {
  .home-btn span { display: none; }
}

/* ---- bảng số liệu dạng bảng tính (Tổng quan + mục 4) */
.sheet-head { cursor: pointer; user-select: none; flex-wrap: wrap; gap: 8px; margin-bottom: 0; }
.sheet-head h2 { margin: 0; }
.sheet-head .chev { width: 16px; color: var(--muted); font-size: 14px; }
.sheet-card.open .sheet-head { margin-bottom: 12px; }
.grid-toolbar { display: grid; gap: 8px; margin-bottom: 8px; }
.grid-toolbar .row { gap: 8px 12px; flex-wrap: wrap; }
.data-grid.sheet table.tbl { width: max-content; min-width: 100%; }
.data-grid.sheet th, .data-grid.sheet td { border-right: 1px solid var(--line-2); }
.data-grid.sheet th.sortable { cursor: pointer; }
.data-grid.sheet th.sortable:hover { color: var(--brand); }
.data-grid.sheet tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--panel-2) 55%, var(--panel)); }
.data-grid.sheet tbody tr:nth-child(even) td:first-child { background: var(--panel); }
.data-grid .rn { display: inline-block; min-width: 26px; color: var(--muted); font-weight: 400; font-size: 11px; font-variant-numeric: tabular-nums; }
.data-grid-host.fullscreen { position: fixed; inset: 0; z-index: 900; background: var(--bg); padding: 12px 16px; display: flex; flex-direction: column; }
.data-grid-host.fullscreen > div:last-child { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.data-grid-host.fullscreen .data-grid { max-height: none !important; flex: 1; }
body.no-scroll { overflow: hidden; }

/* ---- nhập dữ liệu nhanh */
.bulk-groups .thumbs, .card .thumbs.sm-grid { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.thumb.sm { cursor: pointer; }
.thumb.sm .t-file { font-size: 14px; font-weight: 600; text-align: center; padding: 4px; }
.thumb .t-how { position: absolute; top: 4px; right: 4px; }
/* nút trên ô ảnh hồ sơ (sửa / lưu trữ) — hiện khi rê chuột; màn hình cảm ứng luôn hiện */
.thumb .t-tools { position: absolute; top: 4px; left: 4px; display: flex; gap: 3px; opacity: 0; transition: opacity .12s; }
.thumb:hover .t-tools, .thumb:focus-within .t-tools { opacity: 1; }
@media (hover: none) { .thumb .t-tools { opacity: 1; } }
.thumb .t-tools button { width: 26px; height: 26px; border-radius: 6px; border: 0; padding: 0; display: inline-flex; align-items: center;
  justify-content: center; background: rgba(0, 0, 0, .62); color: #fff; cursor: pointer; }
.thumb .t-tools button:hover { background: var(--brand); }
.thumb .t-tools .ico { width: 15px; height: 15px; }
.arch-box { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 8px; }
.arch-box > summary { cursor: pointer; color: var(--muted); }
.arch-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.arch-item { display: grid; grid-template-columns: 72px 1fr auto; gap: 10px; align-items: center; padding: 6px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel-2); }
.arch-th { width: 72px; height: 54px; border-radius: 6px; overflow: hidden; display: flex; align-items: center; justify-content: center;
  background: #000; color: #ccc; font-size: 11px; font-weight: 600; text-decoration: none; }
.arch-th img { width: 100%; height: 100%; object-fit: cover; opacity: .75; }
.arch-meta { min-width: 0; } .arch-meta .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .arch-item { grid-template-columns: 56px 1fr; } .arch-item > .btn { grid-column: 1 / -1; justify-self: end; } }
.thumb .t-check { position: absolute; left: 4px; top: 4px; background: var(--panel); border-radius: 4px; padding: 0 2px; line-height: 1; }
.bulk-group.hold { border-color: color-mix(in srgb, var(--warn) 55%, var(--line)); }
.bulk-group.done { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.bulk-group.error { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); }
.bulk-group .row { gap: 6px; flex-wrap: wrap; }

/* ---- hồ sơ đang thiếu (đầu trang hồ sơ bệnh nhân) */
.miss-panel { margin-bottom: 12px; padding: 10px 14px; border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.miss-panel.callout { display: flex; align-items: center; gap: 6px; }
.miss-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; cursor: pointer; user-select: none; }
.miss-head .chev { width: 14px; color: var(--muted); }
.miss-chips { gap: 6px; flex-wrap: wrap; }
.miss-body { margin-top: 10px; }
.miss-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 12px 18px; }
.miss-group { min-width: 0; }
.miss-title { font-weight: 650; font-size: 13.5px; margin-bottom: 6px; cursor: default; }
details.miss-group > summary.miss-title { cursor: pointer; }
.miss-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.miss-list li { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
.miss-list li .dot { margin-top: 6px; }
.miss-main { flex: 1; min-width: 0; font-size: 13px; }
.miss-sec { padding: 6px 0; border-top: 1px dashed var(--line-2); }
.miss-sec:first-of-type { border-top: 0; }
.miss-vars { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.miss-var { font-size: 12px; padding: 2px 7px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line-2); cursor: pointer; }
.miss-var.core { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); color: var(--bad); }
.miss-var:hover { border-color: var(--brand); color: var(--brand); }

/* ---- trình xem DICOM (tab "Xem DICOM" trong hồ sơ) */
.dv-wrap { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 12px; height: calc(100vh - 250px); min-height: 520px; }
.dv-wrap.fullscreen { position: fixed; inset: 0; z-index: 900; height: auto; padding: 10px; background: var(--bg); }
.dv-side { overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 10px; }
.dv-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; gap: 8px; }
.dv-toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dv-tg { display: inline-flex; gap: 2px; align-items: center; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.dv-tg .btn.sm { padding: 4px 7px; min-width: 30px; }
.dv-tg .btn.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.dv-sel { width: auto; padding: 3px 6px; font-size: 12.5px; }
.dv-fps { width: 54px; padding: 3px 6px; font-size: 12.5px; }
.dv-grid { flex: 1; min-height: 0; display: grid; gap: 4px; background: #000; border-radius: 10px; overflow: hidden; }
.dv-grid.l1, .dv-grid.maxed { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.dv-grid.l2 { grid-template-columns: 1fr 1fr; }
.dv-grid.l4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.dv-port { position: relative; min-width: 0; min-height: 0; background: #000; }
.dv-port canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.dv-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #8aa; font-size: 13px; pointer-events: none; padding: 20px; text-align: center; }
.dv-load { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,.08); }
.dv-load > i { display: block; height: 100%; width: 0; background: #2bb3bb; transition: width .25s; }
.dv-study { margin-top: 10px; }
.dv-study-h { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.dv-card { display: flex; gap: 8px; align-items: center; padding: 6px; border-radius: 8px; cursor: pointer; color: inherit; text-decoration: none; }
.dv-card:hover { background: var(--brand-soft); }
.dv-thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 6px; background: #000; flex: none; display: grid; place-items: center; font-size: 10px; }
.dv-card-t { min-width: 0; font-size: 12.5px; line-height: 1.35; }
.dv-card-t b { word-break: break-word; }
.dv-side-sep { border-top: 1px solid var(--line-2); margin: 12px 0 8px; }
.dv-side-info ol li { margin: 2px 0; }
.dv-fs { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; }
.dv-fs-row { display: grid; grid-template-columns: 20px 18px minmax(0, 1fr) 80px 120px; gap: 6px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line-2); }
.dv-fs-row.click { cursor: pointer; }
.dv-fs-row:hover { background: var(--brand-soft); }
.dv-fs-row svg.ico { width: 16px; height: 16px; }
.dv-fs-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono-tags td { word-break: break-all; }
@media (max-width: 900px) { .dv-wrap { grid-template-columns: 1fr; height: auto; } .dv-main { height: 70vh; } .dv-side { max-height: 260px; } }

/* ---- bố cục nhóm trong bệnh án nghiên cứu (mục D…) */
.crf-group { margin-bottom: 16px; }
.crf-group-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; margin: 4px 0 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line-2); }
.crf-group-head b { font-size: 14px; }
.crf-group-n { width: 20px; height: 20px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: inline-grid;
  place-items: center; font: 700 11px var(--mono); flex: none; align-self: center; }
.crf-hidden { margin-top: 4px; }
.dt-split { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.dt-split input[type=time] { width: 110px; }
.dt-split input[type=date] { width: 150px; }
.dt-split input.invalid { border-color: var(--bad); }
.computed { font-size: 14px; padding: 6px 0; }
.hint-box { width: 100%; margin-top: 4px; padding: 6px 8px; }

/* ---- giờ chụp CT/MRI đầu tiên từ DICOM */
.tbl tr.row-chosen td { background: color-mix(in srgb, var(--ok) 10%, var(--panel)); }

/* ---- dán ảnh (Ctrl+V) vào vùng tải lên + xem ảnh to */
.dz-paste { margin-top: 8px; font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px; align-items: center; justify-content: center; }
.dz-paste .btn.sm { margin-left: 6px; }
kbd { font: 600 11px var(--mono); padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: var(--panel); color: var(--ink-2); }
.dropzone.pasted { animation: dz-flash .9s ease-out; }
@keyframes dz-flash { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--brand) 55%, transparent); background: var(--brand-soft); }
  100% { box-shadow: 0 0 0 14px transparent; } }
.dz-root .thumb img { object-fit: contain; background: color-mix(in srgb, var(--panel-2) 70%, #000 4%); }
.thumb.zoomable { cursor: zoom-in; }
.thumb.zoomable:hover { border-color: var(--brand); box-shadow: 0 2px 10px color-mix(in srgb, var(--brand) 25%, transparent); }
.dz-lightbox { display: grid; place-items: center; background: #111; border-radius: 10px; min-height: 240px; }
.dz-lightbox-img { max-width: 100%; max-height: 72vh; object-fit: contain; display: block; }

/* ---- hộp Tải tài liệu / ảnh: chọn Chỉ lưu / AI xử lý */
.seg.up-mode { display: inline-flex; align-self: flex-start; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg.up-mode button { border: 0; background: var(--panel); padding: 8px 16px; cursor: pointer; font: 600 13.5px var(--font);
  color: var(--ink-2); display: inline-flex; align-items: center; gap: 5px; }
.seg.up-mode button + button { border-left: 1px solid var(--line); }
.seg.up-mode button.on { background: var(--brand); color: #fff; }
.seg.up-mode button svg.ico { width: 15px; height: 15px; }

/* ---- tab Hình ảnh: ảnh & tệp đã lưu trong mục 4/5 */
.img-files .img-sub { padding: 6px 0; border-top: 1px dashed var(--line-2); }
.img-files .img-sub:first-of-type { border-top: 0; }
.thumb.is-new { outline: 2px solid var(--ok); outline-offset: 1px; }

/* ---- bảng số liệu: đổi độ rộng cột kiểu Excel + thu phóng */
.data-grid.sheet table.tbl { min-width: 0; }
.data-grid.sheet td { max-width: none; }
.data-grid.sheet th { overflow: hidden; padding-right: 12px; }
.data-grid.sheet th .th-in { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-grid.sheet th .sub { max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-grid.sheet .col-rs { position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: col-resize; z-index: 4;
  touch-action: none; }
.data-grid.sheet .col-rs::after { content: ""; position: absolute; top: 20%; bottom: 20%; right: 3px; width: 2px; border-radius: 2px;
  background: var(--line); }
.data-grid.sheet .col-rs:hover::after, .data-grid.sheet .col-rs.active::after { background: var(--brand); top: 0; bottom: 0; }
body.col-resizing, body.col-resizing * { cursor: col-resize !important; user-select: none !important; }

/* ---- duyệt nhanh + dấu cần xem lại */
.btn.primary-soft { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 35%, var(--line)); color: var(--brand); font-weight: 600; }
.qr-sum { gap: 6px; flex-wrap: wrap; }
.qr-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 6px; max-height: 46vh; overflow: auto; }
.qr-list.compact { max-height: 30vh; gap: 2px; }
.qr-item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 8px; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); }
.qr-item.bad { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.qr-item.warn { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.qr-list.compact .qr-item { padding: 3px 8px; font-size: 12.5px; }
.qr-cb { flex: none; width: 18px; text-align: center; color: var(--muted); }
.qr-main { flex: 1; min-width: 0; }
.qr-main .row { gap: 6px; flex-wrap: wrap; }
.qr-val { font-weight: 600; }
.qr-flags { margin: 4px 0 0; padding-left: 16px; font-size: 12.5px; }
.qr-flags li.bad { color: var(--bad); }
.qr-flags li.warn { color: var(--warn); }
.qr-note { overflow: hidden; text-overflow: ellipsis; }
.fv.recheck { box-shadow: inset 3px 0 0 var(--warn); }
/* dữ liệu ngoài nghiên cứu (quản trị) */
.ext-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.ext-card { padding: 10px; display: flex; flex-direction: column; gap: 8px; margin: 0; }
.ext-th { display: flex; align-items: center; justify-content: center; height: 150px; border-radius: 8px; overflow: hidden; background: #000;
  color: #ccc; font-weight: 700; text-decoration: none; }
.ext-th img { width: 100%; height: 100%; object-fit: contain; }
.ext-meta { display: flex; flex-direction: column; gap: 3px; word-break: break-word; }
