:root {
  --sidebar-width: 230px;
  --sidebar-collapsed: 64px;
  --primary: #16a34a;
  --primary-light: #dcfce7;
  --top-nav-height: 60px;
  --orange: #f97316;

  /* Theme tokens (light) */
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, .08);

  --kpi-green-bg: #f0fdf4;   --kpi-green-bd: #bbf7d0;  --kpi-green-fg: #16a34a; --kpi-green-val: #15803d;
  --kpi-red-bg: #fef2f2;     --kpi-red-bd: #fecaca;    --kpi-red-fg: #dc2626;   --kpi-red-val: #b91c1c;
  --kpi-blue-bg: #eff6ff;    --kpi-blue-bd: #bfdbfe;   --kpi-blue-fg: #2563eb;  --kpi-blue-val: #1d4ed8;
  --kpi-orange-bg: #fff7ed;  --kpi-orange-bd: #fed7aa; --kpi-orange-fg: #ea580c;--kpi-orange-val: #c2410c;
  --kpi-purple-bg: #f5f3ff;  --kpi-purple-bd: #ddd6fe; --kpi-purple-fg: #7c3aed;--kpi-purple-val: #6d28d9;
}

html[data-theme="dark"] {
  --primary: #22c55e;
  --primary-light: #14351f;

  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f172a;
  --surface-3: #1e293b;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --border: #1f2937;
  --shadow: rgba(0, 0, 0, .5);

  --kpi-green-bg: #0e2418;   --kpi-green-bd: #14532d;  --kpi-green-fg: #4ade80; --kpi-green-val: #86efac;
  --kpi-red-bg: #2a1315;     --kpi-red-bd: #7f1d1d;    --kpi-red-fg: #f87171;   --kpi-red-val: #fca5a5;
  --kpi-blue-bg: #101c33;    --kpi-blue-bd: #1e3a8a;   --kpi-blue-fg: #60a5fa;  --kpi-blue-val: #93c5fd;
  --kpi-orange-bg: #2b1a0d;  --kpi-orange-bd: #7c2d12; --kpi-orange-fg: #fb923c;--kpi-orange-val: #fdba74;
  --kpi-purple-bg: #1b1533;  --kpi-purple-bd: #4c1d95; --kpi-purple-fg: #a78bfa;--kpi-purple-val: #c4b5fd;
}

* { font-family: 'Inter', sans-serif; }
body { background: var(--bg); color: var(--text); transition: background .2s, color .2s; }

/* Bootstrap surface harmonisation */
html[data-theme="dark"] .card,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .input-group-text {
  background-color: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
html[data-theme="dark"] .form-control::placeholder { color: var(--text-faint); }
html[data-theme="dark"] .text-muted { color: var(--text-muted) !important; }
html[data-theme="dark"] .bg-white { background-color: var(--surface) !important; }
html[data-theme="dark"] .table { --bs-table-color: var(--text); --bs-table-bg: transparent; --bs-table-border-color: var(--border); }
html[data-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) > * { --bs-table-accent-bg: var(--surface-2); color: var(--text); }
html[data-theme="dark"] .table-hover > tbody > tr:hover > * { --bs-table-accent-bg: var(--surface-3); color: var(--text); }
html[data-theme="dark"] .modal-header, html[data-theme="dark"] .modal-footer { border-color: var(--border); }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width .3s;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  flex-shrink: 0;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .sidebar-label { display: none; }
.sidebar.collapsed .sidebar-logo { margin: 0 auto; }
.sidebar.collapsed .sidebar-link { justify-content: center; padding: 10px 0; }
.sidebar.collapsed .sidebar-header { justify-content: center; }

.sidebar-header { border-color: var(--border) !important; }
.sidebar-logo { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.sidebar-brand { font-size: .9rem; white-space: nowrap; color: var(--text); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text-muted); text-decoration: none;
  font-size: .85rem; font-weight: 500;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.sidebar-link:hover { background: var(--surface-3); color: var(--text); }
.sidebar-link.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.sidebar-link i { font-size: 1.05rem; flex-shrink: 0; }

/* Top nav */
.top-nav {
  height: var(--top-nav-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

/* Theme toggle */
.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.theme-toggle:hover { background: var(--surface-3); }
html[data-theme="dark"] .theme-toggle i.bi-moon-stars { display: none; }
html:not([data-theme="dark"]) .theme-toggle i.bi-sun { display: none; }

/* Main content */
.main-content { min-height: 100vh; overflow-x: hidden; }
.page-content { min-height: calc(100vh - var(--top-nav-height)); }

/* Cards */
.kpi-card {
  background: var(--surface);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
  transition: box-shadow .2s;
}
.kpi-card:hover { box-shadow: 0 4px 12px var(--shadow); }
.kpi-label { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.kpi-value { font-size: 1.6rem; font-weight: 800; }
.kpi-sub { font-size: .75rem; color: var(--text-faint); margin-top: 4px; }

.kpi-green { border-color: var(--kpi-green-bd); background: var(--kpi-green-bg); }
.kpi-green .kpi-label { color: var(--kpi-green-fg); }
.kpi-green .kpi-value { color: var(--kpi-green-val); }

.kpi-red { border-color: var(--kpi-red-bd); background: var(--kpi-red-bg); }
.kpi-red .kpi-label { color: var(--kpi-red-fg); }
.kpi-red .kpi-value { color: var(--kpi-red-val); }

.kpi-blue { border-color: var(--kpi-blue-bd); background: var(--kpi-blue-bg); }
.kpi-blue .kpi-label { color: var(--kpi-blue-fg); }
.kpi-blue .kpi-value { color: var(--kpi-blue-val); }

.kpi-orange { border-color: var(--kpi-orange-bd); background: var(--kpi-orange-bg); }
.kpi-orange .kpi-label { color: var(--kpi-orange-fg); }
.kpi-orange .kpi-value { color: var(--kpi-orange-val); }

.kpi-purple { border-color: var(--kpi-purple-bd); background: var(--kpi-purple-bg); }
.kpi-purple .kpi-label { color: var(--kpi-purple-fg); }
.kpi-purple .kpi-value { color: var(--kpi-purple-val); }

/* Tables */
.table-card { background: var(--surface); border-radius: 12px; border: 1px solid var(--border); overflow: hidden; }
.table th { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); background: var(--surface-2); }
.table td { font-size: .875rem; vertical-align: middle; color: var(--text); }

/* Badges */
.badge-status { padding: 4px 10px; border-radius: 20px; font-size: .72rem; font-weight: 600; }
.badge-active   { background: var(--kpi-green-bg); color: var(--kpi-green-fg); }
.badge-inactive { background: var(--surface-3); color: var(--text-muted); }
.badge-sick     { background: var(--kpi-red-bg); color: var(--kpi-red-fg); }
.badge-paid     { background: var(--kpi-green-bg); color: var(--kpi-green-fg); }
.badge-pending  { background: var(--kpi-orange-bg); color: var(--kpi-orange-fg); }
.badge-partial  { background: var(--kpi-blue-bg); color: var(--kpi-blue-fg); }

/* Period tabs */
.period-tabs { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--border); padding: 6px; border-radius: 10px; width: fit-content; }
.period-tab { padding: 6px 18px; border-radius: 7px; border: none; background: transparent; font-size: .82rem; font-weight: 500; color: var(--text-muted); cursor: pointer; transition: all .15s; }
.period-tab.active { background: var(--orange); color: #fff; box-shadow: 0 2px 6px rgba(249,115,22,.3); }
.period-tab:hover:not(.active) { background: var(--surface-3); color: var(--text); }

/* Section header */
.section-header { background: var(--surface); border-radius: 12px; border: 1px solid var(--border); padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; }

/* Danger zone */
.danger-zone { border: 1.5px solid var(--kpi-red-bd); border-radius: 12px; }
.danger-zone .danger-body { background: var(--kpi-red-bg); border-radius: 0 0 10px 10px; padding: 16px 20px; }

/* Login page */
.login-bg { min-height: 100vh; background: #0a1f11; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.login-logo { width: 96px; height: 96px; border-radius: 20px; object-fit: cover; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.login-card { background: rgba(255,255,255,.97); backdrop-filter: blur(12px); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }

/* Chart containers */
.chart-wrap { position: relative; height: 220px; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 99px; }

/* PDF export */
.pdf-report-header { display: none; }
body.pdf-exporting .pdf-report-header {
  display: block;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary);
}
body.pdf-exporting .no-print { display: none !important; }
body.pdf-exporting .page-content { padding: 24px !important; }
body.pdf-exporting .pdf-avoid-break, body.pdf-exporting .table-card, body.pdf-exporting .kpi-card { break-inside: avoid; page-break-inside: avoid; }

.pdf-overlay {
  position: fixed; inset: 0; z-index: 20000;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; gap: 12px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -260px; z-index: 999; transition: left .3s; }
  .sidebar.mobile-open { left: 0; }
  .main-content { width: 100%; }
}

@media print {
  .sidebar, .top-nav, .no-print { display: none !important; }
  body { background: #fff; }
}
