:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #1d2939; --muted: #667085; --line: #e4e7ec;
  --primary: #0f766e; --primary-dark: #115e59; --primary-soft: #e6f4f1;
  --danger: #c0362c; --danger-soft: #fdecea; --warn: #b54708; --warn-soft: #fef4e6;
  --ok: #067647; --ok-soft: #e8f6ee; --info: #1d4ed8; --info-soft: #eaf0fe;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); }
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 19px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- Khung ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 232px; background: #0b3b38; color: #d7eeea; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { padding: 18px 18px 10px; font-weight: 700; font-size: 20px; color: #fff; }
.brand small { display: block; font-weight: 400; font-size: 13px; color: #9fd3cb; margin-top: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 12px 18px; color: #d7eeea; text-decoration: none; font-size: 16px; border-left: 4px solid transparent; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: #5eead4; font-weight: 600; }
.nav .ico { width: 24px; text-align: center; font-size: 18px; }
.nav .badge { margin-left: auto; background: #f97316; color: #fff; border-radius: 10px; font-size: 12px; padding: 1px 8px; font-weight: 700; }
.sidebar .me { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.1); font-size: 14px; }
.sidebar .me button { margin-top: 8px; width: 100%; }
.main { flex: 1; min-width: 0; padding: 20px 24px 60px; }
.topbar { display: none; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .grow { flex: 1; }
.help { background: var(--info-soft); color: #1e3a8a; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-size: 15px; }

/* ---------- Thẻ & lưới ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-decoration: none; color: inherit; display: block; }
.stat .n { font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 15px; margin-top: 4px; }
a.stat:hover { outline: 2px solid var(--primary-soft); }
.stat.attn .n { color: var(--warn); }

/* ---------- Nút ---------- */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 10px; padding: 9px 16px; cursor: pointer; min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { background: #f9fafb; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.primary:hover { background: var(--primary-dark); }
.danger { color: var(--danger); border-color: #f3c4bf; }
.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.big { min-height: 52px; font-size: 17px; padding: 12px 22px; }
.link { border: none; background: none; color: var(--primary); padding: 4px 6px; min-height: 0; text-decoration: underline; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.sidebar .me button { background: transparent; color: #d7eeea; border-color: rgba(255,255,255,.25); }

/* ---------- Biểu mẫu ---------- */
label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 15px; }
label .opt { font-weight: 400; color: var(--muted); }
input, select, textarea { font: inherit; width: 100%; padding: 10px 12px; border: 1px solid #cfd4dc; border-radius: 10px; background: #fff; min-height: 44px; color: var(--text); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid #99f6e4; border-color: var(--primary); }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }
.check { display: flex; align-items: flex-start; gap: 10px; font-weight: 400; padding: 8px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; margin-top: 1px; flex-shrink: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid #cfd4dc; border-radius: 999px; padding: 6px 14px; cursor: pointer; background: #fff; min-height: 38px; font-weight: 400; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.search { position: relative; }
.search input { padding-left: 38px; }
.search::before { content: "🔍"; position: absolute; left: 12px; top: 11px; font-size: 15px; }

/* ---------- Bảng ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 14px; color: var(--muted); font-weight: 600; background: #fafbfc; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f6fbfa; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; white-space: nowrap; }

/* ---------- Nhãn trạng thái ---------- */
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; background: #eef0f3; color: #344054; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.primary { background: var(--primary-soft); color: var(--primary-dark); }

/* ---------- Hộp thoại & thông báo ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 620px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 900px; }
.modal h2 { margin-bottom: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 40px); }
.toast { padding: 12px 18px; border-radius: 10px; color: #fff; background: #1f2937; box-shadow: var(--shadow); font-size: 15px; max-width: 420px; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

.alert { border-radius: 10px; padding: 10px 14px; margin: 8px 0; font-size: 15px; }
.alert.warn { background: var(--warn-soft); color: #7a2e0e; }
.alert.danger { background: var(--danger-soft); color: #7a1d16; }
.alert.ok { background: var(--ok-soft); color: #05603a; }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .ico { font-size: 34px; display: block; margin-bottom: 6px; }

/* ---------- Danh sách lịch / hàng chờ ---------- */
.list-item { display: flex; gap: 14px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: #fff; flex-wrap: wrap; }
.list-item .time { font-weight: 700; font-size: 18px; min-width: 64px; }
.list-item .who { flex: 1; min-width: 180px; }
.list-item .who b { font-size: 17px; }
.kanban { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.kanban .col { background: #eef1f4; border-radius: var(--radius); padding: 10px; min-height: 200px; }
.kanban .col h3 { display: flex; justify-content: space-between; font-size: 15px; }
.kanban .kcard { background: #fff; border-radius: 10px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; font-size: 15px; }

/* ---------- Khám bệnh ---------- */
.exam { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; }
.savebar { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin: 0 -24px -60px; flex-wrap: wrap; z-index: 5; }
.savebar .status { margin-right: auto; color: var(--muted); font-size: 14px; }
.dx-item, .rx-item { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: #f8fafc; border-radius: 8px; margin-bottom: 6px; }
.dx-item .x, .rx-item .x { margin-left: auto; }
.rx-item { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr 0.7fr auto; gap: 8px; }
.steps { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.steps span { padding: 6px 12px; border-radius: 999px; background: #eef0f3; font-size: 14px; color: var(--muted); }
.steps span.done { background: var(--ok-soft); color: var(--ok); }
.steps span.cur { background: var(--primary); color: #fff; font-weight: 600; }

/* ---------- Hóa đơn ---------- */
.money-big { font-size: 30px; font-weight: 700; }
.totals td { border: none; padding: 4px 10px; }
.totals tr.total td { font-size: 20px; font-weight: 700; border-top: 2px solid var(--text); padding-top: 8px; }
.qr { text-align: center; }
.qr img { width: 260px; max-width: 100%; border: 1px solid var(--line); border-radius: 10px; }

/* ---------- Biểu đồ cột đơn giản ---------- */
.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 10px; }
.bars .b { flex: 1; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .b:hover { background: var(--primary-dark); }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; font-size: 15px; }
.bar-row .lab { width: 170px; flex-shrink: 0; }
.bar-row .track { flex: 1; background: #eef0f3; border-radius: 6px; height: 24px; overflow: hidden; }
.bar-row .fill { background: var(--primary); height: 100%; border-radius: 6px; }
.bar-row .val { width: 120px; text-align: right; font-weight: 600; }

/* ---------- Đăng nhập / cài đặt ---------- */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #0b3b38, #0f766e); }
.auth .card { width: 100%; max-width: 460px; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- In ấn ---------- */
.print-page { background: #fff; max-width: 800px; margin: 0 auto; padding: 28px; font-size: 15px; }
.print-page h1 { text-align: center; font-size: 22px; margin: 12px 0; }
.print-page .clinic { text-align: center; }
.print-page table th, .print-page table td { border: 1px solid #999; padding: 6px 8px; }
.print-page .sign { display: flex; justify-content: space-between; margin-top: 36px; text-align: center; }
.print-page .sign div { width: 45%; }
@media print {
  .no-print, .sidebar, .topbar, .toast-wrap { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .print-page { padding: 0; max-width: none; }
}

/* ---------- Máy tính bảng & điện thoại ---------- */
@media (max-width: 1100px) {
  .exam { grid-template-columns: 1fr; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .layout { display: block; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; width: 260px; height: 100%; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; background: #0b3b38; color: #fff; padding: 8px 12px; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
  .main { padding: 16px 16px 60px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .savebar { margin: 0 -16px -60px; }
  .rx-item { grid-template-columns: 1fr 1fr; }
  .bar-row .lab { width: 110px; }
}
