:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #1d4ed8;
  --primary-2: #1e40af;
  --primary-soft: #e8efff;
  --good: #15803d;
  --good-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --topbar: 56px;
  --tabbar: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.05rem; }
.ic { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.text-good { color: var(--good); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }
.top-gap { margin-top: 12px; }

/* ---------- Khung ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar);
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--primary); color: #fff;
  padding-top: env(safe-area-inset-top);
}
.brand { color: #fff; font-weight: 700; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand:hover { text-decoration: none; }
.who { margin-left: auto; text-align: right; line-height: 1.2; min-width: 0; }
.who-name { display: block; font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.who-co { display: block; font-size: .75rem; opacity: .85; }
.icon-btn { background: none; border: 0; color: inherit; padding: 6px; border-radius: 8px; cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: rgba(255, 255, 255, .15); }
.shell { display: block; }
.sidenav {
  position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; width: 272px; max-width: 86vw;
  background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px 24px;
  overflow-y: auto; transform: translateX(-100%); transition: transform .2s ease;
}
body.nav-open .sidenav { transform: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .2); }
.scrim { display: none; }
body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, .35); }
.nav-sec { font-size: .72rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); }
.nav-link:hover { background: var(--bg); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.badge { margin-left: auto; background: var(--bad); color: #fff; font-size: .72rem; border-radius: 999px; padding: 1px 7px; }
.main { padding: 16px 14px calc(var(--tabbar) + 24px); max-width: 1240px; margin: 0 auto; }
.page-title { font-size: 1.3rem; margin: 4px 0 14px; }
.tabbar {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a, .tabbar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; background: none; border: 0; font-family: inherit; cursor: pointer; position: relative;
}
.tabbar a.active { color: var(--primary); font-weight: 600; }
.tabbar a:hover { text-decoration: none; }
.tabbar .ic { width: 22px; height: 22px; }
.dot { position: absolute; top: 6px; left: calc(50% + 6px); background: var(--bad); color: #fff; font-size: .65rem; border-radius: 999px; padding: 0 5px; }

@media (min-width: 960px) {
  .menu-btn { display: none; }
  .shell { display: grid; grid-template-columns: 248px 1fr; }
  .sidenav { position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); transform: none; width: auto; max-width: none; z-index: 1; }
  .tabbar, body.nav-open .scrim { display: none; }
  .main { padding: 22px 28px 40px; width: 100%; }
}

/* ---------- Thành phần ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card.narrow, form.narrow { max-width: 520px; }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: 14px; }
.form-card > summary.btn { display: inline-flex; }
.grid-2, .grid-3 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.grid-2.tight { gap: 10px; grid-template-columns: 1fr 1fr; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2, .grid-3 { margin-bottom: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; color: var(--ink-2); font-weight: 500; }
.label-text { font-size: .88rem; color: var(--ink-2); font-weight: 500; display: block; margin-bottom: 6px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.inline-label { flex-direction: row; align-items: center; gap: 6px; }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #cbd5e1; border-radius: 9px;
  padding: 9px 11px; min-height: 42px; width: 100%;
}
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600;
  border-radius: 9px; padding: 9px 16px; min-height: 42px; border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  text-decoration: none !important;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--bad-bg); color: var(--bad); }
.btn-small { padding: 5px 11px; min-height: 34px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.row-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sticky-actions { position: sticky; bottom: calc(var(--tabbar) + 8px); background: var(--bg); padding: 8px 0; z-index: 5; }
@media (min-width: 960px) { .sticky-actions { bottom: 0; } }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar select, .toolbar input[type=search], .toolbar input[type=date] { width: auto; min-width: 140px; flex: 1 1 160px; max-width: 260px; }
.toolbar .btn { flex: none; }
form.inline { display: inline; }
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; display: flex; gap: 8px; align-items: center; }
.flash-success { background: var(--good-bg); color: #14532d; }
.flash-error { background: var(--bad-bg); color: #7f1d1d; }
.flash-info { background: var(--info-bg); color: #0c4a6e; }
.pill { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.pill-good { background: var(--good-bg); color: var(--good); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-muted { background: #eef2f7; color: var(--muted); }
.empty { color: var(--muted); padding: 14px; text-align: center; background: var(--bg); border-radius: 10px; font-size: .9rem; }
.plain-list { list-style: none; margin: 0 0 10px; padding: 0; }
.plain-list li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.plain-list li:last-child { border-bottom: 0; }
.plain-list.compact li { padding: 6px 0; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; margin: 0 0 12px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }
.section-title { font-size: 1.05rem; margin: 18px 0 10px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tab.active { color: var(--primary); border-color: var(--primary); }
.tab:hover { text-decoration: none; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.steps { padding-left: 20px; }
.steps li { margin-bottom: 6px; }

/* Số liệu */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; color: inherit; }
.stat-box.link:hover { border-color: var(--primary); text-decoration: none; }
.stat-box.warn { border-color: #f5c46b; background: #fffbeb; }
.stat { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.stat-sm { font-size: 1.25rem; }
.stat-row { display: flex; gap: 22px; margin-bottom: 12px; }
.stat-row > div { display: flex; flex-direction: column; }

/* Bảng */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; background: #f8fafc; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .row-off td { background: #f8fafc; color: var(--muted); }
.tbl .row-today td { background: #fff7e6; }
.tbl .row-past td { color: var(--muted); }
.tbl .row-error td { background: #fff5f5; }
.tbl .edit-row td { background: var(--primary-soft); }
.tbl .detail { max-width: 360px; word-break: break-word; }

/* Chấm công */
.punch-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.punch-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.clock { font-size: 2.6rem; font-weight: 700; letter-spacing: .02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.net { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 12px; font-size: .85rem; }
.net b { display: block; }
.net span { display: block; opacity: .85; }
.net-ok { background: var(--good-bg); color: #14532d; }
.net-bad { background: var(--warn-bg); color: #78350f; }
.net .ic { width: 26px; height: 26px; }
.punch-times { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 16px 0; }
.punch-times > div { background: var(--bg); border-radius: 12px; padding: 10px 14px; display: flex; flex-direction: column; }
.punch-times strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.punch-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-punch { min-height: 64px; font-size: 1.15rem; border-radius: 14px; }
.hint { color: var(--warn); font-size: .88rem; margin: 10px 0 0; }
.today-logs { margin-top: 12px; font-size: .88rem; }
.today-logs summary { cursor: pointer; color: var(--muted); }
.today-logs ul { margin: 8px 0 0; padding-left: 18px; }
.quick-links { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .quick-links { grid-template-columns: repeat(3, 1fr); } }
.quick { display: flex; gap: 10px; align-items: center; padding: 12px; border-radius: 10px; background: var(--bg); color: var(--ink-2); }
.quick:hover { background: var(--primary-soft); text-decoration: none; }

/* Danh sách thẻ */
.cards-list { display: grid; gap: 10px; }
.item-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.decide { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.decide input { flex: 1 1 180px; min-height: 34px; padding: 5px 10px; }

/* Bảng công tháng */
.sheet-wrap { overflow: auto; max-height: 72vh; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; }
.sheet { border-collapse: separate; border-spacing: 0; font-size: .8rem; }
.sheet th, .sheet td { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 3px; text-align: center; white-space: nowrap; }
.sheet thead th { position: sticky; top: 0; background: #f8fafc; z-index: 2; font-weight: 600; color: var(--ink-2); min-width: 34px; }
.sheet thead th small { font-weight: 400; color: var(--muted); }
.sheet .sticky { position: sticky; left: 0; background: var(--surface); text-align: left; padding: 6px 10px; min-width: 190px; z-index: 1; }
.sheet thead .sticky { z-index: 3; background: #f8fafc; }
.sheet th.we { background: #eef2f7; }
.sheet th.hol { background: #e8efff; color: var(--primary); }
.sheet .tot { background: #fbfcfe; min-width: 52px; font-weight: 600; }
.sheet .tot.strong, .sheet th.strong { background: var(--primary-soft); color: var(--primary); }
.sheet .grp td { background: #eef2f7; font-weight: 700; text-align: left; }
.c { min-width: 34px; font-weight: 600; }
.c-ok { color: var(--good); }
.c-leave { color: #6d28d9; background: #f5f3ff; }
.c-holiday { color: var(--primary); background: #eef4ff; }
.c-absent { color: var(--bad); background: #fff1f1; }
.c-missing { color: var(--warn); background: #fff8e6; }
.c-off { background: #f6f7f9; }
.c-offwork { color: #0e7490; background: #ecfeff; }
.c-na { background: repeating-linear-gradient(45deg, #fafafa, #fafafa 4px, #f1f5f9 4px, #f1f5f9 8px); }
.c-late { box-shadow: inset 0 -3px 0 #f59e0b; }
.c-today { outline: 2px solid var(--primary); outline-offset: -2px; }
.sym { display: inline-block; min-width: 26px; text-align: center; font-weight: 700; padding: 0 4px; border-radius: 6px; }
.sym-ok { color: var(--good); background: var(--good-bg); }
.sym-leave { color: #6d28d9; background: #f5f3ff; }
.sym-holiday { color: var(--primary); background: #eef4ff; }
.sym-absent { color: var(--bad); background: var(--bad-bg); }
.sym-missing { color: var(--warn); background: var(--warn-bg); }
.sym-offwork { color: #0e7490; background: #ecfeff; }
.sym-today, .sym-off, .sym-future, .sym-na { color: var(--muted); }
.sym.late { box-shadow: inset 0 -3px 0 #f59e0b; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); margin: 6px 0 16px; }

/* Sinh nhật */
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border-radius: 999px; padding: 6px 12px; font-size: .88rem; }
.chip-today { background: #fff1d6; color: #7c2d12; }
.chip .ic { width: 16px; height: 16px; }

.bd-list { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.bd-item { display: flex; gap: 14px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.bd-item:last-child { border-bottom: 0; }
.bd-item.is-today { background: #fff7e6; }
.bd-item.is-past { opacity: .62; }
.bd-date { flex: none; width: 74px; text-align: center; background: var(--primary-soft); color: var(--primary); border-radius: 10px; padding: 6px 4px; display: flex; flex-direction: column; line-height: 1.2; }
.bd-date b { font-size: 1.1rem; }
.bd-date span { font-size: .72rem; }
.is-today .bd-date { background: #f59e0b; color: #fff; }
.bd-main { flex: 1; min-width: 0; }
.bd-phone { flex: none; font-size: .88rem; }
@media (max-width: 520px) { .bd-phone { display: none; } }
.nowrap { white-space: nowrap; }
.tbl-compact th, .tbl-compact td { padding: 8px 10px; }

/* Cấu hình */
.week-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.beacon { margin-top: 12px; padding: 12px; background: var(--bg); border-radius: 10px; }
.beacon p { margin: 0 0 8px; }
.dept-row { display: grid; grid-template-columns: 1fr 70px auto auto auto; gap: 6px; align-items: center; margin-bottom: 6px; }
.dept-row input { min-height: 36px; padding: 6px 8px; }
.lockbar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }

/* Đăng nhập */
.bare { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 20px 16px; }
.bare.wide { display: block; max-width: 860px; margin: 0 auto; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px 22px; box-shadow: 0 10px 40px rgba(15, 23, 42, .08); text-align: center; }
.login-card form { text-align: left; margin: 18px 0 12px; }
.login-card h1 { font-size: 1.35rem; margin-bottom: 4px; }
.login-logo { width: 56px; height: 56px; border-radius: 16px; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.login-logo .ic { width: 30px; height: 30px; }
.bare > .flash { width: 100%; max-width: 380px; }
