/* ============================================================================
   GIAO DIỆN  —  SỔ TAY ĐIỆN TỬ CĐHA
   Tách riêng khỏi nội dung. Sửa màu/cỡ chữ/bố cục ở đây, không đụng dữ liệu.
   ============================================================================ */

/* Bộ màu thương hiệu BV Hùng Vương Gia Lai:
   navy (chủ đạo & MRI) · cyan (X-quang) · xanh thép (CT) · đỏ (cấp cứu). */
:root {
  --bg:        #eef3fa;
  --surface:   #ffffff;
  --surface-2: #f1f6fc;
  --text:      #16202e;
  --text-soft: #5a6679;
  --line:      #d7e0ee;
  --brand:     #15509c;   /* navy – chủ đạo */
  --brand-ink: #0e3a73;
  --xq:        #2ba9e0;   /* X-quang – cyan */
  --ct:        #5b8fc9;   /* CT – xanh thép */
  --mri:       #15509c;   /* MRI – navy */
  --warn-bg:   #fff6e6;
  --warn-line: #f0c36d;
  --warn-ink:  #8a5a00;
  --danger:    #d81f26;   /* cấp cứu – đỏ thương hiệu */
  --ok:        #1b7f4b;
  --shadow:    0 2px 12px rgba(16,40,80,.10);
  --radius:    14px;
  --maxw:      920px;
}

:root[data-theme="dark"] {
  --bg:        #0e1420;
  --surface:   #18212f;
  --surface-2: #121a26;
  --text:      #e7edf6;
  --text-soft: #9fb0c6;
  --line:      #2a3646;
  --brand:     #5b9be8;
  --brand-ink: #a9cbf5;
  --xq:        #43c0f0;
  --ct:        #86add8;
  --mri:       #5b9be8;
  --warn-bg:   #352a12;
  --warn-line: #7a5f21;
  --warn-ink:  #ffcf7a;
  --danger:    #ff6b6b;
  --ok:        #5bd997;
  --shadow:    0 2px 14px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* Bảo đảm thuộc tính [hidden] luôn thắng (tránh bị display:flex/grid ghi đè) */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* -------------------------------------------------------- THANH ĐẦU TRANG */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
/* Dải màu thương hiệu (lấy từ chevron trong logo) */
.topbar::before {
  content: ""; display: block; height: 4px;
  background: linear-gradient(90deg, var(--xq), var(--ct) 55%, var(--brand));
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px;
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-logo { font-size: 26px; line-height: 1; flex: none; display: flex; align-items: center; }
.brand-logo img { height: 38px; width: auto; display: block; }
:root[data-theme="dark"] .brand-logo img { background: #fff; padding: 3px 6px; border-radius: 7px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; border-left: 2px solid var(--line); padding-left: 11px; }
.brand-text strong { font-size: 16px; line-height: 1.2; color: var(--brand-ink); }
.brand-text span { font-size: 12.5px; color: var(--text-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.theme-toggle {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 20px; cursor: pointer; color: var(--text);
}
.theme-toggle:active { transform: scale(.94); }

.searchwrap {
  max-width: var(--maxw); margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px 12px;
}
.search-icon { font-size: 18px; opacity: .7; }
#searchInput {
  flex: 1; min-width: 0;
  font-size: 18px; padding: 13px 14px;
  border: 2px solid var(--line); border-radius: 12px;
  background: var(--surface-2); color: var(--text);
}
#searchInput:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.search-clear {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  font-size: 16px; cursor: pointer; color: var(--text-soft);
}

/* ------------------------------------------------------------- THANH TAB */
.tabs {
  max-width: var(--maxw); margin: 12px auto 0;
  display: flex; gap: 8px; padding: 0 16px; flex-wrap: wrap;
}
.tab {
  flex: 1 1 auto; min-width: 140px;
  padding: 11px 12px; font-size: 14.5px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text-soft); cursor: pointer;
}
.tab.is-active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ------------------------------------------------------------- KHẨU HIỆU */
.tagline {
  max-width: var(--maxw); margin: 12px auto 0; padding: 0 16px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--brand-ink); font-size: 14.5px; font-style: italic; font-weight: 600;
  text-align: center; line-height: 1.35;
}
.tagline::before {
  content: ""; width: 8px; height: 8px; flex: none;
  background: var(--xq); transform: rotate(45deg); border-radius: 2px;
}
.tagline::after {
  content: "❤"; color: var(--danger); font-size: 15px; font-style: normal; flex: none;
}

/* ------------------------------------------------------------- NỘI DUNG */
.container { max-width: var(--maxw); margin: 0 auto; padding: 16px; }

.group-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 7px 14px; font-size: 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--text-soft); cursor: pointer; white-space: nowrap;
}
.chip.is-active { background: var(--surface-2); color: var(--brand); border-color: var(--brand); font-weight: 600; }

.result-meta { color: var(--text-soft); font-size: 13.5px; margin: 0 0 10px; }

.card-list { display: grid; gap: 10px; }
.card {
  text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 5px solid var(--xq);
  border-radius: var(--radius); padding: 14px 16px;
  cursor: pointer; box-shadow: var(--shadow); color: var(--text);
}
.card[data-modality="CT"] { border-left-color: var(--ct); }
.card[data-modality="MRI"] { border-left-color: var(--mri); }
.card:active { transform: scale(.995); }
.card-top { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; flex-wrap: wrap; }
.badge {
  font-size: 11.5px; font-weight: 700; letter-spacing: .3px;
  padding: 3px 9px; border-radius: 999px; color: #fff; background: var(--xq);
}
.badge.ct { background: var(--ct); }
.badge.mri { background: var(--mri); }
.badge.ghost { background: var(--surface-2); color: var(--text-soft); }
.card-title { font-size: 17px; font-weight: 600; margin: 0; }
.card-sub { font-size: 13.5px; color: var(--text-soft); margin: 2px 0 0; }
.card-params { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.param-pill {
  font-size: 12.5px; padding: 3px 9px; border-radius: 8px;
  background: var(--surface-2); color: var(--text-soft);
}
.param-pill b { color: var(--text); }

mark { background: #ffe680; color: inherit; padding: 0 2px; border-radius: 3px; }
:root[data-theme="dark"] mark { background: #8a6d1f; color: #fff; }

.empty { text-align: center; color: var(--text-soft); padding: 40px 10px; }
.empty-hint { font-size: 14px; }

/* ------------------------------------------------------- BẢNG CHI TIẾT */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10,18,30,.5); display: flex; justify-content: center;
  align-items: flex-start; overflow-y: auto;
}
.sheet {
  background: var(--bg); width: 100%; max-width: var(--maxw);
  min-height: 100%;
}
.sheet-head {
  position: sticky; top: 0; background: var(--surface);
  border-bottom: 1px solid var(--line); padding: 10px 16px; z-index: 2;
}
.sheet-close {
  border: none; background: none; color: var(--brand);
  font-size: 16px; font-weight: 600; cursor: pointer; padding: 6px 4px;
}
.sheet-body { padding: 18px 16px 60px; }
.detail-title { font-size: 22px; margin: 6px 0 4px; }
.detail-meta { color: var(--text-soft); font-size: 14px; margin: 0 0 16px; }

.param-box {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 6px 4px; margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.param-row {
  display: flex; justify-content: space-between; gap: 14px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
}
.param-row:last-child { border-bottom: none; }
.param-row .k { color: var(--text-soft); font-size: 14.5px; }
.param-row .v { font-weight: 700; text-align: right; font-size: 16px; }

.sec { margin-bottom: 18px; }
.sec h3 {
  font-size: 15px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--brand-ink); margin: 0 0 8px;
  display: flex; align-items: center; gap: 9px;
}
/* dấu "quả trám" lấy từ logo bệnh viện */
.sec h3::before {
  content: ""; width: 10px; height: 10px; flex: none;
  background: var(--brand); transform: rotate(45deg); border-radius: 2px;
}
.sec ul { margin: 0; padding-left: 20px; }
.sec li { margin-bottom: 6px; }

/* --------------------------------------------------------------- CÔNG CỤ */
.tool-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 16px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.tool-card h2 { margin: 0 0 4px; font-size: 19px; }
.tool-card .tool-desc { color: var(--text-soft); font-size: 14px; margin: 0 0 14px; }

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  color: var(--warn-ink); border-radius: 12px; padding: 12px 14px;
  font-size: 14px; margin-bottom: 14px;
}
.notice.ok { background: transparent; border-color: var(--ok); color: var(--ok); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 14px; color: var(--text-soft); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; font-size: 17px; padding: 12px 12px;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
}
.field input:focus { outline: none; border-color: var(--brand); }
.calc-result {
  margin-top: 6px; padding: 14px; border-radius: 12px;
  background: var(--surface-2); font-size: 16px;
}
.calc-result .big { font-size: 28px; font-weight: 800; color: var(--brand); }
.calc-result .calc-sub { font-size: 13px; color: var(--text-soft); font-weight: 600; }
.calc-flag { font-size: 14px; margin-top: 6px; font-weight: 600; }
.calc-flag.warn { color: var(--danger); }
.calc-flag.ok { color: var(--ok); }

/* bảng tham chiếu trong công cụ (kVp/IDR theo cân nặng) */
.ref-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ref-table table { width: 100%; border-collapse: collapse; font-size: 13.5px; min-width: 420px; }
.ref-table th, .ref-table td {
  border: 1px solid var(--line); padding: 7px 9px; text-align: left; white-space: nowrap;
}
.ref-table th { background: var(--surface-2); color: var(--text-soft); font-weight: 700; }

.check-group { margin-bottom: 16px; }
.check-group h3 { font-size: 15px; margin: 0 0 8px; }
.check-group.tuyetdoi h3 { color: var(--danger); }
.check-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 12px; border: 1px solid var(--line);
  border-radius: 10px; margin-bottom: 8px; background: var(--surface-2);
  cursor: pointer;
}
.check-item input { margin-top: 3px; width: 20px; height: 20px; flex: none; }
.check-item.checked { border-color: var(--ok); }

/* ---------------------------------------- BẢN ĐỒ QUY TRÌNH (phản vệ / CPR) */
.flow-arrow {
  text-align: center; color: var(--text-soft);
  font-size: 15px; line-height: 1; margin: 3px 0;
}
.flow-box {
  border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 10px; padding: 10px 12px 10px 14px;
  background: var(--surface-2);
}
.flow-box .flow-h, .flow-col .flow-h { font-weight: 700; font-size: 14.5px; margin-bottom: 6px; }
.flow-box ul, .flow-col ul { margin: 0; padding-left: 18px; }
.flow-box li, .flow-col li { margin-bottom: 4px; font-size: 14px; line-height: 1.5; }
.flow-box ul:empty, .flow-col ul:empty { display: none; }

.flow-box.emph { border-left-width: 5px; }
.flow-box.goal { background: transparent; border-style: dashed; border-left-color: var(--ok); }
.flow-box.goal .flow-h { color: var(--ok); }

.flow-box.brand { border-left-color: var(--brand); }
.flow-box.brand .flow-h { color: var(--brand-ink); }
.flow-box.danger { border-left-color: var(--danger); }
.flow-box.danger .flow-h { color: var(--danger); }

.flow-rowtitle {
  text-align: center; font-size: 12.5px; letter-spacing: .5px;
  text-transform: uppercase; color: var(--text-soft); margin: 4px 0 6px;
}
.flow-row {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}
.flow-col {
  border: 1px solid var(--line); border-top: 4px solid var(--line);
  border-radius: 10px; padding: 10px 12px; background: var(--surface-2);
}
.flow-col.nhe { border-top-color: var(--ok); }
.flow-col.nhe .flow-h { color: var(--ok); }
.flow-col.nang { border-top-color: var(--warn-line); }
.flow-col.nang .flow-h { color: var(--warn-ink); }
.flow-col.nguykich { border-top-color: var(--danger); }
.flow-col.nguykich .flow-h { color: var(--danger); }

/* --------------------------------------------------------------- HÌNH ẢNH */
.img-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.img-fig { margin: 0; }
.img-fig img {
  width: 100%; height: auto; display: block;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  cursor: zoom-in;
}
.img-fig figcaption {
  font-size: 12.5px; color: var(--text-soft); margin-top: 5px; text-align: center;
}
.img-hint { font-size: 12.5px; color: var(--text-soft); margin: 8px 0 0; }

/* chú thích nguồn ảnh (mục Bệnh lý) */
.img-fig .img-src {
  display: block; margin-top: 3px; font-size: 11.5px; font-style: italic;
  color: var(--text-soft); opacity: .9;
}
/* ô ảnh còn trống — chờ chèn ảnh được phép dùng */
.img-missing {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; min-height: 120px; padding: 10px;
  border: 1px dashed var(--line); border-radius: 10px;
  background: var(--surface-2); color: var(--text-soft); font-size: 13px;
}
.img-missing small { opacity: .8; }

/* ô ảnh ca bệnh thật — mã hóa, mở bằng mật khẩu (bản công khai) */
.enc-panel {
  display: flex; flex-direction: column; gap: 7px;
  min-height: 120px; padding: 14px; text-align: center;
  border: 1px dashed var(--brand); border-radius: 10px;
  background: var(--surface-2); color: var(--text-soft);
}
.enc-panel .enc-lock { font-size: 13px; font-weight: 700; color: var(--brand-ink); }
.enc-panel .enc-pass {
  width: 100%; font-size: 15px; padding: 9px 10px;
  border: 1.5px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.enc-panel .enc-pass:focus { outline: none; border-color: var(--cyan, var(--xq)); }
.enc-panel .enc-btn {
  font-size: 14px; font-weight: 600; padding: 8px 14px;
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  border-radius: 8px; cursor: pointer;
}
.enc-panel .enc-btn:disabled { opacity: .6; cursor: default; }
.enc-panel .enc-msg { font-size: 12.5px; color: var(--danger); min-height: 16px; }

/* băng ghi chú đầu phân hệ (mục Bệnh lý = tham khảo) */
.view-note {
  background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink);
  border-radius: 10px; padding: 10px 12px; margin: 0 0 12px;
  font-size: 13px; line-height: 1.5;
}

.lightbox {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(0,0,0,.9); display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.lightbox img {
  max-width: 100%; max-height: 100%; background: #fff;
  border-radius: 8px; object-fit: contain;
}
.lightbox-close {
  position: absolute; top: 14px; right: 16px;
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.15); color: #fff;
  font-size: 22px; cursor: pointer;
}

.footer {
  max-width: var(--maxw); margin: 10px auto 0; padding: 18px 16px 34px;
  color: var(--text-soft); font-size: 12.5px; text-align: center;
  border-top: 1px solid var(--line);
}
.footer-motto { font-style: italic; font-weight: 600; color: var(--brand-ink); font-size: 13.5px; margin: 0 0 8px; }
.footer-motto .motto-heart { color: var(--danger); font-style: normal; }

@media (max-width: 560px) {
  body { font-size: 16px; }
  .tab { min-width: 0; font-size: 13px; padding: 10px 6px; }
  .brand-text span { display: none; }
}
