:root {
  --bg: #f6f7f5; --card: #ffffff; --ink: #1d2320; --muted: #66706b; --line: #e2e5e1;
  --brand: #1f6f4a; --brand-ink: #ffffff; --brand-soft: #e3f1ea;
  --danger: #b42318; --danger-soft: #fde8e6; --warn: #8a5a00; --warn-soft: #fff4d6; --ok: #1f6f4a;
  --c-O: #f8cbad; --c-half: #ffe699; --c-T: #bdd7ee; --c-S: #c6e0b4; --c-KP: #ff9c9e; --c-bo: #d9d9d9; --c-thieu: #e4dfec;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121513; --card: #1b1f1d; --ink: #e8ece9; --muted: #9aa49f; --line: #2c322f;
    --brand: #3fa877; --brand-ink: #0d1510; --brand-soft: #1c2d24;
    --danger: #ff8a7f; --danger-soft: #3a1d1a; --warn: #f2c25b; --warn-soft: #362b12;
    --c-O: #7a4b33; --c-half: #6b5a1c; --c-T: #2c4c6b; --c-S: #36532a; --c-KP: #7a2f31; --c-bo: #3b3b3b; --c-thieu: #463e57;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121513; --card: #1b1f1d; --ink: #e8ece9; --muted: #9aa49f; --line: #2c322f;
  --brand: #3fa877; --brand-ink: #0d1510; --brand-soft: #1c2d24;
  --danger: #ff8a7f; --danger-soft: #3a1d1a; --warn: #f2c25b; --warn-soft: #362b12;
  --c-O: #7a4b33; --c-half: #6b5a1c; --c-T: #2c4c6b; --c-S: #36532a; --c-KP: #7a2f31; --c-bo: #3b3b3b; --c-thieu: #463e57;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
.center { display: grid; place-items: center; min-height: 60vh; padding: 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.danger { color: var(--danger); }
.warn { color: var(--warn); }
.ok { color: var(--ok); }

/* Thanh trên */
.top { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); }
.top-row { display: flex; gap: 10px; align-items: center; padding: 10px 16px; flex-wrap: wrap; }
.brand { font-weight: 700; margin-right: auto; }
.brand small { font-weight: 400; color: var(--muted); }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 0 12px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 10px 12px; border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer; color: var(--muted); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; text-align: center; margin-left: 4px; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin: 0 0 10px; }
.card h3 { font-size: 15px; margin: 14px 0 8px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.banner.warn { background: var(--warn-soft); color: var(--ink); border: 1px solid var(--warn); }
.banner.ok { background: var(--brand-soft); border: 1px solid var(--brand); }
.banner.danger { background: var(--danger-soft); border: 1px solid var(--danger); }

/* Form */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 160px; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 4px; }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; }
input[type="file"] { padding: 6px; }
textarea { min-height: 64px; }
.btn { border: 1px solid var(--line); background: var(--card); padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 40px; white-space: nowrap; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.filters > * { flex: 1 1 180px; max-width: 280px; }

/* Bảng */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; background: var(--card); }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--bg); position: sticky; top: 0; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-soft); }
td.hl { background: var(--danger-soft); color: var(--danger); font-weight: 600; }

/* Lịch tháng */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 12px; color: var(--muted); text-align: center; }
.day { border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-height: 58px; background: var(--card); cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 2px; }
.day:disabled { cursor: default; }
.day .d { font-size: 12px; color: var(--muted); }
.day .c { font-weight: 700; font-size: 14px; }
.day .g { font-size: 11px; color: var(--muted); word-break: break-all; }
.day.O { background: var(--c-O); } .day.half { background: var(--c-half); } .day.T { background: var(--c-T); }
.day.S { background: var(--c-S); } .day.KP { background: var(--c-KP); } .day.bo { background: var(--c-bo); } .day.thieu { background: var(--c-thieu); }
.day.lo { outline: 2px solid var(--danger); }
.day.dc::after { content: "✎"; font-size: 11px; align-self: flex-end; margin-top: auto; }
.day.sel { box-shadow: 0 0 0 2px var(--brand); }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 8px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; }

/* Hộp thoại */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; display: grid; place-items: start center; overflow-y: auto; padding: 24px 12px; }
.modal[hidden] { display: none; }
.dialog { background: var(--card); border-radius: 14px; width: min(760px, 100%); padding: 16px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dialog-head { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 10px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 30; max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }
.login { max-width: 380px; margin: 10vh auto; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; border: 1px solid var(--line); white-space: nowrap; }
.pill.cho_duyet { background: var(--warn-soft); border-color: var(--warn); }
.pill.da_duyet { background: var(--brand-soft); border-color: var(--brand); }
.pill.tu_choi, .pill.da_huy { background: var(--bg); color: var(--muted); text-decoration: line-through; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 6px 0; border-bottom: 1px solid var(--line); }
@media (max-width: 600px) {
  main { padding: 12px; }
  .card { padding: 12px; }
  .day { min-height: 48px; } .day .g { display: none; }
  th, td { padding: 6px 8px; }
}
