:root {
  --ink: #16261c;
  --muted: #5b6b60;
  --line: #dde5df;
  --line-2: #e6ece7;
  --bg: #f3f6f3;
  --card: #fff;
  --green: #1f6b3a;
  --green-deep: #123524;
  --green-soft: #e3f1e8;
  --green-ink: #14502a;
  --amber-soft: #fcebd6;
  --amber-ink: #7a4306;
  --red-soft: #fbe4e1;
  --red-ink: #8e2418;
  --red-row: #fdf4f3;
  --radius: 14px;
  font-family: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid #2e8b57; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100vh; display: flex; flex-wrap: wrap; }
.login-hero { flex: 1 1 420px; background: var(--green-deep); color: #eaf3ec; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; }
.login-hero h1 { font-size: 34px; line-height: 1.2; color: #fff; letter-spacing: -0.01em; }
.login-hero p { margin: 16px 0 0; color: #cfe3d5; font-size: 16px; line-height: 1.6; max-width: 460px; }
.login-form-wrap { flex: 1 1 420px; display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 22px; }
.login-form form { display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: #2e8b57; display: grid; place-items: center; flex: none; }
.brand b { display: block; color: #fff; font-size: 16px; line-height: 1.25; }
.brand span { display: block; font-size: 12px; color: #b9d3c1; }

/* ---------- Khung ứng dụng ---------- */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--green-deep); color: #eaf3ec; padding: 24px 16px; display: flex; flex-direction: column; gap: 6px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 4px 8px 22px; }
.nav-link { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 10px; font-size: 14px; font-weight: 500; color: #cfe3d5; min-height: 44px; background: none; border: 0; width: 100%; text-align: left; }
.nav-link:hover { background: rgba(255, 255, 255, 0.08); }
.nav-link[aria-current="page"] { background: rgba(255, 255, 255, 0.14); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 14px 12px 0; border-top: 1px solid rgba(255, 255, 255, 0.14); display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #b9d3c1; }
.sidebar-foot strong { color: #fff; font-size: 14px; }
.sidebar-foot .linkish { background: none; border: 0; padding: 8px 0 0; color: #cfe3d5; text-align: left; text-decoration: underline; font-size: 13px; min-height: 36px; }
.main { padding: 28px 36px 48px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.topbar, .bottom-nav { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.page-head .sub { display: block; margin-top: 4px; font-size: 14px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* ---------- Nút, ô nhập ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px; border-radius: 10px; border: 1px solid #c9d5cc; background: #fff; font-size: 14px; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f8faf8; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: #195a30; }
.btn.danger { color: var(--red-ink); border-color: #f0bdb6; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.icon { width: 18px; height: 18px; flex: none; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: #44564a; }
.field input, .field select, .input { min-height: 44px; padding: 0 12px; border: 1px solid #c9d5cc; border-radius: 10px; background: #fff; font-size: 15px; font-weight: 400; color: var(--ink); width: 100%; }
.login-form .field input { min-height: 48px; padding: 0 14px; }
.form-msg { min-height: 20px; font-size: 14px; color: var(--red-ink); }
.form-msg.ok { color: var(--green-ink); }

/* ---------- Thẻ, chip ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.card h2 { font-size: 17px; font-weight: 700; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.stat .k { font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
.stat .v { font-size: 30px; font-weight: 700; line-height: 1.1; }
.stat .n { font-size: 13px; color: var(--muted); }
.stat.good { background: var(--green-soft); border-color: #bcdcc8; }
.stat.good .k, .stat.good .v { color: var(--green-ink); }
.stat.bad { background: var(--red-soft); border-color: #f0bdb6; }
.stat.bad .k, .stat.bad .v { color: var(--red-ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot, #888); flex: none; display: inline-block; }
.dot.sm { width: 6px; height: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--bg, #eee); color: var(--fg, #333); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip .ico { width: 13px; height: 13px; }
.chip.ok { --bg: var(--green-soft); --fg: var(--green-ink); }
.chip.wait { --bg: var(--amber-soft); --fg: var(--amber-ink); }
.chip.err { --bg: var(--red-soft); --fg: var(--red-ink); }
.chip.gray { --bg: #e6ece7; --fg: #44564a; }
.chip.lg { padding: 5px 12px; font-size: 13px; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.cols > * { min-width: 0; }
.muted { color: var(--muted); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); border: 1px dashed #c9d5cc; border-radius: 12px; font-size: 14px; }
.loading { padding: 28px; text-align: center; color: var(--muted); }
.alert { padding: 12px 16px; border-radius: 12px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.alert.err { background: var(--red-soft); color: var(--red-ink); }
.alert.warn { background: var(--amber-soft); color: var(--amber-ink); }
.alert.info { background: var(--green-soft); color: var(--green-ink); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* ---------- Lọc ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1.5px solid var(--dot, #c9d5cc); background: var(--bg, #fff); color: var(--fg, var(--ink)); font-size: 14px; font-weight: 600; }
.chip-btn[aria-pressed="false"] { --bg: #fff; --fg: var(--muted); border-color: #c9d5cc; }
.seg { display: inline-flex; background: #e6ece7; border-radius: 10px; padding: 3px; }
.seg button { min-height: 40px; padding: 0 18px; border: 0; border-radius: 8px; background: transparent; font-size: 14px; font-weight: 600; }
.seg button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; align-items: end; }

/* ---------- Lịch ---------- */
.cal-wrap { flex: 3 1 620px; overflow: hidden; padding: 0; }
.cal-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--bg); border-bottom: 1px solid var(--line); }
.cal-head div { padding: 12px 10px; font-size: 13px; font-weight: 600; color: #44564a; text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-cell { all: unset; box-sizing: border-box; cursor: pointer; display: flex; flex-direction: column; gap: 4px; padding: 8px; min-height: 112px; background: #fff; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); min-width: 0; }
.cal-cell:focus-visible { outline: 3px solid #2e8b57; outline-offset: -3px; }
.cal-cell.other { background: #f8faf8; }
.cal-cell.sel { background: var(--green-soft); box-shadow: inset 0 0 0 2px var(--green); }
.cal-grid.week .cal-cell { min-height: 340px; }
.cal-num { align-self: flex-start; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 13px; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; }
.cal-cell.other .cal-num { color: #8a988e; }
.cal-cell.today .cal-num { background: var(--green); color: #fff; }
.pill { display: flex; align-items: center; gap: 6px; padding: 3px 7px; border-radius: 6px; background: var(--bg); color: var(--fg); font-size: 12px; font-weight: 500; line-height: 1.3; min-width: 0; }
.pill span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-more { font-size: 12px; font-weight: 600; color: #44564a; padding-left: 4px; }
.cal-dots { display: none; gap: 3px; height: 6px; }
.day-panel { flex: 1 1 300px; max-width: 400px; display: flex; flex-direction: column; gap: 14px; }
.day-panel h2 { font-size: 18px; }
.task-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.task { border: 1px solid var(--line-2); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; background: #fff; }
.task .t { font-size: 15px; font-weight: 600; }
.task .m { font-size: 13px; color: var(--muted); }

/* ---------- Bảng ---------- */
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 880px; }
table.data th { text-align: left; background: var(--bg); color: #44564a; font-size: 13px; font-weight: 600; padding: 13px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
table.data th button:focus-visible { outline: 3px solid #2e8b57; }
table.data td { padding: 12px 16px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.data tr.row-bad td { background: var(--red-row); }
table.data .num { text-align: right; font-weight: 600; white-space: nowrap; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.pager .btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Tiến trình, bar ---------- */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
.steps li { flex: 1 1 220px; display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 13px 16px; font-size: 14px; font-weight: 600; color: #44564a; }
.steps li .n { width: 28px; height: 28px; border-radius: 50%; background: #e6ece7; display: inline-grid; place-items: center; font-size: 14px; font-weight: 700; flex: none; }
.steps li.done .n { background: var(--green); color: #fff; }
.steps li.cur { background: var(--green-soft); border: 2px solid var(--green); color: var(--green-ink); font-weight: 700; padding: 12px 15px; }
.steps li.cur .n { background: #fff; border: 2px solid var(--green); color: var(--green); }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.bars li { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr) auto; align-items: center; gap: 12px; font-size: 14px; }
.bar-track { height: 12px; border-radius: 6px; background: #e6ece7; }
.bar-fill { height: 12px; border-radius: 6px; background: var(--green); }
.unit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; border: 1px solid var(--line-2); border-radius: 12px; padding: 14px 16px; }
.unit-row .info { flex: 1 1 200px; min-width: 0; }
.unit-row b { display: block; font-size: 15px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.dropzone { border: 2px dashed #b5c6ba; border-radius: 16px; background: #fff; padding: 36px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.dropzone.over { background: var(--green-soft); border-color: var(--green); }
.dropzone input[type="file"] { max-width: 100%; }
.filecard { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
.filecard .ico-box { width: 44px; height: 44px; border-radius: 12px; background: var(--green-soft); display: grid; place-items: center; flex: none; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 18px; letter-spacing: 0.04em; padding: 10px 14px; background: #fff; border: 1px dashed var(--green); border-radius: 10px; display: inline-block; user-select: all; }

.toast { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); background: #16261c; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); }
.toast.err { background: var(--red-ink); }

/* ---------- Điện thoại ---------- */
@media (max-width: 860px) {
  .app { display: block; }
  .sidebar { display: none; }
  .topbar { display: flex; align-items: center; gap: 12px; background: var(--green-deep); color: #fff; padding: 12px 16px; position: sticky; top: 0; z-index: 20; }
  .topbar .brand-mark { width: 36px; height: 36px; border-radius: 10px; }
  .topbar b { display: block; font-size: 16px; line-height: 1.25; }
  .topbar span { display: block; font-size: 12px; color: #b9d3c1; }
  .main { padding: 14px 16px 92px; gap: 14px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: #fff; border-top: 1px solid var(--line); padding: 6px 4px calc(8px + env(safe-area-inset-bottom)); }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; font-size: 12px; font-weight: 600; color: var(--muted); }
  .bottom-nav a .pillbox { padding: 4px 16px; border-radius: 999px; display: flex; }
  .bottom-nav a[aria-current="page"] { color: var(--green-ink); font-weight: 700; }
  .bottom-nav a[aria-current="page"] .pillbox { background: var(--green-soft); }
  .page-head h1 { font-size: 22px; }
  .page-head .actions { width: 100%; }
  .login-hero { padding: 28px 24px; min-height: auto; gap: 20px; }
  .login-hero h1 { font-size: 26px; }
  .toast { bottom: 96px; }
  .cal-head div { padding: 8px 0; font-size: 12px; }
  .cal-cell { min-height: 50px; padding: 4px 2px; align-items: center; justify-content: center; gap: 3px; border-radius: 10px; border: 0; }
  .cal-cell .pill, .cal-cell .cal-more { display: none; }
  .cal-dots { display: flex; }
  .cal-num { align-self: center; font-size: 14px; }
  .cal-grid.week { display: block; }
  .cal-grid.week .cal-cell { min-height: 0; flex-direction: row; justify-content: flex-start; padding: 10px 12px; gap: 10px; border-bottom: 1px solid var(--line-2); border-radius: 0; align-items: center; }
  .cal-head.week { display: none; }
  .cal-wrap { flex-basis: 100%; }
  .day-panel { max-width: none; flex-basis: 100%; }
  /* bảng thành thẻ */
  table.data { min-width: 0; display: block; }
  table.data thead { display: none; }
  table.data tbody { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
  table.data tr { display: flex; flex-direction: column; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
  table.data tr.row-bad { background: var(--red-row); border-color: #f0bdb6; }
  table.data td { border: 0; padding: 0; display: flex; gap: 8px; justify-content: space-between; font-size: 14px; }
  table.data td::before { content: attr(data-label); color: var(--muted); font-size: 12px; flex: none; padding-top: 2px; }
  table.data td[data-label=""]::before, table.data td:not([data-label])::before { content: none; }
  table.data td.num { text-align: right; }
  table.data td:empty { display: none; } /* thẻ không hiện ô trống */
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters > :first-child, .filters > .btn { grid-column: 1 / -1; }
  .table-card { background: transparent; border: 0; }
  .table-card .pager { padding: 8px 0; }
  .bars li { grid-template-columns: 1fr auto; }
  .bars li .bar-track { grid-column: 1 / -1; order: 3; }
}
@media (max-width: 480px) {
  .stat .v { font-size: 26px; }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
