:root {
  --red: #d7263d; --red-d: #a8172b; --bg: #f6f3f1; --card: #fff; --ink: #1f1a1c; --muted: #6b6266;
  --line: #e7dfdc; --ok: #1d7a46; --ok-bg: #e5f5ec; --warn: #8a5a00; --warn-bg: #fff3d6; --bad-bg: #fde6e8;
  --radius: 14px; font-size: 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #161314; --card: #221d1f; --ink: #f3eeee; --muted: #b3a9ac; --line: #3a3235;
    --ok-bg: #12301f; --ok: #6fd39b; --warn-bg: #3a2c0d; --warn: #f3c45b; --bad-bg: #3d1a1f;
  }
}
:root[data-theme="dark"] {
  --bg: #161314; --card: #221d1f; --ink: #f3eeee; --muted: #b3a9ac; --line: #3a3235;
  --ok-bg: #12301f; --ok: #6fd39b; --warn-bg: #3a2c0d; --warn: #f3c45b; --bad-bg: #3d1a1f;
}
* { box-sizing: border-box; }
/* phần tử có thuộc tính hidden luôn ẩn, kể cả input/label có display riêng */
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5; -webkit-text-size-adjust: 100%; }
a { color: var(--red); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h2 { font-size: 1.3rem; } h3 { font-size: 1.12rem; } h4 { font-size: 1rem; margin-top: 1.1em; color: var(--red-d); }
@media (prefers-color-scheme: dark) { h4 { color: #ff8a98; } }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--red); color: #fff; font-weight: 700; font-size: 1.1rem; }
.logo { font-size: 1.3rem; }
.fz { margin-left: auto; background: rgba(255,255,255,.18); color: #fff; border: 1.5px solid rgba(255,255,255,.6); border-radius: 10px;
  font: inherit; font-weight: 800; font-size: .95rem; min-width: 48px; min-height: 40px; padding: 4px 10px; cursor: pointer; }
.demo-tag + .fz { margin-left: 8px; }
.demo-tag { margin-left: auto; background: #fff; color: var(--red); font-size: .7rem; padding: 2px 8px; border-radius: 99px; }
main { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 8px 2px 10px; font-size: .78rem; color: var(--muted); text-decoration: none; }
.tabs a span { font-size: 1.4rem; line-height: 1.2; }
.tabs a.on { color: var(--red); font-weight: 700; }

.card { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; color: inherit; text-decoration: none; }
a.card:active { transform: scale(.99); }
.empty { text-align: center; color: var(--muted); }
.muted { color: var(--muted); } .small, small { font-size: .85rem; } .center { text-align: center; }
.loading { text-align: center; color: var(--muted); padding: 40px 0; }

label { display: block; margin: 0 0 12px; font-weight: 600; font-size: .95rem; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 1rem; color: var(--ink); background: var(--bg);
  border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(215, 38, 61, .25); border-color: var(--red); }
label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
label.check input { width: 24px; min-height: 24px; height: 24px; margin: 2px 0 0; flex: none; accent-color: var(--red); }
.code-input { text-transform: uppercase; letter-spacing: .2em; font-size: 1.3rem; text-align: center; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 18px; border: 0; border-radius: 12px;
  background: var(--red); color: #fff; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .55; }
.btn.big { width: 100%; font-size: 1.05rem; margin-top: 6px; }
.btn.alt { background: #3b3336; }
.btn.ghost { background: transparent; color: var(--red); border: 1.5px solid var(--red); }
.btn.danger { background: transparent; color: #c0182c; border: 1.5px solid #e9a1aa; }
.btn.small { min-height: 38px; padding: 6px 12px; font-size: .9rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.row.between { justify-content: space-between; margin-top: 0; }
.links { text-align: center; font-size: .95rem; }

.hero { text-align: center; padding: 12px 0 18px; }
.hero-icon { font-size: 3.2rem; }
.hero p { color: var(--muted); margin: 0; }
.demo { background: var(--warn-bg); border-color: transparent; }

.chip { display: inline-block; background: var(--bad-bg); color: var(--red-d); border-radius: 99px; padding: 3px 10px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.chip.grey { background: var(--line); color: var(--muted); }
.chip.red { background: var(--red); color: #fff; }
@media (prefers-color-scheme: dark) { .chip { color: #ffb3bc; } .chip.red { color: #fff; } }

.p-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.p-name { font-size: 1.25rem; font-weight: 800; }
.device-line { margin: 8px 0; font-weight: 600; }
.followup { border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: .95rem; }
.followup.ok { background: var(--ok-bg); color: var(--ok); }
.followup.soon { background: var(--warn-bg); color: var(--warn); }
.followup.late { background: var(--bad-bg); color: #c0182c; }
.note { background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: .92rem; margin: 10px 0; }
.note.danger { background: var(--bad-bg); }
details { margin: 10px 0; } summary { cursor: pointer; font-weight: 700; color: var(--red); padding: 6px 0; min-height: 40px; }
dl { display: grid; grid-template-columns: minmax(120px, 40%) 1fr; gap: 6px 12px; margin: 0; }
dt { color: var(--muted); font-size: .9rem; } dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table.leads { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.leads th, table.leads td { border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: left; }
table.leads th small { font-weight: 400; color: var(--muted); }

.code { font-size: 2rem; font-weight: 800; letter-spacing: .25em; text-align: center; padding: 10px; background: var(--bg); border-radius: 10px; font-family: ui-monospace, Consolas, monospace; }
.msg-img img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 4px; background: var(--line); min-width: 120px; min-height: 80px; object-fit: cover; }
.send .pick { flex: none; padding: 10px 12px; font-size: 1.2rem; position: relative; overflow: hidden; }
/* ẩn ô chọn tệp nhưng vẫn bấm được trên iPhone (không dùng display:none) */
.vh, input.vh { position: absolute !important; inset: 0; width: 100% !important; height: 100% !important; min-height: 0 !important;
  margin: 0 !important; padding: 0 !important; border: 0 !important; opacity: 0; cursor: pointer; font-size: 0; }
.send { align-items: flex-end; }
.send textarea { width: 100%; min-width: 0; }
.send > .btn { flex: none; }
.send-main { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.img-prev { display: flex; align-items: center; gap: 8px; font-size: .85rem; }
.img-prev img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.post-img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; margin: 8px 0; background: var(--bg); }
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 10px; }
.pgrid figure { margin: 0; background: var(--bg); border-radius: 10px; padding: 6px; }
.pgrid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.pgrid figcaption { font-size: .85rem; margin: 4px 2px; overflow-wrap: anywhere; }
#upf input { flex: 1 1 200px; margin: 0; }
.chip-btn { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 99px; padding: 8px 14px; font: inherit; font-size: .9rem; min-height: 40px; cursor: pointer; }
.chip-btn.on { background: var(--red); border-color: var(--red); color: #fff; font-weight: 700; }
.filters { margin: 10px 0 0; }
/* nút cấp cứu */
.sos { position: fixed; right: 14px; bottom: calc(82px + env(safe-area-inset-bottom)); z-index: 6; display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 68px; height: 68px; border-radius: 50%; border: 3px solid #fff; background: #b0122a; color: #fff; font-size: 1.6rem; line-height: 1;
  box-shadow: 0 6px 18px rgba(176,18,42,.45); cursor: pointer; }
.sos span { font-size: .6rem; font-weight: 800; margin-top: 2px; }
.sos.notabs { bottom: calc(18px + env(safe-area-inset-bottom)); }
main:has(.send) ~ .sos { bottom: calc(150px + env(safe-area-inset-bottom)); }
.sos-ov { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.sos-sheet { background: var(--card); color: var(--ink); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; max-height: 92vh; overflow-y: auto; }
.sos-sheet h2 { margin: 0; color: #b0122a; }
.sos-call { font-size: 1.3rem !important; min-height: 64px; }
.sos-tips { background: var(--bg); border-radius: 12px; padding: 10px 12px; font-size: .95rem; }
.sos-tips ul { margin: 6px 0 0; padding-left: 1.2em; }
/* bài viết */
.post .post-img { margin: 0 0 8px; }
.post h3 { margin-bottom: 4px; }
.pbody summary { font-size: 1rem; }
.post .body h4.ph { margin: 14px 0 4px; color: var(--red-d); font-size: 1.02rem; }
@media (prefers-color-scheme: dark) { .post .body h4.ph { color: #ff8a98; } }
/* nơi kiểm tra máy */
.clinic .cl-name { font-size: 1.05rem; line-height: 1.3; }
.clinic .cl-km { color: var(--ok); font-weight: 600; margin-top: 4px; }
.clinic > div { margin-top: 4px; }
.tabs a { font-size: .72rem; }
/* thẻ máy điện tử */
.card-btn { margin: 10px 0 4px; }
.devcard { background: linear-gradient(160deg, #fff 0%, #fff5f6 100%); color: #1f1a1c; border: 2px solid var(--red); border-radius: 18px; padding: 18px; margin: 12px 0; display: flex; flex-direction: column; gap: 8px; }
.dc-head { display: flex; justify-content: space-between; font-weight: 800; color: var(--red); letter-spacing: .04em; }
.dc-head span { font-size: .8rem; color: #6b6266; letter-spacing: 0; }
.dc-name { font-size: 1.5rem; font-weight: 800; line-height: 1.2; }
.dc-sub { color: #6b6266; margin-top: -4px; }
.dc-type { font-size: 1.15rem; font-weight: 700; background: var(--red); color: #fff; border-radius: 10px; padding: 8px 12px; }
.dc-row { display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px dashed #e7dfdc; padding: 6px 0; }
.dc-row span { color: #6b6266; } .dc-row b { text-align: right; overflow-wrap: anywhere; }
.dc-mri { background: #fde6e8; color: #a8172b; border-radius: 10px; padding: 10px 12px; font-weight: 700; }
.dc-mri.ok { background: #fff3d6; color: #8a5a00; }
.dc-warn { background: #f6f3f1; border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.devcard .btn.big { margin-top: 2px; }
.btn.danger-solid { background: #b0122a; }
.dc-qr { display: flex; justify-content: center; padding: 8px; background: #fff; border-radius: 12px; }
.dc-qr svg { width: 220px; height: 220px; }
/* xác nhận tái khám */
.fu-ask { background: var(--warn-bg); border-radius: 12px; padding: 12px; margin: 10px 0; }
.fu-ask form { margin-top: 10px; }
.fu-chip { display: inline-block; border-radius: 99px; padding: 2px 10px; font-size: .8rem; font-weight: 700; }
.fu-chip.yes { background: var(--ok-bg); color: var(--ok); } .fu-chip.chg { background: var(--warn-bg); color: var(--warn); } .fu-chip.none { background: var(--line); color: var(--muted); }
/* bảng việc hôm nay */
.dash h3 { display: flex; justify-content: space-between; align-items: center; }
.dash .cnt { background: var(--red); color: #fff; border-radius: 99px; padding: 2px 10px; font-size: .85rem; }
.dash .cnt.zero { background: var(--line); color: var(--muted); }
.drow { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.drow a.nm { color: inherit; text-decoration: none; flex: 1; min-width: 0; }
.drow .tel { flex: none; text-decoration: none; font-size: 1.3rem; padding: 6px 10px; border-radius: 10px; background: var(--ok-bg); }
.code-small { font-family: ui-monospace, Consolas, monospace; letter-spacing: .12em; }
.acc { padding: 10px 0; border-top: 1px solid var(--line); }
.search { display: flex; gap: 8px; margin: 10px 0 14px; } .search input { margin: 0; } .search .btn { flex: none; }
.thread .preview { margin-top: 4px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.post video { width: 100%; max-height: 70vh; border-radius: 10px; background: #000; margin: 8px 0; }
.post .body { margin-top: 8px; }

.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { max-width: 82%; background: var(--card); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 10px 12px; align-self: flex-start; overflow-wrap: anywhere; }
.msg.mine { align-self: flex-end; background: var(--red); color: #fff; border-color: var(--red); border-radius: 16px 16px 4px 16px; }
.msg time { display: block; font-size: .72rem; opacity: .7; margin-top: 2px; }
.send { position: fixed; left: 0; right: 0; bottom: calc(66px + env(safe-area-inset-bottom)); display: flex; gap: 8px; padding: 8px 12px; background: var(--bg); border-top: 1px solid var(--line); z-index: 4; }
.send textarea { margin: 0; min-height: 48px; resize: none; } .send .btn { flex: none; }
main:has(.send) { padding-bottom: calc(170px + env(safe-area-inset-bottom)); }
.note-card p.note { margin-bottom: 0; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid .wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .grid { grid-template-columns: 1fr; } }
.lead-head, .lead-row { display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr 1fr auto; gap: 6px; align-items: center; }
.lead-head { font-size: .72rem; color: var(--muted); font-weight: 600; }
.lead-row { margin-bottom: 8px; } .lead-row input, .lead-row select { margin: 0; padding: 8px; font-size: .9rem; min-height: 44px; }
@media (max-width: 520px) {
  .lead-head { display: none; }
  .lead-row { grid-template-columns: 1fr 1fr; padding: 8px; border: 1px dashed var(--line); border-radius: 10px; }
  .lead-row select { grid-column: 1 / -1; }
}
.consent ul { padding-left: 1.2em; } .consent li { margin-bottom: 6px; }

.toast { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 20; max-width: calc(100% - 32px);
  background: #1f1a1c; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: .95rem; }
.toast.bad { background: #b0122a; }

/* tìm bài viết + chủ đề */
.post-tools { padding-bottom: 10px; }
.psearch { margin-bottom: 4px; }
.psearch input { font-size: 1.05rem; }
.ptopics { gap: 8px; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; scroll-snap-type: x proximity; }
.ptopics .chip-btn { white-space: nowrap; flex: none; scroll-snap-align: start; }
.post .chip.grey { margin-bottom: 6px; }

/* hotline cấp cứu của từng bệnh viện */
.cl-hot { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bad-bg); }
.cl-hot .row { margin-top: 6px; }
.cl-hot .btn { font-size: 1rem; font-weight: 700; }

/* khung cài app */
.install { border: 2px solid var(--red); }
.install h3 { margin-top: 0; }
.install ol { padding-left: 1.3em; margin: 8px 0; }
.install li { margin: 6px 0; line-height: 1.5; }
.ios-ic { width: 1.4em; height: 1.4em; vertical-align: -0.35em; color: #0a84ff; display: inline-block; }

/* sổ tay bảo hành máy tim (warranty.js) */
.wty h3 { margin-top: 4px; }
.wty > h3 { margin: 18px 0 10px; }
.wty-hero h2 { margin-bottom: 6px; }
.wty-link { display: flex; gap: 12px; align-items: center; border-color: var(--ok); }
.wty-link-ic { font-size: 1.8rem; line-height: 1; }
.wty-mnemo { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.wty-mnemo div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.wty-mnemo b { font-size: 1.6rem; color: var(--red); line-height: 1.1; }
.wty-mnemo span { font-size: .92rem; }
@media (max-width: 560px) { .wty-mnemo { grid-template-columns: 1fr; } }
.wty-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 10px; }
.wty-pair > div { min-width: 0; }
.wty-pair h4 { margin-top: 0; }
.wty-pair ul, .wty-pro, .wty-src { padding-left: 1.2em; margin: 6px 0; }
.wty-pair li, .wty-pro li { margin-bottom: 6px; }
@media (max-width: 560px) { .wty-pair { grid-template-columns: 1fr; } }
.wty-chart { width: 100%; height: auto; display: block; margin: 8px 0; }
.wty-chart text { fill: var(--muted); font-size: 14px; font-family: inherit; }
.wty-chart text.lbl { fill: var(--ink); font-weight: 700; }
.wty-out { display: flex; flex-direction: column; gap: 10px; }
.wty-out p { margin: 0; }
.wty-status { align-self: flex-start; font-weight: 700; padding: 5px 12px; border-radius: 99px; font-size: .95rem; }
.wty-status.ok { background: var(--ok-bg); color: var(--ok); }
.wty-status.soon { background: var(--warn-bg); color: var(--warn); }
.wty-status.late { background: var(--bad-bg); color: #c0182c; }
.wty-strip { position: relative; height: 44px; border-radius: 8px; border: 1px solid var(--line); background-color: var(--bg);
  background-image: linear-gradient(rgba(215, 38, 61, .10) 1px, transparent 1px), linear-gradient(90deg, rgba(215, 38, 61, .10) 1px, transparent 1px);
  background-size: 8px 8px; overflow: hidden; }
.wty-seg { position: absolute; top: 8px; bottom: 8px; }
.wty-seg.f { background: var(--ok); border-radius: 4px 0 0 4px; }
.wty-seg.p { background: linear-gradient(90deg, color-mix(in srgb, var(--ok) 55%, transparent), color-mix(in srgb, var(--ok) 8%, transparent)); border-radius: 0 4px 4px 0; }
.wty-seg.u { background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--ok) 40%, transparent) 0 6px, transparent 6px 12px); border-radius: 4px; }
.wty-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--red); }
.wty-today::after { content: "Hôm nay"; position: absolute; top: 0; left: 4px; font-size: .7rem; font-weight: 700; color: var(--red); white-space: nowrap; }
.wty-today.flip::after { left: auto; right: 4px; }
.wty-scale { display: flex; justify-content: space-between; font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.wty-facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: .95rem; }
.wty-facts dt { color: var(--muted); } .wty-facts dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.wty-table { min-width: 560px; }
.wty-table th, .wty-table td { vertical-align: top; text-align: left; }
.wty-table small { color: var(--muted); }
.wty-steps { padding-left: 1.4em; margin: 6px 0; } .wty-steps li { margin-bottom: 8px; }
.wty-suggest { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin: -4px 0 12px; }

/* trợ lý AI */
.ai-link { display: flex; gap: 12px; align-items: center; border-color: #6b5bd6; }
.ai-ic { font-size: 1.8rem; line-height: 1; }
#aiq textarea { width: 100%; }
.ai-chips { flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.ai-chips .chip-btn { font-size: .85rem; text-align: left; }
.ai-qa { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.ai-qa .msg.ai { max-width: 100%; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); }
.msg.ai-sos { border-color: var(--red); }
.ai-tag { font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
