/* ============================================================
   HR & Payroll — Professional UI
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  --hrp-brand:        #4361ee;
  --hrp-brand-dark:   #3651d4;
  --hrp-brand-light:  #eef1fd;
  --hrp-sidebar-bg:   #111827;
  --hrp-sidebar-w:    240px;
  --hrp-topbar-h:     60px;
  --hrp-text:         #1f2937;
  --hrp-muted:        #6b7280;
  --hrp-border:       #e5e7eb;
  --hrp-surface:      #ffffff;
  --hrp-page-bg:      #f3f4f8;
  --hrp-radius:       10px;
  --hrp-radius-sm:    6px;
  --hrp-shadow-sm:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --hrp-shadow:       0 4px 12px rgba(0,0,0,.08), 0 1px 3px rgba(0,0,0,.05);
  --hrp-shadow-lg:    0 10px 30px rgba(0,0,0,.12);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--hrp-page-bg);
  color: var(--hrp-text);
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.925rem;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--hrp-brand); }
a:hover { color: var(--hrp-brand-dark); }

/* ---------- Layout ---------- */
.container-fluid > .row {
  flex-wrap: nowrap;
}

/* ---------- Topbar ---------- */
.navbar {
  height: var(--hrp-topbar-h);
  background: var(--hrp-surface) !important;
  border-bottom: 1px solid var(--hrp-border) !important;
  box-shadow: 0 1px 8px rgba(0,0,0,.06);
  position: sticky;
  top: 0;
  z-index: 1030;
  padding: 0 1.25rem;
}

.navbar-brand {
  font-size: 1.05rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.3px;
  color: var(--hrp-brand) !important;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.navbar-brand i { font-size: 1.2rem; }

/* ---------- Sidebar ---------- */
aside.sidebar {
  width: var(--hrp-sidebar-w);
  min-width: var(--hrp-sidebar-w);
  max-width: var(--hrp-sidebar-w);
  background: var(--hrp-sidebar-bg) !important;
  border-right: none !important;
  min-height: calc(100vh - var(--hrp-topbar-h));
  position: sticky;
  top: var(--hrp-topbar-h);
  height: calc(100vh - var(--hrp-topbar-h));
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #374151 transparent;
  flex-shrink: 0;
}

aside.sidebar::-webkit-scrollbar { width: 4px; }
aside.sidebar::-webkit-scrollbar-track { background: transparent; }
aside.sidebar::-webkit-scrollbar-thumb { background: #374151; border-radius: 4px; }

.sidebar-nav { padding: 0.75rem 0 1rem; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: #9ca3af;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.48rem 1rem;
  border-radius: 0;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.sidebar-nav .nav-link i {
  font-size: 1rem;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-nav .nav-link:hover {
  background: rgba(255,255,255,.07);
  color: #f3f4f6;
  border-left-color: rgba(67,97,238,.5);
}

.sidebar-nav .nav-link.active {
  background: rgba(67,97,238,.15);
  color: #fff;
  border-left-color: var(--hrp-brand);
  font-weight: 600;
}

.sidebar-nav .nav-link.active i { opacity: 1; }

.sidebar-group {
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  color: #9ca3af;          /* was #4b5563 — failed WCAG AA (2.6:1); now ~4.7:1 */
  padding: 1rem 1rem 0.3rem;
  font-weight: 700;
}

/* ---------- Main content ---------- */
main.col-md-9, main.col-lg-10 {
  flex: 1;
  min-width: 0;
  padding: 1.5rem 1.75rem !important;
}

/* Page header (title + actions) */
.d-flex.justify-content-between.align-items-center.mb-3 {
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--hrp-border);
  margin-bottom: 1.25rem !important;
}

.d-flex.justify-content-between.align-items-center.mb-3 h5 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--hrp-text);
  letter-spacing: -0.2px;
}

/* ---------- Cards ---------- */
.card {
  border: 1px solid var(--hrp-border) !important;
  border-radius: var(--hrp-radius) !important;
  box-shadow: var(--hrp-shadow-sm) !important;
  background: var(--hrp-surface);
  overflow: hidden;
}

.card-header {
  background: var(--hrp-surface) !important;
  border-bottom: 1px solid var(--hrp-border) !important;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.9rem 1.1rem;
  color: var(--hrp-text);
}

.card-body { padding: 1.1rem; }

/* ---------- KPI / stat cards ---------- */
.stat-card {
  border-radius: var(--hrp-radius) !important;
  border: none !important;
  box-shadow: var(--hrp-shadow) !important;
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--hrp-shadow-lg) !important;
}

/* ---------- Tables ---------- */
.table {
  font-size: 0.875rem;
  margin-bottom: 0;
  color: var(--hrp-text);
}

.table thead th {
  background: #f8f9fc;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--hrp-muted);
  white-space: nowrap;
  padding: 0.7rem 0.9rem;
  border-bottom: 2px solid var(--hrp-border);
  border-top: none;
}

.table td {
  padding: 0.7rem 0.9rem;
  vertical-align: middle;
  border-color: #f1f3f7;
}

.table tbody tr {
  transition: background 0.1s;
}

.table-hover tbody tr:hover {
  background: #f7f9ff;
}

.table-actions {
  white-space: nowrap;
  width: 1%;
}

/* ---------- Buttons ---------- */
.btn {
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--hrp-radius-sm);
  padding: 0.45rem 0.9rem;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.32rem 0.75rem;
  border-radius: 5px;
}

.btn-primary {
  background: var(--hrp-brand) !important;
  border-color: var(--hrp-brand) !important;
  box-shadow: 0 2px 6px rgba(67,97,238,.35);
}

.btn-primary:hover {
  background: var(--hrp-brand-dark) !important;
  border-color: var(--hrp-brand-dark) !important;
  box-shadow: 0 4px 10px rgba(67,97,238,.4);
  transform: translateY(-1px);
}

.btn-outline-primary {
  color: var(--hrp-brand);
  border-color: var(--hrp-brand);
}

.btn-outline-primary:hover {
  background: var(--hrp-brand);
  border-color: var(--hrp-brand);
  box-shadow: 0 2px 6px rgba(67,97,238,.3);
}

.btn-outline-secondary {
  color: #4b5563;
  border-color: #d1d5db;
  background: white;
}

.btn-outline-secondary:hover {
  background: #f9fafb;
  border-color: #9ca3af;
  color: #1f2937;
}

.btn-outline-danger { border-radius: var(--hrp-radius-sm); }

.btn-group > .btn { border-radius: var(--hrp-radius-sm) !important; }

/* ---------- Forms ---------- */
.form-control, .form-select {
  border: 1px solid #d1d5db;
  border-radius: var(--hrp-radius-sm);
  font-size: 0.875rem;
  color: var(--hrp-text);
  padding: 0.48rem 0.75rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  background-color: #fff;
}

.form-control:focus, .form-select:focus {
  border-color: var(--hrp-brand);
  box-shadow: 0 0 0 3px rgba(67,97,238,.15);
  outline: none;
}

.form-label {
  font-weight: 600;
  font-size: 0.82rem;
  color: #374151;
  margin-bottom: 0.35rem;
}

.form-text { color: var(--hrp-muted); font-size: 0.78rem; }

.form-section + .form-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--hrp-border);
}

.form-section h6 {
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--hrp-muted);
  font-weight: 700;
  margin-bottom: 1rem;
}

.entry-form {
  color: var(--hrp-text);
}

.entry-form-grid {
  align-items: start;
}

.entry-field,
.entry-check {
  min-height: 100%;
}

.entry-field .form-label,
.entry-check .form-check-label {
  color: #1f2937;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 0.4rem;
}

.entry-field .form-label {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
}

.required-mark {
  color: #dc2626;
  font-size: 0.86rem;
  font-weight: 800;
  margin-left: 0.12rem;
}

.entry-field .form-control,
.entry-field .form-select,
.entry-field input:not([type="checkbox"]):not([type="radio"]),
.entry-field select,
.entry-field textarea {
  width: 100%;
  min-height: 2.65rem;
  border-color: #cbd5e1;
  border-radius: 8px;
  background-color: #fff;
  box-shadow: 0 1px 1px rgba(15,23,42,.02);
}

.entry-field textarea {
  min-height: 6.75rem;
  resize: vertical;
}

.entry-field .form-control:hover,
.entry-field .form-select:hover,
.entry-field input:not([type="checkbox"]):not([type="radio"]):hover,
.entry-field select:hover,
.entry-field textarea:hover {
  border-color: #94a3b8;
}

.entry-field .form-control:focus,
.entry-field .form-select:focus,
.entry-field input:not([type="checkbox"]):not([type="radio"]):focus,
.entry-field select:focus,
.entry-field textarea:focus {
  border-color: var(--hrp-brand);
  box-shadow: 0 0 0 3px rgba(67,97,238,.14), 0 2px 8px rgba(15,23,42,.06);
}

.entry-field.has-error .form-control,
.entry-field.has-error .form-select,
.entry-field.has-error input:not([type="checkbox"]):not([type="radio"]),
.entry-field.has-error select,
.entry-field.has-error textarea {
  border-color: #ef4444;
  box-shadow: 0 0 0 3px rgba(239,68,68,.08);
}

.entry-check {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 2.65rem;
  padding: 0.72rem 0.85rem;
  border: 1px solid #dbe3ef;
  border-radius: 8px;
  background: #f8fafc;
}

.entry-check .form-check {
  display: flex;
  align-items: center;
  gap: 0.58rem;
  min-height: 1.5rem;
  padding-left: 0;
}

.entry-check .form-check-input,
.entry-check input[type="checkbox"] {
  float: none;
  flex: 0 0 auto;
  width: 2.45rem;
  height: 1.3rem;
  margin: 0;
  cursor: pointer;
}

.entry-check .form-check-label {
  margin-bottom: 0;
  cursor: pointer;
}

.entry-check:hover {
  border-color: #cbd5e1;
  background: #f1f5f9;
}

.entry-check.has-error {
  border-color: #ef4444;
  background: #fff7f7;
}

.entry-form .form-text {
  margin-top: 0.35rem;
  line-height: 1.35;
}

.entry-form .invalid-feedback {
  color: #b91c1c;
  font-size: 0.78rem;
  font-weight: 600;
  margin-top: 0.38rem;
}

.entry-alert {
  display: flex;
  align-items: flex-start;
  margin-bottom: 1rem;
  font-size: 0.84rem;
}

.entry-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.35rem;
  padding-top: 1rem;
  border-top: 1px solid var(--hrp-border);
}

.entry-form-actions .btn {
  min-width: 6.75rem;
}

/* ---------- Badges ---------- */
.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.3em 0.65em;
  border-radius: 4px;
  letter-spacing: 0.02em;
}

.badge.bg-success-soft   { background: #dcfce7; color: #15803d; }
.badge.bg-warning-soft   { background: #fef9c3; color: #a16207; }
.badge.bg-danger-soft    { background: #fee2e2; color: #b91c1c; }
.badge.bg-secondary-soft { background: #f1f5f9; color: #475569; }
.badge.bg-primary-soft   { background: var(--hrp-brand-light); color: var(--hrp-brand); }
.badge.bg-info-soft      { background: #e0f2fe; color: #0369a1; }

/* ---------- Modals ---------- */
.modal-content {
  border: none;
  border-radius: var(--hrp-radius) !important;
  box-shadow: var(--hrp-shadow-lg);
  overflow: hidden;
}

.modal-header {
  background: #f8f9fc;
  border-bottom: 1px solid var(--hrp-border);
  padding: 1rem 1.25rem;
}

.modal-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--hrp-text);
}

.modal-body { padding: 1.5rem 1.25rem; }

/* ---------- Nav tabs ---------- */
.nav-tabs {
  border-bottom: 2px solid var(--hrp-border);
  gap: 0.25rem;
}

.nav-tabs .nav-link {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--hrp-muted);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.55rem 0.85rem;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}

.nav-tabs .nav-link:hover {
  color: var(--hrp-brand);
  background: transparent;
  border-bottom-color: rgba(67,97,238,.3);
}

.nav-tabs .nav-link.active {
  color: var(--hrp-brand);
  font-weight: 700;
  border-bottom-color: var(--hrp-brand);
  background: transparent;
}

/* ---------- Profile header ---------- */
.profile-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #fff 0%, var(--hrp-brand-light) 100%);
  border: 1px solid var(--hrp-border);
  border-radius: var(--hrp-radius);
  margin-bottom: 1.25rem;
  box-shadow: var(--hrp-shadow-sm);
}

.profile-photo {
  width: 88px;
  height: 88px;
  border-radius: 50%;
  background: var(--hrp-brand-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--hrp-brand);
  font-weight: 700;
  flex-shrink: 0;
  overflow: hidden;
  border: 3px solid white;
  box-shadow: 0 2px 10px rgba(67,97,238,.2);
}

.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- ESS profile card ---------- */
.profile-photo-lg {
  width: 96px;
  height: 96px;
  font-size: 2.4rem;
}

.ess-photo-wrap { position: relative; }

.ess-photo-edit {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

.ess-profile-card .card-body {
  background: linear-gradient(135deg, #f8fafc 0%, var(--hrp-brand-light) 100%);
}

/* ---------- Permission matrix ---------- */
.perm-matrix {
  background: var(--hrp-surface);
  border: 1px solid var(--hrp-border);
  border-radius: var(--hrp-radius);
  padding: 1rem;
}

.perm-matrix .module-name {
  font-weight: 700;
  color: var(--hrp-brand);
  margin-top: 1rem;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---------- Topbar avatar ---------- */
.topbar-me {
  border: 1px solid var(--hrp-border);
  padding: 0.25rem 0.75rem 0.25rem 0.3rem;
  text-decoration: none;
  color: var(--hrp-text);
  border-radius: 999px;
  transition: background 0.15s, box-shadow 0.15s;
}

.topbar-me:hover {
  background: #f5f7fa;
  box-shadow: var(--hrp-shadow-sm);
  color: var(--hrp-text);
}

.topbar-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--hrp-brand-light);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--hrp-brand);
  overflow: hidden;
}

.topbar-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- Breadcrumb ---------- */
.breadcrumb {
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.breadcrumb-item + .breadcrumb-item::before { color: #d1d5db; }
.breadcrumb-item.active { color: var(--hrp-muted); }

/* ---------- Alerts / Messages ---------- */
.alert {
  border: none;
  border-radius: var(--hrp-radius-sm);
  font-size: 0.875rem;
  padding: 0.75rem 1rem;
  border-left: 4px solid;
}

.alert-success { background: #f0fdf4; color: #15803d; border-left-color: #22c55e; }
.alert-danger   { background: #fff1f2; color: #b91c1c; border-left-color: #ef4444; }
.alert-warning  { background: #fffbeb; color: #a16207; border-left-color: #f59e0b; }
.alert-info     { background: #eff6ff; color: #1d4ed8; border-left-color: #3b82f6; }

/* ---------- Empty state ---------- */
.empty-state {
  padding: 3.5rem 1rem;
  text-align: center;
  color: #9ca3af;
}

.empty-state i {
  font-size: 2.75rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

/* ---------- HTMX loading indicator ---------- */
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { opacity: 1; }

/* loading bar at top of page — width driven by app.js JS events */
#htmx-loader {
  position: fixed;
  top: 0; left: 0;
  height: 3px;
  width: 0;
  background: linear-gradient(90deg, var(--hrp-brand), #818cf8);
  z-index: 9999;
  transition: width 0.3s ease;
  pointer-events: none;
}

/* ---------- Dropdown menus ---------- */
.dropdown-menu {
  border: 1px solid var(--hrp-border);
  border-radius: var(--hrp-radius-sm);
  box-shadow: var(--hrp-shadow);
  font-size: 0.875rem;
  padding: 0.4rem 0;
}

.dropdown-item {
  padding: 0.48rem 1rem;
  color: #374151;
  transition: background 0.1s;
  border-radius: 0;
}

.dropdown-item:hover {
  background: var(--hrp-brand-light);
  color: var(--hrp-brand);
}

.dropdown-divider { border-color: var(--hrp-border); margin: 0.3rem 0; }

/* ---------- Select (filter dropdowns) ---------- */
.form-select-sm {
  padding: 0.32rem 2rem 0.32rem 0.7rem;
  font-size: 0.82rem;
  border-radius: var(--hrp-radius-sm);
}

/* ---------- Utility ---------- */
.text-muted { color: var(--hrp-muted) !important; }
.border-bottom { border-color: var(--hrp-border) !important; }

/* Small filter/search bar inside card */
.p-3.border-bottom {
  background: #fafbfd;
  border-bottom: 1px solid var(--hrp-border) !important;
}

/* ---------- Realtime toasts ---------- */
.toast-container { z-index: 1090; }

.toast {
  border: none !important;
  border-radius: var(--hrp-radius) !important;
  box-shadow: var(--hrp-shadow-lg) !important;
}

.toast .toast-body {
  padding: 0.75rem 0.9rem;
  font-size: 0.875rem;
  line-height: 1.4;
}

/* ---------- Scrollbar (content area) ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ---------- Flash message icons ---------- */
.alert .bi { font-size: 1rem; line-height: 1.5; }

/* ---------- Alert colour polish ---------- */
.alert-info    { --bs-alert-color: #1e6091; --bs-alert-bg: #d8eef9; --bs-alert-border-color: #bde0f5; }
.alert-success { --bs-alert-color: #166534; --bs-alert-bg: #dcfce7; --bs-alert-border-color: #bbf7d0; }
.alert-warning { --bs-alert-color: #92400e; --bs-alert-bg: #fef9c3; --bs-alert-border-color: #fde68a; }
.alert-danger  { --bs-alert-color: #991b1b; --bs-alert-bg: #fee2e2; --bs-alert-border-color: #fca5a5; }

/* ---------- Sidebar collapsible groups (Phase UX) ---------- */
.sidebar-section-toggle {
  cursor: pointer;
  user-select: none;
}
.sidebar-section-toggle::after {
  content: '\F282';              /* bi-chevron-down */
  font-family: 'bootstrap-icons';
  font-size: 0.65rem;
  margin-left: auto;
  transition: transform 0.2s;
  opacity: 0.6;
}
.sidebar-section-toggle.collapsed::after {
  transform: rotate(-90deg);
}

/* ---------- Print styles ---------- */
@media print {
  aside.sidebar,
  .navbar,
  #htmx-loader,
  .breadcrumb,
  #hrp-messages,
  .btn-close,
  .no-print { display: none !important; }

  main.col-md-9,
  main.col-lg-10 {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
  }

  .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
  body { font-size: 11pt; background: white !important; }
}
