:root {
  --brand: #0f5c4d;
  --brand-strong: #0a4438;
  --brand-soft: #e6f2ef;
  --bg: #f4f6f8;
  --card: #fff;
  --text: #1c2733;
  --muted: #5b6b7c;
  --border: #dde3ea;
  --ok: #15803d;
  --ok-soft: #e8f6ed;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --info: #1d5fbf;
  --info-soft: #e9f1fc;
  --radius: 10px;
  --side: 232px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ===== Khung ===== */
.layout { display: flex; min-height: 100vh; }
.side {
  width: var(--side); background: #0d2b26; color: #d5e4e0; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.side .logo { padding: 16px 18px; font-weight: 700; font-size: 16px; color: #fff; display: flex; gap: 10px; align-items: center; }
.side .logo .mark { width: 30px; height: 30px; border-radius: 8px; background: #19a689; display: grid; place-items: center; font-size: 13px; }
.side .grp { padding: 14px 18px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #7fa39b; }
.side a {
  display: flex; align-items: center; gap: 10px; padding: 9px 18px; color: inherit; text-decoration: none; border-left: 3px solid transparent;
}
.side a:hover { background: rgba(255, 255, 255, .06); }
.side a.on { background: rgba(25, 166, 137, .18); border-left-color: #19a689; color: #fff; }
.side .badge { margin-left: auto; background: #e8a33d; color: #1c1300; border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 600; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  height: 54px; background: var(--card); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px;
  padding: 0 18px; position: sticky; top: 0; z-index: 20;
}
.top .title { font-weight: 600; font-size: 16px; }
.top .sp { flex: 1; }
.top .menu-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; position: relative; }
.user-chip:hover { background: var(--bg); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.dropdown { position: absolute; right: 0; top: 42px; background: var(--card); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); min-width: 220px; padding: 6px; z-index: 30; }
.dropdown button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.dropdown button:hover { background: var(--bg); }
.dropdown .who { padding: 8px 10px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.content { padding: 18px; max-width: 1280px; width: 100%; }
.scrim { display: none; }

@media (max-width: 960px) {
  .side { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .scrim.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .top .menu-btn { display: inline-flex; }
  .content { padding: 12px; }
  .top { padding: 0 10px; }
  .user-chip .uname { display: none; }
}

/* ===== Thành phần ===== */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card .card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card .card-head h3 { margin: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row > .auto { flex: 0 0 auto; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  height: 38px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px; background: #fff; width: 100%; outline: none;
}
textarea.input { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 92, 77, .12); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input[readonly], .input:disabled { background: #f6f8fa; color: var(--muted); }
.btn {
  height: 38px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; font-weight: 500; text-decoration: none; color: inherit;
}
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f1c4c4; }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.lg { height: 46px; font-size: 15px; padding: 0 20px; }
.btn.block { width: 100%; }
.btn.ghost { border-color: transparent; background: transparent; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.b { font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag.DANG_MO { background: var(--info-soft); color: var(--info); }
.tag.CHO_NHAN { background: var(--warn-soft); color: var(--warn); }
.tag.DA_NHAN, .tag.DA_CHOT { background: var(--ok-soft); color: var(--ok); }
.tag.TRA_LAI { background: var(--bad-soft); color: var(--bad); }
.tag.NHAP, .tag.HUY { background: #eef1f4; color: var(--muted); }
.tag.CHO_NOP { background: var(--warn-soft); color: var(--warn); }
.tag.DA_NOP { background: var(--ok-soft); color: var(--ok); }
tr.huy td { color: var(--muted); text-decoration: line-through; }
tr.huy td.keep { text-decoration: none; }
.flow { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0; margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); overflow: hidden; }
.flow > div { padding: 12px; border-right: 1px solid var(--border); position: relative; }
.flow > div:last-child { border-right: 0; }
.flow .k { font-size: 12px; color: var(--muted); min-height: 30px; }
.flow .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 4px; }
.flow .v.zero { color: var(--muted); font-weight: 400; }
.flow .end { background: var(--ok-soft); }
.grid-pb input.input { min-width: 64px; text-align: right; padding: 6px; }
.grid-pb td.over { background: var(--bad-soft); }
.presets { display: flex; gap: 6px; flex-wrap: wrap; }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 12px; border: 1px solid; }
.alert.err { background: var(--bad-soft); border-color: #f3c2c2; color: #8b1c1c; }
.alert.warn { background: var(--warn-soft); border-color: #f1d9ac; color: #7a3d03; }
.alert.info { background: var(--info-soft); border-color: #c5d9f5; color: #154685; }
.alert.ok { background: var(--ok-soft); border-color: #bfe3cb; color: #14532d; }

/* bảng */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.tbl th { background: #f7f9fb; font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; background: #f7f9fb; border-top: 2px solid var(--border); }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover { background: #f5faf8; }
.tbl tr.off td { color: #9aa7b4; }
.tbl input.input { height: 32px; }

/* thẻ số liệu */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.warn .v { color: var(--warn); }
.stat.ok .v { color: var(--ok); }
.stat.info .v { color: var(--info); }

/* tab */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

/* hộp thoại */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 25, 35, .45); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { max-width: 860px; }
.modal-h { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-h h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-b { padding: 16px; overflow-y: auto; }
.modal-f { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 600px) {
  .modal-bg { padding: 0; align-items: flex-end; }
  .modal { border-radius: 14px 14px 0 0; max-height: 92vh; }
}

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1c2733; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 200; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 92vw; }
.toast.err { background: var(--bad); }

/* đăng nhập */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0d2b26 0%, #0f5c4d 60%, #19a689 100%); }
.login { width: 100%; max-width: 380px; background: #fff; border-radius: 14px; padding: 28px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login .sub { color: var(--muted); margin-bottom: 20px; }

/* ===== Màn ca (ưu tiên điện thoại) ===== */
.ca-head { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.ca-head .it { background: var(--bg); border-radius: 8px; padding: 10px; }
.ca-head .it .k { font-size: 12px; color: var(--muted); }
.ca-head .it .v { font-weight: 700; font-size: 16px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.ke-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.ke-row { display: grid; grid-template-columns: 48px minmax(140px, 220px) 1fr; gap: 8px; align-items: center; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.ke-row .mg { font-weight: 700; }
.ke-row .stepper { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ke-row .stepper .btn { width: 36px; padding: 0; flex-shrink: 0; }
.ke-row .stepper .input { text-align: center; min-width: 56px; flex: 1; padding: 0 4px; }
.ke-row .stepper.off { opacity: .45; }
.ke-row .tt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.sum-bar { position: sticky; bottom: 0; background: #fff; border-top: 1px solid var(--border); padding: 10px 0 calc(10px + env(safe-area-inset-bottom)); margin-top: 12px; }
.sum-line { display: flex; justify-content: space-between; padding: 4px 0; }
.sum-line.big { font-size: 18px; font-weight: 700; }
.chi-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.chi-item .grow { flex: 1; min-width: 0; }
.chi-item:last-child { border-bottom: 0; }
.shift-list { display: flex; gap: 8px; flex-wrap: wrap; }
.shift-pill { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: #fff; cursor: pointer; min-width: 120px; }
.shift-pill.on { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(15,92,77,.15); }
.shift-pill .n { font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* in */
.print-only { display: none; }
@media print {
  .side, .top, .no-print, .scrim { display: none !important; }
  .print-only { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; }
  body { background: #fff; }
  .tbl th { position: static; }
}
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 0 14px; }
.bang-ke { font-size: 14px; }
.tag.CHI_TIET { background: var(--info-soft); color: var(--info); }
.tag.SO_TONG { background: var(--ok-soft); color: var(--ok); }
.tag.CHUA_KEO { background: var(--warn-soft); color: var(--warn); }
.kv-days { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.kv-day { border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px; background: #fff; min-height: 62px; }
.kv-day.co { cursor: pointer; border-color: var(--brand); }
.kv-day.co:hover { background: var(--ok-soft); }
.kv-day.loi { border-color: var(--bad); }
tr.off td { color: var(--muted); }
.tag.CHUA_GAN { background: #eef1f4; color: var(--muted); }
.chip { display: inline-block; padding: 2px 8px; margin: 2px 4px 2px 0; border: 1px solid var(--border); border-radius: 999px; background: #fff; }
.card.off { opacity: .6; }
