:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #1f2333;
  --muted: #6b7080;
  --border: #e5e7ef;
  --primary: #4f46e5;
  --primary-50: #eef0ff;
  --side: #17182b;
  --side-text: #b9bcd3;
  --green: #12805c; --green-bg: #e3f6ee;
  --red: #c0352b;   --red-bg: #fde9e7;
  --amber: #a15c00; --amber-bg: #fff2dc;
  --blue: #1e5fbf;  --blue-bg: #e5efff;
  --gray-bg: #eef0f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20,22,40,.06), 0 2px 8px rgba(20,22,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 15px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); display: grid; place-items: center; font-weight: 800; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6f7290; padding: 14px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-text); }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--primary); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav .badge-count { margin-left: auto; background: #ef4444; color: #fff; border-radius: 99px; font-size: 11px; padding: 0 7px; }
.sidebar .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.sidebar .me .name { color: #fff; font-weight: 600; }
.sidebar .me button { margin-top: 8px; }
.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.menu-toggle { display: none; }

/* ---------- cards & grids ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card, .balance > .card { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: repeat(3, 1fr); }
.grid.four { grid-template-columns: repeat(4, 1fr); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .hint { color: var(--muted); font-size: 12px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: #fafbfd; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbff; }
table.compact th, table.compact td { padding: 10px 7px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }
.empty { padding: 34px; text-align: center; color: var(--muted); }
.person { display: flex; align-items: center; gap: 10px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-bg); color: var(--muted); text-transform: capitalize; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.purple { background: var(--primary-50); color: var(--primary); }

/* ---------- forms & buttons ---------- */
button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: #f4f5fa; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: #4338ca; }
button.danger { color: var(--red); }
button.danger:hover { background: var(--red-bg); }
button.success { background: var(--green); border-color: var(--green); color: #fff; }
button.sm, .btn.sm { padding: 4px 10px; font-size: 12.5px; }
button.ghost { background: transparent; border-color: transparent; }
button:disabled { opacity: .55; cursor: not-allowed; }
.sidebar button { background: transparent; color: var(--side-text); border-color: rgba(255,255,255,.15); }
.sidebar button:hover { background: rgba(255,255,255,.06); color: #fff; }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 12.5px; font-weight: 600; color: #444a5e; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-section { grid-column: 1 / -1; font-weight: 700; font-size: 13px; color: var(--primary); margin: 6px 0 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 150px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, #e4e6ff, transparent), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth .sub { color: var(--muted); margin-bottom: 20px; }
.auth button.primary { width: 100%; justify-content: center; padding: 10px; }
.error { background: var(--red-bg); color: var(--red); padding: 8px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }

/* ---------- modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,17,35,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 780px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #1f2333; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); animation: slide .2s ease; max-width: 360px; }
.toast.err { background: var(--red); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- misc components ---------- */
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 36px; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.bar { height: 8px; background: var(--gray-bg); border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.clock-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.clock { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.balance { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.balance .card { padding: 14px; margin: 0; }
.balance .big { font-size: 24px; font-weight: 700; }

/* attendance register */
.register td, .register th { padding: 5px 4px; text-align: center; font-size: 12px; }
.register td:first-child, .register th:first-child { text-align: left; padding-left: 10px; position: sticky; left: 0; background: #fff; z-index: 1; }
.register th.off, .register td.off { background: #f3f4f8; color: #aaa; }
.cell { display: inline-block; width: 22px; height: 22px; line-height: 22px; border-radius: 5px; font-weight: 700; font-size: 11px; cursor: pointer; }
.cell.present { background: var(--green-bg); color: var(--green); }
.cell.wfh { background: var(--blue-bg); color: var(--blue); }
.cell.absent { background: var(--red-bg); color: var(--red); }
.cell.half_day { background: var(--amber-bg); color: var(--amber); }
.cell.leave { background: var(--primary-50); color: var(--primary); }
.cell.holiday { background: var(--gray-bg); color: var(--muted); }
.cell.none { color: #ccc; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

/* payslip */
.payslip { max-width: 820px; margin: 0 auto; }
.payslip .head { display: flex; justify-content: space-between; border-bottom: 2px solid var(--text); padding-bottom: 12px; margin-bottom: 16px; }
.payslip table td, .payslip table th { white-space: normal; }
.payslip .net { margin-top: 16px; padding: 14px 18px; background: var(--primary-50); border-radius: 8px; display: flex; justify-content: space-between; font-size: 16px; font-weight: 700; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 18px 16px 50px; }
  .grid.two, .grid.three, .grid.four, .form-grid { grid-template-columns: 1fr; }
}
@media print {
  .sidebar, .page-head .actions, .no-print, #toast-root { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; border: 0; }
  body { background: #fff; }
}

/* logo, insurance */
.brand-logo { max-height: 32px; max-width: 120px; border-radius: 6px; background: #fff; padding: 2px; object-fit: contain; }
.auth-logo { display: block; max-height: 56px; max-width: 220px; margin-bottom: 16px; }
.logo-box { display: flex; align-items: center; gap: 16px; padding: 12px; border: 1px dashed var(--border); border-radius: 8px; margin-bottom: 6px; flex-wrap: wrap; }
#logo-preview img { max-height: 60px; max-width: 200px; display: block; }
.dep-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.filters input[type=checkbox] { min-width: 0; }
