/* HRM v2 — admin (desktop-first). Không framework. */
:root {
  --primary: #1e3a5f; --primary-hover: #2d5282; --bg: #f0f4f8; --card: #ffffff;
  --text: #2d3748; --muted: #718096; --border: #e2e8f0;
  --success: #38a169; --danger: #e53e3e; --warning: #d69e2e;
  --radius: 8px; --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --sidebar: 240px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); }
h1, h2, h3 { margin: 0 0 .75rem; line-height: 1.3; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }
[x-cloak] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.req { color: var(--danger); }

/* ── Layout ─────────────────────────────────────────── */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--primary); color: #fff; padding: 20px 12px; overflow-y: auto; z-index: 900; }
.brand { font-size: 22px; font-weight: 700; letter-spacing: .04em; padding: 0 12px 20px; }
.sidebar nav a { display: block; color: rgba(255, 255, 255, .85); text-decoration: none; padding: 10px 12px; border-radius: 6px; margin-bottom: 2px; }
.sidebar nav a:hover { background: var(--primary-hover); color: #fff; }
.sidebar nav a.active { background: var(--primary-hover); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 #90cdf4; }
.main { margin-left: var(--sidebar); min-height: 100vh; }
.topbar { display: flex; align-items: center; gap: 16px; height: 56px; padding: 0 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 800; }
.topbar-title { font-weight: 600; font-size: 16px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user form { margin: 0; }
.hamburger { display: none; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--primary); padding: 4px 8px; }
.backdrop { display: none; }
.content { padding: 24px; max-width: 1280px; }

/* ── Cards / stats ──────────────────────────────────── */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 20px; border-top: 3px solid var(--primary); }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; }
.notice { background: #fffaf0; border: 1px solid #fbd38d; border-radius: var(--radius); padding: 10px 14px; margin: 0 0 16px; }

/* ── Tables ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f7fafc; font-weight: 600; }
.table tbody tr:nth-child(even) { background: #fafbfc; }
.table tbody tr:hover { background: #edf2f7; }
.table tfoot th { background: #f7fafc; color: var(--text); font-size: 14px; text-transform: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; white-space: normal; }
.table-compact th, .table-compact td { padding: 6px 8px; }
.row-muted { opacity: .6; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; padding-top: 16px; }

/* ── Badges ─────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #edf2f7; color: var(--muted); }
.badge-dang_lam { background: #c6f6d5; color: #22543d; }
.badge-hoan_thanh, .badge-active { background: #e2e8f0; color: #2d3748; }
.badge-sua_gio { background: #fefcbf; color: #744210; }
.badge-da_xoa, .badge-inactive { background: #fed7d7; color: #822727; }

/* ── Toolbar ────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.toolbar-right { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
.search input[type=search] { width: 280px; }

/* ── Forms ──────────────────────────────────────────── */
.form-card { max-width: 860px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.field { margin-bottom: 16px; }
.field label, .field > .label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input, select, textarea { font: inherit; color: inherit; }
.field input, .field select, .field textarea, .search input, .search select, .input-unit input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; min-height: 38px; }
.search input, .search select { width: auto; }
.field input:focus, .field select:focus, .field textarea:focus, .search input:focus, .search select:focus, .input-unit input:focus {
  outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.err { color: var(--danger); font-size: 12px; margin-top: 4px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; border: 1px solid var(--border); border-radius: 6px; padding: 12px; max-height: 280px; overflow-y: auto; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400 !important; cursor: pointer; }
.check input { width: auto; min-height: 0; }
.inline-field { display: grid; grid-template-columns: 1fr 180px; align-items: center; gap: 12px; }
.inline-field .err { grid-column: 2; }
.input-unit { display: flex; align-items: center; gap: 8px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset[disabled] input, fieldset[disabled] select { background: #f7fafc; }
form.inline { display: inline; margin: 0; }

/* ── Buttons ────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 36px; border-radius: 6px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c53030; }
.btn-secondary { background: #edf2f7; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-link { background: none; color: var(--primary); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Flash ──────────────────────────────────────────── */
.flash { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; margin: 16px 24px 0; border-radius: 6px; font-weight: 500; }
.card .flash, .login-card .flash, .modal .flash { margin: 0 0 16px; }
.flash button { border: 0; background: none; font-size: 18px; cursor: pointer; color: inherit; }
.flash-success { background: #c6f6d5; color: #22543d; border: 1px solid #9ae6b4; }
.flash-error { background: #fed7d7; color: #822727; border: 1px solid #feb2b2; }
#toast { position: fixed; right: 24px; bottom: 24px; margin: 0; z-index: 1100; box-shadow: var(--shadow); }
#toast[hidden] { display: none; }

/* ── Modal ──────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(26, 32, 44, .5); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; z-index: 1000; overflow-y: auto; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0, 0, 0, .2); width: 100%; max-width: 460px; padding: 20px; }
.modal-wide { max-width: 680px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-close { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); }
.audit { border-top: 1px solid var(--border); padding: 12px 0; }
.audit-head { margin-bottom: 4px; }

/* ── Login / error ──────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 36px 32px; width: 100%; max-width: 400px; text-align: center; }
.login-card h1 { font-size: 18px; }
.login-logo { display: inline-flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 16px; background: var(--primary); color: #fff; font-weight: 700; font-size: 20px; margin-bottom: 16px; }
.tg-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 48px; padding: 0 24px; margin: 20px 0 12px; border-radius: 24px; background: #54a9eb; color: #fff; font-size: 16px; font-weight: 600; text-decoration: none; }
.tg-btn:hover, .tg-btn:focus-visible { background: #3d97dc; color: #fff; text-decoration: none; }
.tg-btn svg { flex: none; }
.login-switch { color: var(--primary); font-size: 13px; }

/* ── Mobile ─────────────────────────────────────────── */
@media (max-width: 1024px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .nav-open .sidebar { transform: none; }
  .nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 850; }
  .main { margin-left: 0; }
  .hamburger { display: block; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-user span { display: none; }
  .content { padding: 16px 12px; }
  .flash { margin: 12px 12px 0; }
  .grid-2 { grid-template-columns: 1fr; }
  .search input[type=search] { width: 100%; }
  .inline-field { grid-template-columns: 1fr; }
  .inline-field .err { grid-column: 1; }
  .card { padding: 16px 12px; }
}
@media (max-width: 480px) { .stats { grid-template-columns: 1fr; } }

/* ── G4 Super Admin ─────────────────────────────────────────────────────── */
.brand small { display: block; font-size: 12px; font-weight: 600; letter-spacing: .02em; color: #90cdf4; margin-top: 2px; }
.sidebar nav .nav-sep { border-top: 1px solid rgba(255, 255, 255, .15); margin: 12px 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.tab { padding: 6px 12px; border-radius: 999px; background: var(--border); color: var(--text); text-decoration: none; font-size: 14px; }
.tab:hover { background: #cbd5e0; }
.tab.active { background: var(--primary); color: #fff; }
.tab-count { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: rgba(0, 0, 0, .08); font-size: 12px; text-align: center; }
.tab.active .tab-count { background: rgba(255, 255, 255, .2); }
.badge-t-active { background: #c6f6d5; color: #22543d; }
.badge-t-expired { background: #fefcbf; color: #744210; }
.badge-t-locked { background: #fed7d7; color: #822727; }
.badge-t-pending { background: #e9d8fd; color: #44337a; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.meter { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.meter > span { display: block; height: 100%; background: var(--primary); }
.extend-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.extend-form label { width: 100%; font-weight: 600; }
.extend-form input { width: 110px; }
.extend-form .hint { width: 100%; margin: 0; }

/* ── Sau G5: duyệt đơn nghỉ (/leave) + chuyển vai ─────────────────────────── */
.badge-cho_duyet { background: #fefcbf; color: #744210; }
.badge-duyet { background: #c6f6d5; color: #22543d; }
.badge-tu_choi { background: #fed7d7; color: #822727; }
.table td.wrap { white-space: normal; min-width: 160px; max-width: 320px; }
.decide { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.decide input[type=text] { min-width: 150px; padding: 4px 8px; min-height: 30px; font-size: 13px; }

/* ── /register (29/11) ─────────────────────────────────────────────────────── */
.reg-who { display: flex; align-items: center; gap: 12px; text-align: left; background: var(--bg, #f0f4f8); border-radius: var(--radius); padding: 10px 12px; margin: 16px 0; }
.reg-avatar { flex: none; width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.reg-avatar-empty { display: inline-flex; align-items: center; justify-content: center; background: var(--primary); color: #fff; font-weight: 700; font-size: 22px; }
.reg-who-text { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.reg-form { text-align: left; }
.reg-submit { width: 100%; min-height: 44px; font-size: 15px; }
.reg-options { text-align: left; background: #fffaf0; border: 1px solid #fbd38d; border-radius: var(--radius); padding: 4px 14px; margin: 12px 0; }
.reg-plans { border: 0; padding: 0; margin: 0 0 16px; }
.reg-plans legend { padding: 0; margin-bottom: 8px; font-weight: 600; font-size: 13px; }
.reg-plan { display: flex; align-items: center; gap: 10px; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.reg-plan:has(input:checked) { border-color: var(--primary); background: #ebf4ff; }
.reg-plan input { margin: 0; accent-color: var(--primary); }
.reg-plan-body { display: flex; flex-direction: column; }
.has-error.reg-plans .reg-plan { border-color: var(--danger); }
.badge-t-trial { background: #bee3f8; color: #2a4365; }
.extend-form .check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 8px 0; font-weight: normal; }

/* ── /stores (29/11) ──────────────────────────────────────────────────────── */
.badge-gps-ok { background: #c6f6d5; color: #22543d; }
.badge-gps-no { background: #fefcbf; color: #744210; }
.gps-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.bk-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
form.inline { display: inline; }
.gps-notice a { font-weight: 600; }

/* ── Kết nối Telegram nhân viên (29/11) ───────────────────────────────────── */
.badge-tg-ok { background: #c6f6d5; color: #22543d; }
.badge-tg-wait { background: #bee3f8; color: #2a4365; }
.tg-link-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin: 8px 0 12px; }
.tg-qr { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.tg-link-box { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.tg-url { width: 100%; font-family: ui-monospace, monospace; font-size: 13px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius); }

/* 29/11/2026: ghi chú đi muộn / về sớm (services/payroll.py) */
.late-note { color: #9c4221; font-size: 12px; white-space: nowrap; }
