/* ═══════════════════════════════════════════════
   ATTENDANCE PORTAL — Sage-Style Dark Theme
   ═══════════════════════════════════════════════ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-main: #121212;
  --bg-card: #1a1a1a;
  --bg-sidebar: #121212;
  --bg-input: #1a1a1a;
  --border: #2a2a2a;
  --border-light: #333;
  --text: #ffffff;
  --text-secondary: #d1d5db;
  --text-muted: #9ca3af;
  --accent: #2563eb;
  --accent-hover: #3b82f6;
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.12);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59,130,246,0.12);
  --orange: #f59e0b;
  --orange-bg: rgba(245,158,11,0.12);
  --purple: #a855f7;
  --gray-bg: rgba(107,114,128,0.15);
  --sidebar-w: 240px;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text);
  min-height: 100vh;
  display: flex;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar .logo {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar .logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.sidebar .logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.sidebar nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav .nav-section {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 16px 12px 8px;
  font-weight: 600;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border-radius: 8px;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: var(--text-secondary); }
.sidebar nav a.active { background: rgba(37,99,235,0.12); color: var(--accent); }
.sidebar nav a .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar .nav-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ═══ MAIN ═══ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ═══ TOPBAR ═══ */
.topbar {
  padding: 14px 24px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  z-index: 200;
}

.search-box {
  flex: 1;
  max-width: 500px;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  font-size: 14px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 10px 14px 10px 40px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.search-shortcut {
  position: absolute;
  right: 12px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--border);
  padding: 2px 8px;
  border-radius: 4px;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
}

.user-name { font-size: 13px; font-weight: 500; }

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 99;
}

/* ═══ CONTENT ═══ */
.content {
  padding: 24px;
  flex: 1;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
}

.page-header p {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ═══ STAT CARDS ═══ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.stat-icon.green { background: var(--green-bg); }
.stat-icon.red { background: var(--red-bg); }
.stat-icon.blue { background: var(--blue-bg); }
.stat-icon.orange { background: var(--orange-bg); }

.stat-info { flex: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.stat-value.green { color: var(--green); }
.stat-value.red { color: var(--red); }
.stat-value.blue { color: var(--blue); }
.stat-value.orange { color: var(--orange); }

/* ═══ TABLES ═══ */
.table-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 24px;
}

.table-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.table-header h3 { font-size: 16px; font-weight: 600; }

.table-responsive { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: rgba(255,255,255,0.03);
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody td { padding: 12px 16px; }

/* ═══ EMPLOYEE ROW (with avatar) ═══ */
.emp-cell {
  display: flex;
  align-items: center;
  gap: 12px;
}

.emp-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  flex-shrink: 0;
}

.emp-name { font-weight: 600; font-size: 13px; }
.emp-dept { font-size: 11px; color: var(--text-muted); }

/* ═══ STATUS BADGES ═══ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-present { background: var(--green-bg); color: var(--green); }
.badge-leave { background: var(--blue-bg); color: var(--blue); }
.badge-absent { background: var(--red-bg); color: var(--red); }
.badge-active { background: transparent; border: 1px solid var(--green); color: var(--green); }
.badge-offday { background: rgba(255,255,255,0.05); color: var(--text-muted); }
.badge-late { background: var(--red-bg); color: var(--red); }
.badge-early { background: var(--orange-bg); color: var(--orange); }
.badge-both { background: rgba(168,85,247,0.12); color: var(--purple); }
.badge-on-time { background: var(--green-bg); color: var(--green); }

/* ═══ HOURS BADGE ═══ */
.hours-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}

.hours-badge.green { background: var(--green-bg); color: var(--green); }
.hours-badge.red { background: var(--red-bg); color: var(--red); }
.hours-badge.blue { background: var(--blue-bg); color: var(--blue); }
.hours-badge.gray { background: rgba(255,255,255,0.05); color: var(--text-muted); }

/* ═══ ATTENDANCE HIGHLIGHTS ═══ */
.cell-late { background: rgba(239,68,68,0.12) !important; color: #f87171; font-weight: 600; }
.cell-late-severe { background: rgba(239,68,68,0.2) !important; color: #ef4444; font-weight: 700; }
.cell-early { background: rgba(245,158,11,0.12) !important; color: #fbbf24; font-weight: 600; }
.cell-early-severe { background: rgba(245,158,11,0.2) !important; color: #f59e0b; font-weight: 700; }
.cell-perfect { background: rgba(34,197,94,0.1) !important; color: #86efac; }
.cell-offday { background: rgba(255,255,255,0.03) !important; color: var(--text-muted); font-style: italic; }
.cell-absent { background: rgba(239,68,68,0.1) !important; color: #fca5a5; font-weight: 600; }
.cell-total-high { color: var(--red) !important; font-weight: 700; }

/* ═══ BUTTONS ═══ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-download { background: var(--accent); color: #fff; gap: 8px; }

/* ═══ FORMS ═══ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }

.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus { border-color: var(--accent); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239ca3af' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ═══ FILTER BAR ═══ */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.filter-bar .form-control { max-width: 200px; }

.filter-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.filter-tag .remove { cursor: pointer; color: var(--text-muted); font-size: 14px; }

/* ═══ UPLOAD ZONE ═══ */
.upload-zone {
  border: 2px dashed var(--border-light);
  border-radius: 16px;
  padding: 48px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: var(--bg-card);
}

.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(37,99,235,0.05);
}

.upload-zone .upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-zone h3 { font-size: 16px; margin-bottom: 8px; }
.upload-zone p { font-size: 13px; color: var(--text-muted); }
.upload-zone input[type="file"] { display: none; }

/* ═══ TABS ═══ */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg-card);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { background: var(--accent); color: #fff; }

/* ═══ CHARTS ═══ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.chart-card h4 {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.chart-card canvas { max-height: 300px; }

/* ═══ EMPLOYEE HEADER ═══ */
.employee-header {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.employee-avatar-lg {
  width: 64px; height: 64px;
  background: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: #fff;
}

.employee-info h2 { font-size: 22px; font-weight: 700; }
.employee-info .meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 16px;
  margin-top: 4px;
}

/* ═══ TOAST ═══ */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 20px;
  margin-bottom: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideIn 0.3s ease;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--accent); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ═══ LOADING ═══ */
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  flex-direction: column;
  gap: 16px;
  color: var(--text-muted);
}

/* ═══ EMPTY STATE ═══ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* ═══ MOBILE ═══ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    z-index: 1000;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 999;
  }
  .sidebar-overlay.show { display: block; }
  .hamburger {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 20px;
    cursor: pointer;
    z-index: 1001;
  }
  .main { margin-left: 0; }
  .topbar {
    padding: 12px 16px;
    gap: 10px;
  }
  .content { padding: 16px; }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .page-header h1 { font-size: 20px; }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .stat-card {
    padding: 14px;
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .stat-icon { width: 36px; height: 36px; font-size: 16px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 11px; }
  .stat-sub { font-size: 10px; }
  .charts-grid { grid-template-columns: 1fr; }
  .chart-card { padding: 14px; }
  .table-wrapper { border-radius: 10px; }
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { font-size: 11px; min-width: 600px; }
  thead th { padding: 8px 10px; font-size: 10px; }
  tbody td { padding: 8px 10px; }
  .emp-cell { gap: 8px; }
  .emp-avatar { width: 28px; height: 28px; font-size: 10px; }
  .emp-name { font-size: 12px; }
  .employee-header {
    flex-direction: column;
    text-align: center;
    padding: 16px;
    gap: 16px;
  }
  .employee-avatar-lg { width: 52px; height: 52px; font-size: 20px; }
  .employee-info h2 { font-size: 18px; }
  .employee-info .meta {
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
  }
  .filter-bar {
    flex-direction: column;
    gap: 10px;
  }
  .filter-bar .form-control {
    max-width: 100%;
    font-size: 13px;
  }
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    padding: 3px;
  }
  .tab-btn {
    padding: 8px 14px;
    font-size: 12px;
    white-space: nowrap;
  }
  .search-shortcut { display: none; }
  .user-name { display: none; }
  .upload-zone { padding: 32px 16px; }
  .badge { padding: 3px 8px; font-size: 10px; }
  .hours-badge { padding: 3px 7px; font-size: 10px; }
  .btn { padding: 8px 14px; font-size: 12px; }
  .btn-sm { padding: 5px 10px; font-size: 11px; }
  .toast { min-width: auto; max-width: 90vw; font-size: 12px; }
  .toast-container { left: 16px; right: 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { flex-direction: row; }
  table { min-width: 500px; }
}

/* Touch-friendly tap targets */
@media (hover: none) and (pointer: coarse) {
  .nav-link { padding: 14px 16px; min-height: 44px; }
  .btn { min-height: 44px; }
  .tab-btn { min-height: 44px; padding: 10px 16px; }
  tbody tr { min-height: 48px; }
  .form-control { min-height: 44px; }
  select.form-control { min-height: 44px; }
}

/* ═══ PRINT ═══ */
@media print {
  .sidebar, .topbar, .hamburger, .btn, .filter-bar { display: none !important; }
  .main { margin-left: 0 !important; }
  body { background: #fff; color: #000; }
  .stat-card { border: 1px solid #ddd; }
  table { font-size: 11px; }
  thead th { background: #f0f0f0; color: #333; }
}
