/* =============================================================================
   Viện Dưỡng Lão — giao diện quản lý vận hành.
   Nguyên tắc: phẳng, sắc nét, mật độ cao. Không đổ bóng trang trí, không gradient
   trang trí, không bo góc lớn. Trạng thái mã hoá bằng CẢ màu lẫn hình khối để
   còn đọc được khi in đen trắng hoặc khi người dùng mù màu đỏ-lục.
   ========================================================================== */

:root {
  --bg: #eff2f1; --surface: #fff; --sunk: #f4f7f6;
  --border: #d6dedc; --border-s: #bcc9c6;
  --text: #15211f; --muted: #4c5e5b; --faint: #74847f;

  --primary: #0f6b60; --primary-dark: #0a4f47; --primary-light: #e2efec;
  --rail: #122b28; --rail-ink: #a9bfba; --rail-dim: #6f8a85; --rail-hi: #1d403b;

  --red: #c0342b;   --red-w: #fae9e7;   --red-b: #efc6c1;
  --yellow: #a9690c; --yellow-w: #fbf0de; --yellow-b: #e8d3ac;
  --green: #1f7a3d; --green-w: #e4f2e7; --green-b: #bedcc6;
  --blue: #1f5fa8;  --blue-w: #e6edf7;  --blue-b: #c6d5ea;
  --orange: #a9560c; --orange-w: #fbeade; --orange-b: #e8c3ac;

  --radius: 5px; --sidebar: 240px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5rem; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.4rem; } h2 { font-size: 1.1rem; } h3 { font-size: .98rem; }
p { margin: 0 0 .6rem; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }

.muted { color: var(--muted); }
.small { font-size: .84rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 1rem; } .mb { margin-bottom: 1rem; }
.flex { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1; }
/* Số liệu xếp cột phải thẳng hàng chữ số */
.num, .mono, .code { font-variant-numeric: tabular-nums; }
.mono, .code { font-family: var(--mono); font-size: .93em; }

/* Icon SVG nội tuyến (thay emoji) */
.ico { flex: none; vertical-align: -.16em; }
.ico-red { color: var(--red); } .ico-green { color: var(--green); }

/* ===== Bố cục ============================================================ */
.app { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--rail); color: var(--rail-ink); padding: .9rem .6rem; position: fixed; top: 0; bottom: 0; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 1rem; padding: .4rem .65rem .9rem; display: block; line-height: 1.3; }
.brand:hover { text-decoration: none; }
.brand small { display: block; color: var(--rail-dim); font-weight: 400; font-size: .73rem; margin-top: .15rem; }
.nav-section { font-size: .67rem; text-transform: uppercase; letter-spacing: .1em; color: var(--rail-dim); padding: .95rem .65rem .3rem; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: .55rem; padding: .42rem .65rem; border-radius: 4px; color: var(--rail-ink); font-size: .89rem; }
.nav-item:hover { background: var(--rail-hi); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.nav-icon { flex: none; }
.main { margin-left: var(--sidebar); flex: 1; min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: .5rem 1.4rem; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 5; }
.content { padding: 1.3rem 1.4rem; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }
.avatar { width: 32px; height: 32px; border-radius: 4px; background: var(--primary-light); color: var(--primary-dark); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .78rem; }
.avatar.lg { width: 60px; height: 60px; font-size: 1.25rem; border-radius: 6px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.bell { position: relative; display: inline-flex; color: var(--muted); }
.bell:hover { color: var(--primary); }
.bell .dot { position: absolute; top: -5px; right: -9px; background: var(--red); color: #fff; border-radius: 3px; font-size: .64rem; font-weight: 700; padding: 0 4px; line-height: 1.45; font-variant-numeric: tabular-nums; }

/* ===== Thẻ & lưới ======================================================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .7rem; gap: .5rem; flex-wrap: wrap; }
.card-head h2, .card-head h3 { margin: 0; display: flex; align-items: center; gap: .4rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } .sidebar { display: none; } .main { margin-left: 0; } }

/* Ô số liệu: vạch màu bên trái thay vì tô màu con số, để in đen trắng vẫn phân biệt được */
.stat { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--border-s); border-radius: var(--radius); padding: .7rem .85rem; }
.stat .label { color: var(--faint); font-size: .69rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.stat .value { font-size: 1.5rem; font-weight: 700; margin: .1rem 0; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .sub { font-size: .76rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.stat.red { border-left-color: var(--red); }    .stat.red .value { color: var(--red); }
.stat.green { border-left-color: var(--green); } .stat.green .value { color: var(--green); }
.stat.blue { border-left-color: var(--blue); }   .stat.blue .value { color: var(--blue); }
.stat.yellow { border-left-color: var(--yellow); } .stat.yellow .value { color: var(--yellow); }

/* ===== Bảng ============================================================== */
table { width: 100%; border-collapse: collapse; }
th, td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: .68rem; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 700; background: var(--sunk); border-bottom: 1px solid var(--border-s); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--sunk); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.code, .resident-code { font-family: var(--mono); font-size: .8rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.empty { padding: 1.4rem; text-align: center; color: var(--faint); }

/* ===== Nhãn trạng thái ===================================================
   Chấm dẫn ở đầu mang hình khác nhau: tròn = thường, tam giác = nguy hiểm,
   vuông = trung tính. Không chỉ dựa vào màu. ============================ */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .42rem; border-radius: 3px; border: 1px solid transparent; font-size: .71rem; font-weight: 700; white-space: nowrap; }
.badge::before { content: ""; width: 5px; height: 5px; flex: none; background: currentColor; }
.badge-gray { background: #e9edec; color: #47544f; border-color: #d2dbd9; }
.badge-dark { background: #3a4744; color: #fff; border-color: #3a4744; }
.badge-green { background: var(--green-w); color: var(--green); border-color: var(--green-b); }
.badge-green::before { border-radius: 50%; }
.badge-red { background: var(--red-w); color: var(--red); border-color: var(--red-b); }
.badge-red::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); width: 7px; height: 6px; }
.badge-yellow { background: var(--yellow-w); color: var(--yellow); border-color: var(--yellow-b); }
.badge-yellow::before { border-radius: 50%; }
.badge-orange { background: var(--orange-w); color: var(--orange); border-color: var(--orange-b); }
.badge-orange::before { clip-path: polygon(50% 0, 100% 100%, 0 100%); width: 7px; height: 6px; }
.badge-blue { background: var(--blue-w); color: var(--blue); border-color: var(--blue-b); }
.badge-blue::before { border-radius: 50%; }
.badge-teal { background: var(--primary-light); color: var(--primary-dark); border-color: #bcd9d3; }
.badge-teal::before { border-radius: 50%; }

/* Cảnh báo dị ứng: luôn kèm tam giác, không bao giờ chỉ có màu đỏ */
.allergy { display: inline-flex; align-items: center; gap: .25rem; color: var(--red); font-weight: 650; }

/* ===== Biểu mẫu ========================================================== */
label { display: block; font-size: .8rem; font-weight: 650; color: var(--muted); margin-bottom: .22rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=datetime-local], input[type=month], input[type=file], select, textarea {
  width: 100%; padding: .44rem .6rem; border: 1px solid var(--border-s); border-radius: 4px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea { min-height: 88px; resize: vertical; }
.field { margin-bottom: .8rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .8rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; font-size: .93rem; cursor: pointer; padding: .42rem .2rem; border-bottom: 1px solid var(--border); }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.inline-form { display: flex; gap: .5rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin: 0; }
.hint { color: var(--faint); font-size: .79rem; margin-top: .2rem; }

/* ===== Nút ============================================================== */
.btn, :where(input[type=submit]) { display: inline-flex; align-items: center; gap: .35rem; padding: .42rem .8rem; border-radius: 4px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; font-weight: 650; cursor: pointer; text-decoration: none; line-height: 1.25; }
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-outline { background: var(--surface); color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); color: var(--primary-dark); }
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border-s); }
.btn-light:hover { background: var(--sunk); color: var(--text); border-color: var(--border-s); }
.btn-danger { background: var(--red); border-color: var(--red); }
.btn-danger:hover { background: #9e2a22; border-color: #9e2a22; }
.btn-sm { padding: .26rem .58rem; font-size: .81rem; }
.btn-xs { padding: .13rem .45rem; font-size: .74rem; }
form.inline, .inline-block-form, form.button_to { display: inline-block; }
.btn-group { display: inline-flex; gap: .3rem; flex-wrap: wrap; }

/* ===== Thông báo ======================================================== */
.alert { padding: .6rem .9rem; border-radius: 4px; margin-bottom: .9rem; border: 1px solid; border-left-width: 3px; }
.alert-notice { background: var(--green-w); border-color: var(--green-b); border-left-color: var(--green); color: #16542c; }
.alert-alert, .alert-error { background: var(--red-w); border-color: var(--red-b); border-left-color: var(--red); color: #8f2720; }
.alert-warn { background: var(--yellow-w); border-color: var(--yellow-b); border-left-color: var(--yellow); color: #7d4d09; }

/* ===== Tab & bộ lọc ===================================================== */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border-s); margin-bottom: .9rem; flex-wrap: wrap; }
.tabs a { padding: .45rem .8rem; border-bottom: 2px solid transparent; color: var(--faint); font-weight: 650; font-size: .89rem; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--primary-dark); }
.filters { display: flex; gap: .55rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: .9rem; }
.filters .field { margin: 0; min-width: 160px; }

/* ===== Thanh tiến độ ==================================================== */
.progress { height: 6px; background: #e3e9e8; border-radius: 2px; overflow: hidden; }
.progress-bar { height: 100%; }
.bar-green { background: var(--green); } .bar-blue { background: var(--blue); }
.bar-yellow { background: var(--yellow); } .bar-red { background: var(--red); }

/* ===== Danh sách định nghĩa ============================================= */
.dl { display: grid; grid-template-columns: 160px 1fr; gap: .32rem .8rem; }
.dl dt { color: var(--faint); font-size: .83rem; }
.dl dd { margin: 0; }

/* ===== Dòng thời gian =================================================== */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .55rem 0 .55rem 1.05rem; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 1rem; width: 8px; height: 8px; background: var(--primary); }
.timeline li.incident::before { background: var(--red); clip-path: polygon(50% 0, 100% 100%, 0 100%); width: 10px; height: 9px; left: -6px; }
.timeline .meta { font-size: .78rem; color: var(--faint); font-variant-numeric: tabular-nums; }

/* ===== Khung chat ======================================================= */
.chat { display: flex; flex-direction: column; gap: .45rem; max-height: 60vh; overflow-y: auto; padding: .5rem 0; }
.bubble { max-width: 72%; padding: .5rem .75rem; border-radius: 6px; background: var(--sunk); border: 1px solid var(--border); }
.bubble.mine { align-self: flex-end; background: var(--primary-light); border-color: #bcd9d3; }
.bubble .meta { font-size: .71rem; color: var(--faint); margin-top: .2rem; font-variant-numeric: tabular-nums; }

/* ===== Lưới ca trực ===================================================== */
.shift-grid td { min-width: 110px; }
.chip { display: inline-block; padding: .16rem .45rem; border-radius: 3px; font-size: .73rem; font-weight: 600; margin: .1rem; background: var(--blue-w); color: var(--blue); border: 1px solid var(--blue-b); }
.chip.afternoon { background: var(--yellow-w); color: var(--yellow); border-color: var(--yellow-b); }
.chip.night { background: #ece9f6; color: #4c3a8c; border-color: #d3cbe9; }
.chip.done { text-decoration: line-through; opacity: .65; }

/* ===== Khung giờ cấp thuốc ============================================== */
.slot-time { font-family: var(--mono); font-size: .95rem; font-weight: 700; letter-spacing: -.01em; }

/* ===== Lưới ảnh ========================================================= */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .7rem; }
.photos figure { margin: 0; background: #fff; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.photos img { width: 100%; height: 150px; object-fit: cover; display: block; }
.photos figcaption { padding: .38rem .55rem; font-size: .8rem; }

/* ===== Biểu đồ cột =======================================================
   Cột vuông cạnh (bo góc làm sai lệch cảm nhận chiều cao ở giá trị nhỏ),
   lưới ngang 4 vạch và đường nền đậm để ước lượng được giá trị. ========= */
.bars {
  display: flex; align-items: flex-end; gap: .5rem; height: 140px;
  border-bottom: 1.5px solid var(--border-s);
  background-image: repeating-linear-gradient(to top, transparent 0, transparent calc(25% - 1px), var(--border) calc(25% - 1px), var(--border) 25%);
}
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: .7rem; color: var(--faint); }
.bars .bar i { display: block; width: 100%; max-width: 2.8rem; background: var(--primary); min-height: 2px; }
.bars .bar b { font-size: .69rem; font-weight: 700; color: var(--text); margin-bottom: 2px; font-variant-numeric: tabular-nums; }
/* Nhãn trục hoành nằm dưới đường nền, không đè lên vùng vẽ */
.bars .bar span { display: none; }
.bars + .bars-x { display: flex; gap: .5rem; padding-top: .3rem; }
.bars-x span { flex: 1; text-align: center; font-size: .68rem; color: var(--faint); font-variant-numeric: tabular-nums; }
.chart-unit { font-size: .69rem; color: var(--faint); padding-top: .25rem; }

/* ===== Đăng nhập ======================================================== */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--rail); padding: 1rem; }
.auth .card { width: 100%; max-width: 390px; padding: 1.8rem; margin: 0; }
.auth .logo { text-align: center; margin-bottom: 1.1rem; }
.auth .logo b { font-size: 1.25rem; }

/* ===== Cổng người nhà =================================================== */
.family-top { background: var(--rail); color: #fff; padding: .7rem 1.1rem; display: flex; justify-content: space-between; align-items: center; }
.family-top a { color: #fff; margin-left: 1rem; }
.family-top .bell { color: #fff; }
.family-nav { background: #fff; border-bottom: 1px solid var(--border); padding: .35rem 1.1rem; display: flex; gap: .25rem; overflow-x: auto; }
.family-nav a { padding: .42rem .75rem; border-radius: 4px; font-weight: 650; white-space: nowrap; font-size: .89rem; }
.family-nav a.active { background: var(--primary-light); color: var(--primary-dark); }
.family-content { padding: 1.1rem; max-width: 960px; margin: 0 auto; }
.family-content .content { padding: 0; }

/* ===== In ấn =============================================================
   Hóa đơn hay được in, nên bỏ nền màu và giữ đường kẻ mảnh. ============ */
@media print {
  .sidebar, .topbar, .no-print, .tabs, .filters { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  body { background: #fff; font-size: 12px; }
  .card { border: 1px solid #999; break-inside: avoid; margin-bottom: .6rem; }
  .stat { border-left-width: 1px; }
  th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { border-color: #999 !important; }
  a { color: inherit; text-decoration: none; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
