:root {
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --danger-color: #ef4444;
  --warning-color: #f59e0b;
  --light-bg: #f9fafb;
  --card-bg: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  --sidebar-bg: #1f2937;
  --sidebar-hover: #374151;
  --sidebar-active: #4f46e5;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 60px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--light-bg);
}

/* App Layout */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar - Collapsed by default, expands on hover */
.sidebar {
  width: var(--sidebar-collapsed-width);
  background: var(--sidebar-bg);
  color: white;
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transition: width 0.2s ease;
  overflow-x: hidden;
  overflow-y: hidden;
}

.sidebar:hover {
  width: var(--sidebar-width);
}

/* Hide text when collapsed */
.sidebar .nav-text,
.sidebar .sidebar-brand h1,
.sidebar .sidebar-brand p,
.sidebar .sidebar-user-details,
.sidebar .sidebar-logout,
.sidebar .sidebar-bottom .sidebar-user-info {
  opacity: 0;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}

.sidebar:hover .nav-text,
.sidebar:hover .sidebar-brand h1,
.sidebar:hover .sidebar-brand p,
.sidebar:hover .sidebar-user-details,
.sidebar:hover .sidebar-logout,
.sidebar:hover .sidebar-bottom .sidebar-user-info {
  opacity: 1;
}

.sidebar-brand {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
}

.sidebar-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
  margin: 0;
}

.sidebar-brand p {
  font-size: 0.875rem;
  color: #9ca3af;
  margin: 0.25rem 0 0 0;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: #4b5563;
  border-radius: 2px;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li {
  margin: 0.25rem 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: #d1d5db;
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: white;
  border-left-color: var(--primary-color);
}

.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: white;
  border-left-color: white;
}

.sidebar-nav .nav-icon {
  font-size: 1.125rem;
  width: 1.25rem;
  text-align: center;
}

.sidebar-bottom {
  padding: 1rem 1.25rem;
  border-top: 1px solid #374151;
  flex-shrink: 0;
}

.sidebar-user {
  padding: 1rem 1.25rem;
  border-top: 1px solid #374151;
  flex-shrink: 0;
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.sidebar-user-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
}

.sidebar-user-details h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: white;
  margin: 0;
}

.sidebar-user-details p {
  font-size: 0.75rem;
  color: #9ca3af;
  margin: 0;
}

.sidebar-logout {
  width: 100%;
  background: #374151;
  color: #d1d5db;
  border: none;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.sidebar-logout:hover {
  background: #4b5563;
  color: white;
}

/* Main Content */
.main-content {
  margin-left: var(--sidebar-collapsed-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.2s ease;
}

.top-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

.page-header h1 {
  font-size: 1.875rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.page-header p {
  font-size: 1rem;
  color: var(--text-secondary);
  margin: 0.25rem 0 0 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.content-wrapper {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  width: 100%;
}

/* Enhanced Cards */
.card {
  background: var(--card-bg);
  border-radius: 0.375rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.card-header {
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--border-color);
  background: var(--light-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: var(--text-primary);
}

.card-body {
  padding: 2rem;
}

/* Enhanced Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.25rem;
  font-weight: 500;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
  line-height: 1.25;
}

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

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--primary-hover);
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px 0 rgb(59 130 246 / 0.4);
}

.btn-secondary {
  background-color: #f3f4f6;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #e5e7eb;
  border-color: #d1d5db;
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  color: var(--primary-color);
  border: 1.5px solid var(--primary-color);
}

.btn-outline:hover:not(:disabled) {
  background-color: var(--primary-color);
  color: white;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.8125rem;
}

.btn-xs {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
}

/* Enhanced Form Controls */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 0.875rem;
}

.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: 0.25rem;
  font-size: 0.875rem;
  transition: all 0.2s ease;
  background-color: var(--card-bg);
  color: var(--text-primary);
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

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

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  text-align: center;
  padding: 2rem 1.5rem;
}

.stat-number {
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.stat-label {
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
}

/* Activity Section */
.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.activity-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.activity-toggle {
  width: 2rem;
  height: 2rem;
  border: 1.5px solid var(--border-color);
  background: var(--card-bg);
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.activity-toggle:hover {
  border-color: var(--primary-color);
  background: var(--primary-light);
  color: var(--primary-color);
}

.activity-filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-group select {
  min-width: 140px;
}

/* Activity Items */
.activity-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.activity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  background: var(--light-bg);
  border-radius: 0.25rem;
  border-left: 4px solid var(--primary-color);
}

.activity-content h4 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin: 0 0 0.25rem 0;
}

.activity-content p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin: 0;
}

.activity-meta {
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.activity-meta div:first-child {
  font-weight: 500;
  margin-bottom: 0.125rem;
}

/* Pagination */
.pagination-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: 1rem;
}

.pagination-info {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pagination-nav {
  display: flex;
  gap: 0.5rem;
}

.page-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 0.25rem;
  margin-bottom: 1rem;
  border: 1px solid;
}

.alert-success {
  background-color: #ecfdf5;
  color: var(--success-color);
  border-color: #a7f3d0;
}

.alert-danger {
  background-color: #fef2f2;
  color: var(--danger-color);
  border-color: #fecaca;
}

/* Responsive */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main-content {
    margin-left: 0;
  }
  
  .content-wrapper {
    padding: 1.5rem;
  }
}

@media (max-width: 768px) {
  .activity-header {
    flex-direction: column;
    align-items: stretch;
  }
  
  .activity-filters {
    justify-content: stretch;
  }
  
  .filter-group {
    flex: 1;
  }
  
  .filter-group select {
    width: 100%;
  }
  
  .pagination-wrapper {
    flex-direction: column;
    text-align: center;
  }
  
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* Loading states */
.loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* ========== Dark Mode ========== */
[data-theme="dark"] {
  --primary-color: #60a5fa;
  --primary-hover: #3b82f6;
  --primary-light: #1e3a5f;
  --secondary-color: #94a3b8;
  --success-color: #34d399;
  --danger-color: #f87171;
  --warning-color: #fbbf24;
  --light-bg: #111827;
  --card-bg: #1f2937;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #6b7280;
  --border-color: #374151;
  --sidebar-bg: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #4f46e5;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

/* Form controls */
[data-theme="dark"] .form-control,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] input[type="text"],
[data-theme="dark"] input[type="email"],
[data-theme="dark"] input[type="number"],
[data-theme="dark"] input[type="date"] {
  background-color: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--border-color);
}

/* Buttons */
[data-theme="dark"] .btn-secondary {
  background-color: #374151;
  color: var(--text-primary);
  border-color: #4b5563;
}

[data-theme="dark"] .btn-secondary:hover:not(:disabled) {
  background-color: #4b5563;
  border-color: #6b7280;
}

[data-theme="dark"] .btn-success {
  background-color: #059669;
  color: white;
}

[data-theme="dark"] .btn-warning {
  background-color: #d97706;
  color: white;
}

/* Activity toggle */
[data-theme="dark"] .activity-toggle {
  background: var(--card-bg);
}

/* Alerts */
[data-theme="dark"] .alert-success {
  background-color: #064e3b;
  color: #6ee7b7;
  border-color: #065f46;
}

[data-theme="dark"] .alert-danger {
  background-color: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}

/* DataTables overrides */
[data-theme="dark"] .dataTables_wrapper {
  color: var(--text-primary);
}

[data-theme="dark"] table.dataTable {
  background: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] table.dataTable thead th,
[data-theme="dark"] table.dataTable thead td {
  background: var(--light-bg);
  color: var(--text-primary);
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] table.dataTable tbody tr {
  background: var(--card-bg);
  color: var(--text-primary);
}

[data-theme="dark"] table.dataTable tbody tr:hover {
  background: #374151;
}

[data-theme="dark"] table.dataTable tbody td {
  border-bottom-color: var(--border-color);
}

[data-theme="dark"] table.dataTable.stripe tbody tr.odd,
[data-theme="dark"] table.dataTable.display tbody tr.odd {
  background: #1a2332;
}

[data-theme="dark"] table.dataTable.stripe tbody tr.even,
[data-theme="dark"] table.dataTable.display tbody tr.even {
  background: var(--card-bg);
}

[data-theme="dark"] .dataTables_info,
[data-theme="dark"] .dataTables_length,
[data-theme="dark"] .dataTables_filter {
  color: var(--text-secondary);
}

[data-theme="dark"] .dataTables_length select,
[data-theme="dark"] .dataTables_filter input {
  background: var(--card-bg);
  color: var(--text-primary);
  border-color: var(--border-color);
}

[data-theme="dark"] .dataTables_paginate .paginate_button {
  color: var(--text-primary) !important;
  background: var(--card-bg);
  border-color: var(--border-color);
}

[data-theme="dark"] .dataTables_paginate .paginate_button:hover {
  background: #374151 !important;
  color: var(--text-primary) !important;
  border-color: #4b5563;
}

[data-theme="dark"] .dataTables_paginate .paginate_button.current {
  background: var(--primary-color) !important;
  color: white !important;
  border-color: var(--primary-color);
}

[data-theme="dark"] .dataTables_paginate .paginate_button.disabled {
  color: var(--text-muted) !important;
}

/* Status badges dark mode */
[data-theme="dark"] .status-pending {
  background-color: #422006;
  color: #fbbf24;
}

[data-theme="dark"] .status-queued {
  background-color: #1e3a5f;
  color: #93c5fd;
}

[data-theme="dark"] .status-running {
  background-color: #064e3b;
  color: #6ee7b7;
}

[data-theme="dark"] .status-completed {
  background-color: #14532d;
  color: #86efac;
}

[data-theme="dark"] .status-failed {
  background-color: #7f1d1d;
  color: #fca5a5;
}

/* Links */
[data-theme="dark"] a {
  color: var(--primary-color);
}

/* Sidebar brand border */
[data-theme="dark"] .sidebar-brand {
  border-bottom-color: #1e293b;
}

[data-theme="dark"] .sidebar-user,
[data-theme="dark"] .sidebar-bottom {
  border-top-color: #1e293b;
}

/* Scrollbar */
[data-theme="dark"] ::-webkit-scrollbar {
  background: var(--light-bg);
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
  background: #4b5563;
  border-radius: 4px;
}

/* Login page */
[data-theme="dark"] .login-container,
[data-theme="dark"] .login-card {
  background: var(--card-bg);
  color: var(--text-primary);
}