:root {
  --bg: linear-gradient(120deg, #fff3a6 0%, #c9f5d6 35%, #a9e4ff 70%, #ffd0e8 100%);
  --accent: #0f9bd7;
  --accent-2: #10b981;
  --accent-soft: rgba(15, 155, 215, .15);
  --hero-bg: linear-gradient(125deg, rgba(255,251,235,.86) 0%, rgba(220,252,231,.82) 45%, rgba(224,242,254,.86) 100%);
  --hero-border: rgba(255,255,255,.95);
  --card: rgba(255, 255, 255, .75);
  --card-hover: rgba(255, 255, 255, .93);
  --card-solid: #ffffff;
  --border: rgba(255, 255, 255, .92);
  --border-subtle: rgba(30, 41, 59, .09);
  --text: #1d2433;
  --muted: #5b6478;
  --chip: rgba(255, 255, 255, .7);
  --input-bg: rgba(255, 255, 255, .86);
  --shadow: 0 8px 28px rgba(30, 40, 80, .09);
  --shadow-hover: 0 14px 36px rgba(30, 40, 80, .15);
  --table-head: rgba(255, 255, 255, .65);
  --table-hl: rgba(15, 155, 215, .09);
  --orb-1: rgba(251, 191, 36, .30);
  --orb-2: rgba(52, 211, 153, .28);
  --orb-3: rgba(56, 189, 248, .30);
}
[data-theme="spring"] {
  --bg: linear-gradient(135deg, #f9d9f0 0%, #e6dcff 45%, #d8e8ff 100%);
  --accent: #b44fd8; --accent-2: #ec4899; --accent-soft: rgba(180, 79, 216, .15);
  --hero-bg: linear-gradient(135deg, rgba(255,245,252,.86) 0%, rgba(243,232,255,.82) 55%, rgba(224,242,254,.84) 100%);
  --table-hl: rgba(180, 79, 216, .08);
  --orb-1: rgba(244, 114, 182, .30); --orb-2: rgba(192, 132, 252, .30); --orb-3: rgba(125, 211, 252, .25);
}
[data-theme="summer"] {
  --bg: linear-gradient(120deg, #fff3a6 0%, #c9f5d6 35%, #a9e4ff 70%, #ffd0e8 100%);
  --accent: #0f9bd7; --accent-2: #10b981; --accent-soft: rgba(15, 155, 215, .15);
  --hero-bg: linear-gradient(125deg, rgba(255,251,235,.86) 0%, rgba(220,252,231,.82) 45%, rgba(224,242,254,.86) 100%);
  --table-hl: rgba(15, 155, 215, .09);
  --orb-1: rgba(251, 191, 36, .30); --orb-2: rgba(52, 211, 153, .28); --orb-3: rgba(56, 189, 248, .30);
}
[data-theme="autumn"] {
  --bg: linear-gradient(135deg, #ffe2b8 0%, #ffd0a6 45%, #ffe9cf 100%);
  --accent: #e07a1f; --accent-2: #ea580c; --accent-soft: rgba(224, 122, 31, .16);
  --hero-bg: linear-gradient(135deg, rgba(255,247,237,.88) 0%, rgba(255,237,213,.84) 55%, rgba(254,243,199,.86) 100%);
  --table-hl: rgba(224, 122, 31, .09);
  --orb-1: rgba(251, 146, 60, .30); --orb-2: rgba(245, 158, 11, .28); --orb-3: rgba(244, 63, 94, .18);
}
[data-theme="winter"] {
  --bg: linear-gradient(135deg, #dfe9f5 0%, #eef3f9 50%, #d3e2f2 100%);
  --accent: #3d7ab8; --accent-2: #0284c7; --accent-soft: rgba(61, 122, 184, .15);
  --hero-bg: linear-gradient(135deg, rgba(255,255,255,.86) 0%, rgba(224,242,254,.82) 55%, rgba(224,231,255,.84) 100%);
  --table-hl: rgba(61, 122, 184, .09);
  --orb-1: rgba(56, 189, 248, .26); --orb-2: rgba(99, 102, 241, .20); --orb-3: rgba(147, 197, 253, .28);
}
[data-theme="dark"] {
  --bg: linear-gradient(135deg, #0b1120 0%, #131d36 50%, #0e172a 100%);
  --accent: #60a5fa; --accent-2: #a78bfa; --accent-soft: rgba(96, 165, 250, .18);
  --hero-bg: linear-gradient(135deg, rgba(30, 41, 72, .86) 0%, rgba(37, 46, 86, .78) 55%, rgba(22, 34, 62, .88) 100%);
  --hero-border: rgba(148, 163, 184, .22);
  --card: rgba(24, 34, 58, .74); --card-hover: rgba(33, 47, 79, .9); --card-solid: #18223a;
  --border: rgba(148, 163, 184, .2); --border-subtle: rgba(148, 163, 184, .15);
  --text: #f1f5f9; --muted: #94a3b8; --chip: rgba(30, 41, 68, .75); --input-bg: rgba(15, 23, 42, .68);
  --shadow: 0 10px 32px rgba(0, 0, 0, .4); --shadow-hover: 0 16px 40px rgba(0, 0, 0, .55);
  --table-head: rgba(15, 23, 42, .68); --table-hl: rgba(96, 165, 250, .12);
  --orb-1: rgba(59, 130, 246, .22); --orb-2: rgba(168, 85, 247, .20); --orb-3: rgba(20, 184, 166, .16);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body { font-family: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif; color: var(--text); overflow-x: hidden; }
body::before { content: ''; position: fixed; inset: 0; background: var(--bg); z-index: -2; transition: background .35s; }
body::after {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(42% 45% at 12% 14%, var(--orb-1), transparent 70%),
              radial-gradient(38% 42% at 88% 18%, var(--orb-2), transparent 70%),
              radial-gradient(40% 42% at 75% 88%, var(--orb-3), transparent 70%);
}
.mono { font-family: 'Roboto Mono', monospace; }
.hidden { display: none !important; }

.glass {
  background: var(--card); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
}

/* Login */
.login-wrap {
  min-height: 100vh; display: grid; grid-template-columns: 6fr 4fr;
}
.login-hero {
  position: relative; overflow: hidden; color: #fff;
  background:
    radial-gradient(60% 50% at 15% 10%, rgba(56,189,248,.35), transparent 70%),
    radial-gradient(50% 45% at 90% 95%, rgba(99,102,241,.35), transparent 70%),
    linear-gradient(140deg, #0b3d91 0%, #1257c7 45%, #0ea5e9 100%);
  display: flex; align-items: center; justify-content: center; padding: 48px 56px;
}
.login-hero::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .18;
  background-image: radial-gradient(rgba(255,255,255,.7) 1px, transparent 1.4px);
  background-size: 22px 22px;
}
.login-hero-inner { position: relative; width: 100%; max-width: 760px; }
.login-hero-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-hero-logo {
  width: 46px; height: 46px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.35); flex: none;
}
.login-hero-kicker { font-size: 13px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.login-hero-org { font-size: 13px; opacity: .85; }
.login-hero-title { margin: 0 0 12px; font-size: clamp(28px, 2.6vw, 40px); line-height: 1.2; font-weight: 800; }
.login-hero-sub { margin: 0 0 22px; font-size: 16px; line-height: 1.55; opacity: .9; max-width: 600px; }
.login-hero-art { display: block; width: 100%; height: auto; margin: 6px 0 24px; filter: drop-shadow(0 18px 30px rgba(3,20,60,.35)); }
.login-hero-features { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 14px; }
.login-hero-features li {
  display: flex; gap: 11px; align-items: flex-start; padding: 14px; border-radius: 16px;
  background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.22);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.login-hero-features b { display: block; font-size: 14.5px; margin-bottom: 3px; }
.login-hero-features span { font-size: 12.8px; line-height: 1.45; opacity: .88; }
.lhf-ico {
  width: 36px; height: 36px; border-radius: 11px; flex: none; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.95); color: #1257c7;
}
.login-hero-features .lhf-ico { opacity: 1; }

.login-side {
  display: flex; align-items: center; justify-content: center; padding: 40px 36px;
  position: sticky; top: 0; min-height: 100vh; align-self: start;
}
.login-card { width: 100%; max-width: 500px; padding: 40px 38px; }
.login-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.login-card-logo { width: 56px; height: 56px; font-size: 20px; border-radius: 16px; }
.login-card-title { font-size: 22px; font-weight: 800; line-height: 1.25; }
.login-card-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.login-card-welcome { font-size: 16px; font-weight: 700; margin-bottom: 18px; }
.login-card .field { margin-bottom: 18px; }
.login-card .field label { font-size: 14px; margin-bottom: 7px; }
.login-card .input { height: 50px; font-size: 15.5px; padding: 0 16px; border-radius: 13px; }
.login-submit { width: 100%; justify-content: center; height: 52px; font-size: 16px; border-radius: 14px; margin-top: 4px; }
.btn.login-submit:hover { background: linear-gradient(135deg, var(--accent), var(--accent-2)); filter: brightness(1.06); }

/* Chọn bệnh viện trước khi đăng nhập */
.bv-list { display: flex; flex-direction: column; gap: 10px; max-height: min(52vh, 420px); overflow-y: auto; padding: 2px; }
.bv-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 58px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 14px; background: var(--chip); color: var(--text);
  font: inherit; text-align: left; cursor: pointer; transition: border-color .15s, transform .15s;
}
.bv-item:hover, .bv-item:focus-visible { border-color: var(--accent); transform: translateY(-1px); outline: none; }
.bv-item-ico {
  width: 40px; height: 40px; border-radius: 12px; flex: none; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: 12px; font-weight: 800;
}
.bv-item-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 700; line-height: 1.35; }
.bv-item-go { font-size: 22px; color: var(--muted); flex: none; }
.bv-empty { font-size: 14px; color: var(--muted); padding: 12px 2px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bv-chosen {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px;
  padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); background: var(--chip);
}
.bv-chosen-k { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bv-chosen-v { font-size: 15px; font-weight: 800; line-height: 1.35; }
.bv-change { flex: none; }

/* Cài đặt → Cơ sở & phân quyền */
.cs-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.cs-sub { font-size: 13px; color: var(--muted); max-width: 620px; line-height: 1.45; }
.cs-search { max-width: 260px; }
.cs-empty { font-size: 14px; color: var(--muted); padding: 8px 0; }
.cs-chip { display: inline-block; padding: 3px 9px; margin: 2px 0; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: var(--chip); border: 1px solid var(--border); }
.cs-check { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 7px 2px; cursor: pointer; }
.cs-check input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.cs-all { border-bottom: 1px solid var(--border); margin-bottom: 6px; padding-bottom: 10px; }
.cs-list { max-height: 46vh; overflow-y: auto; }
.cs-disabled { opacity: .45; pointer-events: none; }
@media (max-width: 600px) { .cs-search { max-width: none; width: 100%; } }

@media (max-width: 1200px) {
  .login-hero { padding: 40px 36px; }
  .login-hero-features { grid-template-columns: 1fr; gap: 10px; }
}
/* Màn vừa (máy tính bảng, điện thoại bật "trang cho máy tính" hoặc xoay ngang): vẫn giữ minh hoạ bên trái,
   nhưng cột form luôn đủ rộng để không bị bóp nhỏ */
@media (max-width: 1200px) {
  .login-wrap { grid-template-columns: minmax(0, 1fr) minmax(400px, 46%); }
  .login-side { padding: 28px 22px; }
  .login-card { padding: 32px 26px; }
}
/* Điện thoại dọc: form lên trước, minh hoạ xếp xuống dưới */
@media (max-width: 760px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-side { order: 1; position: static; min-height: auto; padding: 20px 14px 8px; align-items: flex-start; }
  .login-hero { order: 2; padding: 26px 18px 30px; }
  .login-hero-title { font-size: 24px; }
  .login-hero-sub { font-size: 14.5px; }
  .login-card { padding: 24px 18px; }
  .login-card-title { font-size: 19px; }
}
.demo-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.demo-btn {
  border: 1px solid var(--border); background: var(--chip); color: var(--text);
  padding: 8px 10px; border-radius: 12px; font-family: inherit; font-size: 12px; font-weight: 700;
  text-align: left; cursor: pointer; transition: all .15s;
}
.demo-btn:hover { background: var(--card-hover); border-color: var(--accent); transform: translateY(-1px); }
.demo-btn small { display: block; font-weight: 500; color: var(--muted); font-size: 10.8px; margin-top: 2px; }

/* App Shell */
.app-shell { width: 100%; max-width: none; margin: 0; padding: 16px 22px 42px; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 11px 18px; margin-bottom: 18px;
  position: sticky; top: 10px; z-index: 40; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 18px var(--accent-soft); flex: none;
}
.brand-title { font-weight: 800; font-size: 15.5px; line-height: 1.2; }
.brand-sub { font-size: 11.8px; color: var(--muted); font-weight: 500; }

.search-wrap { flex: 1; min-width: 200px; max-width: 400px; margin: 0 auto; position: relative; }
.search-wrap input {
  width: 100%; height: 40px; padding: 0 14px 0 38px; border-radius: 13px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text);
  font-family: inherit; font-size: 13px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-wrap input::-webkit-search-cancel-button { cursor: pointer; }

/* Gợi ý tìm kiếm */
.search-suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  max-height: min(60vh, 440px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card-solid); border: 1px solid var(--border-subtle); border-radius: 14px;
  box-shadow: var(--shadow-hover); padding: 6px;
}
.sg-item { padding: 10px 12px; border-radius: 10px; cursor: pointer; min-height: 44px; }
.sg-item + .sg-item { margin-top: 2px; }
.sg-item.active { background: var(--accent-soft); }
.sg-name { font-weight: 700; font-size: 13.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-meta { font-size: 11.8px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sg-meta .mono { color: var(--accent); font-weight: 700; }
.sg-empty { padding: 12px; font-size: 13px; color: var(--muted); text-align: center; }
.sg-head { padding: 6px 12px 4px; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Popup chi tiết thiết bị */
.modal.modal-wide { max-width: 820px; height: min(90vh, 780px); } /* cao cố định: đổi tab không làm popup nhảy */
tr.dv-row { cursor: pointer; }
tr.dv-row:hover td { background: var(--table-hl); }
.dd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.dd-title { font-size: 19px; font-weight: 800; line-height: 1.3; overflow-wrap: anywhere; }
.dd-sub { margin-top: 6px; }
.dd-info {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 14px;
  padding: 14px; border-radius: 14px; background: var(--chip); border: 1px solid var(--border-subtle); margin-bottom: 12px;
}
.dd-k { font-size: 11.5px; font-weight: 700; color: var(--muted); }
.dd-v { font-size: 13.5px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.dd-v .mono { color: var(--accent); font-weight: 700; }
.dd-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.dd-tabs { margin-bottom: 12px; }
.dd-body { min-height: 180px; }
.dd-sec { margin-bottom: 14px; }
.dd-sec-title { font-size: 13px; font-weight: 800; margin-bottom: 8px; }
.dd-list { display: flex; flex-direction: column; gap: 8px; }
.dd-item { padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border-subtle); background: var(--card); }
.dd-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13.5px; }
.dd-item-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.dd-item-txt { font-size: 13px; margin-top: 5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.dd-empty { padding: 14px; border-radius: 12px; background: var(--chip); color: var(--muted); font-size: 13px; text-align: center; }
.dd-note { font-size: 12px; color: var(--muted); margin: -4px 0 14px; }
.dd-img-ph {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 96px; margin-top: 4px;
  border: 2px dashed var(--border-subtle); border-radius: 14px; color: var(--muted); font-size: 13px;
}
.dd-img-ph span { font-size: 24px; opacity: .7; }
@media (max-width: 700px) {
  .dd-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal.modal-wide { padding: 18px 16px; }
  .subtabs.dd-tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
  .subtabs.dd-tabs .subtab-btn { padding: 0 4px; justify-content: center; font-size: 12px; min-height: 40px; }
  .dd-ico { display: none; }
}

/* Trang thống kê: khung bấm được và popup danh sách thiết bị */
.an-hint { font-size: 12.5px; color: var(--muted); margin: -4px 0 12px; }
.an-click { cursor: pointer; -webkit-tap-highlight-color: transparent; transition: transform .12s, box-shadow .12s, background .12s; }
.an-click:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kpi-card.an-click:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0,0,0,.14); }
.kpi-card.an-click::after { content: '›'; position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 22px; font-weight: 700; color: var(--muted); opacity: .6; }
.an-row.an-click { margin: -5px -8px; padding: 5px 8px; border-radius: 10px; }
.an-row.an-click:hover, .dleg-item.an-click:hover, .vbar-col.an-click:hover { background: var(--chip); }
.dleg-item.an-click { padding: 5px 8px; margin: -3px -8px; border-radius: 9px; min-height: 32px; }
.vbar-col.an-click { border-radius: 10px; padding: 0 2px 4px; }
circle.an-seg.an-click:hover { stroke-width: 24; }
.an-more { font-size: 12px; font-weight: 700; color: var(--accent); margin-left: 8px; white-space: nowrap; }
.modal.modal-an { display: flex; flex-direction: column; }
.modal-an .an-back { margin-bottom: 8px; }
.an-search { width: 100%; margin-bottom: 12px; flex-shrink: 0; }
.an-list { display: flex; flex-direction: column; gap: 8px; }
.an-item { padding: 11px 13px; border-radius: 12px; border: 1px solid var(--border-subtle); background: var(--card); cursor: pointer; }
.an-item:hover, .an-item:focus-visible { border-color: var(--accent); background: var(--chip); outline: none; }
.an-item-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.an-name { font-size: 14px; font-weight: 700; overflow-wrap: anywhere; }
.an-num { font-weight: 800; white-space: nowrap; }
.an-meta { font-size: 12px; color: var(--muted); margin-top: 3px; overflow-wrap: anywhere; }
.an-meta .mono { color: var(--accent); font-weight: 700; }
.an-more-btn { width: 100%; justify-content: center; min-height: 44px; margin-top: 4px; }
@media (max-width: 700px) {
  .an-kpi { grid-template-columns: 1fr !important; gap: 10px; }
  .kpi-card.an-click { min-height: 64px; }
  .an-row.an-click { padding: 8px; }
  .an-search { height: 44px; font-size: 16px; } /* 16px: tránh iOS tự phóng to khi focus */
  .an-item { padding: 12px; }
}

tr.row-hl td { background: var(--table-hl); box-shadow: inset 0 0 0 9999px var(--accent-soft); }
@media (max-width: 700px) {
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
  .search-wrap input { height: 44px; font-size: 16px; } /* 16px: tránh iOS tự phóng to khi focus */
  .search-suggest { max-height: 55vh; }
}

.top-actions { display: flex; align-items: center; gap: 9px; position: relative; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--chip); color: var(--accent); display: flex; align-items: center; justify-content: center;
  cursor: pointer; position: relative; transition: transform .15s, background .15s;
}
.icon-btn:hover { transform: translateY(-1px); background: var(--card-hover); }
.user-pill {
  display: flex; align-items: center; gap: 9px; padding: 4px 12px 4px 5px;
  border-radius: 13px; background: var(--chip); border: 1px solid var(--border);
}
.avatar {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center;
}
.user-name { font-weight: 700; font-size: 12.8px; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--muted); }

/* Theme Dropdown */
.theme-menu {
  position: absolute; top: 48px; right: 0; width: 210px; padding: 8px; border-radius: 18px;
  background: var(--card-solid); border: 1px solid var(--border); box-shadow: 0 18px 44px rgba(15,23,42,.24);
  display: none; z-index: 60;
}
.theme-menu.open { display: block; }
.theme-opt {
  width: 100%; border: none; background: transparent; color: var(--text);
  padding: 8px 10px; border-radius: 11px; font-family: inherit; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.theme-opt:hover, .theme-opt.active { background: var(--accent-soft); color: var(--accent); }
.theme-opt .sw { width: 17px; height: 17px; border-radius: 6px; flex: none; }
.theme-opt .ck { margin-left: auto; font-weight: 800; }

/* Hero */
.hero {
  position: relative; overflow: hidden; padding: 22px 26px; margin-bottom: 18px; border-radius: 22px;
  background: var(--hero-bg); border: 1px solid var(--hero-border); box-shadow: var(--shadow);
  backdrop-filter: blur(18px); display: flex; align-items: center; justify-content: space-between; gap: 18px;
}
.hero-tag {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; margin-bottom: 8px;
}
.hero h1 { margin: 0 0 6px; font-size: 25px; font-weight: 800; }
.hero p { margin: 0; font-size: 13.8px; color: var(--muted); }
.hero-kpis { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 12px; }
.kpi-chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); font-size: 12.2px; font-weight: 600;
}
.kpi-chip .dot { width: 8px; height: 8px; border-radius: 999px; }
button.kpi-chip { font-family: inherit; color: var(--text); cursor: pointer; min-height: 34px; transition: transform .12s, box-shadow .12s, border-color .12s; }
button.kpi-chip:hover { transform: translateY(-1px); border-color: var(--accent); box-shadow: 0 6px 16px rgba(0,0,0,.1); }
.kpi-chip .chip-go { color: var(--muted); font-weight: 800; margin-left: 2px; }

/* Thời tiết tại vị trí bệnh viện (bên phải khung chào) */
.hero-main { min-width: 0; flex: 1 1 320px; }
.hero-weather { flex: 0 1 430px; min-width: 0; }
.wx-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 13px 16px; }
.wx-place { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; color: var(--muted); }
.wx-edit { margin-left: auto; border: 0; background: none; color: var(--accent); font: inherit; font-size: 12px; font-weight: 700; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.wx-edit:hover { background: var(--chip); }
.wx-sub { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.wx-empty .btn { margin-top: 10px; }
.wx-now { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.wx-icon { font-size: 44px; line-height: 1; }
.wx-temp { font-size: 30px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.wx-desc { font-size: 13px; font-weight: 600; margin-top: 2px; }
.wx-stats { margin-left: auto; display: grid; grid-template-columns: auto auto; gap: 3px 14px; font-size: 12px; color: var(--muted); }
.wx-stats b { color: var(--text); }
.wx-days { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--border-subtle); }
.wx-day { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; }
.wx-dname { font-weight: 700; color: var(--muted); }
.wx-dicon { font-size: 18px; }
.wx-dtemp { color: var(--muted); white-space: nowrap; }
.wx-dtemp b { color: var(--text); }
@media (max-width: 1100px) {
  .hero { flex-wrap: wrap; }
  .hero-weather { flex: 1 1 100%; }
}
@media (max-width: 640px) {
  .wx-now { flex-wrap: wrap; }
  .wx-stats { margin-left: 0; width: 100%; grid-template-columns: 1fr 1fr; }
  .wx-day { flex-direction: column; gap: 1px; }
  .hero-kpis { display: grid; grid-template-columns: 1fr; gap: 7px; }
  .hero-kpis .kpi-chip { min-height: 40px; }
  .kpi-chip .chip-go { margin-left: auto; }
}

/* Tiles & Sidebar */
.main-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
@media (max-width: 1060px) { .main-grid { grid-template-columns: 1fr; } }
.tile-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }
@media (max-width: 860px) { .tile-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.ftile {
  position: relative; overflow: hidden; padding: 17px 17px 15px; border-radius: 20px;
  background: var(--card); backdrop-filter: blur(18px); border: 1px solid var(--border);
  box-shadow: var(--shadow); cursor: pointer; transition: transform .18s, box-shadow .18s, background .18s;
  display: flex; flex-direction: column; min-height: 148px;
}
.ftile::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: var(--tile-grad); }
.ftile:hover { transform: translateY(-4px); background: var(--card-hover); box-shadow: var(--shadow-hover); }
.ftile-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.ftile-icon {
  width: 46px; height: 46px; border-radius: 14px; background: var(--tile-grad); color: #fff;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 18px var(--tile-glow); flex: none;
}
.ftile-badge {
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  background: var(--badge-bg); color: var(--badge-fg);
}
.ftile-title { font-size: 15px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.ftile-desc { font-size: 12.2px; color: var(--muted); line-height: 1.38; }

.c-red    { --tile-grad: linear-gradient(135deg, #ff5f6d, #e11d48); --tile-glow: rgba(225,29,72,.30);  --badge-bg: rgba(225,29,72,.14);  --badge-fg: #e11d48; }
.c-orange { --tile-grad: linear-gradient(135deg, #fb923c, #ea580c); --tile-glow: rgba(234,88,12,.30);  --badge-bg: rgba(234,88,12,.14);  --badge-fg: #c2410c; }
.c-amber  { --tile-grad: linear-gradient(135deg, #fbbf24, #d97706); --tile-glow: rgba(217,119,6,.30);  --badge-bg: rgba(217,119,6,.15);  --badge-fg: #b45309; }
.c-green  { --tile-grad: linear-gradient(135deg, #34d399, #059669); --tile-glow: rgba(5,150,105,.30);  --badge-bg: rgba(5,150,105,.14);  --badge-fg: #047857; }
.c-sky    { --tile-grad: linear-gradient(135deg, #38bdf8, #0284c7); --tile-glow: rgba(2,132,199,.30);  --badge-bg: rgba(2,132,199,.14);  --badge-fg: #0369a1; }
.c-violet { --tile-grad: linear-gradient(135deg, #a78bfa, #7c3aed); --tile-glow: rgba(124,58,237,.30); --badge-bg: rgba(124,58,237,.14); --badge-fg: #6d28d9; }
.c-pink   { --tile-grad: linear-gradient(135deg, #f472b6, #db2777); --tile-glow: rgba(219,39,119,.30); --badge-bg: rgba(219,39,119,.14); --badge-fg: #be185d; }
.c-indigo { --tile-grad: linear-gradient(135deg, #60a5fa, #4f46e5); --tile-glow: rgba(79,70,229,.30);  --badge-bg: rgba(79,70,229,.14);  --badge-fg: #4338ca; }
.c-teal   { --tile-grad: linear-gradient(135deg, #2dd4bf, #0d9488); --tile-glow: rgba(13,148,136,.30); --badge-bg: rgba(13,148,136,.14); --badge-fg: #0f766e; }
[data-theme="dark"] .c-red    { --badge-bg: rgba(244,63,94,.22);  --badge-fg: #fda4af; }
[data-theme="dark"] .c-orange { --badge-bg: rgba(251,146,60,.22); --badge-fg: #fdba74; }
[data-theme="dark"] .c-amber  { --badge-bg: rgba(251,191,36,.22); --badge-fg: #fde047; }
[data-theme="dark"] .c-green  { --badge-bg: rgba(52,211,153,.22); --badge-fg: #6ee7b7; }
[data-theme="dark"] .c-sky    { --badge-bg: rgba(56,189,248,.22); --badge-fg: #7dd3fc; }
[data-theme="dark"] .c-violet { --badge-bg: rgba(167,139,250,.22);--badge-fg: #c4b5fd; }
[data-theme="dark"] .c-pink   { --badge-bg: rgba(244,114,182,.22);--badge-fg: #f9a8d4; }
[data-theme="dark"] .c-indigo { --badge-bg: rgba(129,140,248,.22);--badge-fg: #a5b4fc; }
[data-theme="dark"] .c-teal   { --badge-bg: rgba(45,212,191,.22); --badge-fg: #5eead4; }

/* Common UI */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-title { font-size: 21px; font-weight: 800; display: flex; align-items: center; gap: 10px; }
.panel-title { display: flex; align-items: center; gap: 8px; font-size: 14.5px; font-weight: 800; }
.panel-title::before { content: ''; width: 7px; height: 7px; background: var(--accent); transform: rotate(45deg); border-radius: 1px; }
.notif-panel { padding: 18px; }
.notif-list { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.notif-item {
  padding: 11px 13px; border-radius: 14px; background: var(--chip); border: 1px solid var(--border);
  border-left: 4px solid var(--n-color, var(--accent));
}
.notif-item-title { font-size: 13px; font-weight: 700; line-height: 1.35; margin-bottom: 3px; }
.notif-item-sub { font-size: 11.6px; color: var(--muted); }

.btn {
  height: 38px; padding: 0 15px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); font-family: inherit; font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; transition: all .15s;
}
.btn:not(.btn-primary):not(.btn-danger):not(.btn-success):hover { background: var(--card-hover); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 11.8px; border-radius: 9px; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px var(--accent-soft);
}
.btn-primary:hover, .btn-danger:hover, .btn-success:hover { filter: brightness(1.06); }
.btn-danger { background: linear-gradient(135deg, #ff5f6d, #e11d48); border-color: transparent; color: #fff; }
.btn-success { background: linear-gradient(135deg, #34d399, #059669); border-color: transparent; color: #fff; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.input, select.input, textarea.input {
  height: 38px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--border-subtle);
  background: var(--input-bg); color: var(--text); font-family: inherit; font-size: 13px; outline: none;
}
textarea.input { height: auto; padding: 10px 12px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.kpi-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
@media (max-width: 820px) { .kpi-row { grid-template-columns: repeat(2, 1fr); } }
.kpi-card { padding: 15px 17px; display: flex; align-items: center; gap: 13px; position: relative; overflow: hidden; }
.kpi-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tile-grad); }
.kpi-val { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-lbl { font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--border-subtle); }
th { background: var(--table-head); font-size: 11.3px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
th.col-hl, td.col-hl { background: var(--table-hl); }
tr:hover td { background: var(--chip); }

.st-pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.st-ok { background: rgba(16,185,129,.16); color: #059669; }
.st-warn { background: rgba(245,158,11,.18); color: #b45309; }
.st-err { background: rgba(239,68,68,.16); color: #dc2626; }
.st-info { background: rgba(59,130,246,.16); color: #2563eb; }
[data-theme="dark"] .st-ok { color: #6ee7b7; }
[data-theme="dark"] .st-warn { color: #fcd34d; }
[data-theme="dark"] .st-err { color: #fca5a5; }
[data-theme="dark"] .st-info { color: #93c5fd; }

.subtabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.subtab-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 8px 15px; border-radius: 12px; font-family: inherit; font-size: 12.8px; font-weight: 700; cursor: pointer;
}
.subtab-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }

/* Charts */
.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 960px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.hbar-list { display: flex; flex-direction: column; gap: 10px; }
.hbar-meta { display: flex; justify-content: space-between; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.hbar-track { height: 11px; border-radius: 999px; background: var(--border-subtle); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 999px; }
.donut-wrap { display: flex; align-items: center; justify-content: center; gap: 22px; flex-wrap: wrap; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; min-width: 155px; }
.dleg-item { display: flex; align-items: center; gap: 8px; font-size: 12.8px; font-weight: 600; }
.dleg-dot { width: 11px; height: 11px; border-radius: 4px; }
.vbar-chart { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; height: 190px; padding-top: 18px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; height: 100%; justify-content: flex-end; }
.vbar-bar { width: 100%; max-width: 38px; border-radius: 9px 9px 3px 3px; min-height: 6px; }

/* Modal */
.modal-bg {
  position: fixed; inset: 0; z-index: 90; background: rgba(15, 23, 42, .52);
  backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 22px 24px; background: var(--card-solid); border-radius: 22px; border: 1px solid var(--border); box-shadow: 0 24px 60px rgba(0,0,0,.35); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 5px; }
.field .input { width: 100%; }
.form-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-2 { grid-template-columns: 1fr; } }

/* Toast */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 120;
  padding: 12px 18px; border-radius: 14px; background: #0f172a; color: #fff;
  font-size: 13px; font-weight: 600; box-shadow: 0 14px 34px rgba(0,0,0,.3);
}

/* ==================== ẢNH THIẾT BỊ (device-media.js) ==================== */
.dm-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 14px 0 8px; }
.dm-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--border-subtle); font-size: 11.5px; text-align: center; margin-left: 4px; }
.dm-up { cursor: pointer; }
.dm-form { border: 1px dashed var(--accent); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.dm-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.dm-pv { width: 72px; text-align: center; font-size: 11px; color: var(--muted); }
.dm-pv img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.dm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.dm-cell { margin: 0; cursor: pointer; border-radius: 10px; overflow: hidden; border: 1px solid var(--border-subtle); background: rgba(127,127,127,.08); }
.dm-cell img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: rgba(127,127,127,.15); }
.dm-cell figcaption { font-size: 10.5px; color: var(--muted); padding: 4px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dm-cell:hover { border-color: var(--accent); }
.dm-broken { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }
.dm-lb { position: fixed; inset: 0; z-index: 2000; background: rgba(0,0,0,.82); display: none; align-items: center; justify-content: center; padding: 16px; }
.dm-lb.open { display: flex; }
.dm-lb-box { width: min(1100px, 100%); max-height: 100%; display: flex; flex-direction: column; gap: 8px; }
.dm-lb-img { flex: 1; min-height: 200px; display: flex; align-items: center; justify-content: center; }
.dm-lb-img img { max-width: 100%; max-height: calc(100vh - 120px); object-fit: contain; border-radius: 8px; }
.dm-lb-bar { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card-solid); color: var(--text); border-radius: 12px; padding: 8px 12px; }
@media (max-width: 600px) { .dm-grid { grid-template-columns: repeat(3, 1fr); } .dm-lb { padding: 8px; } }
.dd-steps { margin-top: 4px; }
.dd-steps summary { cursor: pointer; font-size: 12px; color: var(--accent); }
.dd-note-form { margin-top: 10px; }
.dd-note-form textarea { width: 100%; resize: vertical; }

/* ===== Header gọn: user pill là nút mở menu ===== */
button.user-pill { font-family: inherit; color: var(--text); cursor: pointer; text-align: left; }
button.user-pill:hover { background: var(--card-hover); }
.user-caret { color: var(--muted); margin-left: 2px; }
#user-menu { width: 220px; }
@media (max-width: 700px) {
  .user-pill-txt, .user-caret { display: none; }
  button.user-pill { padding: 4px; }
  .top-actions { margin-left: auto; }
}
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn-ghost-danger { color: #e11d48; border-color: rgba(225, 29, 72, .35); background: var(--chip); }
.btn-ghost-danger:hover { background: rgba(225, 29, 72, .1); }

/* ===== Cài đặt ===== */
.set-wrap { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 16px; align-items: start; }
.set-nav { padding: 8px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 84px; }
.set-nav-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: none; border-radius: 11px;
  background: transparent; color: var(--text); font-family: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer; text-align: left;
}
.set-nav-btn:hover { background: var(--accent-soft); }
.set-nav-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.set-card { padding: 18px 20px; }
.set-card-title { font-size: 16px; font-weight: 800; margin-bottom: 12px; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.theme-card {
  display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 14px; border: 1px solid var(--border-subtle);
  background: var(--card); color: var(--text); font-family: inherit; font-weight: 700; font-size: 13px; cursor: pointer;
}
.theme-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.theme-card-sw { width: 28px; height: 28px; border-radius: 9px; flex: none; }
@media (max-width: 860px) {
  .set-wrap { grid-template-columns: minmax(0, 1fr); } /* minmax: bảng rộng không đẩy trang tràn ngang trên điện thoại */
  .set-nav { position: static; flex-direction: row; overflow-x: auto; }
  .set-nav-btn { white-space: nowrap; width: auto; }
}

/* Sao lưu & thùng rác */
.bk-title { font-size: 21px; font-weight: 800; }
.bk-sub { font-size: 13px; color: var(--muted); margin: 2px 0 14px; }
.bk-sec { padding: 0; margin-bottom: 14px; overflow: hidden; }
.bk-sec > summary { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 13px 16px; cursor: pointer; list-style: none; }
.bk-sec > summary::-webkit-details-marker { display: none; }
.bk-sec > summary::before { content: '▸'; color: var(--muted); transition: transform .15s; }
.bk-sec[open] > summary::before { transform: rotate(90deg); }
.bk-sec[open] > summary { border-bottom: 1px solid var(--border-subtle); }
.bk-sec-name { font-weight: 800; font-size: 15px; }
.bk-badge { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; border: 1px solid var(--border-subtle); background: var(--chip); color: var(--muted); }
.bk-badge.warn { background: #fef3c7; border-color: #fcd34d; color: #92400e; }
.bk-sec .bk-note { font-size: 12.5px; color: var(--muted); padding: 10px 16px 0; line-height: 1.55; }
.bk-sec .toolbar { padding: 0 16px; }
.bk-sec .table-wrap { margin: 10px 0 0; border-radius: 0; box-shadow: none; border: none; }
.bk-warn { font-size: 13px; line-height: 1.55; padding: 11px 13px; border-radius: 12px; background: rgba(225, 29, 72, .08); border: 1px solid rgba(225, 29, 72, .25); }

/* ===== Vai trò & phân quyền ===== */
.re-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.re-title { font-size: 21px; font-weight: 800; }
.re-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.re-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.re-wrap { display: grid; grid-template-columns: 300px minmax(0, 1fr); padding: 0; overflow: hidden; height: calc(100vh - 230px); min-height: 460px; }
.re-left { border-right: 1px solid var(--border-subtle); display: flex; flex-direction: column; min-height: 0; }
.re-right { display: flex; flex-direction: column; min-height: 0; }
.re-col-title { font-weight: 800; font-size: 15px; padding: 12px 16px; border-bottom: 1px solid var(--border-subtle); display: flex; align-items: center; flex-wrap: wrap; }
.re-search { padding: 12px 14px 6px; }
.re-search .input { width: 100%; }
.re-list { overflow-y: auto; padding: 6px 14px 14px; display: flex; flex-direction: column; gap: 8px; }
.re-role { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border-subtle); background: var(--card); cursor: pointer; }
.re-role:hover { border-color: var(--accent); }
.re-role.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); background: var(--accent-soft); }
.re-role-name { font-weight: 700; font-size: 13.5px; }
.re-role-desc { font-size: 12px; color: var(--muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.re-role-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 11.5px; color: var(--muted); }
.re-role-btns { display: flex; gap: 2px; }
.re-ico { width: 28px; height: 26px; border: none; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; }
.re-ico:hover:not(:disabled) { background: var(--chip); color: var(--accent); }
.re-ico.danger:hover:not(:disabled) { color: #e11d48; }
.re-ico:disabled { opacity: .3; cursor: not-allowed; }
.re-tag { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); border: 1px solid var(--border-subtle); margin-left: 4px; }
.re-lock { margin: 12px 16px 0; padding: 9px 12px; border-radius: 10px; background: var(--chip); font-size: 12.5px; color: var(--muted); }
.re-grid { overflow-y: auto; padding: 14px 16px 16px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; align-content: start; align-items: start; }
.re-group { border: 1px solid var(--border-subtle); border-radius: 12px; background: var(--card); }
.re-group.open { border-color: var(--accent); }
.re-group-head { display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 46px; cursor: pointer; user-select: none; }
.re-group-head input, .re-item input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; flex: none; }
.re-group-name { flex: 1; font-weight: 700; font-size: 13.5px; }
.re-count { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.re-chev { color: var(--muted); transition: transform .15s; flex: none; }
.re-group.open .re-chev { transform: rotate(180deg); }
.re-items { border-top: 1px solid var(--border-subtle); padding: 6px 8px 8px; display: flex; flex-direction: column; }
.re-item { display: flex; align-items: flex-start; gap: 9px; padding: 7px 6px; border-radius: 8px; font-size: 12.8px; cursor: pointer; line-height: 1.35; }
.re-item:hover { background: var(--chip); }
.re-item.dis { opacity: .55; cursor: not-allowed; }
@media (max-width: 1200px) { .re-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  .re-wrap { grid-template-columns: 1fr; height: auto; }
  .re-left { border-right: none; border-bottom: 1px solid var(--border-subtle); }
  .re-list { max-height: 260px; }
  .re-grid { grid-template-columns: 1fr; }
}
.bk-sec .btn { white-space: nowrap; }
.bk-sec td:last-child { white-space: nowrap; }

/* ===== Cơ sở → Khoa/Phòng; form Thêm thiết bị ===== */
.cs-tag { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; font-weight: 800; color: var(--accent); background: var(--accent-soft); vertical-align: 1px; white-space: nowrap; }
.ad-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 14px; }
.ad-name-wrap { position: relative; z-index: 5; }
.ad-suggest .sg-name { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ad-suggest { top: calc(100% + 2px); z-index: 95; }
.ad-suggest .sg-meta { white-space: normal; }
.ad-hint { font-size: 12px; color: var(--muted); margin: -4px 0 12px; line-height: 1.45; }
.ad-hint:empty { display: none; }
.ad-warn { font-size: 12.5px; padding: 9px 12px; border-radius: 10px; background: rgba(245, 158, 11, .14); color: var(--text); margin-bottom: 12px; }
.ad-mau { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; padding: 10px 12px; margin: -4px 0 12px; border-radius: 12px; background: var(--accent-soft); border: 1px solid var(--border-subtle); }
.ad-mau-t { font-weight: 800; font-size: 13px; }
.ad-mau-s { font-size: 12px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.ad-mau .btn { flex: none; }
.ad-photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 8px; margin-bottom: 8px; }
.ad-photos:empty { display: none; }
.ad-ph { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--chip); }
.ad-ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ad-ph button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(15, 23, 42, .65); color: #fff; font-size: 12px; cursor: pointer; }
.ad-pick { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; min-height: 40px; }
.ad-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.kp-toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.kp-toolbar .input { flex: 1 1 240px; }
.kp-cs { margin-bottom: 12px; padding: 0; overflow: hidden; }
.kp-cs > summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 16px; min-height: 52px; }
.kp-cs > summary::-webkit-details-marker { display: none; }
.kp-cs > summary::after { content: '▾'; color: var(--muted); transition: transform .15s; }
.kp-cs:not([open]) > summary::after { transform: rotate(-90deg); }
.kp-cs-name { font-weight: 800; font-size: 15px; flex: 1 1 auto; }
.kp-cs-meta { font-size: 12.5px; color: var(--muted); }
.kp-add { padding: 0 14px 10px; }
.kp-rows { border-top: 1px solid var(--border-subtle); }
.kp-row { display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--border-subtle); }
.kp-row:last-child { border-bottom: 0; }
.kp-row.kp-off { opacity: .55; }
.kp-main { flex: 1; min-width: 0; }
.kp-name { font-weight: 700; font-size: 13.5px; }
.kp-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kp-kieu { display: inline-block; padding: 0 7px; border-radius: 6px; background: var(--chip); border: 1px solid var(--border-subtle); font-weight: 700; font-size: 11px; color: var(--text); }
.kp-btns { display: flex; gap: 6px; flex: none; }
.kp-btns .btn { min-width: 38px; min-height: 36px; }
@media (max-width: 600px) {
  .modal.modal-add-device { padding: 16px 14px; max-height: 94vh; border-radius: 18px; }
  .modal-add-device .input { font-size: 16px; }  /* iOS không tự phóng to khi gõ */
  .ad-actions { position: sticky; z-index: 2; bottom: -16px; background: var(--card-solid); padding: 10px 0 4px; margin-bottom: -4px; }
  .ad-actions .btn { flex: 1; min-height: 44px; }
  .kp-row { padding: 10px 12px; }
}
/* Popup xác nhận chuyển trạng thái (confirmAction / caSummaryHtml) */
.modal.modal-confirm { max-width: 480px; }
.ca-title { display: flex; align-items: center; gap: 8px; font-size: 17px; font-weight: 800; margin-bottom: 10px; line-height: 1.3; }
.ca-ico { font-size: 20px; flex: none; }
.ca-intro { font-size: 13.5px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.ca-rows { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; margin: 0 0 12px; padding: 11px 13px; border-radius: 12px; background: var(--chip); border: 1px solid var(--border-subtle); font-size: 13.5px; }
.ca-rows dt { color: var(--muted); font-weight: 600; white-space: nowrap; }
.ca-rows dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.ca-flow { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.ca-flow .st-pill { font-size: 13px; padding: 5px 12px; white-space: normal; }
.ca-arrow { font-size: 18px; font-weight: 800; color: var(--muted); }
.ca-eff { margin: 0 0 12px; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.ca-eff li + li { margin-top: 2px; }
.ca-actor { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 12px; padding: 8px 12px; border-radius: 10px; border: 1px dashed var(--border-subtle); font-size: 12.5px; }
.ca-actor span { color: var(--muted); font-weight: 600; margin-right: 6px; }
.ca-actor em { color: var(--muted); font-style: normal; }
.ca-err { color: #dc2626; font-size: 13px; font-weight: 600; margin: 4px 0 0; }
.ca-err:empty { display: none; }
@media (max-width: 600px) {
  .modal.modal-confirm { padding: 16px 14px; max-height: 94vh; border-radius: 18px; }
  .modal-confirm .input { font-size: 16px; }
  .ca-rows { grid-template-columns: 1fr; gap: 0; }
  .ca-rows dd + dt { margin-top: 6px; }
}
/* Chọn nhiều thiết bị để chuyển khoa */
.dv-ck { width: 44px; text-align: center; }
.dv-ck input { width: 20px; height: 20px; cursor: pointer; accent-color: var(--accent); }
tr.dv-picked td { background: var(--accent-soft); }
.dv-selbar { position: sticky; top: 8px; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 10px; }
.dv-sel-info { font-size: 13px; }
.dv-sel-btns { display: flex; gap: 6px; flex-wrap: wrap; }
@media (max-width: 600px) { .dv-sel-btns { width: 100%; } .dv-sel-btns .btn { flex: 1; min-height: 40px; } }

/* Vị trí hành chính (Cài đặt → Cơ sở) */
.loc-head { font-size: 13px; font-weight: 800; margin: 6px 0 8px; }
.loc-head span { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.loc-note { font-size: 12px; color: var(--muted); margin: -4px 0 8px; min-height: 1em; }
/* ===== Nhân sự: tìm kiếm tài khoản, nhập từ Excel, mật khẩu tạm, quyền riêng ===== */
.tk-head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.tk-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 12px; }
.tk-toolbar .input { height: 38px; }
.tk-toolbar .tk-search { flex: 1 1 280px; min-width: 0; }
.tk-toolbar select.input { flex: 0 1 190px; min-width: 0; }
.tk-count { font-size: 12.5px; color: var(--muted); font-weight: 600; margin-left: auto; white-space: nowrap; }
.tk-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.4; }
.tk-table tr.tk-off td { opacity: .62; }
.tk-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.tk-empty { color: var(--muted); text-align: center; padding: 22px; }
.tk-more { margin: 2px 0 6px; font-size: 13px; }
.tk-more summary { cursor: pointer; color: var(--accent); font-weight: 700; padding: 6px 0; }
.tk-warn { font-size: 12.8px; line-height: 1.55; padding: 10px 12px; border-radius: 12px; background: rgba(245, 158, 11, .13); border: 1px solid rgba(245, 158, 11, .35); margin-bottom: 12px; }
.modal.modal-pw { max-width: 620px; }
.tk-pw-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--border-subtle); border-radius: 12px; }
.tk-pw-v { font-weight: 800; font-size: 14px; letter-spacing: .04em; user-select: all; }
.modal.modal-wide { max-width: 1040px; }
.im-steps { margin: 0 0 14px; padding-left: 20px; font-size: 13px; line-height: 1.55; }
.im-steps li + li { margin-top: 6px; }
.im-def-title { font-weight: 800; font-size: 13px; margin: 4px 0 8px; }
.im-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.im-chip { border: 1px solid var(--border-subtle); background: var(--card); color: var(--text); border-radius: 999px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 34px; }
.im-chip b { margin-left: 4px; }
.im-chip.ok b { color: #059669; } .im-chip.bad b { color: #dc2626; }
.im-chip.active { border-color: var(--accent); background: var(--accent-soft); }
.im-table-wrap { max-height: 52vh; overflow: auto; border: 1px solid var(--border-subtle); border-radius: 12px; }
.im-table th { position: sticky; top: 0; z-index: 1; }
.im-table tr.im-loi td { background: rgba(225, 29, 72, .05); }
.im-table tr.im-trung td { background: rgba(245, 158, 11, .07); }
.im-err { font-size: 11.8px; color: #b91c1c; margin-top: 4px; line-height: 1.4; }
[data-theme="dark"] .im-err { color: #fca5a5; }
.up-wrap { height: calc(100vh - 260px); }
.up-title { flex-direction: column; align-items: flex-start; gap: 4px; }
.up-mono { font-size: 12px; color: var(--muted); font-weight: 600; }
.up-sum { font-size: 12.5px; font-weight: 500; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.up-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 10px 16px 0; }
.up-tools .input { height: 36px; flex: 1 1 200px; min-width: 0; }
.up-only { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; cursor: pointer; min-height: 36px; }
.up-only input { width: 17px; height: 17px; accent-color: var(--accent); }
.up-legend { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.up-tag { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; white-space: nowrap; border: 1px solid transparent; line-height: 1.5; }
.up-role { background: var(--chip); color: var(--muted); border-color: var(--border-subtle); }
.up-add { background: rgba(16, 185, 129, .14); color: #047857; border-color: rgba(16, 185, 129, .35); }
.up-del { background: rgba(225, 29, 72, .1); color: #be123c; border-color: rgba(225, 29, 72, .3); }
[data-theme="dark"] .up-add { color: #6ee7b7; } [data-theme="dark"] .up-del { color: #fda4af; }
.up-item { align-items: center; }
.up-item .up-name { flex: 1; }
.up-item.up-them { background: rgba(16, 185, 129, .07); }
.up-item.up-bo .up-name { text-decoration: line-through; color: var(--muted); }
.up-log { margin-top: 12px; padding: 14px 16px; }
.up-float { position: sticky; bottom: 10px; z-index: 30; margin-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 14px; font-size: 13px; box-shadow: 0 8px 28px rgba(15, 23, 42, .18); }
.up-float-btns { display: flex; gap: 6px; }
@media (max-width: 600px) { .up-float-btns { width: 100%; } .up-float-btns .btn { flex: 1; min-height: 42px; } }
.up-log-list { display: flex; flex-direction: column; max-height: 320px; overflow-y: auto; }
.up-log-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.up-log-row:last-child { border-bottom: 0; }
.up-log-t { color: var(--muted); font-size: 12px; white-space: nowrap; }
@media (max-width: 860px) {
  .up-wrap { height: auto; }
  .up-wrap .re-grid { overflow: visible; }
}
@media (max-width: 700px) {
  .tk-head-btns { width: 100%; }
  .tk-head-btns .btn { flex: 1 1 auto; min-height: 42px; }
  .tk-toolbar .tk-search { flex-basis: 100%; }
  .tk-toolbar select.input { flex: 1 1 calc(50% - 4px); font-size: 16px; }
  .tk-toolbar .input { font-size: 16px; height: 42px; }
  .tk-count { margin-left: 0; }
  /* Bảng tài khoản / xem trước nhập file thành thẻ trên điện thoại */
  .tk-table thead { display: none; }
  .tk-table, .tk-table tbody, .tk-table tr, .tk-table td { display: block; width: 100%; }
  .tk-table tr { padding: 10px 12px; border-bottom: 1px solid var(--border-subtle); }
  .tk-table td { border: 0; padding: 3px 0; display: grid; grid-template-columns: 92px minmax(0, 1fr); column-gap: 10px; align-items: baseline; overflow-wrap: anywhere; }
  .tk-table td[data-label=""], .tk-table td.tk-empty { grid-template-columns: minmax(0, 1fr); }
  .tk-table td[data-label]:not([data-label=""])::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 4; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  .tk-table td > * { min-width: 0; grid-column: -2; justify-self: start; }
  .tk-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -2px; padding: 2px; }
  .tk-tabs .subtab-btn { flex: none; }
  .tk-table td.tk-acts { padding-top: 8px; }
  .tk-table .tk-btns { width: 100%; }
  .tk-table .tk-btns .btn { flex: 1 1 auto; min-height: 38px; font-size: 12.5px; }
  .tk-table td.tk-empty { display: block; }
  .tk-pw-wrap, .im-table-wrap { max-height: none; border: 0; }
  .up-log-row { grid-template-columns: 1fr; gap: 2px; }
  .up-tools .input { font-size: 16px; }
  .modal.modal-wide { max-width: none; }
}

/* Chọn khoa nhanh: hàng cơ sở nằm ngang + nút khoa */
.kpk { border: 1px solid var(--border-subtle); border-radius: 12px; padding: 8px; background: var(--card); }
.kpk-cs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid var(--border-subtle); }
.kpk-cs-btn { flex: none; border: 1px solid var(--border-subtle); background: var(--chip); color: var(--text); border-radius: 999px; padding: 0 12px; min-height: 34px; font-size: 12.8px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.kpk-cs-btn span { font-weight: 600; color: var(--muted); margin-left: 3px; font-size: 11.5px; }
.kpk-cs-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.kpk-cs-btn.active span { color: rgba(255, 255, 255, .85); }
.kpk-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; }
.kpk-k { border: 1px solid var(--border-subtle); background: var(--card-solid); color: var(--text); border-radius: 9px; padding: 5px 10px; min-height: 34px; font-size: 12.8px; cursor: pointer; text-align: left; }
.kpk-k:hover { border-color: var(--accent); }
.kpk-k.active { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; box-shadow: 0 0 0 1px var(--accent); }
.kpk-cur { font-size: 12px; color: var(--muted); margin-top: 6px; }
@media (max-width: 600px) { .kpk-list { max-height: 240px; } .kpk-k, .kpk-cs-btn { min-height: 38px; } }

/* ==================== TRỢ LÝ AI ==================== */
.ai-fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 95; display: flex; align-items: center; gap: 8px;
  padding: 11px 16px; border: 0; border-radius: 999px; cursor: pointer; font: inherit; font-weight: 800; font-size: 14px;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 12px 30px rgba(15, 23, 42, .28);
}
.ai-fab span:first-child { font-size: 19px; line-height: 1; }
.ai-panel {
  position: fixed; right: 18px; bottom: 76px; z-index: 96; width: min(400px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 110px)); display: flex; flex-direction: column; padding: 14px;
  background: var(--card-solid); border-radius: 18px; box-shadow: 0 22px 60px rgba(15, 23, 42, .3);
}
.ai-panel.hidden { display: none; }
.ai-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.ai-title { font-weight: 800; font-size: 16px; }
.ai-sub { font-size: 12.5px; color: var(--muted); }
.ai-msgs { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; }
.ai-hello { font-size: 14px; line-height: 1.5; }
.ai-red { color: #dc2626; font-weight: 800; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ai-chip { border: 1px solid var(--border-subtle); background: var(--chip); border-radius: 999px; padding: 6px 11px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); text-align: left; }
.ai-msg { max-width: 92%; padding: 9px 12px; border-radius: 14px; font-size: 14px; line-height: 1.5; }
.ai-me, .ai-txt { white-space: pre-wrap; }
.ai-me { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.ai-bot { align-self: flex-start; background: var(--accent-soft); color: var(--text); border-bottom-left-radius: 4px; }
.ai-err { background: rgba(239, 68, 68, .12); color: #b91c1c; }
.ai-steps { margin: 6px 0 4px; padding-left: 20px; white-space: normal; }
.ai-steps li { margin: 3px 0; }
.ai-step-btn { display: inline; border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.ai-step-btn:hover { text-decoration: underline; }
.ai-step-go { font-size: 12px; }
.ai-tour-btn { margin-top: 6px; }
.ai-typing span { animation: aiDot 1.2s infinite; }
.ai-typing span:nth-child(2) { animation-delay: .2s; } .ai-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes aiDot { 0%, 100% { opacity: .2; } 50% { opacity: 1; } }
.ai-form { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; }
.ai-form textarea { flex: 1; resize: none; min-height: 44px; }
/* Ô/nút được khoanh đỏ */
.ai-hl { outline: 3px solid #ef4444 !important; outline-offset: 3px; border-radius: 8px; animation: aiPulse 1.4s ease-in-out infinite; position: relative; z-index: 1; }
@keyframes aiPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .55); } 50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); } }
.ai-card {
  position: fixed; z-index: 130; width: min(340px, calc(100vw - 24px)); padding: 12px 14px; border-radius: 14px;
  background: var(--card-solid); color: var(--text); border: 2px solid #ef4444; box-shadow: 0 18px 44px rgba(15, 23, 42, .3);
}
.ai-card-bottom { left: 50% !important; top: auto !important; bottom: 14px; transform: translateX(-50%); width: min(520px, calc(100vw - 24px)); }
.ai-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.ai-card-n { font-size: 12px; font-weight: 800; color: #dc2626; text-transform: uppercase; letter-spacing: .03em; }
.ai-card-x { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.ai-card-txt { font-size: 14.5px; font-weight: 600; line-height: 1.45; }
.ai-card-wait { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.ai-card-btns { display: flex; gap: 6px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.ai-note { font-size: 12.5px; color: var(--muted); margin: -4px 0 12px; }
.ai-usage { font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }
.im-ai-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; }
.im-ai-from { color: var(--muted); text-decoration: line-through; font-size: 12.5px; }
.im-ai-to { color: #047857; font-weight: 700; }
tr.im-ai-on { background: rgba(16, 185, 129, .07); }
@media (max-width: 720px) {
  .ai-fab { right: 12px; bottom: 12px; padding: 10px 13px; }
  .ai-fab-txt { display: none; }
  .ai-panel { right: 8px; left: 8px; bottom: 66px; width: auto; height: min(70vh, calc(100vh - 90px)); }
}

/* ==================== MƯỢN ĐỒ (muon-do.js) ==================== */
.md-head-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.md-tabs { margin-bottom: 12px; }
.md-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 3px; border-radius: 10px; background: var(--border-subtle); font-size: 11.5px; text-align: center; }
.subtab-btn.active .md-count { background: rgba(255,255,255,.28); }
.md-count-hot { background: #ef4444 !important; color: #fff; }
.md-filter { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 12px 14px; margin-bottom: 12px; }
.md-filter #md-q { flex: 1 1 280px; min-width: 0; }
.md-filter #md-khoa { flex: 0 1 260px; min-width: 0; }
.md-mine { display: flex; gap: 6px; align-items: center; font-size: 12.8px; font-weight: 600; white-space: nowrap; }
.md-table td { vertical-align: top; }
.md-row { cursor: pointer; }
.md-row:hover td { background: var(--card-hover); }
.md-row-late td:first-child { box-shadow: inset 3px 0 0 #ef4444; }
.md-so { font-weight: 800; white-space: nowrap; }
.md-pills { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.md-strong { font-weight: 700; }
.md-sub { font-size: 11.8px; color: var(--muted); line-height: 1.45; }
.md-sub b { color: var(--text); font-weight: 700; }
.md-item { font-size: 12.8px; line-height: 1.45; overflow-wrap: anywhere; }
.md-item-done { color: var(--muted); text-decoration: line-through; }
.md-tag { font-size: 11px; color: var(--accent); }
.md-remain { display: inline-block; margin-top: 3px; padding: 1px 8px; border-radius: 8px; font-size: 11.5px; font-weight: 700; background: rgba(16,185,129,.14); color: #059669; }
.md-remain.md-soon { background: rgba(245,158,11,.18); color: #b45309; }
.md-remain.md-late { background: rgba(239,68,68,.16); color: #dc2626; }
[data-theme="dark"] .md-remain { color: #6ee7b7; }
[data-theme="dark"] .md-remain.md-soon { color: #fcd34d; }
[data-theme="dark"] .md-remain.md-late { color: #fca5a5; }
.md-media { display: flex; gap: 8px; align-items: flex-start; max-width: 240px; }
.md-thumb { position: relative; flex: none; width: 56px; height: 56px; border-radius: 9px; overflow: hidden; background: rgba(127,127,127,.15); }
.md-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.md-thumb span { position: absolute; right: 2px; bottom: 2px; padding: 0 5px; border-radius: 7px; background: rgba(0,0,0,.6); color: #fff; font-size: 10.5px; font-weight: 700; }
.md-note { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.md-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.md-info { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.md-box { padding: 9px 12px; border-radius: 11px; background: var(--chip); border: 1px solid var(--border-subtle); font-size: 13px; margin-bottom: 10px; overflow-wrap: anywhere; }
.md-box-err { border-color: rgba(239,68,68,.35); }
.md-timeline { display: flex; flex-direction: column; gap: 10px; }
.md-ev { display: flex; gap: 10px; font-size: 13px; }
.md-ev-ico { flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--chip); display: flex; align-items: center; justify-content: center; font-size: 14px; }
.md-click { cursor: pointer; }
.md-click:hover { border-color: var(--accent); }
.md-step { font-size: 13.5px; font-weight: 800; margin: 16px 0 8px; color: var(--accent); }
.md-mode { margin-bottom: 8px; }
.md-pick-wrap { position: relative; margin-bottom: 8px; }
.md-pick-wrap .input { width: 100%; }
.md-pick { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; max-height: 280px; overflow-y: auto; border-radius: 12px; border: 1px solid var(--border); background: var(--card-solid); box-shadow: 0 12px 30px rgba(0,0,0,.18); }
.md-pick-row { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--border-subtle); background: transparent; color: var(--text); font-family: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.md-pick-row:hover:not(:disabled) { background: var(--card-hover); }
.md-pick-row:disabled { opacity: .5; cursor: not-allowed; }
.md-pick-row > span:last-child { flex: none; text-align: right; }
.md-pick-empty { padding: 12px; font-size: 12.5px; color: var(--muted); }
.md-free { display: grid; grid-template-columns: minmax(0, 1fr) 80px auto; gap: 8px; margin-bottom: 8px; }
.md-items { display: flex; flex-direction: column; gap: 6px; }
.md-chip { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 220px) auto; gap: 8px; align-items: center; padding: 7px 10px; border-radius: 11px; border: 1px solid var(--border-subtle); background: var(--card); font-size: 13px; margin-bottom: 6px; }
#md-person .md-chip { grid-template-columns: minmax(0, 1fr) auto; }
.md-chip .input { height: 32px; font-size: 12.5px; }
.md-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.md-ret-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.md-ret { padding: 9px 11px; border-radius: 11px; border: 1px solid var(--border-subtle); background: var(--card); }
.md-ret-top { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin-bottom: 7px; cursor: pointer; }
.md-ret .form-2 { gap: 8px; }
.md-img-err { visibility: hidden; }
.modal.modal-wide.md-modal { height: auto; max-height: 90vh; }
@media (max-width: 760px) {
  .md-info { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md-media { max-width: none; }
  .md-chip { grid-template-columns: minmax(0, 1fr) auto; }
  .md-chip .md-chip-tt { grid-column: 1 / -1; grid-row: 2; }
  .md-free { grid-template-columns: minmax(0, 1fr) 64px; }
  .md-free .btn { grid-column: 1 / -1; }
  .md-filter #md-khoa { flex: 1 1 100%; }
  .md-head-btns { width: 100%; }
  .md-head-btns .btn { flex: 1 1 auto; }
}

/* ===== 26/11/2026 – Giao diện điện thoại (mọi màn) =====
   Lỗi: bảng nhiều cột bị bóp vào màn hẹp → chữ trong nút thao tác / nhãn trạng thái bị bẻ dòng, đè lên icon.
   Sửa: nút nhỏ, nút trong bảng và nhãn trạng thái không xuống dòng; bảng từ 5 cột trở lên giữ bề rộng tối thiểu
   và cuộn ngang trong khung chứa (kể cả bảng không nằm trong .table-wrap). */
.btn-sm, td .btn, .st-pill { white-space: nowrap; }
.btn > svg, .btn > img { flex-shrink: 0; }
@media (max-width: 760px) {
  :has(> table:has(th:nth-child(5))) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table:has(th:nth-child(5)) { min-width: 720px; }
  table:has(th:nth-child(5)) th { white-space: nowrap; }
  table:has(th:nth-child(5)) td:last-child { white-space: nowrap; }
}

/* 26/11/2026 – Form thêm thiết bị: chọn hãng + thêm hãng nhanh */
.ad-hang-row { display: flex; gap: 8px; }
.ad-hang-row select { flex: 1 1 auto; min-width: 0; }
.ad-hang-row .btn, .ad-hang-new .btn { white-space: nowrap; flex-shrink: 0; }
.ad-hang-new { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.ad-hang-new.hidden { display: none; }
.ad-hang-new .input { flex: 1 1 200px; }

/* 26/11/2026 – Mượn đồ / Điều chuyển: hai menu, tệp đính kèm, bên cho mượn */
.md-modes { display: flex; gap: 10px; margin: 4px 0 8px; flex-wrap: wrap; }
.md-mode-btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: 14px; border: 1px solid var(--border-subtle);
  background: var(--card); color: var(--text); font: inherit; font-size: 14.5px; font-weight: 800; cursor: pointer; white-space: nowrap; }
.md-mode-btn.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; box-shadow: 0 6px 18px rgba(0, 0, 0, .12); }
.md-mode-btn.active .md-count { background: rgba(255, 255, 255, .28); color: #fff; }
.md-mode-hint { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; line-height: 1.5; }
.md-files { display: flex; flex-direction: column; gap: 6px; }
.md-file { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--card); border: 1px solid var(--border-subtle); }
.md-file .btn { flex-shrink: 0; }
.md-file-ico { font-size: 20px; flex-shrink: 0; }
.md-file-name { all: unset; cursor: pointer; font-weight: 700; color: var(--accent); word-break: break-word; }
.md-file-name:hover { text-decoration: underline; }
.md-file-pv { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; }
.md-file-chip { display: flex; align-items: center; gap: 6px; font-size: 13px; flex-wrap: wrap; }
.md-file-chip .btn { margin-left: auto; }
.md-file-count { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 8px; background: var(--border-subtle); white-space: nowrap; }
.md-doc-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.md-doc-row select { flex: 1 1 200px; }
.md-seg { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.md-seg-opt { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-subtle);
  background: var(--card); font-weight: 700; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
.md-seg-opt:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.md-free-ext { grid-template-columns: minmax(0, 1.6fr) 70px minmax(0, 1fr) minmax(0, 1fr) auto; }
@media (max-width: 760px) {
  .md-free-ext { grid-template-columns: minmax(0, 1fr) 64px; }
  .md-free-ext .btn { grid-column: 1 / -1; }
  .md-mode-btn { flex: 1 1 0; justify-content: center; padding: 10px 8px; }
}
