/* ==========================================================================
   EVER MED — hệ thiết kế giao diện
   --------------------------------------------------------------------------
   Nguyên tắc màu: màu NHẬN DIỆN (navy + đồng EVER) và màu LÂM SÀNG
   (đỏ/cam/xanh dương/xanh lá) là hai hệ tách rời. Màu lâm sàng chỉ được dùng
   cho cảnh báo và đánh giá chỉ số, không bao giờ dùng để trang trí — để khi
   nhân viên thấy màu đỏ trên màn hình thì đó luôn là việc cần xử lý.
   ========================================================================== */

/* ---------- 1. Token ---------- */
:root {
  /* Nhận diện */
  --navy-900: #0F1B2F;
  --navy-800: #16243D;
  --navy-700: #1F3050;
  --navy-600: #2B4068;
  --bronze:      #8F6A3C;   /* lấy từ logo EVER */
  --bronze-deep: #6F5029;
  --bronze-lift: #B08A57;
  --bronze-wash: #F7F1E7;

  /* Nền và chữ */
  --paper:       #F3F5F8;
  --surface:     #FFFFFF;
  --surface-2:   #F8FAFC;
  --surface-3:   #EEF1F6;
  --ink:         #15202F;
  --ink-2:       #33415A;
  --muted:       #64718A;
  --muted-2:     #8A94A8;
  --hair:        #DEE4ED;
  --hair-soft:   #EAEEF4;

  /* Lâm sàng — chỉ dùng cho cảnh báo và đánh giá chỉ số */
  --crit:        #B3261E;
  --crit-wash:   #FCEBE9;
  --high:        #A2560B;
  --high-wash:   #FDF1E3;
  --low:         #1A4FC4;
  --low-wash:    #E9EFFC;
  --normal:      #15713F;
  --normal-wash: #E7F4EC;
  --info:        #2563A5;
  --info-wash:   #E9F1FA;

  /* Hình khối */
  --r-sm: 5px;
  --r:    8px;
  --r-lg: 12px;
  --shadow-1: 0 1px 2px rgba(15, 27, 47, .06);
  --shadow-2: 0 1px 3px rgba(15, 27, 47, .08), 0 6px 18px rgba(15, 27, 47, .06);
  --shadow-3: 0 12px 40px rgba(15, 27, 47, .18);

  /* Chữ */
  --sans: "Plus Jakarta Sans", "Noto Sans JP", "Segoe UI", system-ui, -apple-system, sans-serif;
  --jp:   "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", var(--sans);
  --serif: var(--sans);
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Code", Consolas, monospace;

  /* Kích thước bố cục */
  --rail: 312px;
  --bar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --navy-900: #070C15;
    --navy-800: #0C1523;
    --navy-700: #142035;
    --navy-600: #1D2D49;
    --bronze:      #C09A67;
    --bronze-deep: #D8B98D;
    --bronze-lift: #E0C69F;
    --bronze-wash: #23190C;

    --paper:     #080D16;
    --surface:   #101927;
    --surface-2: #0C1420;
    --surface-3: #16202F;
    --ink:       #E6ECF5;
    --ink-2:     #C3CDDC;
    --muted:     #94A1B7;
    --muted-2:   #75839B;
    --hair:      #23304A;
    --hair-soft: #1A2537;

    --crit:        #FF8A80;
    --crit-wash:   #331512;
    --high:        #F0B168;
    --high-wash:   #2E1F0C;
    --low:         #93B4FF;
    --low-wash:    #12203F;
    --normal:      #6FD69B;
    --normal-wash: #0D2618;
    --info:        #8FC0F0;
    --info-wash:   #0E1E30;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 1px 3px rgba(0, 0, 0, .5), 0 6px 18px rgba(0, 0, 0, .35);
    --shadow-3: 0 12px 40px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  --navy-900: #070C15; --navy-800: #0C1523; --navy-700: #142035; --navy-600: #1D2D49;
  --bronze: #C09A67; --bronze-deep: #D8B98D; --bronze-lift: #E0C69F; --bronze-wash: #23190C;
  --paper: #080D16; --surface: #101927; --surface-2: #0C1420; --surface-3: #16202F;
  --ink: #E6ECF5; --ink-2: #C3CDDC; --muted: #94A1B7; --muted-2: #75839B;
  --hair: #23304A; --hair-soft: #1A2537;
  --crit: #FF8A80; --crit-wash: #331512; --high: #F0B168; --high-wash: #2E1F0C;
  --low: #93B4FF; --low-wash: #12203F; --normal: #6FD69B; --normal-wash: #0D2618;
  --info: #8FC0F0; --info-wash: #0E1E30;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 1px 3px rgba(0,0,0,.5), 0 6px 18px rgba(0,0,0,.35);
  --shadow-3: 0 12px 40px rgba(0,0,0,.6);
}

/* ---------- 2. Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(ja), .jp { font-family: var(--jp); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.3; letter-spacing: -.01em; }
h1 { font-size: 19px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
p { margin: 0; }
a { color: var(--bronze-deep); text-underline-offset: 2px; }

.section-title {
  font-size: 11px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--hair-soft); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.xs { font-size: 11.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- 3. Thanh ứng dụng ---------- */
.appbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 60;
  display: flex; align-items: center; gap: 16px;
  height: var(--bar-h); padding: 0 18px;
  background: var(--navy-900); color: #E8EDF6;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.appbar .spacer { flex: 1; }
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.brand svg { display: block; }
.brand .company-logo { display: block; width: 100px; height: 40px; object-fit: contain; }
.gateway-header .brand .company-logo { width: 150px; height: 60px; }
.brand .sub {
  font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase;
  color: var(--bronze-lift); padding-left: 11px; border-left: 1px solid rgba(255,255,255,.16);
}
.appbar .who { font-size: 12.5px; color: #B9C4D6; display: flex; align-items: center; gap: 8px; }
.appbar .who .avatar {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bronze); color: #15202F; font-weight: 700; font-size: 11px;
}
.appbar button.ghost-light {
  background: transparent; color: #C7D1E1; border: 1px solid rgba(255,255,255,.18);
  padding: 5px 11px; font-size: 12.5px;
}
.appbar button.ghost-light:hover { background: rgba(255,255,255,.09); color: #fff; }

/* ---------- 4. Bố cục ---------- */
.shell {
  display: grid; grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 14px; padding: 14px 16px 40px; align-items: start;
  max-width: 1560px; margin: 0 auto;
}
@media (max-width: 1040px) { .shell { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--hair);
  border-radius: var(--r-lg); box-shadow: var(--shadow-1);
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-bottom: 1px solid var(--hair-soft);
  font-weight: 600; font-size: 13.5px;
}
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 0; }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* ---------- 5. Thanh thông tin bệnh nhân (chuẩn bệnh viện) ---------- */
.patient-banner {
  position: sticky; top: calc(var(--bar-h) + env(safe-area-inset-top, 0px)); z-index: 40;
  background: var(--surface);
  border: 1px solid var(--hair); border-bottom-color: var(--hair);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-1);
}
.pb-main {
  display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap;
  padding: 13px 16px 11px;
}
.pb-id { min-width: 0; flex: 1 1 260px; }
.pb-name {
  font-size: 17px; font-weight: 600; letter-spacing: -.015em;
  display: flex; align-items: baseline; gap: 9px; flex-wrap: wrap;
}
.pb-name .ja { font-family: var(--jp); font-size: 13px; font-weight: 400; color: var(--muted); }
.pb-facts {
  display: flex; gap: 0; flex-wrap: wrap; margin-top: 3px;
  font-size: 12.5px; color: var(--muted);
}
.pb-facts > span { padding-right: 10px; margin-right: 10px; border-right: 1px solid var(--hair); }
.pb-facts > span:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.pb-facts .mrn { font-family: var(--mono); color: var(--ink-2); font-weight: 500; }
.pb-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

/* Dải cảnh báo — chỉ hiện khi thật sự có cảnh báo */
.pb-alerts { display: flex; flex-direction: column; }
.alert-strip {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 7px 16px; font-size: 12.5px; font-weight: 500;
  border-top: 1px solid var(--hair-soft);
}
.alert-strip .k {
  font-size: 10.5px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase;
  padding-top: 2px; white-space: nowrap; flex: 0 0 auto;
}
.alert-strip.crit { background: var(--crit-wash); color: var(--crit); }
.alert-strip.high { background: var(--high-wash); color: var(--high); }
.alert-strip.warn { background: var(--high-wash); color: var(--high); }
.alert-strip .v { color: inherit; }
.alert-strip button {
  margin-left: auto; background: transparent; border-color: currentColor;
  color: inherit; padding: 2px 9px; font-size: 11.5px;
}

/* ---------- 6. Tab ---------- */
.tabs {
  display: flex; gap: 2px; padding: 0 10px; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--hair); border-top: 0;
  border-radius: 0 0 var(--r-lg) var(--r-lg); scrollbar-width: thin;
}
.tabs.detached { border-radius: var(--r-lg); border-top: 1px solid var(--hair); }
.tab {
  flex: 0 0 auto; border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 11px 13px 9px; border-bottom: 2px solid transparent; border-radius: 0;
  display: flex; align-items: center; gap: 7px; white-space: nowrap;
}
.tab:hover { color: var(--ink); background: transparent; }
.tab[aria-selected="true"] { color: var(--navy-700); border-bottom-color: var(--bronze); }
:root[data-theme="dark"] .tab[aria-selected="true"],
:root:not([data-theme="light"]) .tab[aria-selected="true"] { color: var(--ink); }
.tab .count {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  background: var(--surface-3); color: var(--muted); border-radius: 99px; padding: 1px 6px;
}
.tab[aria-selected="true"] .count { background: var(--bronze-wash); color: var(--bronze-deep); }

/* ---------- 7. Danh sách hồ sơ ---------- */
.rail-filters { padding: 12px 12px 10px; display: flex; flex-direction: column; gap: 8px; }
.search {
  position: relative; display: flex; align-items: center;
}
.search svg { position: absolute; left: 10px; color: var(--muted-2); pointer-events: none; }
.search input { padding-left: 32px; }

.plist { max-height: min(62vh, 640px); overflow: auto; }
.pitem {
  display: block; width: 100%; text-align: left; border: 0; border-radius: 0;
  background: none; font: inherit; cursor: pointer;
  padding: 10px 14px 10px 13px; border-bottom: 1px solid var(--hair-soft);
  border-left: 3px solid transparent;
}
.pitem:hover { background: var(--surface-2); }
.pitem[aria-current="true"] {
  background: var(--bronze-wash); border-left-color: var(--bronze);
}
.pitem .row1 { display: flex; align-items: baseline; gap: 8px; }
.pitem .nm { font-weight: 600; font-size: 13.5px; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pitem .row2 {
  display: flex; align-items: center; gap: 8px; margin-top: 2px;
  font-size: 11.5px; color: var(--muted);
}
.pitem .row2 .mono { font-size: 11px; }
.pitem .flagdot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }

/* ---------- 8. Form ---------- */
label, .lbl {
  display: block; font-size: 11.5px; font-weight: 600; color: var(--muted);
  margin-bottom: 5px; letter-spacing: .01em;
}
input, select, textarea {
  width: 100%; padding: 8px 11px; font: inherit; font-size: 13.5px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--hair); border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:hover, select:hover, textarea:hover { border-color: var(--muted-2); }
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--bronze);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bronze) 18%, transparent);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.6; }
select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%2364718A' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; }
.field { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.check {
  display: flex; gap: 9px; align-items: flex-start;
  font-weight: 400; color: var(--ink); font-size: 13px; margin: 0;
  padding: 7px 9px; border: 1px solid var(--hair-soft); border-radius: var(--r-sm);
  cursor: pointer; text-transform: none; letter-spacing: 0;
}
.check:hover { border-color: var(--hair); background: var(--surface-2); }
.check input { width: auto; margin: 3px 0 0; flex: 0 0 auto; accent-color: var(--bronze); }
.check .ja { display: block; font-family: var(--jp); font-size: 11.5px; color: var(--muted); }

/* ---------- 9. Nút ---------- */
button {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 8px 14px; border-radius: var(--r-sm);
  border: 1px solid var(--hair); background: var(--surface); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
}
button:hover { background: var(--surface-2); border-color: var(--muted-2); color: var(--ink); }
button:focus-visible { outline: 2px solid var(--bronze); outline-offset: 2px; }
button.primary { background: var(--navy-700); border-color: var(--navy-700); color: #fff; }
button.primary:hover { background: var(--navy-600); border-color: var(--navy-600); color: #fff; }
button.bronze { background: var(--bronze); border-color: var(--bronze); color: #fff; }
button.bronze:hover { background: var(--bronze-deep); border-color: var(--bronze-deep); color: #fff; }
button.danger { background: var(--crit); border-color: var(--crit); color: #fff; }
button.ghost { background: transparent; border-color: transparent; color: var(--bronze-deep); padding: 5px 9px; }
button.ghost:hover { background: var(--bronze-wash); color: var(--bronze-deep); }
button.sm { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }

/* ---------- 10. Nhãn trạng thái ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 99px; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: .015em;
  background: var(--surface-3); color: var(--muted); border: 1px solid transparent;
}
.tag.ok     { background: var(--normal-wash); color: var(--normal); }
.tag.warn   { background: var(--high-wash);   color: var(--high); }
.tag.danger { background: var(--crit-wash);   color: var(--crit); }
.tag.info   { background: var(--info-wash);   color: var(--info); }
.tag.low    { background: var(--low-wash);    color: var(--low); }
.tag.brand  { background: var(--bronze-wash); color: var(--bronze-deep); }
.tag .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- 11. Bảng ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 12px; background: var(--surface-2);
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); border-bottom: 1px solid var(--hair); white-space: nowrap;
}
td { padding: 9px 12px; border-bottom: 1px solid var(--hair-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Hàng chỉ số bất thường: một vạch màu mảnh bên trái, không tô nền cả hàng */
tr.abn td:first-child { box-shadow: inset 3px 0 0 var(--high); }
tr.abn-low td:first-child { box-shadow: inset 3px 0 0 var(--low); }
tr.abn-crit td:first-child { box-shadow: inset 3px 0 0 var(--crit); }
tr.abn-crit { background: var(--crit-wash); }

/* ---------- 12. Thanh đo khoảng tham chiếu ---------- */
.rr { display: flex; align-items: center; gap: 9px; min-width: 168px; }
.rr svg { display: block; flex: 0 0 auto; }
.rr .delta {
  font-family: var(--mono); font-size: 11px; font-variant-numeric: tabular-nums;
  white-space: nowrap; color: var(--muted);
}
.rr .delta.up { color: var(--high); }
.rr .delta.down { color: var(--low); }
.rr .delta.good { color: var(--normal); }

/* ---------- 13. Dòng thời gian ---------- */
.tl { position: relative; padding-left: 26px; }
.tl::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--hair);
}
.tl-item { position: relative; padding: 0 0 20px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot {
  position: absolute; left: -26px; top: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--hair);
  display: grid; place-items: center;
}
.tl-dot i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); display: block; }
.tl-item.k-intake  .tl-dot { border-color: var(--info); }
.tl-item.k-intake  .tl-dot i { background: var(--info); }
.tl-item.k-lab     .tl-dot { border-color: var(--bronze); }
.tl-item.k-lab     .tl-dot i { background: var(--bronze); }
.tl-item.k-consult .tl-dot { border-color: var(--navy-600); }
.tl-item.k-consult .tl-dot i { background: var(--navy-600); }
.tl-item.k-session .tl-dot { border-color: var(--normal); }
.tl-item.k-session .tl-dot i { background: var(--normal); }
.tl-when {
  font-family: var(--mono); font-size: 11px; color: var(--muted);
  letter-spacing: .02em;
}
.tl-title { font-weight: 600; font-size: 13.5px; margin-top: 1px; }
.tl-body { font-size: 12.5px; color: var(--muted); margin-top: 3px; }

/* ---------- 14. Song ngữ ---------- */
.bilingual {
  display: grid; grid-template-columns: repeat(2, minmax(0,1fr));
  border: 1px solid var(--hair-soft); border-radius: var(--r); overflow: hidden;
}
@media (max-width: 820px) { .bilingual { grid-template-columns: 1fr; } }
.bilingual > div { padding: 11px 13px; }
.bilingual > div + div { border-left: 1px solid var(--hair-soft); background: var(--surface-2); }
@media (max-width: 820px) {
  .bilingual > div + div { border-left: 0; border-top: 1px solid var(--hair-soft); }
}
.bilingual .lang {
  font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted-2); margin-bottom: 5px;
}
.bilingual .txt { font-size: 13px; line-height: 1.65; white-space: pre-wrap; }
.bilingual .txt.jp { font-family: var(--jp); }

.dossier {
  background: var(--surface-2); border: 1px solid var(--hair-soft);
  border-radius: var(--r); padding: 15px 17px;
  max-height: 56vh; overflow: auto; white-space: pre-wrap;
  font-size: 12.5px; line-height: 1.75; font-family: var(--jp);
}

/* ---------- 15. Ghi chú, rỗng, nạp ---------- */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 13px; border-radius: var(--r); font-size: 12.5px;
  border: 1px solid transparent; line-height: 1.55;
}
.notice .k { font-weight: 700; flex: 0 0 auto; }
.notice.ok    { background: var(--normal-wash); color: var(--normal); }
.notice.warn  { background: var(--high-wash);   color: var(--high); }
.notice.err   { background: var(--crit-wash);   color: var(--crit); }
.notice.info  { background: var(--info-wash);   color: var(--info); }
.notice.plain { background: var(--surface-2); color: var(--muted); border-color: var(--hair-soft); }

.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  font-size: 13px; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.empty svg { color: var(--muted-2); }

.skel { background: var(--surface-3); border-radius: var(--r-sm); animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@media (prefers-reduced-motion: reduce) { .skel { animation: none; } }

/* ---------- 16. Thống kê nhỏ ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 7px 16px; font-size: 13px; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink); }

.chiplist { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-sm); font-size: 12.5px;
  background: var(--surface-2); border: 1px solid var(--hair-soft);
}
.chip .yr { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.chip.crit { background: var(--crit-wash); border-color: transparent; color: var(--crit); font-weight: 600; }

.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--bronze); border-radius: 99px; }

/* ---------- 17. Đăng nhập ---------- */
.login-wrap {
  min-height: 100dvh; display: grid; grid-template-columns: 1fr;
  background: var(--navy-900);
}
@media (min-width: 920px) { .login-wrap { grid-template-columns: 1.1fr 1fr; } }
.login-aside {
  display: none; padding: 48px; color: #D6DEEC; position: relative; overflow: hidden;
  background:
    radial-gradient(1000px 500px at 12% 18%, rgba(143,106,60,.28), transparent 62%),
    linear-gradient(160deg, var(--navy-800) 0%, var(--navy-900) 100%);
}
@media (min-width: 920px) { .login-aside { display: flex; flex-direction: column; justify-content: space-between; } }
.login-aside h2 { font-size: 27px; font-weight: 600; letter-spacing: -.02em; color: #fff; max-width: 15ch; }
.login-aside .pts { display: flex; flex-direction: column; gap: 14px; margin-top: 22px; max-width: 42ch; }
.login-aside .pt { display: flex; gap: 11px; font-size: 13.5px; line-height: 1.6; color: #AFBBCE; }
.login-aside .pt .n {
  font-family: var(--mono); font-size: 11px; color: var(--bronze-lift);
  padding-top: 3px; flex: 0 0 auto;
}
.login-aside footer { font-size: 11.5px; color: #7C8AA3; letter-spacing: .02em; }

.login-main {
  display: grid; place-items: center; padding: 32px 20px;
  background: var(--paper);
}
.login-card { width: 100%; max-width: 372px; }
.login-card .cap {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--bronze-deep); margin-bottom: 7px;
}
.login-card h1 { font-size: 22px; margin-bottom: 5px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card .foot { margin-top: 20px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- 18. Lớp phủ ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; padding: 24px 16px;
  background: rgba(15, 27, 47, .55); backdrop-filter: blur(2px);
  overflow: auto;
}
.modal {
  max-width: 880px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--hair); border-radius: var(--r-lg); box-shadow: var(--shadow-3);
}

/* ---------- 19. Toast ---------- */
.toast-host {
  position: fixed; z-index: 120; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: min(560px, calc(100% - 32px));
}
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--r); box-shadow: var(--shadow-2);
  font-size: 13px; line-height: 1.5; border: 1px solid transparent;
}
.toast.ok   { background: var(--normal); color: #fff; }
.toast.err  { background: var(--crit);   color: #fff; }
.toast.warn { background: var(--high);   color: #fff; }
.toast.info { background: var(--navy-700); color: #fff; }
:root[data-theme="dark"] .toast, :root:not([data-theme="light"]) .toast { color: #0B1220; }

/* ---------- 20. Bản in ---------- */
#printRoot { display: none; }
@media print {
  @page { size: A4; margin: 14mm 13mm 16mm; }
  .appbar, .shell, .overlay, .toast-host, .login-wrap { display: none !important; }
  #printRoot { display: block !important; }
  body { background: #fff; color: #000; font-size: 10.5pt; }
  .pr-head {
    display: flex; align-items: flex-start; gap: 16px;
    border-bottom: 2px solid #8F6A3C; padding-bottom: 10px; margin-bottom: 14px;
  }
  .pr-head .wm { font-family: var(--serif); font-size: 21pt; letter-spacing: .22em; color: #8F6A3C; }
  .pr-head .meta { margin-left: auto; text-align: right; font-size: 8.5pt; color: #444; }
  .pr-sec { margin-bottom: 13px; break-inside: avoid; }
  .pr-sec > h3 {
    font-size: 9pt; letter-spacing: .1em; text-transform: uppercase;
    color: #8F6A3C; border-bottom: 1px solid #DDD; padding-bottom: 3px; margin-bottom: 7px;
  }
  .pr-kv { display: grid; grid-template-columns: 34mm 1fr 34mm 1fr; gap: 3px 8px; font-size: 9.5pt; }
  .pr-kv dt { color: #555; }
  .pr-kv dd { margin: 0; }
  #printRoot table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  #printRoot th { background: #F3F3F3; border: 1px solid #CCC; padding: 3px 5px; color: #333;
    font-size: 8pt; text-transform: uppercase; letter-spacing: .06em; }
  #printRoot td { border: 1px solid #DDD; padding: 3px 5px; }
  #printRoot tr.abn td { font-weight: 700; }
  .pr-bi { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; break-inside: avoid; }
  .pr-bi .lang { font-size: 7.5pt; letter-spacing: .1em; text-transform: uppercase; color: #888; }
  .pr-foot {
    margin-top: 16px; padding-top: 7px; border-top: 1px solid #DDD;
    font-size: 7.5pt; color: #666; line-height: 1.5;
  }
}

/* ---------- 21. Tiện ích ---------- */
[hidden] { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--hair); border-radius: 99px; border: 3px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }

/* ---------- 22. Cổng chuyên gia: đọc hồ sơ và ghi ý kiến cạnh nhau ---------- */
.work { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
@media (min-width: 1240px) { .work { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); } }
.work .read { position: sticky; top: calc(var(--bar-h) + 14px + env(safe-area-inset-top, 0px)); }
@media (max-width: 1239px) { .work .read { position: static; } }
.work .dossier { max-height: min(64vh, 720px); }
.jp-field textarea { font-family: var(--jp); line-height: 1.75; }
.signed-seal {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--normal); border-radius: var(--r);
  background: var(--normal-wash); color: var(--normal);
  padding: 11px 14px; font-size: 13px;
}
.signed-seal .stamp {
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid currentColor; display: grid; place-items: center;
  font-size: 9px; font-weight: 800; letter-spacing: .04em;
}

/* ---------- 23. Màn hình hẹp ---------- */
@media (max-width: 620px) {
  .appbar { gap: 10px; padding: 0 12px; }
  .appbar .who { min-width: 0; }
  .appbar .who > span:last-child { display: none; }   /* chỉ giữ ảnh đại diện */
  .brand .sub { display: none; }
  .appbar button.ghost-light { padding: 5px 10px; }
  .shell { padding: 12px 12px 32px; gap: 12px; }
  .panel-body { padding: 13px; }
  .pb-main { padding: 12px 13px 10px; }
  .pb-name { font-size: 16px; }
  .alert-strip { padding: 7px 13px; }
  .kv { grid-template-columns: 1fr; gap: 3px 0; }
  .kv dt { margin-top: 7px; }
  .kv dt:first-child { margin-top: 0; }
  .work .dossier { max-height: 48vh; }
  .rr { min-width: 0; }
}
@media (max-width: 480px) {
  /* Bảng xét nghiệm: bỏ cột thanh đo để còn đọc được số */
  .tbl-wrap table th:nth-child(4), .tbl-wrap table td:nth-child(4) { display: none; }
}
