:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #dbeafe;
  --secondary: #8b5cf6;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --info: #06b6d4;
  --info-light: #cffafe;
  --bg: #f8fafc;
  --bg-secondary: #f1f5f9;
  --sidebar-bg: #ffffff;
  --sidebar-text: #475569;
  --sidebar-active: #3b82f6;
  --white: #ffffff;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --text: #1e293b;
  --text-muted: #64748b;
  --card-shadow: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.05);
  --card-shadow-hover: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: -0.2px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrapper { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 200;
  overflow-y: auto;
  overflow-x: hidden;
  transition: var(--transition);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 12px rgba(0,0,0,.05);
}

.sidebar-header {
  padding: 18px 16px 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid #f3f4f6;
}
.logo {
  width: 40px; height: 40px;
  background: var(--primary);
  border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 18px; color: #fff;
  text-decoration: none; flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(37,99,235,.3);
}
.logo-text {
  font-size: 15px; font-weight: 700; color: #111827;
  line-height: 1.2;
}
.logo-text small {
  display: block; font-size: 10px; font-weight: 400;
  color: #9ca3af; text-transform: uppercase; letter-spacing: .5px;
}

/* Menu */
.sidebar-menu { list-style: none; padding: 10px 0 24px; flex: 1; }

.sidebar-menu li a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 3px 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: var(--transition);
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
  position: relative;
}
.sidebar-menu li a i {
  width: 20px;
  text-align: center;
  font-size: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: var(--transition);
}
.sidebar-menu li a:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.sidebar-menu li a:hover i {
  color: var(--primary);
}

.sidebar-menu li.active a {
  background: linear-gradient(135deg, var(--primary-light) 0%, #e0e7ff 100%);
  color: var(--primary);
  font-weight: 600;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.sidebar-menu li.active a i {
  color: var(--primary);
}

.menu-header {
  padding: 16px 22px 5px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; color: #9ca3af; font-weight: 700;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: #f1f5f9; }
.sidebar::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 4px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: #64748b; }

/* Main */
.main-content {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

.topbar {
  background: var(--white);
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
  backdrop-filter: blur(10px);
}
.sidebar-toggle { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text); padding: 6px; }
.topbar-right { display: flex; align-items: center; gap: 20px; }
.date-display { color: var(--text-muted); font-size: 13px; }
.user-menu { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.user-menu i { font-size: 22px; color: var(--primary); }
.btn-logout { color: var(--danger); text-decoration: none; margin-left: 8px; font-size: 16px; }

.content-area {
  padding: 30px;
  flex: 1;
}

/* Cards */
.card {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  transition: var(--transition);
}
.card:hover {
  box-shadow: var(--card-shadow-hover);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--border-light);
}
.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--white);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  transition: var(--transition);
}
.stat-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-shadow-hover);
}
.stat-icon {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}
.stat-icon.blue {
  background: linear-gradient(135deg, var(--primary-light) 0%, #e0e7ff 100%);
  color: var(--primary);
}
.stat-icon.green {
  background: linear-gradient(135deg, var(--success-light) 0%, #ecfdf5 100%);
  color: var(--success);
}
.stat-icon.red {
  background: linear-gradient(135deg, var(--danger-light) 0%, #fef2f2 100%);
  color: var(--danger);
}
.stat-icon.orange {
  background: linear-gradient(135deg, var(--warning-light) 0%, #fffbeb 100%);
  color: var(--warning);
}
.stat-icon.cyan {
  background: linear-gradient(135deg, var(--info-light) 0%, #ecf9ff 100%);
  color: var(--info);
}
.stat-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  letter-spacing: -1px;
}
.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  font-weight: 500;
}

/* Table */
.table-responsive {
  overflow-x: auto;
  border-radius: 12px;
}
table {
  width: 100%;
  border-collapse: collapse;
}
table th {
  background: var(--bg-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 700;
  padding: 14px 16px;
  text-align: left;
  border-bottom: 2px solid var(--border);
}
table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
  font-size: 13px;
}
table tbody tr {
  transition: var(--transition);
}
table tbody tr:hover {
  background: var(--bg-secondary);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  transition: var(--transition);
}
.badge-success {
  background: var(--success-light);
  color: #065f46;
}
.badge-danger {
  background: var(--danger-light);
  color: #7f1d1d;
}
.badge-warning {
  background: var(--warning-light);
  color: #78350f;
}
.badge-info {
  background: var(--info-light);
  color: #0e5a6f;
}
.badge-secondary {
  background: var(--bg-secondary);
  color: #334155;
}
.badge-primary {
  background: var(--primary-light);
  color: #1e3a8a;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}
.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}
.btn-warning {
  background: var(--warning);
  color: #fff;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}
.btn-warning:hover {
  transform: translateY(-2px);
}
.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}
.btn-secondary:hover {
  background: var(--border);
  transform: translateY(-2px);
}
.btn-sm {
  padding: 6px 12px;
  font-size: 12px;
}
.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Forms */
.form-group {
  margin-bottom: 18px;
}
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: -0.1px;
}
.form-control {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  transition: var(--transition);
  font-family: inherit;
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}
.form-control::placeholder {
  color: var(--text-muted);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.page-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
}
.page-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
  font-weight: 500;
}

/* Alert */
.alert {
  padding: 14px 18px;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-left: 4px solid transparent;
  transition: var(--transition);
}
.alert-success {
  background: var(--success-light);
  color: #065f46;
  border-left-color: var(--success);
}
.alert-danger {
  background: var(--danger-light);
  color: #7f1d1d;
  border-left-color: var(--danger);
}
.alert-info {
  background: var(--info-light);
  color: #0e5a6f;
  border-left-color: var(--info);
}
.alert-warning {
  background: var(--warning-light);
  color: #78350f;
  border-left-color: var(--warning);
}

/* Attendance status colors */
.status-present { color: var(--success); font-weight: 600; }
.status-absent { color: var(--danger); font-weight: 600; }
.status-late { color: var(--warning); font-weight: 600; }
.status-half_day { color: var(--info); font-weight: 600; }
.status-holiday { color: var(--secondary); font-weight: 600; }
.status-leave { color: var(--primary); font-weight: 600; }

/* Login Page */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e293b 0%, #334155 100%); }
.login-box { background: var(--white); border-radius: 16px; padding: 40px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo i { font-size: 48px; color: var(--primary); }
.login-logo h2 { font-size: 22px; font-weight: 700; margin-top: 10px; }
.login-logo p { color: var(--text-muted); font-size: 13px; }

/* Avatar */
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }

/* ── Overlay — always in DOM, hidden by default ── */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,.5);
  z-index: 1099;
}
.sidebar-overlay.show { display: block; }

/* ── Mobile — 768px and below ── */
@media (max-width: 768px) {

  /* Sidebar: slide off-screen left, override base transition */
  .sidebar {
    transform: translateX(-100%) !important;
    transition: transform .26s ease !important;
    z-index: 1100;
    box-shadow: none !important;
    width: 260px;
  }
  .sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 8px 0 32px rgba(0,0,0,.28) !important;
  }

  /* Content: full width, no left margin */
  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
  }

  /* Topbar */
  .topbar {
    height: 54px !important;
    padding: 0 12px !important;
  }
  .topbar-right { gap: 8px; }
  .date-display { display: none !important; }
  #session-timer { display: none !important; }

  /* Content padding */
  .content-area { padding: 12px !important; }

  /* Page header stacks vertically */
  .page-header {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px;
  }
  .page-header > .btn,
  .page-header > a.btn { width: 100%; justify-content: center; }

  /* Stats grid: 2 columns */
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 18px !important; }

  /* Tables: scrollable, no overflow break */
  .table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 480px; }
  th, td {
    padding: 7px 9px !important;
    font-size: 12px !important;
    white-space: nowrap;
  }

  /* Forms stack vertically */
  .card form {
    flex-direction: column !important;
    gap: 10px !important;
  }
  .card form .form-group {
    min-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
  }
  .card form .form-control { width: 100% !important; }
  .card form .btn { width: 100% !important; }

  /* Two-column dashboard grids → single column */
  div[style*="grid-template-columns:2fr 1fr"],
  div[style*="grid-template-columns: 2fr 1fr"] {
    display: flex !important;
    flex-direction: column !important;
  }

  /* User menu: icon only */
  .user-menu > span:not(.avatar) { display: none; }

  .hide-mobile { display: none !important; }
}

/* Print */
@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0; }
  .content-area { padding: 0; }
}

/* ===== PERFORMANCE MODULE ===== */
.perf-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.perf-card {
  background: #fff;
  border-radius: 12px;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--card-shadow);
  border-left: 4px solid transparent;
}
.perf-card-purple { border-color: #6c63ff; }
.perf-card-blue   { border-color: #3b82f6; }
.perf-card-green  { border-color: #10b981; }
.perf-card-orange { border-color: #f59e0b; }
.perf-card-red    { border-color: #ef4444; }

.perf-card-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff; flex-shrink: 0;
}
.perf-card-purple .perf-card-icon { background: #6c63ff; }
.perf-card-blue   .perf-card-icon { background: #3b82f6; }
.perf-card-green  .perf-card-icon { background: #10b981; }
.perf-card-orange .perf-card-icon { background: #f59e0b; }
.perf-card-red    .perf-card-icon { background: #ef4444; }

.perf-card-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.perf-card-label { font-size: 12px; color: #888; margin-top: 4px; }

.perf-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 0;
}

.perf-table th, .perf-table td { vertical-align: middle !important; }

/* Rank badges */
.rank-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  font-weight: 700; font-size: 13px; color: #fff;
}
.rank-1 { background: #f59e0b; }
.rank-2 { background: #9ca3af; }
.rank-3 { background: #b45309; }

/* Grade badges */
.grade-badge {
  display: inline-block;
  padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 700; color: #fff;
}
.grade-a\+, .grade-ap { background: #10b981; }
.grade-a              { background: #22c55e; }
.grade-b\+, .grade-bp { background: #84cc16; }
.grade-b              { background: #eab308; color: #000; }
.grade-c\+, .grade-cp { background: #f97316; }
.grade-c              { background: #ef4444; }
.grade-d              { background: #dc2626; }
.grade-f, .grade---   { background: #9ca3af; }

/* Platform badge */
.platform-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 12px; color: #fff; font-weight: 500;
}

/* Employee avatars */
.emp-avatar-sm {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #6c63ff, #3b82f6);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.emp-avatar-lg {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, #6c63ff, #3b82f6);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; flex-shrink: 0;
}

/* Metric inputs grid */
.perf-metrics { grid-template-columns: repeat(5, 1fr) !important; }
.metric-input label { font-size: 12px; }

/* Score formula */
.score-formula-row {
  display: flex; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid #f0f0f5;
  font-size: 13px;
}
.score-formula-row:last-of-type { border-bottom: none; }

/* Row no data */
.row-no-data { opacity: 0.5; }

@media (max-width: 900px) {
  .perf-cards { grid-template-columns: 1fr 1fr; }
  .perf-grid-2 { grid-template-columns: 1fr; }
  .perf-metrics { grid-template-columns: 1fr 1fr !important; }
}
