/* ============================================================
   COMPONENTS.CSS — Clovr Media HR System
   Reusable UI components: buttons, cards, tables, forms,
   badges, alerts, modals, toasts
   Loaded on every page alongside base.css and layout.css
   ============================================================ */

/* ============================================================
   CARDS
   The primary container for content sections
   ============================================================ */
.card {
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--clr-border);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  transition: box-shadow var(--transition-base);
}

.card:last-child {
  margin-bottom: 0;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--clr-border);
}

.card-title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--clr-text-primary);
}

.card-subtitle {
  font-size: var(--text-xs);
  color: var(--clr-text-muted);
  margin-top: 2px;
}

/* Flush card — no padding, for tables that go edge to edge */
.card-flush {
  padding: 0;
  overflow: hidden;
}

.card-flush .card-header {
  padding: var(--space-5) var(--space-6);
  margin-bottom: 0;
}

/* Stat card — used in dashboard summary grid */
.stat-card {
  display: block;
  background: var(--clr-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--clr-border);
  padding: var(--space-5) var(--space-6);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  color: inherit;
  text-decoration: none;
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Clickable stat cards get a subtle accent border on hover */
a.stat-card:hover {
  border-color: var(--clr-brand-accent);
}

/* Colored left accent bar */
.stat-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--stat-accent, var(--clr-brand-accent));
  border-radius: var(--radius-lg) 0 0 var(--radius-lg);
}

.stat-card-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-2);
}

.stat-card-value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--clr-text-primary);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-card-meta {
  font-size: var(--text-xs);
  color: var(--clr-text-muted);
  margin-top: var(--space-2);
}

/* Stat card accent variants */
.stat-accent-gold    { --stat-accent: var(--clr-brand-accent); }
.stat-accent-success { --stat-accent: var(--clr-success); }
.stat-accent-warning { --stat-accent: var(--clr-warning); }
.stat-accent-danger  { --stat-accent: var(--clr-danger); }
.stat-accent-info    { --stat-accent: var(--clr-info); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-5);
  height: 38px;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--transition-fast),
    color var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    transform var(--transition-fast);
  white-space: nowrap;
  user-select: none;
  letter-spacing: 0.01em;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Primary — gold accent */
.btn-primary {
  background: var(--clr-brand-accent);
  color: var(--clr-brand-dark);
  border-color: var(--clr-brand-accent);
}

.btn-primary:hover {
  background: var(--clr-brand-accent-h);
  border-color: var(--clr-brand-accent-h);
  box-shadow: var(--shadow-accent);
}

/* Secondary — outlined */
.btn-secondary {
  background: transparent;
  color: var(--clr-text-secondary);
  border-color: var(--clr-border-strong);
}

.btn-secondary:hover {
  background: var(--clr-neutral-bg);
  border-color: var(--clr-text-muted);
  color: var(--clr-text-primary);
}

/* Success */
.btn-success {
  background: var(--clr-success);
  color: white;
  border-color: var(--clr-success);
}

.btn-success:hover {
  background: #248a5c;
  box-shadow: 0 4px 12px rgba(45,158,107,0.3);
}

/* Danger */
.btn-danger {
  background: var(--clr-danger);
  color: white;
  border-color: var(--clr-danger);
}

.btn-danger:hover {
  background: #b91c1c;
  box-shadow: 0 4px 12px rgba(220,38,38,0.3);
}

/* Ghost — transparent, subtle */
.btn-ghost {
  background: transparent;
  color: var(--clr-text-secondary);
  border-color: transparent;
}

.btn-ghost:hover {
  background: var(--clr-neutral-bg);
  color: var(--clr-text-primary);
}

/* Dark — for use on light backgrounds */
.btn-dark {
  background: var(--clr-brand-dark);
  color: white;
  border-color: var(--clr-brand-dark);
}

.btn-dark:hover {
  background: var(--clr-brand-mid);
  box-shadow: var(--shadow-md);
}

/* Size variants */
.btn-sm {
  height: 30px;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

.btn-lg {
  height: 48px;
  padding: var(--space-3) var(--space-8);
  font-size: var(--text-md);
  border-radius: var(--radius-lg);
}

.btn-full {
  width: 100%;
}

/* Icon button */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-icon.btn-sm {
  width: 28px;
  height: 28px;
}

/* ============================================================
   BADGES & STATUS PILLS
   Used throughout for attendance status, leave status, etc.
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  letter-spacing: 0.04em;
  white-space: nowrap;
  border: 1px solid transparent;
}

/* Attendance statuses */
.badge-present {
  background: var(--clr-success-bg);
  color: var(--clr-success);
  border-color: var(--clr-success-border);
}

.badge-late {
  background: var(--clr-warning-bg);
  color: var(--clr-warning);
  border-color: var(--clr-warning-border);
}

.badge-half-day {
  background: var(--clr-info-bg);
  color: var(--clr-info);
  border-color: var(--clr-info-border);
}

.badge-absent {
  background: var(--clr-danger-bg);
  color: var(--clr-danger);
  border-color: var(--clr-danger-border);
}

.badge-absent-unresolved {
  background: #fdf4ff;
  color: #7e22ce;
  border-color: #d8b4fe;
}

.badge-on-leave {
  background: var(--clr-neutral-bg);
  color: var(--clr-neutral);
  border-color: var(--clr-neutral-border);
}

/* Unpaid leave: approved leave but a day's pay is deducted — distinct orange */
.badge-unpaid-leave {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

/* Approval statuses */
.badge-pending {
  background: var(--clr-warning-bg);
  color: var(--clr-warning);
  border-color: var(--clr-warning-border);
}

.badge-approved {
  background: var(--clr-success-bg);
  color: var(--clr-success);
  border-color: var(--clr-success-border);
}

.badge-rejected {
  background: var(--clr-danger-bg);
  color: var(--clr-danger);
  border-color: var(--clr-danger-border);
}

/* Employment statuses */
.badge-permanent {
  background: rgba(200,169,110,0.12);
  color: var(--clr-brand-accent-h);
  border-color: rgba(200,169,110,0.3);
}

.badge-probation {
  background: var(--clr-neutral-bg);
  color: var(--clr-neutral);
  border-color: var(--clr-neutral-border);
}

/* Dot indicator before badge text */
.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
  flex-shrink: 0;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--clr-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--clr-surface);
  font-size: var(--text-sm);
}

thead tr {
  background: var(--clr-surface-2);
  border-bottom: 1px solid var(--clr-border);
}

th {
  padding: var(--space-3) var(--space-5);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

td {
  padding: var(--space-4) var(--space-5);
  color: var(--clr-text-primary);
  border-bottom: 1px solid var(--clr-border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr {
  transition: background var(--transition-fast);
}

tbody tr:hover {
  background: var(--clr-surface-2);
}

/* Right-align last column (actions) */
th:last-child,
td:last-child {
  text-align: right;
}

.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Employee name + ID combined cell */
.table-employee {
  display: flex;
  flex-direction: column;
}

.table-employee-name {
  font-weight: var(--weight-medium);
}

.table-employee-id {
  font-size: var(--text-xs);
  color: var(--clr-text-muted);
  font-family: var(--font-mono);
  margin-top: 1px;
}

/* Date cell with BS date below AD */
.table-date {
  display: flex;
  flex-direction: column;
}

.table-date-ad {
  font-weight: var(--weight-medium);
}

.table-date-bs {
  font-size: var(--text-xs);
  color: var(--clr-brand-accent);
  margin-top: 1px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--clr-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-label .required {
  color: var(--clr-danger);
  margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-family: var(--font-sans);
  color: var(--clr-text-primary);
  background: var(--clr-surface);
  border: 1px solid var(--clr-border-strong);
  border-radius: var(--radius-md);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
  outline: none;
  appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--clr-text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--clr-brand-accent);
  box-shadow: 0 0 0 3px rgba(200,169,110,0.15);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
  background: var(--clr-neutral-bg);
  color: var(--clr-text-muted);
  cursor: not-allowed;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  cursor: pointer;
}

.form-textarea {
  resize: vertical;
  min-height: 90px;
  line-height: var(--leading-relaxed);
}

/* Error state */
.form-input.error,
.form-select.error,
.form-textarea.error {
  border-color: var(--clr-danger);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.1);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--clr-danger);
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Help text below input */
.form-hint {
  font-size: var(--text-xs);
  color: var(--clr-text-muted);
  line-height: var(--leading-relaxed);
}

/* Input with icon */
.input-group {
  position: relative;
}

.input-group .form-input {
  padding-left: 2.5rem;
}

.input-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--clr-text-muted);
  pointer-events: none;
  width: 16px;
  height: 16px;
}

/* Form row — multiple inputs on one line */
.form-row {
  display: flex;
  gap: var(--space-4);
  align-items: flex-end;
}

.form-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* Form actions bar */
.form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--clr-border);
  margin-top: var(--space-6);
}

/* ============================================================
   ALERTS
   Contextual feedback messages
   ============================================================ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  border: 1px solid transparent;
  margin-bottom: var(--space-5);
  animation: slideInDown 250ms ease both;
}

.alert-icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.alert-body {
  flex: 1;
  line-height: var(--leading-relaxed);
}

.alert-title {
  font-weight: var(--weight-semibold);
  margin-bottom: 2px;
}

.alert-success {
  background: var(--clr-success-bg);
  color: #145e3c;
  border-color: var(--clr-success-border);
}

.alert-warning {
  background: var(--clr-warning-bg);
  color: #854d0e;
  border-color: var(--clr-warning-border);
}

.alert-danger {
  background: var(--clr-danger-bg);
  color: #991b1b;
  border-color: var(--clr-danger-border);
}

.alert-info {
  background: var(--clr-info-bg);
  color: #1e40af;
  border-color: var(--clr-info-border);
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(3px);
  z-index: var(--z-modal);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 200ms ease;
}

.modal {
  background: var(--clr-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: scaleIn 200ms ease both;
  position: relative;
}

.modal-header {
  padding: var(--space-6) var(--space-6) var(--space-4);
  border-bottom: 1px solid var(--clr-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--clr-text-muted);
  transition: all var(--transition-fast);
  cursor: pointer;
}

.modal-close:hover {
  background: var(--clr-neutral-bg);
  color: var(--clr-text-primary);
}

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  padding: var(--space-4) var(--space-6) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
}

/* Modal sizes */
.modal-sm { max-width: 380px; }
.modal-lg { max-width: 720px; }

/* ============================================================
   TOAST NOTIFICATIONS
   Brief pop-up feedback messages (auto-dismiss)
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--clr-brand-dark);
  color: var(--clr-text-inverse);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  pointer-events: all;
  animation: slideInRight 250ms ease both;
  max-width: 360px;
  border-left: 4px solid var(--clr-brand-accent);
}

.toast-success { border-left-color: var(--clr-success); }
.toast-warning { border-left-color: var(--clr-warning); }
.toast-danger  { border-left-color: var(--clr-danger); }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--clr-border);
}

.pagination-info {
  font-size: var(--text-xs);
  color: var(--clr-text-muted);
  margin-right: auto;
}

.page-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--clr-text-secondary);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.page-btn:hover {
  background: var(--clr-neutral-bg);
  border-color: var(--clr-border);
}

.page-btn.active {
  background: var(--clr-brand-accent);
  color: var(--clr-brand-dark);
  font-weight: var(--weight-bold);
  border-color: var(--clr-brand-accent);
}

.page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ============================================================
   FILTER BAR
   Search + filter controls above tables
   ============================================================ */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding: var(--space-5) var(--space-6);
  background: var(--clr-surface-2);
  border-bottom: 1px solid var(--clr-border);
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 140px;
}

.filter-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.filter-actions {
  display: flex;
  gap: var(--space-2);
  align-items: flex-end;
}

/* ============================================================
   DIVIDER
   ============================================================ */
.divider {
  height: 1px;
  background: var(--clr-border);
  margin: var(--space-5) 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--clr-text-muted);
  font-size: var(--text-xs);
  margin: var(--space-5) 0;
}

.divider-text::before,
.divider-text::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--clr-border);
}

/* ============================================================
   AVATAR
   Employee photo or initials placeholder
   ============================================================ */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--clr-brand-accent-l);
  color: var(--clr-brand-accent-h);
  font-size: var(--text-sm);
  font-weight: var(--weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  text-transform: uppercase;
}

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

.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 52px; height: 52px; font-size: var(--text-xl); }
.avatar-xl { width: 80px; height: 80px; font-size: var(--text-2xl); }

/* ============================================================
   LOGOUT BUTTON (top header)
   ============================================================ */
.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--clr-danger);
  border: 1px solid var(--clr-danger-border);
  background: var(--clr-danger-bg);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  text-decoration: none;
  letter-spacing: 0.03em;
}

.btn-logout:hover {
  background: var(--clr-danger);
  color: white;
  border-color: var(--clr-danger);
}