/* ============================================================
   WorkPass Cert Manager — Design System & Styles
   Premium dark-mode dashboard with glassmorphism accents
   ============================================================ */

/* ─── CSS Custom Properties (Design Tokens) ──────────────── */
:root {
  /* Colors */
  --bg-primary: #0f1117;
  --bg-secondary: #161822;
  --bg-card: #1c1f2e;
  --bg-card-hover: #232740;
  --bg-sidebar: #12141e;
  --bg-input: #1c1f2e;
  --bg-modal: #1c1f2e;

  --text-primary: #e8eaed;
  --text-secondary: #9ba1b0;
  --text-muted: #6b7280;
  --text-white: #ffffff;

  --border-color: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);

  /* Accent Colors */
  --accent-primary: #6366f1;
  --accent-primary-hover: #818cf8;
  --accent-primary-glow: rgba(99, 102, 241, 0.25);

  --accent-success: #10b981;
  --accent-success-bg: rgba(16, 185, 129, 0.12);
  --accent-warning: #f59e0b;
  --accent-warning-bg: rgba(245, 158, 11, 0.12);
  --accent-danger: #ef4444;
  --accent-danger-bg: rgba(239, 68, 68, 0.12);
  --accent-info: #3b82f6;
  --accent-info-bg: rgba(59, 130, 246, 0.12);
  --accent-purple: #a855f7;
  --accent-purple-bg: rgba(168, 85, 247, 0.12);

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.8125rem;
  --font-size-base: 0.875rem;
  --font-size-md: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;

  /* Spacing */
  --sidebar-width: 260px;
  --header-height: 64px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-primary-glow);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  line-height: 1.6;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

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

/* ─── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-base);
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), #a855f7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-glow);
}

.logo-title {
  font-size: var(--font-size-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-white);
  line-height: 1.2;
}

.logo-subtitle {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-weight: 500;
  transition: all var(--transition-fast);
  cursor: pointer;
  position: relative;
}

.nav-link:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.nav-link.active {
  color: var(--text-white);
  background: rgba(99, 102, 241, 0.12);
}

.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  border-radius: 0 3px 3px 0;
  background: var(--accent-primary);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
}

.sidebar-footer-text {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.version {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.env-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-success-bg);
  color: var(--accent-success);
  letter-spacing: 0.05em;
}

/* ─── Mobile Header ──────────────────────────────────────── */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  z-index: 90;
  padding: 0 16px;
  align-items: center;
  gap: 12px;
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.menu-toggle:hover {
  background: rgba(255,255,255,0.06);
}

.mobile-title {
  font-weight: 700;
  font-size: var(--font-size-md);
  color: var(--text-white);
}

/* ─── Main Content ───────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 32px;
  min-height: 100vh;
}

.page { display: none; animation: fadeIn 0.3s ease; }
.page.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  margin-bottom: 28px;
}

.page-title {
  font-size: var(--font-size-xl);
  font-weight: 800;
  color: var(--text-white);
  letter-spacing: -0.02em;
}

.page-description {
  color: var(--text-secondary);
  margin-top: 4px;
  font-size: var(--font-size-sm);
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* ─── Stats Grid ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

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

.stat-card--primary::after { background: linear-gradient(90deg, var(--accent-primary), var(--accent-purple)); }
.stat-card--success::after { background: var(--accent-success); }
.stat-card--warning::after { background: var(--accent-warning); }
.stat-card--danger::after { background: var(--accent-danger); }
.stat-card--info::after { background: var(--accent-info); }
.stat-card--purple::after { background: var(--accent-purple); }

.stat-card--primary .stat-icon { background: var(--accent-primary-glow); color: var(--accent-primary); }
.stat-card--success .stat-icon { background: var(--accent-success-bg); color: var(--accent-success); }
.stat-card--warning .stat-icon { background: var(--accent-warning-bg); color: var(--accent-warning); }
.stat-card--danger .stat-icon { background: var(--accent-danger-bg); color: var(--accent-danger); }
.stat-card--info .stat-icon { background: var(--accent-info-bg); color: var(--accent-info); }
.stat-card--purple .stat-icon { background: var(--accent-purple-bg); color: var(--accent-purple); }

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 800;
  color: var(--text-white);
  line-height: 1;
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  margin-top: 4px;
  font-weight: 500;
}

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--text-white);
}

/* ─── Tables ─────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 12px 16px;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

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

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

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

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 16px !important;
  font-style: italic;
}

/* ─── Status Badges ──────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge--active, .badge--valid {
  background: var(--accent-success-bg);
  color: var(--accent-success);
}

.badge--expired {
  background: var(--accent-danger-bg);
  color: var(--accent-danger);
}

.badge--cancelled, .badge--revoked {
  background: var(--accent-warning-bg);
  color: var(--accent-warning);
}

/* ─── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-primary);
  color: white;
  box-shadow: 0 2px 8px var(--accent-primary-glow);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--border-hover);
}

.btn-danger {
  background: var(--accent-danger-bg);
  color: var(--accent-danger);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn-sm {
  padding: 5px 10px;
  font-size: var(--font-size-xs);
}

.btn-block {
  width: 100%;
  justify-content: center;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ─── Action Buttons (in table) ──────────────────────────── */
.action-btns {
  display: flex;
  gap: 6px;
}

.action-btn {
  background: none;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.action-btn:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background: var(--accent-primary-glow);
}

.action-btn--danger:hover {
  border-color: var(--accent-danger);
  color: var(--accent-danger);
  background: var(--accent-danger-bg);
}

/* ─── Search Box ─────────────────────────────────────────── */
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: border-color var(--transition-fast);
}

.search-box:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

.search-box svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-box input {
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  padding: 9px 0;
  outline: none;
  width: 220px;
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* ─── Select Filter ──────────────────────────────────────── */
.select-filter {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  padding: 9px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba1b0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.select-filter:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

/* ─── Form Controls ──────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.form-group label {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-control {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--transition-fast);
  width: 100%;
}

.form-control:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-primary-glow);
}

.form-control::placeholder {
  color: var(--text-muted);
}

.form-row {
  display: flex;
  gap: 12px;
}

select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba1b0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

/* ─── Upload Zone ────────────────────────────────────────── */
.upload-area {
  max-width: 640px;
}

.upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
  background: var(--bg-card);
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.04);
}

.upload-zone.drag-over {
  transform: scale(1.01);
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 12px;
}

.upload-zone h3 {
  color: var(--text-primary);
  font-size: var(--font-size-md);
  font-weight: 600;
  margin-bottom: 4px;
}

.upload-zone p {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.upload-form {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ─── Progress Bar ───────────────────────────────────────── */
.upload-progress {
  margin-top: 20px;
}

.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-purple));
  border-radius: 3px;
  width: 0%;
  transition: width var(--transition-base);
}

.progress-text {
  display: block;
  margin-top: 8px;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  text-align: center;
}

/* ─── Upload Results ─────────────────────────────────────── */
.upload-results {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
}

.upload-result-item.success { border-left: 3px solid var(--accent-success); }
.upload-result-item.error { border-left: 3px solid var(--accent-danger); }

/* ─── Pagination ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px;
}

.pagination button {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination button:hover {
  background: rgba(255,255,255,0.08);
  color: var(--text-primary);
}

.pagination button.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Modal ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
  padding: 20px;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

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

.modal-title {
  font-size: var(--font-size-md);
  font-weight: 700;
  color: var(--text-white);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255,255,255,0.06);
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ─── Toast Notifications ────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 380px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  animation: toastSlideIn 0.3s ease;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
}

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

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast-dismiss {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
  margin-left: auto;
  line-height: 1;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-header {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 80px 16px 24px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .page-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .search-box input {
    width: 100%;
  }

  .form-row {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
