:root {
  --navy: #1f3864; --navy2: #2f5597; --ink: #1d2433; --muted: #6b7486; --line: #dfe4ee; --line2: #c7d0e0;
  --bg: #f4f6fa; --card: #fff; --soft: #eef3fb; --input: #fffbea; --ok: #1e7b34; --warn: #b45309; --danger: #c0392b;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--navy2); text-decoration: none; }
h1 { font-size: 22px; margin: 4px 0; color: var(--navy); }
h2 { font-size: 15px; margin: 0; color: var(--navy); }
h3 { font-size: 14px; margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.sm { font-size: 12px; }
.strong, .b { font-weight: 700; }
.err { color: var(--danger); }
.nowrap { white-space: nowrap; }
input, select, button { font: inherit; color: inherit; }
input, select {
  border: 1px solid var(--line2); border-radius: 7px; padding: 7px 9px; background: #fff; min-width: 0;
}
input:focus, select:focus { outline: 2px solid #9cb6e6; outline-offset: 0; border-color: var(--navy2); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line2); background: #fff;
  border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; color: var(--ink);
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.danger, .ib.danger { color: var(--danger); }
.ib { border: 0; background: transparent; cursor: pointer; padding: 3px 6px; border-radius: 5px; color: var(--muted); }
.ib:hover { background: var(--soft); color: var(--ink); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: #fff; padding: 32px 28px; border-radius: 14px; box-shadow: var(--shadow); width: 100%; max-width: 360px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 6px 0 0; }
.login-card p { margin: 0; }
.brand-mark { width: 52px; height: 52px; border-radius: 12px; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; margin: 0 auto; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 8px; margin: 0; }

/* topbar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; padding: 10px 20px; background: #fff; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--navy); }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.topbar nav a.active, .topbar nav a:hover { background: var(--soft); color: var(--navy); }

.page { max-width: 1180px; margin: 0 auto; padding: 20px; }
.page.wide { max-width: 1500px; }
.page.narrow { max-width: 760px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; }
.head-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.back { font-size: 13px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.check { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; cursor: pointer; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.empty.sm { padding: 14px; font-size: 13px; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafbfd; white-space: nowrap; }
.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid .num { text-align: right; }
.grid .actions { text-align: right; white-space: nowrap; }
.grid .actions .btn { margin-left: 4px; }

/* editor */
.info { padding: 14px 16px; margin-bottom: 14px; }
.info-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px 14px; }
.fld { display: grid; gap: 4px; }
.fld > span { font-size: 12px; color: var(--muted); font-weight: 600; }
.fld input, .fld select { width: 100%; }
.info .fld input { background: var(--input); }
.save-state { font-size: 13px; color: var(--muted); min-width: 90px; text-align: right; }
.save-state.ok { color: var(--ok); }
.save-state.warn { color: var(--warn); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.warn { background: var(--warn); }

/* ===== chấm công ===== */
.chip { white-space: nowrap; border: 1px solid var(--line2); background: #fff; border-radius: 99px; padding: 5px 11px; font-size: 13px; cursor: pointer; font-weight: 600; color: var(--ink); display: inline-flex; gap: 6px; align-items: center; }
.chip:hover { border-color: var(--navy2); }
.chip.on { outline: 2px solid var(--navy); outline-offset: 1px; }
.dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; gap: 5px; align-items: center; }

/* lưới phân ca / bảng công: cột tên dính bên trái */
.mx-wrap { overflow: auto; max-height: calc(100vh - 210px); }
table.mx { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.mx th, .mx td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 0; }
.mx thead th { position: sticky; top: 0; z-index: 3; background: #fafbfd; font-size: 12px; color: var(--muted); padding: 6px 4px; text-align: center; white-space: nowrap; }
.mx thead th.we { color: var(--danger); }
.mx th.name, .mx td.name { position: sticky; left: 0; z-index: 2; background: #fff; text-align: left; padding: 6px 10px; min-width: 190px; max-width: 230px; }
.mx thead th.name { z-index: 4; background: #fafbfd; }
.mx td.name .sub { font-size: 11px; color: var(--muted); }
.mx tr.grp td { background: var(--soft); font-weight: 700; color: var(--navy); padding: 5px 10px; position: sticky; left: 0; }
.mx tfoot td { position: sticky; bottom: 0; background: #fafbfd; font-size: 11px; color: var(--muted); text-align: center; padding: 4px 2px; z-index: 1; }
.mx tfoot td.name { z-index: 3; }
.mx td.tot { text-align: right; padding: 6px 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mx td.tot.b { color: var(--navy); }

.sc { min-width: 92px; height: 38px; cursor: pointer; user-select: none; vertical-align: middle; padding: 3px !important; }
.sc:hover { background: var(--soft); }
.sc.today { box-shadow: inset 0 0 0 2px #9cb6e6; }
.tag { display: inline-block; border-radius: 5px; color: #fff; font-size: 11px; font-weight: 700; padding: 2px 5px; margin: 1px; line-height: 1.3; white-space: nowrap; }

.tc { position: relative; min-width: 46px; text-align: center; cursor: pointer; height: 36px; font-variant-numeric: tabular-nums; }
.tc:hover { outline: 2px solid var(--navy2); outline-offset: -2px; }
.tc .h { font-weight: 700; }
.tc .c { font-size: 10px; color: var(--muted); }
.st-ok { background: #fff; }
.st-late, .st-early, .st-late_early { background: #fff2dd; }
.st-missing_in, .st-missing_out { background: #fde4e1; }
.st-absent { background: #eceff4; color: #8a93a5; }
.st-auto { background: #e4ecfb; }
.st-extra { box-shadow: inset 0 -3px 0 #c084fc; }
.st-ov { box-shadow: inset 3px 0 0 var(--ok); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-h { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-b { padding: 14px 18px; display: grid; gap: 12px; }
.modal-f { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.shift-box { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; display: grid; gap: 8px; }
.shift-box .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.shift-box .row .fld { width: 120px; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 12px; font-size: 13px; }
.kv b { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 2px 8px; background: var(--soft); color: var(--navy); }
.badge.warn { background: #fff2dd; color: var(--warn); }
.badge.bad { background: #fde4e1; color: var(--danger); }
.badge.ok { background: #e3f4e8; color: var(--ok); }

.panel { padding: 16px; margin-bottom: 14px; }
.panel h2 { margin-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 0; }
pre.code { background: #10182a; color: #e6edf7; border-radius: 8px; padding: 12px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.drop { border: 2px dashed var(--line2); border-radius: 10px; padding: 26px; text-align: center; cursor: pointer; background: #fafbfd; }
.drop.over { border-color: var(--navy2); background: var(--soft); }
.preview { max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.preview table { border-collapse: collapse; font-size: 12px; }
.preview td, .preview th { border: 1px solid var(--line); padding: 3px 6px; white-space: nowrap; }
.preview tr.hdr td { background: #e4ecfb; font-weight: 700; }
td input.inl { width: 100%; border-color: transparent; background: transparent; padding: 5px 6px; }
td input.inl:hover { border-color: var(--line2); }
td input.inl:focus { background: #fff; }
input[type=color] { padding: 2px; width: 44px; height: 32px; }

@media (max-width: 720px) {
  .topbar { padding: 8px 12px; gap: 10px; }
  .topbar .brand span:last-child { display: none; }
  .page { padding: 14px 12px; }
  .kv { grid-template-columns: repeat(2, 1fr); }
  .mx th.name, .mx td.name { min-width: 130px; }
}
.tc .ot { color: #0e7490; font-size: 10px; }
.tc .ot.wait { text-decoration: underline wavy #b45309; }

/* phân quyền, đề xuất, chốt công */
.nbadge { display: inline-block; min-width: 18px; padding: 1px 5px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 11px; line-height: 16px; text-align: center; margin-left: 2px; }
.mx td.sc.lock { background: repeating-linear-gradient(135deg, #f6f7fa 0 6px, #eef0f5 6px 12px); cursor: not-allowed; }
.tc .pend { position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: #e3f4e8; color: var(--ok); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: #fff2dd; color: var(--warn); }
.req-box { border: 1px dashed #f59e0b; background: #fffbeb; border-radius: 8px; padding: 8px 10px; margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.req-box .grow { min-width: 160px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 8px 12px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--navy); }
.grid td.hi { color: var(--danger); font-weight: 700; }
.grid td.wrap { white-space: normal; max-width: 520px; }
.grid.rep th { white-space: normal; vertical-align: bottom; }
.grid.rep td:first-child { white-space: nowrap; }
