/* School Payroll Module — modern sidebar admin layout (no framework, responsive) */

:root {
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-border: #e5e8ee;
  --color-text: #1a1f2b;
  --color-text-muted: #68707e;
  --color-primary: #4f46e5;
  --color-primary-dark: #4338ca;
  --color-primary-soft: #eef2ff;
  --color-success: #16a34a;
  --color-warning: #d97706;
  --color-danger: #dc2626;
  --color-secondary: #6b7280;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 4px 14px rgba(16, 24, 40, 0.08);

  --sidebar-width: 252px;
  --sidebar-bg: #161c2d;
  --sidebar-bg-hover: #1f2740;
  --sidebar-text: #aab1c5;
  --sidebar-text-active: #ffffff;
  --sidebar-border: #262e46;

  --topbar-height: 60px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14.5px;
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   App shell: sidebar + content
   ============================================================ */
.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 30;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-brand-mark {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--color-primary), #7c3aed);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-brand-text {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
}
.sidebar-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #5b637a;
  font-weight: 700;
  padding: 14px 10px 6px;
}
.sidebar-section-label:first-child { padding-top: 4px; }

.sidebar-nav a, .sidebar-nav .nav-disabled {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
}
.sidebar-nav a:hover {
  background: var(--sidebar-bg-hover);
  color: #fff;
  text-decoration: none;
}
.sidebar-nav a.active {
  background: var(--color-primary);
  color: #fff;
}
.sidebar-nav .nav-disabled {
  color: #4b5169;
  cursor: not-allowed;
}
.nav-icon {
  width: 18px; height: 18px;
  flex-shrink: 0;
  display: inline-flex;
}
.nav-icon svg { width: 100%; height: 100%; }

.sidebar-footer {
  border-top: 1px solid var(--sidebar-border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}
.sidebar-user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user-avatar-sm { width: 30px; height: 30px; font-size: 12px; }
.sidebar-user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.sidebar-user-name {
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 11.5px;
  color: #7d859c;
}
.sidebar-logout {
  color: #8890a5;
  display: flex;
  flex-shrink: 0;
  padding: 6px;
  border-radius: var(--radius-sm);
}
.sidebar-logout:hover { background: var(--sidebar-bg-hover); color: #fff; }
.sidebar-logout svg { width: 18px; height: 18px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 18, 28, 0.5);
  z-index: 25;
}

/* ---------- Content area ---------- */
.app-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  /* The single source of the page title on every page — pages set
     $pageTitle / $pageSubtitle and no longer render their own <h1>,
     so the title never appears twice. */
  display: flex;
  min-height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-titles {
  flex: 1;
  min-width: 0;
}
.topbar-spacer { flex: 1; }
.topbar-page-title {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--color-text);
  line-height: 1.3;
}
.topbar-page-subtitle {
  font-size: 12.5px;
  color: var(--color-text-muted);
  margin-top: 2px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-date {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-size: 12.5px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 999px;
  white-space: nowrap;
}
.topbar-divider {
  width: 1px;
  height: 28px;
  background: var(--color-border);
}
.topbar-user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.topbar-user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.topbar-user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--color-text);
  white-space: nowrap;
}
.topbar-user-role {
  font-size: 12px;
  color: var(--color-text-muted);
}
.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
  padding: 4px;
}
.nav-toggle svg { width: 22px; height: 22px; }

.page-wrap {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 60px;
}
.site-footer {
  text-align: center;
  color: var(--color-text-muted);
  font-size: 12px;
  padding: 20px 16px;
  border-top: 1px solid var(--color-border);
}

/* Page title/subtitle now live in the shared topbar (see .topbar-titles
   above) so they appear once, consistently, on every page. .page-header
   is kept only as a right-aligned bar for page-specific action buttons
   (e.g. "+ Add Staff Member") — omit it entirely on pages with no actions. */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-header h1 {
  margin: 0 0 4px;
  font-size: 21px;
  letter-spacing: -0.01em;
}
.page-header p.subtitle {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 13.5px;
}
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 {
  margin-top: 0;
  font-size: 15px;
}
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stat-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card .stat-label { color: var(--color-text-muted); font-size: 12.5px; font-weight: 500; }
.stat-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 17px; height: 17px; }
.stat-icon-indigo { background: #eef2ff; color: #4f46e5; }
.stat-icon-green  { background: #dcfce7; color: #16a34a; }
.stat-icon-blue   { background: #dbeafe; color: #2563eb; }
.stat-icon-amber  { background: #fef3c7; color: #d97706; }
.stat-icon-rose   { background: #ffe4e6; color: #e11d48; }
.stat-card .stat-value { font-size: 27px; font-weight: 700; letter-spacing: -0.02em; }
.stat-trend { font-size: 12px; font-weight: 600; margin-top: 6px; }
.stat-trend-up { color: var(--color-success); }

/* ---------- Forms ---------- */
form .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group.full-width { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: var(--color-text); }
label .required { color: var(--color-danger); }
input[type="text"], input[type="password"], input[type="email"],
input[type="date"], input[type="number"], input[type="tel"],
input[type="file"], select, textarea {
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.13);
}
.field-error { color: var(--color-danger); font-size: 12px; }
.form-hint { color: var(--color-text-muted); font-size: 12px; }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 18px; padding: 14px 16px; }
legend { font-weight: 700; font-size: 13.5px; padding: 0 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--color-primary);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-outline { background: transparent; border-color: var(--color-border); color: var(--color-text); }
.btn-outline:hover { background: var(--color-bg); }
.btn-danger { background: var(--color-danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: var(--color-secondary); }
.btn-secondary:hover { background: #4b5563; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Table ---------- */
.table-responsive { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  font-size: 13.5px;
}
table th, table td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
table th {
  color: var(--color-text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table tr:hover td { background: #fafbfc; }
.row-actions { display: flex; gap: 10px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-secondary { background: #e5e7eb; color: #374151; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  font-size: 13.5px;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Login (no sidebar) ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(160deg, #161c2d 0%, #262e46 100%);
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 28px;
}
.login-card h1 { font-size: 18px; margin: 0 0 4px; text-align: center; }
.login-card p.subtitle { text-align: center; color: var(--color-text-muted); font-size: 13px; margin-top: 0; margin-bottom: 22px; }

/* ---------- Filters ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; min-width: 160px; }

/* ---------- List card (unified header + filters + table + pagination) ---------- */
.list-card { padding: 0; overflow: hidden; }
.list-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--color-border);
}
.list-card-title-row {
  display: flex;
  align-items: center;
  gap: 9px;
}
.list-card-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.count-badge {
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
}
.list-card-subtitle {
  margin: 3px 0 0;
  color: var(--color-text-muted);
  font-size: 13px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--color-border);
  background: #fafbfc;
}
.filter-row input[type="text"],
.filter-row select {
  width: auto;
  min-width: 160px;
}
.filter-row input[type="text"] {
  flex: 1;
  min-width: 220px;
}
.filter-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 400;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.filter-checkbox input { width: auto; }

.list-card .table-responsive { padding: 0; }
.list-card table { font-size: 13.5px; }
.list-card thead tr { background: #f6f7f9; }
.list-card thead th { border-bottom: 1px solid var(--color-border); }
.list-card tbody tr:last-child td { border-bottom: none; }
.empty-row {
  text-align: center;
  color: var(--color-text-muted);
  padding: 36px 16px !important;
  white-space: normal !important;
}

.list-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 16px 22px;
}
.pagination-summary { font-size: 13px; color: var(--color-text-muted); }
.pagination { display: flex; align-items: center; gap: 6px; }
.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  font-size: 13px;
  font-weight: 600;
}
.page-btn:hover { background: var(--color-bg); text-decoration: none; }
.page-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.page-btn.disabled {
  opacity: 0.4;
  pointer-events: none;
}
.page-ellipsis { padding: 0 4px; color: var(--color-text-muted); }

/* ---------- Avatar ---------- */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
}
.staff-name-cell { display: flex; align-items: center; gap: 10px; }

/* ---------- Detail view ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px 24px;
}
.detail-item .detail-label { font-size: 11.5px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.detail-item .detail-value { font-size: 13.5px; margin-top: 2px; }

/* ============================================================
   Responsive: sidebar becomes an off-canvas drawer
   ============================================================ */
@media (max-width: 960px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }
  .sidebar-backdrop.open { display: block; }
  .app-content { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
}
@media (max-width: 600px) {
  .page-wrap { padding: 18px 16px 48px; }
  table th, table td { white-space: normal; }
  .topbar { padding: 0 16px; }
  .topbar-date, .topbar-divider, .topbar-user-info { display: none; }
}

/* ============================================================
   Stage 2 — Salary Structure / Allowances / Deductions
   ============================================================ */

/* A submit button styled to look like a plain text link, for actions
   (like "Deactivate") that sit inline with real <a> links but need to
   POST rather than navigate via GET. */
.btn-linklike {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--color-primary);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.btn-linklike:hover { text-decoration: underline; }

/* Salary summary card (Stage 2 §7/§8 layout) */
.salary-summary-card { max-width: 640px; }
.salary-summary-header { margin-bottom: 18px; }
.salary-summary-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  font-weight: 600;
}
.salary-summary-employee {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 2px;
}
.salary-summary-section { margin-bottom: 4px; }
.salary-summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 14px;
}
.salary-summary-row-heading {
  border-bottom: none;
  padding-top: 16px;
  padding-bottom: 4px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  font-weight: 700;
}
.salary-summary-row-muted { color: var(--color-text-muted); font-style: italic; }
.salary-summary-row-subtotal {
  font-weight: 600;
  border-bottom: 2px solid var(--color-border);
}
.salary-summary-row-total {
  font-weight: 700;
  font-size: 15.5px;
  color: var(--color-primary-dark);
  border-bottom: none;
  padding-top: 12px;
}
.salary-summary-net {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-weight: 700;
  font-size: 17px;
}

/* ============================================================
   Stage 3 — Attendance / Leave / Short Leave
   ============================================================ */
.attendance-table th, .attendance-table td { vertical-align: top; }
.attendance-table select.attn-status-select {
  min-width: 130px;
  padding: 7px 9px;
  font-size: 13px;
}
.attn-io-fields, .attn-sl-times { display: flex; gap: 6px; align-items: center; }
.attn-io-fields input[type="time"],
.attn-sl-times input[type="time"] {
  width: 100px;
  padding: 6px 8px;
  font-size: 12.5px;
}
.attn-sl-fields { display: flex; flex-direction: column; gap: 6px; min-width: 210px; }
.attn-sl-fields input[type="text"] { padding: 6px 8px; font-size: 12.5px; }
.attn-sl-duration { font-size: 12px; color: var(--color-text-muted); font-weight: 600; white-space: nowrap; }
.attn-io-fields[hidden], .attn-sl-fields[hidden], .attn-late-input[hidden] { display: none; }
.stat-grid .stat-card .stat-value { font-size: 26px; }

/* ------------------------------------------------------------
   Radio/checkbox option with a longer wrapping description
   (e.g. Attendance Mode) — unlike .filter-checkbox, this is meant
   to wrap onto multiple lines instead of forcing the page wider.
   ------------------------------------------------------------ */
.option-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13.5px;
  color: var(--color-text-muted);
  white-space: normal;
}
.option-row input { width: auto; margin-top: 3px; flex-shrink: 0; }
