* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-bg: #101828;
  --sidebar-text: #cbd5e1;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e4e8ef;
  --text: #1d2939;
  --muted: #667085;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 16px; }
.brand-icon { font-size: 26px; }
.brand-icon img { width: 34px; height: 34px; display: block; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; }
.brand-sub { font-size: 11px; color: #94a3b8; }
#nav { display: flex; flex-direction: column; gap: 2px; padding: 8px; flex: 1; }
#nav button {
  all: unset; cursor: pointer; padding: 10px 12px; border-radius: 8px;
  font-size: 14px; color: var(--sidebar-text); transition: background .15s;
}
#nav button:hover { background: rgba(255,255,255,.07); }
#nav button.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding: 14px 16px; font-size: 11px; color: #64748b; }

/* ---------- Ai đang mở app ---------- */
.online-users { padding: 10px 16px 0; border-top: 1px solid rgba(255,255,255,.08); margin-top: 4px; }
.online-users:empty { display: none; padding: 0; border: none; margin: 0; }
.online-title { font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }
.online-person { font-size: 12.5px; color: var(--sidebar-text); padding: 2px 0; display: flex; align-items: center; }
.online-person i { color: #64748b; font-style: normal; margin-left: 4px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 99px; margin-right: 6px; flex: 0 0 auto; }
.status-dot.on { background: var(--green); }

/* ---------- Nội dung ---------- */
main { flex: 1; min-width: 0; padding: 24px 28px; max-width: 1200px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head .actions { display: flex; gap: 8px; align-items: center; }
.page-head .actions input, .page-head .actions select { width: auto; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters select { width: auto; }

/* ---------- Nút ---------- */
.btn {
  border: none; cursor: pointer; border-radius: 8px; padding: 9px 14px;
  font-size: 13.5px; font-weight: 600; background: var(--primary); color: #fff;
  transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f1f5f9; }
.btn.danger { background: #fee2e2; color: var(--red); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Thẻ ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 22px; }
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.card .label { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.card .value { font-size: 21px; font-weight: 700; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }
.card.alert-card { border-color: #fecaca; background: #fff7f7; }
.section-title { font-size: 15px; font-weight: 700; margin: 20px 0 10px; }

/* ---------- Bảng ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td.wrap { white-space: normal; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #fafbfc; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; cursor: pointer; }
.right { text-align: right; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.money-in { color: var(--green); font-weight: 600; }
.money-out { color: var(--red); font-weight: 600; }

/* ---------- Biểu đồ ---------- */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 22px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.chart-head h2 { font-size: 15px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 99px; margin-right: 5px; vertical-align: -1px; }
.chart-svg { width: 100%; height: auto; display: block; }

/* ---------- Badge ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge.dang_nuoi { background: #ecfdf5; color: var(--green); }
.badge.da_ban { background: #eff6ff; color: #1d4ed8; }
.badge.da_chet { background: #f1f5f9; color: var(--muted); }
.badge.chua_lam { background: #f1f5f9; color: var(--muted); }
.badge.dang_lam { background: #fffbeb; color: var(--amber); }
.badge.cho_duyet { background: #eff6ff; color: #1d4ed8; }
.badge.xong { background: #ecfdf5; color: var(--green); }
.badge.dau_bau { background: #ecfdf5; color: var(--green); }
.badge.khong_dau { background: #fef2f2; color: var(--red); }
.badge.cho_ket_qua { background: #f1f5f9; color: var(--muted); }
.badge.da_huy { background: #f8fafc; color: var(--muted); border: 1px dashed #cbd5e1; }
/* Hộp chi tiết hiện khi trỏ chuột (máy tính) hoặc chạm (điện thoại) vào thẻ thống kê */
.co-pop { position: relative; cursor: help; }
.co-pop .pop { display: none; position: absolute; left: 0; top: calc(100% + 6px); z-index: 30;
  min-width: 260px; max-width: 360px; max-height: 320px; overflow-y: auto;
  background: #fff; color: var(--text, #0f172a); border: 1px solid var(--line, #e2e8f0); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15,23,42,.18); padding: 10px 12px; font-size: 12.5px; line-height: 1.55; text-align: left; }
.co-pop:hover .pop, .co-pop.mo .pop { display: block; }
.pop-tieu-de { font-weight: 700; margin-bottom: 6px; font-size: 13px; }
.pop-dong { padding: 2px 0; border-bottom: 1px dashed #f1f5f9; }
.pop-dong:last-child { border-bottom: none; }
@media (hover: none) { .co-pop { cursor: pointer; } }

/* Khối thu gọn (VD: mục ổ con trong trang Đàn) — trang bớt dài, bấm mới xổ ra */
.thu-gon { background: #fff; border: 1px solid var(--line, #e2e8f0); border-radius: 12px; padding: 4px 14px 10px; margin-bottom: 14px; }
.thu-gon-dau { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  width: 100%; background: none; border: none; padding: 10px 0 6px; cursor: pointer; font-size: 14px; text-align: left; }
/* Bảng dài cuộn trong khung riêng, tiêu đề cột dính trên đầu — trang không dài thêm */
.khung-cuon { max-height: 62vh; overflow-y: auto; }
.khung-cuon thead th { position: sticky; top: 0; background: #f8fafc; z-index: 2; box-shadow: 0 1px 0 var(--line, #e2e8f0); }

/* Nút tích đánh giá mẹ ngay trên bảng đàn: bật = màu đậm, tắt = mờ + nét đứt */
.tag-me { display: inline-block; padding: 1px 7px; margin: 1px 2px 1px 0; border-radius: 99px;
  font-size: 10.5px; font-weight: 600; cursor: pointer; border: 1px solid transparent; user-select: none; }
.tag-me.xanh.bat { background: #ecfdf5; color: var(--green); border-color: #6ee7b7; }
.tag-me.vang.bat { background: #fffbeb; color: var(--amber); border-color: #fcd34d; }
.tag-me.do.bat { background: #fee2e2; color: var(--red); border-color: #fca5a5; }
.tag-me.tat { background: #f8fafc; color: #94a3b8; border: 1px dashed #cbd5e1; opacity: .75; }
.tag-me:hover { filter: brightness(.95); }

.badge.CAI { background: #dbeafe; color: #1d4ed8; }   /* cái = lạnh */
.badge.DUC { background: #ffedd5; color: #ea580c; }   /* đực = nóng */
.badge.overdue { background: #fef2f2; color: var(--red); }
.badge.thuong { background: #f1f5f9; color: var(--muted); }
.badge.nghi_tuan { background: #fffbeb; color: var(--amber); }
.badge.le { background: #fdf2f8; color: #be185d; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: start; }
.kanban-col { background: #eef1f6; border-radius: var(--radius); padding: 10px; min-height: 180px; }
.kanban-col.drag-over { outline: 2px dashed var(--primary); }
.kanban-col h3 { font-size: 13px; color: var(--muted); padding: 4px 6px 10px; text-transform: uppercase; letter-spacing: .04em; }
.task-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow);
}
.task-card:hover { border-color: var(--primary); }
.task-card.overdue { border-color: var(--red); background: #fff7f7; }
.task-card .t-title { font-weight: 600; margin-bottom: 6px; }
.task-card .t-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }

/* ---------- Form ---------- */
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
.form-row { display: flex; gap: 10px; }
.form-row > * { flex: 1; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(16,24,40,.5);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: 14px; width: 100%; max-width: 560px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal.wide { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-close { all: unset; cursor: pointer; font-size: 20px; color: var(--muted); padding: 0 4px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

/* ---------- Bình luận ---------- */
.report-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.report-item { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.report-item:last-child { border-bottom: none; }
.report-item .r-meta { color: var(--muted); font-size: 11.5px; margin-top: 2px; }

/* ---------- Dashboard ---------- */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.dash-grid .span2 { grid-column: 1 / -1; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }
.hbar-row { display: grid; grid-template-columns: 110px 1fr 60px; gap: 10px; align-items: center; margin-bottom: 9px; font-size: 13px; }
.hbar-label { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: #eef1f6; border-radius: 99px; height: 14px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 99px; min-width: 2px; background: var(--primary); }
.hbar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.status-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.status-row:last-child { border-bottom: none; }
.status-row b { font-size: 15px; }
/* ---------- Sơ đồ trại ---------- */
.sodo-legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; font-size: 12.5px; color: var(--muted); margin-bottom: 14px; }
.sodo-legend > span { display: flex; align-items: center; gap: 5px; }
/* Giong bo tri that o trai: 4 khoi (8 day) dan NGANG mot hang tren man hinh lon.
   O thu nho toi da de ca trai lot vao mot khung nhin; man hinh hep tu xuong 2 khoi/hang. */
.sodo-wrap { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding-bottom: 10px; }
/* iPad dọc / laptop nhỏ: còn ~800px sau thanh bên → 4 khối sẽ cắt chữ → xuống 2 khối/hàng */
@media (max-width: 1180px) { .sodo-wrap { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
/* Điện thoại: 1 khối/hàng, ô cao hơn chút cho dễ chạm */
@media (max-width: 640px) {
  .sodo-wrap { grid-template-columns: 1fr; }
  .o-nuoi { height: 26px; font-size: 11.5px; }
  .sodo-wrap .chip { font-size: 10.5px; padding: 1px 6px; }
}
.sodo-khoi { display: flex; gap: 3px; background: #eef1f6; border-radius: 8px; padding: 5px; }
.sodo-khoi .sodo-day { flex: 1; min-width: 0; }
.sodo-day { display: flex; flex-direction: column; gap: 2px; }
.sodo-day-ten { font-size: 10.5px; font-weight: 700; color: var(--muted); text-align: center; padding-bottom: 3px; letter-spacing: .03em; }
/* MỌI Ô CAO BẰNG NHAU để 8 dãy ngay hàng thẳng lối (chuẩn chốt 18/08/2026) */
.o-nuoi {
  display: flex; align-items: center; gap: 3px;
  min-width: 0; height: 22px; padding: 1px 4px; overflow: hidden;
  background: var(--card); border: 1px solid var(--border); border-radius: 4px; font-size: 10.5px;
}
.o-nuoi.trong { background: #f8fafc; border-style: dashed; opacity: .55; }
.o-nuoi .o-con { flex-wrap: nowrap; overflow: hidden; }
.o-nuoi .chip { white-space: nowrap; }
/* Chip trong so do nho lai de 8 day lot ngang man hinh */
.sodo-wrap .chip { font-size: 9.5px; padding: 0 4px; }
.sodo-wrap .chip-gia { font-size: 8.5px; padding-left: 3px; margin-left: 3px; }
.o-nuoi.drag-over { outline: 2px dashed var(--primary); outline-offset: 1px; }
.o-nuoi.tim-thay { outline: 2px solid var(--amber); background: #fffbeb; }
.o-so { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 17px; font-size: 9px; }
.o-con { display: flex; flex-wrap: wrap; gap: 2px; }
.chip { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; cursor: pointer; white-space: nowrap; }
/* Quy uoc mau chu trai chot 18/08/2026: DUC = mau NONG (do-cam), CAI = mau LANH (xanh duong),
   BABY (ca 2 gioi) = HONG. Trang thai cang quan trong mau cang dam. */
.chip.bau { background: #1e40af; color: #fff; }                                  /* cái bầu — đậm nhất nhà lạnh */
.chip.ghep { background: #93c5fd; color: #1e3a8a; }
.chip.cai { background: #ec4899; color: #fff; }        /* cái trưởng thành: nền hồng chữ trắng */
.chip.cai-haubi { background: #7c3aed; color: #fff; }  /* cái hậu bị: nền tím chữ trắng */
.chip.cai-to { background: #fbcfe8; color: #9d174d; }    /* cái tơ: hồng nhạt chữ đậm */
.chip.cai-baby { background: #fdf2f8; color: #db2777; border: 1px dashed #f9a8d4; }
.chip.duc-chien { background: #b91c1c; color: #fff; }                            /* đực chiến — đậm nhất nhà nóng */
.chip.duc-nhay { background: #fdba74; color: #9a3412; }
.chip.duc { background: #fff; color: #111; border: 1px solid #cbd5e1; }  /* đực trưởng thành: nền trắng chữ đen */
.chip.duc-haubi { background: #16a34a; color: #fff; }                        /* đực hậu bị: nền xanh lá chữ trắng */
.chip.duc-to { background: #dbeafe; color: #1d4ed8; }    /* đực tơ: xanh dương nhạt */
/* Dấu bệnh trên chip sơ đồ trại: ✚ xanh lá = bệnh nhẹ, ✚ đỏ = bệnh nặng */
.benh-dau { margin-left: 3px; font-weight: 800; font-size: 10px; background: #fff;
  border-radius: 999px; padding: 0 3px; display: inline-block; line-height: 1.3; }
.benh-dau.nhe { color: #16a34a; border: 1px solid #86efac; }
.benh-dau.nang { color: #dc2626; border: 1px solid #fca5a5; }
.chip.duc-baby { background: #fff; color: #60a5fa; border: 1px dashed #93c5fd; }  /* đực baby: xanh nhạt nét đứt */
.chip[draggable="true"] { cursor: grab; }
.chip[draggable="true"]:active { cursor: grabbing; }
/* Nhãn giá trị gắn kèm mã khi bật "Hiện giá trị" */
.chip-gia { margin-left: 4px; padding-left: 4px; border-left: 1px solid currentColor; opacity: .75; font-weight: 700; font-size: 10px; }
.o-nuoi.co-gia { min-width: 0; }

.delta { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 99px; margin-left: 6px; vertical-align: 2px; }
.delta.up { background: #ecfdf5; color: var(--green); }
.delta.down { background: #fef2f2; color: var(--red); }
.delta.flat { background: #f1f5f9; color: var(--muted); }

/* ---------- Đăng nhập ---------- */
body.auth-mode .layout { display: none; }
#auth-root .auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #101828 0%, #1d3a6e 100%); padding: 20px;
}
.auth-box {
  background: var(--card); border-radius: 16px; padding: 32px 30px;
  width: 100%; max-width: 400px; box-shadow: 0 24px 64px rgba(0,0,0,.35);
}
.auth-box .auth-logo { text-align: center; font-size: 40px; }
.auth-box .auth-logo img { width: 72px; height: 72px; }
.auth-box h1 { text-align: center; font-size: 19px; margin: 6px 0 2px; }
.auth-box .auth-sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.auth-box .btn { width: 100%; padding: 11px; font-size: 14.5px; margin-top: 4px; }
.auth-footer { position: fixed; left: 14px; bottom: 12px; font-size: 12px; color: rgba(255,255,255,.6); }
.auth-error { color: var(--red); font-size: 13px; text-align: center; margin-top: 12px; min-height: 18px; }

/* ---------- Người dùng ở sidebar ---------- */
.user-chip { border-top: 1px solid rgba(255,255,255,.08); padding-top: 12px; }
.user-chip .u-name { color: #fff; font-weight: 600; font-size: 13px; }
.user-chip .u-role { font-size: 11px; color: #94a3b8; margin-bottom: 8px; }
.user-chip button {
  all: unset; cursor: pointer; font-size: 12px; color: #cbd5e1;
  border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 4px 10px;
}
.user-chip button:hover { background: rgba(255,255,255,.1); }

/* ---------- Đầu hồ sơ cá thể, làm giống thẻ theo dõi giấy của trại ---------- */
.the-chon {
  display: flex; align-items: stretch; justify-content: space-between; gap: 12px;
  border-radius: 12px; padding: 12px 16px; margin-bottom: 14px; color: #fff;
}
.the-chon.duc { background: #1e3a8a; }   /* đực — xanh dương như thẻ giấy */
.the-chon.cai { background: #b91c1c; }   /* cái — đỏ như thẻ giấy */
.the-ma { display: flex; align-items: center; gap: 10px; }
.the-ky-tu {
  font-size: 30px; font-weight: 800; line-height: 1;
  background: rgba(255,255,255,.18); border-radius: 8px; padding: 6px 12px;
}
.the-ma-so { font-size: 26px; font-weight: 700; letter-spacing: .02em; }
.the-can { text-align: right; }
.the-can-nhan { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; opacity: .8; }
.the-can-so { font-size: 24px; font-weight: 700; }
.the-can-ngay { font-size: 11px; opacity: .75; }
@media (max-width: 600px) {
  .the-chon { flex-direction: column; gap: 8px; }
  .the-can { text-align: left; }
}

/* ---------- Nhãn nhỏ & chữ phụ (dùng trong bảng lương) ---------- */
.tag {
  display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px;
  font-weight: 600; background: #fffbeb; color: var(--amber);
}
.muted { color: var(--muted); font-size: 13px; }
.xoa-dong { font-size: 12px; color: var(--red); text-decoration: none; margin-left: 6px; }
.xoa-dong:hover { text-decoration: underline; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--sidebar-bg); color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 100;
}
#toast.show { opacity: 1; }

/* iPad dọc & laptop nhỏ: thanh bên hẹp lại 170px, chữ nhỏ hơn → phần nội dung rộng thêm */
@media (max-width: 1100px) and (min-width: 901px) {
  .sidebar { width: 170px; }
  #nav button { font-size: 13px; padding: 8px 10px; }
  .brand { padding: 14px 10px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
  .page-head h1 { font-size: 20px; }
}
/* Điện thoại / iPad mini dọc: thanh bên nằm trên thành dải nút ngang, nội dung chiếm hết bề rộng */
@media (max-width: 900px) {
  .kanban { grid-template-columns: 1fr; }
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  #nav { flex-direction: row; flex-wrap: wrap; }
  #nav button { font-size: 12.5px; padding: 7px 9px; }
  .brand { padding: 10px 12px; }
  #online-users, .sidebar-footer .u-role { display: none; }   /* bớt chỗ trên màn nhỏ */
  .form-row { flex-direction: column; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .card .value { font-size: 20px; }
  .page-head { flex-wrap: wrap; gap: 8px; }
  .page-head .actions { flex-wrap: wrap; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .khung-cuon { max-height: none; }   /* điện thoại cuộn cả trang tự nhiên hơn khung trong khung */
  .co-pop .pop { left: auto; right: 0; max-width: 92vw; }
}

/* Chip ổ con chưa tách mẹ trên sơ đồ trại */
/* Khoảng hở giữa các cụm chuồng trong một khối (giống lối đi ngoài trại thật) */
.cum-cach { height: 8px; border-bottom: 2px solid #cbd5e1; margin: 1px 2px 5px; }
.chip.o-con-chip { background: #fef3c7; color: #92400e; border: 1px dashed #d97706; }
.chip.o-con-chip.canh-bao { background: #fee2e2; color: var(--red); border-color: var(--red); }

/* ---------- Cây phả hệ: F0 (đàn gốc) trên cùng, các đời toả xuống ---------- */
.cay-chu-thich {
  background: #f8fafc; border: 1px solid var(--border); border-left: 3px solid var(--primary);
  border-radius: 8px; padding: 10px 14px; margin-bottom: 16px;
  font-size: 12.5px; color: var(--muted); line-height: 1.65;
}
.cay-chu-thich b { color: var(--text); }

.cay-hop {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.cay-tieu-de { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.cay-tieu-de b { color: var(--text); font-size: 14px; }
.cay-cuon { overflow-x: auto; padding-top: 10px; }

.cay, .cay ul { list-style: none; margin: 0; padding: 0; }
.cay { width: max-content; min-width: 100%; }
.cay li { display: flex; flex-direction: column; align-items: center; position: relative; }

/* hàng các con: dàn ngang, canh giữa dưới cha/mẹ */
.cay ul { display: flex; justify-content: center; align-items: flex-start; gap: 10px; padding-top: 22px; position: relative; }
/* vạch dọc từ cha/mẹ xuống thanh ngang */
.cay ul::before { content: ""; position: absolute; top: 0; left: 50%; width: 1px; height: 22px; background: #c3cddd; }
/* thanh ngang nối các anh em */
.cay ul > li { padding-top: 22px; }
.cay ul > li::after { content: ""; position: absolute; top: 0; left: -5px; right: -5px; height: 1px; background: #c3cddd; }
.cay ul > li:first-child::after { left: 50%; }
.cay ul > li:last-child::after { right: 50%; }
.cay ul > li:only-child::after { display: none; }
/* vạch dọc từ thanh ngang xuống từng con */
.cay ul > li::before { content: ""; position: absolute; top: 0; left: 50%; width: 1px; height: 22px; background: #c3cddd; }

/* Ô cá thể — mọi ô cùng một cỡ để cây thẳng hàng */
.nut {
  box-sizing: border-box; cursor: pointer; width: 136px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s; text-align: left;
}
.nut:hover { border-color: var(--primary); box-shadow: 0 2px 6px rgba(37,99,235,.15); }
.nut.cai { border-left: 4px solid #1d4ed8; }   /* cái = lạnh */
.nut.duc { border-left: 4px solid #dc2626; }   /* đực = nóng */
.nut.het-doi { border-style: dashed; background: #fffdf5; }
.nut.ocon { border-left: 4px solid var(--amber); background: #fffbeb; cursor: default; }
.nut.ocon .doi { background: #fef3c7; color: #92400e; }
.nut-dau { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.nut-dau b { font-size: 14px; }
.doi {
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 99px;
  background: #eef2f8; color: #52627a; flex: 0 0 auto;
}
.nut.het-doi .doi { background: #fef3c7; color: #92400e; }
.nut-phu { font-size: 11px; color: var(--muted); margin-top: 1px; }
.nut-bo { font-size: 11px; color: #1d4ed8; margin-top: 1px; }
.nut-ocon { font-size: 11px; color: var(--amber); margin-top: 1px; }
.nut-mo-dong { font-size: 10.5px; color: #92400e; font-weight: 600; margin-top: 3px; }

.cay-roi { display: flex; flex-wrap: wrap; gap: 8px; }

/* Ô khớp từ khóa tìm kiếm trên cây */
.nut.tim-thay {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, .25);
  background: #fffbeb;
}

@media (max-width: 700px) {
  .cay-hop { padding: 12px 12px 14px; }
  .nut { width: 124px; }
  .cay-roi .nut { width: calc(50% - 4px); }
}


/* ---------- Bảng Thu - Chi: cân cột để không phải cuộn ngang trên máy tính ----------
   Chỗ thừa dồn hết cho Ghi chú; Số tiền luôn hiện; nút gọn thành biểu tượng. */
#tc-bang table { font-size: 13px; }
#tc-bang th, #tc-bang td { padding: 9px 7px; }
#tc-bang th:nth-child(1) { width: 34px; }                       /* STT */
#tc-bang th:nth-child(2) { width: 84px; }                       /* Ngày */
#tc-bang th:nth-child(3) { width: 50px; }                       /* Loại */
#tc-bang th:nth-child(4) { width: 14%; }                        /* Hạng mục — được xuống dòng */
#tc-bang th:nth-child(5) { width: 92px; }                       /* Nhóm (tên rút gọn) */
#tc-bang th:nth-child(6) { min-width: 170px; }                  /* Ghi chú — nhận hết chỗ thừa */
#tc-bang th:nth-child(7) { width: 104px; }                      /* Người ghi */
#tc-bang th:nth-child(8) { width: 106px; }                      /* Số tiền */
#tc-bang th:nth-child(9) { width: 68px; }                       /* Sửa / Xóa */
#tc-bang .btn.small { padding: 4px 7px; }
#tc-tong-hop th, #tc-tong-hop td { padding: 9px 10px; }
