/* ============ BASE & ANIMATIONS ============ */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(59, 130, 246, 0); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.animate-fade-in {
  animation: fadeIn 0.4s ease-out;
}

/* ============ SIDEBAR NAVIGATION ============ */
.sidebar {
  width: 240px;
  min-height: calc(100vh - 64px);
  background: white;
  border-right: 1px solid #e2e8f0;
  position: fixed;
  top: 64px;
  left: 0;
  z-index: 40;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 35;
  top: 64px;
}

@media (max-width: 1023px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open {
    display: block;
  }
}

.main-content {
  margin-left: 240px;
  min-height: calc(100vh - 64px);
}

@media (max-width: 1023px) {
  .main-content {
    margin-left: 0;
  }
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin: 2px 8px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  user-select: none;
}
.nav-item:hover {
  background: #f1f5f9;
  color: #334155;
}
.nav-item.active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.35);
}
.nav-item.active svg {
  color: white;
}
.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: #94a3b8;
  transition: color 0.2s;
}
.nav-item:hover svg {
  color: #475569;
}
.nav-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  padding: 16px 16px 4px 24px;
}

/* ============ TAB BUTTONS (fallback, hidden with sidebar) ============ */
.tab-btn {
  @apply px-4 py-3 text-sm font-medium text-gray-500 border-b-2 border-transparent whitespace-nowrap
         hover:text-gray-700 hover:border-gray-300 transition-all;
}
.tab-btn.active {
  @apply text-blue-600 border-blue-600;
}

/* ============ METRIC CARDS ============ */
.metric-card {
  @apply bg-white rounded-2xl p-5 border border-surface-200 relative overflow-hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  transition: all 0.25s ease;
}
.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.08), 0 1px 4px rgba(0,0,0,0.04);
}
.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 2px 2px 0 0;
}
.metric-card:nth-child(1)::before { background: linear-gradient(90deg, #3b82f6, #60a5fa); }
.metric-card:nth-child(2)::before { background: linear-gradient(90deg, #10b981, #34d399); }
.metric-card:nth-child(3)::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.metric-card:nth-child(4)::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.metric-card:nth-child(5)::before { background: linear-gradient(90deg, #ef4444, #f87171); }
.metric-card:nth-child(6)::before { background: linear-gradient(90deg, #06b6d4, #22d3ee); }

.metric-card-sm {
  @apply bg-white rounded-xl p-4 border border-surface-200;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: all 0.2s ease;
}
.metric-card-sm:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.metric-label {
  @apply text-xs font-semibold uppercase tracking-wider mb-1;
  color: #94a3b8;
}
.metric-value {
  @apply text-2xl sm:text-3xl font-extrabold truncate;
  color: #1e293b;
  letter-spacing: -0.02em;
}
.metric-value-sm {
  @apply text-lg font-bold;
  color: #334155;
}

/* ============ CHART CARDS ============ */
.chart-card {
  @apply bg-white rounded-2xl p-6 border border-surface-200;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.03);
  animation: fadeIn 0.4s ease-out;
}
.chart-title {
  @apply text-sm font-bold uppercase tracking-wider mb-4;
  color: #475569;
  letter-spacing: 0.05em;
}

/* ============ DATA TABLES ============ */
.data-table {
  @apply w-full;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 800px;
}
.data-table thead tr {
  background: linear-gradient(135deg, #f8fafc, #f1f5f9);
}
.data-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: pointer;
  color: #64748b;
  transition: all 0.2s;
  border-bottom: 2px solid #e2e8f0;
  position: sticky;
  top: 0;
  z-index: 1;
  background: inherit;
}
.data-table th:hover {
  color: #1e293b;
  background: #e2e8f0;
}
.data-table th:first-child {
  border-radius: 8px 0 0 0;
}
.data-table th:last-child {
  border-radius: 0 8px 0 0;
}
.data-table td {
  padding: 12px 16px;
  white-space: nowrap;
  color: #475569;
  font-size: 0.8125rem;
  border-bottom: 1px solid #f1f5f9;
}
/* First column (name) gets more space and allows wrapping */
.data-table td:first-child {
  min-width: 200px;
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
  font-weight: 500;
  color: #334155;
}
/* Numeric columns need min-width so they don't collapse */
.data-table td.text-right,
.data-table th.text-right {
  text-align: right;
  min-width: 90px;
  font-variant-numeric: tabular-nums;
}
.data-table td.font-mono {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.75rem;
  letter-spacing: -0.02em;
}
.data-table tbody tr {
  transition: background 0.15s ease;
}
.data-table tbody tr:hover {
  background: #f0f7ff;
}
.data-table tbody tr:hover td {
  color: #1e293b;
}
.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ============ BUTTONS ============ */
.btn-primary {
  @apply px-5 py-2.5 text-white text-sm font-semibold rounded-xl transition-all;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
  @apply px-5 py-2.5 text-sm font-semibold rounded-xl border-2 transition-all;
  color: #475569;
  border-color: #e2e8f0;
  background: white;
}
.btn-secondary:hover {
  border-color: #93c5fd;
  color: #2563eb;
  background: #eff6ff;
}

.sort-btn {
  @apply px-4 py-1.5 text-xs font-semibold rounded-full border-2 transition-all;
  border-color: #e2e8f0;
  color: #64748b;
}
.sort-btn:hover {
  border-color: #93c5fd;
  color: #3b82f6;
  background: #eff6ff;
}
.sort-btn.active {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.3);
}

/* ============ INPUTS ============ */
.input-field {
  @apply w-full px-4 py-2.5 text-sm rounded-xl transition-all;
  border: 2px solid #e2e8f0;
  background: #f8fafc;
}
.input-field:focus {
  outline: none;
  border-color: #3b82f6;
  background: white;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ============ SCROLLBAR ============ */
.scrollbar-hide::-webkit-scrollbar { display: none; }
.scrollbar-hide { -ms-overflow-style: none; scrollbar-width: none; }

/* Nice scrollbar for sidebar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ============ FUNNEL BARS ============ */
.funnel-bar {
  @apply h-14 rounded-xl flex items-center justify-between px-5 text-white font-bold text-sm transition-all;
  min-width: 80px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* ============ STATUS BADGES ============ */
.badge-success {
  @apply inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold;
  background: #dcfce7;
  color: #166534;
}
.badge-error {
  @apply inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold;
  background: #fee2e2;
  color: #991b1b;
}
.badge-info {
  @apply inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold;
  background: #dbeafe;
  color: #1e40af;
}
.badge-warn {
  @apply inline-flex items-center px-3 py-1 rounded-full text-xs font-semibold;
  background: #fef3c7;
  color: #92400e;
}

/* ============ UPLOAD ITEMS ============ */
.upload-item {
  @apply flex items-center justify-between p-4 rounded-xl border-2 transition-all;
  border-color: #f1f5f9;
  background: #fafbfc;
}
.upload-item:hover {
  border-color: #e2e8f0;
  background: white;
}

/* ============ DROP ZONE ============ */
.drop-zone-custom {
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  padding: 48px 24px;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
  background: linear-gradient(135deg, #fafbfc, #f1f5f9);
}
.drop-zone-custom:hover {
  border-color: #3b82f6;
  background: linear-gradient(135deg, #eff6ff, #dbeafe);
}

/* ============ HEADER GRADIENT ============ */
.header-gradient {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

/* ============ LOGIN SCREEN ============ */
.login-bg {
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #1e293b 100%);
  position: relative;
  overflow: hidden;
}
.login-bg::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 40%, rgba(59, 130, 246, 0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 60%, rgba(139, 92, 246, 0.06) 0%, transparent 50%);
}

/* ============ TOGGLE SWITCH ============ */
.toggle-track {
  width: 44px;
  height: 24px;
  background: #cbd5e1;
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.3s;
}
.toggle-track.active {
  background: #3b82f6;
}
.toggle-track::after {
  content: '';
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle-track.active::after {
  transform: translateX(20px);
}
