/* ============================================================
   Design tokens
   Direction: "digital ledger" — warm paper surfaces, deep ledger-
   green primary, a stamp/seal motif for status badges. Built for
   daily, data-dense HR/payroll use: calm, legible, fast to scan.
   ============================================================ */

:root {
  --ink: #14231f;
  --paper: #f6f5f0;
  --surface: #ffffff;
  --primary: #1f6f54;
  --primary-dark: #14513d;
  --primary-light: #e6f0ec;
  --accent: #c77f2c;
  --accent-light: #f7e8d5;
  --border: #e3e0d6;
  --border-strong: #cfcabb;
  --danger: #b3432b;
  --danger-light: #f8e3dd;
  --muted: #6b6a5f;
  --muted-2: #948f80;
  --sidebar-bg: #122019;
  --sidebar-text: #cfe0d8;
  --sidebar-text-dim: #7f9b8e;
  --sidebar-active: #1f6f54;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(20, 35, 31, 0.06);
  --shadow-md: 0 4px 16px rgba(20, 35, 31, 0.08);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--ink); }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

::selection { background: var(--primary-light); }

*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- App shell ---------- */

#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 22px;
  color: #fff;
}
.sidebar-brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
}
.sidebar-brand-name { font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.sidebar-company { font-size: 11px; color: var(--sidebar-text-dim); padding: 0 10px 18px; text-transform: uppercase; letter-spacing: .04em; }

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-text-dim);
  padding: 14px 10px 6px;
}
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease;
}
.nav-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-link .icon { flex-shrink: 0; opacity: .9; }

.sidebar-footer { margin-top: auto; }
.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.08);
}
.sidebar-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12.5px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: var(--sidebar-text-dim); text-transform: capitalize; }
.sidebar-logout { color: var(--sidebar-text-dim); cursor: pointer; padding: 6px; border-radius: 6px; display:flex; }
.sidebar-logout:hover { background: rgba(255,255,255,0.08); color: #fff; }

.main {
  flex: 1;
  min-width: 0;
  padding: 28px 36px 60px;
  max-width: 1280px;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-title { font-size: 24px; }
.page-subtitle { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: all .12s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--paper); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-light); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { opacity: .92; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px; }

/* ---------- Cards / surfaces ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 16px 18px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; margin-top: 6px; }
.stat-sub { font-size: 12px; color: var(--muted-2); margin-top: 3px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 11px 14px; background: var(--paper); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(31,111,84,0.035); }
td.num, th.num { text-align: right; font-family: var(--font-mono); }
.table-empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.row-link { cursor: pointer; }

/* ---------- Forms ---------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field-hint { font-size: 11.5px; color: var(--muted-2); margin-top: 5px; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
}
.input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
textarea.input { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }
@media (max-width: 760px) { .form-grid, .form-grid-3 { grid-template-columns: 1fr; } }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; }
.checkbox-row label { margin: 0; font-weight: 500; }

/* ---------- Badges (stamp motif) ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .03em;
  border: 1px solid currentColor;
}
.badge-draft { color: var(--muted); background: #f1f0eb; }
.badge-simulated { color: var(--accent); background: var(--accent-light); }
.badge-processed { color: var(--primary); background: var(--primary-light); }
.badge-paid { color: var(--primary-dark); background: var(--primary-light); }
.badge-cancelled { color: var(--danger); background: var(--danger-light); }
.badge-active { color: var(--primary); background: var(--primary-light); }
.badge-inactive { color: var(--muted); background: #f1f0eb; }
.badge-resigned { color: var(--danger); background: var(--danger-light); }

.stamp {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border: 2px dashed currentColor;
  border-radius: var(--radius-sm);
  font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em;
  transform: rotate(-2deg);
}
.stamp-paid { color: var(--primary); }
.stamp-processed { color: var(--accent); }

/* ---------- Tabs ---------- */

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tab {
  padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Banners / alerts ---------- */

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 16px;
}
.banner-warn { background: var(--accent-light); color: #6b4513; }
.banner-error { background: var(--danger-light); color: var(--danger); }
.banner-info { background: var(--primary-light); color: var(--primary-dark); }
.banner .icon { flex-shrink: 0; margin-top: 1px; }
.banner-list { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Empty states ---------- */

.empty-state { text-align: center; padding: 60px 24px; }
.empty-state .icon { color: var(--muted-2); margin-bottom: 14px; }
.empty-state h3 { font-size: 16px; margin-bottom: 6px; }
.empty-state p { color: var(--muted); font-size: 13px; margin-bottom: 18px; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,35,31,0.45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  z-index: 100;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-lg { max-width: 760px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 16px; }
.modal-body { padding: 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.modal-close { cursor: pointer; color: var(--muted); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--paper); }

/* ---------- Toast ---------- */

#toast-stack { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 16px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow-md); display: flex; align-items: center; gap: 8px;
  animation: toast-in .18s ease;
}
.toast-error { background: var(--danger); }
.toast-success { background: var(--primary-dark); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Auth pages ---------- */

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--paper);
  padding: 24px;
  position: relative;
  overflow: hidden;
}
.auth-shell::before {
  content: '';
  position: absolute; inset: 0;
  background-image: radial-gradient(circle, var(--border-strong) 1px, transparent 1px);
  background-size: 22px 22px;
  opacity: .35;
}
.auth-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 38px 36px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow-md);
}
.auth-card.wide { max-width: 520px; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand-mark { width: 38px; height: 38px; border-radius: 9px; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 700; }
.auth-brand-name { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.auth-title { font-size: 21px; margin-bottom: 6px; }
.auth-subtitle { color: var(--muted); font-size: 13px; margin-bottom: 26px; }
.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--muted); }
.auth-error { background: var(--danger-light); color: var(--danger); padding: 10px 13px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 16px; }

/* ---------- Payslip (public view) ---------- */

.payslip-shell { min-height: 100vh; background: var(--paper); padding: 40px 20px; }
.payslip-doc {
  max-width: 640px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 36px 40px; box-shadow: var(--shadow-md);
  position: relative;
}
.payslip-header { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--ink); padding-bottom: 18px; margin-bottom: 22px; }
.payslip-company { font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.payslip-period { text-align: right; color: var(--muted); font-size: 13px; }
.payslip-row { display: flex; justify-content: space-between; padding: 7px 0; font-size: 13.5px; border-bottom: 1px dashed var(--border); }
.payslip-row.total { border-bottom: none; border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 12px; font-weight: 700; font-size: 16px; }
.payslip-section-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 20px 0 8px; }

/* ---------- Misc ---------- */

.muted { color: var(--muted); }
.rotate-180 { transform: rotate(180deg); display: inline-block; }
.mt-0 { margin-top: 0 !important; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.loading-spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--primary);
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--border) 25%, #ece9df 37%, var(--border) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; border-radius: 6px; }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.search-box { position: relative; max-width: 320px; }
.search-box .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted-2); }
.search-box input { padding-left: 34px; }

@media (max-width: 880px) {
  .sidebar { position: fixed; left: -260px; z-index: 90; transition: left .18s ease; box-shadow: var(--shadow-md); }
  .sidebar.open { left: 0; }
  .main { padding: 20px 18px 60px; }
  .mobile-topbar { display: flex !important; }
}
.mobile-topbar { display: none; align-items: center; justify-content: space-between; padding: 10px 4px 18px; }

@media print {
  #print-btn { display: none !important; }
  .payslip-shell { padding: 0; background: #fff; }
  .payslip-doc { box-shadow: none; border: none; }
}
