/* ============================================
   BIDSY DESIGN SYSTEM
   SpaceX-inspired dark theme with purple accent
   ============================================ */

/* ---- CSS Custom Properties (Design Tokens) ---- */
:root {
  /* Background Colors */
  --bg-base: #0D0D12;
  --bg-surface: #16161D;
  --bg-elevated: #1E1E28;
  --bg-hover: #252530;
  
  /* Border Colors */
  --border-color: #2A2A35;
  --border-subtle: #1F1F28;
  
  /* Text Colors */
  --text-primary: #FFFFFF;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --text-dim: #4B5563;
  
  /* Accent Colors */
  --accent: #953EF1;
  --accent-hover: #A855F7;
  --accent-muted: rgba(149, 62, 241, 0.15);
  --accent-glow: rgba(149, 62, 241, 0.4);
  
  /* Status Colors */
  --success: #10B981;
  --success-muted: rgba(16, 185, 129, 0.15);
  --warning: #F59E0B;
  --warning-muted: rgba(245, 158, 11, 0.15);
  --error: #EF4444;
  --error-muted: rgba(239, 68, 68, 0.15);
  --info: #3B82F6;
  --info-muted: rgba(59, 130, 246, 0.15);
  
  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  
  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  
  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--accent-glow);
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
  
  /* Layout */
  --sidebar-width: 240px;
  --sidebar-collapsed: 72px;
  --header-height: 64px;
}

/* ---- Reset & Base Styles ---- */
*, *::before, *::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--accent-hover);
}

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

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-6);
  min-height: 100vh;
  transition: margin-left var(--transition-base);
}

@media (max-width: 1024px) {
  .main-content {
    margin-left: var(--sidebar-collapsed);
  }
}

@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
    padding-bottom: 80px;
  }
}

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

@media (max-width: 1024px) {
  .sidebar {
    width: var(--sidebar-collapsed);
  }
  
  .sidebar .nav-label,
  .sidebar .sidebar-logo-text,
  .sidebar .sidebar-status-text {
    display: none;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
}

.sidebar-logo {
  padding: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-bottom: 1px solid var(--border-color);
}

.sidebar-logo svg {
  width: 70px;
  height: 28px;
  flex-shrink: 0;
}

.sidebar-logo-text {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
}

/* Nav Section Headers */
.nav-section {
  margin-bottom: var(--space-3);
}

.nav-section:last-child {
  margin-bottom: 0;
}

.nav-section-header {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  padding: var(--space-3) var(--space-4);
  display: block;
  margin-bottom: var(--space-1);
}

.nav-section-divider {
  height: 1px;
  background: var(--border-color);
  margin: var(--space-3) var(--space-2);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  transition: all var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.nav-label {
  white-space: nowrap;
}

.sidebar-status {
  padding: var(--space-4);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-glow 2s infinite;
}

.status-dot.disconnected {
  background: var(--error);
}

.status-dot.running {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-glow 2s infinite;
}

.status-dot.paused {
  background: var(--warning);
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.sidebar-status-text {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* ---- Mobile Bottom Nav ---- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: var(--space-2) var(--space-4);
  z-index: 100;
}

@media (max-width: 768px) {
  .mobile-nav {
    display: flex;
    justify-content: space-around;
  }
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-2);
  color: var(--text-secondary);
  font-size: var(--text-xs);
}

.mobile-nav-item.active {
  color: var(--accent);
}

.mobile-nav-item svg {
  width: 24px;
  height: 24px;
}

/* ---- Page Header ---- */
.page-header {
  margin-bottom: var(--space-6);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 var(--space-2) 0;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
}

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

.card:hover {
  border-color: var(--border-subtle);
}

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

.card-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-body {
  padding: var(--space-5);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-color);
  background: var(--bg-elevated);
}

/* ---- KPI Stat Cards ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  position: relative;
  overflow: hidden;
  transition: all var(--transition-fast);
}

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

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--kpi-color, var(--accent));
}

.kpi-card.pending { --kpi-color: var(--info); }
.kpi-card.scraping { --kpi-color: var(--accent); }
.kpi-card.processing { --kpi-color: var(--warning); }
.kpi-card.completed { --kpi-color: var(--success); }
.kpi-card.unprocessable { --kpi-color: #9ca3af; }
.kpi-card.failed { --kpi-color: var(--error); }

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: var(--space-2);
}

.kpi-value {
  font-size: var(--text-4xl);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--space-2);
}

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

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-glow);
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-muted);
}

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

.btn-success:hover:not(:disabled) {
  background: #0ea572;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.btn-warning {
  background: var(--warning);
  color: #1a1a1a;
  border-color: var(--warning);
}

.btn-warning:hover:not(:disabled) {
  background: #e69009;
}

.btn-danger {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.4);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-muted {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border-color: var(--border-color);
  cursor: not-allowed;
}

.btn-muted:hover {
  background: var(--bg-elevated);
  transform: none;
  box-shadow: none;
}

.btn-running {
  background: var(--accent-muted);
  color: var(--accent);
  border-color: var(--accent);
  opacity: 0.8;
  cursor: not-allowed;
}

.btn-running:hover {
  background: var(--accent-muted);
  transform: none;
  box-shadow: none;
}

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.btn-icon {
  padding: var(--space-2);
  border-radius: var(--radius-md);
}

.btn-group {
  display: inline-flex;
  gap: var(--space-2);
}

/* ---- Forms ---- */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
}

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

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

.form-control:disabled,
.form-control[readonly] {
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: not-allowed;
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

/* Custom Select Styling */
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  -moz-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='%239CA3AF' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 36px;
  cursor: pointer;
}

select.form-control:hover {
  border-color: var(--text-dim);
}

select.form-control:focus {
  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='%23953EF1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

select.form-control option {
  background: var(--bg-elevated);
  color: var(--text-primary);
  padding: var(--space-2);
}

/* Small form controls */
.form-control-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  height: 32px;
}

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

select.form-control-sm:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23953EF1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
}

/* Number input cleanup */
input[type="number"].form-control {
  -moz-appearance: textfield;
}

input[type="number"].form-control::-webkit-outer-spin-button,
input[type="number"].form-control::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.form-text {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--space-1);
}

.input-group {
  display: flex;
  align-items: stretch;
}

.input-group .form-control {
  border-radius: 0;
}

.input-group .form-control:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group .form-control:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.input-group-text {
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
}

.input-group-text:first-child {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  border-right: none;
}

.input-group-text:last-child {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-left: none;
}

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-primary {
  background: var(--accent-muted);
  color: var(--accent);
}

.badge-success {
  background: var(--success-muted);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-muted);
  color: var(--warning);
}

.badge-error {
  background: var(--error-muted);
  color: var(--error);
}

.badge-unprocessable {
  background: rgba(156, 163, 175, 0.15);
  color: #9ca3af;
}

.badge-info {
  background: var(--info-muted);
  color: var(--info);
}

.badge-muted {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge.processing .badge-dot {
  animation: pulse-glow 1.5s infinite;
}

/* ---- Tables ---- */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.05em;
  position: sticky;
  top: 0;
  z-index: 10;
}

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

.data-table tbody tr:hover {
  background: var(--bg-hover);
}

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

/* ---- Sortable Table Headers ---- */
.data-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: calc(var(--space-4) + 16px);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.data-table th.sortable:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.data-table th.sortable::after {
  content: '';
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid var(--text-dim);
  opacity: 0.4;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.data-table th.sortable:hover::after {
  opacity: 0.7;
}

.data-table th.sortable.sort-asc::after {
  border-bottom: 5px solid var(--accent);
  opacity: 1;
}

.data-table th.sortable.sort-desc::after {
  border-top: 5px solid var(--accent);
  border-bottom: none;
  opacity: 1;
}

.data-table th.sortable.sort-asc,
.data-table th.sortable.sort-desc {
  color: var(--accent);
}

/* ---- Pipeline Visualization ---- */
.pipeline-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

@media (max-width: 1200px) {
  .pipeline-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

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

.pipeline-column {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.pipeline-header {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.pipeline-header.pending { border-top: 3px solid var(--info); }
.pipeline-header.scraping { border-top: 3px solid var(--accent); }
.pipeline-header.processing { border-top: 3px solid var(--warning); }
.pipeline-header.completed { border-top: 3px solid var(--success); }
.pipeline-header.unprocessable { border-top: 3px solid #9ca3af; }
.pipeline-header.failed { border-top: 3px solid var(--error); }

.pipeline-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
}

.pipeline-count {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.pipeline-body {
  flex: 1;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 350px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Loading indicator for infinite scroll */
.pipeline-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  gap: var(--space-2);
  flex-shrink: 0;
}

.pipeline-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  transition: all var(--transition-fast);
}

.pipeline-card:hover {
  border-color: var(--accent);
}

.pipeline-card.processing {
  border-left: 3px solid var(--warning);
}

.pipeline-card.completed {
  border-left: 3px solid var(--success);
}

.pipeline-card.unprocessable {
  border-left: 3px solid #9ca3af;
}

.pipeline-card.failed {
  border-left: 3px solid var(--error);
}

.pipeline-handle {
  font-weight: 600;
  font-size: var(--text-sm);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.pipeline-step {
  font-size: var(--text-xs);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.pipeline-progress {
  height: 4px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  margin-top: var(--space-2);
  overflow: hidden;
}

.pipeline-progress-bar {
  height: 100%;
  background: var(--warning);
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.pipeline-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-dim);
  font-size: var(--text-sm);
}

.pipeline-overflow {
  text-align: center;
  padding: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* ---- Activity Feed ---- */
.activity-feed {
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  height: 300px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.activity-item {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-left: 3px solid transparent;
  transition: background var(--transition-fast);
  animation: slideIn var(--transition-base);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.activity-item:hover {
  background: var(--bg-surface);
}

.activity-item.completed {
  border-left-color: var(--success);
}

.activity-item.failed {
  border-left-color: var(--error);
}

.activity-item.processing {
  border-left-color: var(--warning);
}

.activity-item.info {
  border-left-color: var(--info);
}

.activity-timestamp {
  color: var(--text-dim);
  flex-shrink: 0;
}

.activity-handle {
  color: var(--accent);
  font-weight: 600;
}

.activity-message {
  color: var(--text-secondary);
}

/* ---- Alerts / Toasts ---- */
.alert {
  padding: var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.alert-success {
  background: var(--success-muted);
  border: 1px solid var(--success);
  color: var(--success);
}

.alert-warning {
  background: var(--warning-muted);
  border: 1px solid var(--warning);
  color: var(--warning);
}

.alert-error {
  background: var(--error-muted);
  border: 1px solid var(--error);
  color: var(--error);
}

.alert-info {
  background: var(--info-muted);
  border: 1px solid var(--info);
  color: var(--info);
}

/* Toast container */
.toast-container {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
}

.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  animation: toastIn var(--transition-base);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 300px;
}

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

.toast.toast-out {
  animation: toastOut var(--transition-base) forwards;
}

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

/* ---- Loading States ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

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

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-hover) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin-top: var(--space-6);
}

.page-link {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.page-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--accent);
}

.page-link.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.page-link.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ---- Empty States ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12);
  text-align: center;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  color: var(--text-dim);
}

.empty-state-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-6);
  max-width: 400px;
}

/* ---- Profile Cards ---- */
.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 2px solid var(--border-color);
}

.profile-avatar-lg {
  width: 80px;
  height: 80px;
}

.profile-avatar-placeholder {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--accent-muted);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
}

/* ---- Image Previews ---- */
.img-preview {
  max-width: 150px;
  max-height: 150px;
  object-fit: cover;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  transition: all var(--transition-fast);
}

.img-preview:hover {
  border-color: var(--accent);
  transform: scale(1.05);
}

/* ---- Accordion ---- */
.accordion {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.accordion-item {
  border-bottom: 1px solid var(--border-color);
}

.accordion-item:last-child {
  border-bottom: none;
}

.accordion-header {
  background: var(--bg-elevated);
}

.accordion-button {
  width: 100%;
  padding: var(--space-4);
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  transition: background var(--transition-fast);
}

.accordion-button:hover {
  background: var(--bg-hover);
}

.accordion-button::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  margin-left: auto;
  transition: transform var(--transition-fast);
}

.accordion-button.collapsed::after {
  transform: rotate(45deg);
}

.accordion-collapse {
  display: none;
}

.accordion-collapse.show {
  display: block;
}

.accordion-body {
  padding: var(--space-4);
  background: var(--bg-surface);
}

/* ---- Code / Monospace ---- */
.code-editor {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  color: var(--text-primary);
  line-height: 1.6;
  resize: vertical;
  min-height: 200px;
  width: 100%;
  display: block;
}

.code-editor:focus {
  outline: none;
  border-color: var(--accent);
}

pre {
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-elevated);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
}

/* ---- Utilities ---- */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-error { color: var(--error) !important; }
.text-accent { color: var(--accent) !important; }

.bg-surface { background: var(--bg-surface) !important; }
.bg-elevated { background: var(--bg-elevated) !important; }

.font-mono { font-family: var(--font-mono) !important; }

.d-flex { display: flex; }
.d-grid { display: grid; }
.d-none { display: none; }
.d-block { display: block; }

.flex-1 { flex: 1; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

.w-full { width: 100%; }
.h-full { height: 100%; }

.rounded { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-full { border-radius: var(--radius-full); }

.border { border: 1px solid var(--border-color); }
.border-t { border-top: 1px solid var(--border-color); }
.border-b { border-bottom: 1px solid var(--border-color); }

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* ---- Responsive Utilities ---- */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}

@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}

/* ---- Scrollbar Styling ---- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ---- Selection ---- */
::selection {
  background: var(--accent-muted);
  color: var(--text-primary);
}

/* ---- Page Transitions ---- */
.main-content {
  animation: fadeIn var(--transition-slow);
}

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

/* ---- Card Hover Effects ---- */
.card {
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ---- Button Active States ---- */
.btn:active:not(:disabled) {
  transform: scale(0.98);
}

/* ---- Focus States for Accessibility ---- */
.btn:focus-visible,
.form-control:focus-visible,
.nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Link Hover Underline ---- */
a:not(.btn):not(.nav-item):not(.mobile-nav-item):not(.page-link):hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---- Loading Overlay ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(13, 13, 18, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

/* ---- Stat Counter Animation ---- */
.kpi-value {
  transition: color var(--transition-fast);
}

.kpi-value.updating {
  color: var(--accent);
}

/* ---- Table Row Animations ---- */
.data-table tbody tr {
  animation: fadeInRow var(--transition-base);
}

@keyframes fadeInRow {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ---- Pipeline Card Enter Animation ---- */
.pipeline-card {
  animation: slideInCard var(--transition-base);
}

@keyframes slideInCard {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ---- Form Validation States ---- */
.form-control.is-valid {
  border-color: var(--success);
}

.form-control.is-invalid {
  border-color: var(--error);
}

.form-control.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--error-muted);
}

/* ---- Floating Label (optional enhancement) ---- */
.form-floating {
  position: relative;
}

.form-floating .form-control {
  padding-top: 1.625rem;
  padding-bottom: 0.625rem;
}

.form-floating .form-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: var(--space-3) var(--space-4);
  pointer-events: none;
  transition: all var(--transition-fast);
  transform-origin: left top;
}

.form-floating .form-control:focus ~ .form-label,
.form-floating .form-control:not(:placeholder-shown) ~ .form-label {
  transform: scale(0.85) translateY(-0.5rem);
  opacity: 0.65;
}

/* ---- Tooltip ---- */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-primary);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: 100;
}

[data-tooltip]:hover::after {
  opacity: 1;
  visibility: visible;
}

/* ---- Progress Ring (for future use) ---- */
.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-circle {
  stroke-linecap: round;
  transition: stroke-dashoffset var(--transition-slow);
}

/* ---- Responsive Table Scroll Shadow ---- */
.table-container {
  position: relative;
}

.table-container::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 30px;
  background: linear-gradient(to right, transparent, var(--bg-surface));
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.table-container.has-scroll::after {
  opacity: 1;
}

/* ---- Print Styles ---- */
@media print {
  .sidebar,
  .mobile-nav,
  .btn,
  .toast-container {
    display: none !important;
  }
  
  .main-content {
    margin-left: 0 !important;
    padding: 0 !important;
  }
  
  .card {
    break-inside: avoid;
    border: 1px solid #ccc !important;
    box-shadow: none !important;
  }
  
  body {
    background: white !important;
    color: black !important;
  }
}

/* ---- Niche Editor ---- */
.niche-editor {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  overflow: hidden;
}

.niche-list {
  padding: var(--space-2);
  min-height: 60px;
}

.niche-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-style: italic;
}

.niche-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-2);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: grab;
}

.niche-item:last-child {
  margin-bottom: 0;
}

.niche-item:hover {
  border-color: var(--text-dim);
}

.niche-item.niche-primary {
  background: var(--accent-muted);
  border-color: var(--accent);
}

.niche-item.niche-primary:hover {
  border-color: var(--accent-hover);
}

.niche-item.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.niche-item.drag-over {
  border-color: var(--accent);
  border-style: dashed;
  background: var(--bg-hover);
}

.niche-drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  color: var(--text-dim);
  cursor: grab;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.niche-item:hover .niche-drag-handle {
  color: var(--text-muted);
}

.niche-star {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.niche-star:hover {
  color: var(--warning);
  background: var(--warning-muted);
}

.niche-star.active {
  color: var(--warning);
}

.niche-text {
  flex: 1;
  font-size: var(--text-sm);
  color: var(--text-primary);
  font-weight: 500;
}

.niche-item.niche-primary .niche-text {
  color: var(--accent);
}

.niche-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.niche-remove:hover {
  color: var(--error);
  background: var(--error-muted);
}

.niche-add-row {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.niche-add-row .form-control {
  margin: 0;
}

/* Badge for accent color (Primary niche badge) */
.badge-accent {
  background: var(--accent-muted);
  color: var(--accent);
}

/* ---- Premium Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 300ms cubic-bezier(0.4, 0, 0.2, 1), visibility 300ms;
}

.lightbox.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(13, 13, 18, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.lightbox-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  transform: scale(0.92);
  transition: transform 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.lightbox.active .lightbox-container {
  transform: scale(1);
}

.lightbox-image {
  display: block;
  max-width: 90vw;
  max-height: 85vh;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6),
              0 0 60px -15px var(--accent-glow);
  opacity: 1;
  transition: opacity 200ms ease;
}

.lightbox-image.transitioning {
  opacity: 0;
}

.lightbox-close {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  z-index: 10;
}

.lightbox-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-muted);
  transform: scale(1.05);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  cursor: pointer;
  opacity: 0;
  transition: all var(--transition-base);
  z-index: 10;
}

.lightbox:hover .lightbox-nav {
  opacity: 1;
}

.lightbox-nav:hover {
  background: var(--accent-muted);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-50%) scale(1.08);
  box-shadow: 0 0 20px var(--accent-glow);
}

.lightbox-nav.prev {
  left: var(--space-4);
}

.lightbox-nav.next {
  right: var(--space-4);
}

.lightbox-nav.hidden {
  display: none;
}

.lightbox-counter {
  position: absolute;
  bottom: var(--space-4);
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-2) var(--space-4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  letter-spacing: 0.1em;
}

.lightbox-counter.hidden {
  display: none;
}

/* Lightbox image thumbnail clickable state */
.img-preview.lightbox-trigger {
  cursor: zoom-in;
}

.img-preview.lightbox-trigger:hover {
  box-shadow: 0 0 20px var(--accent-glow);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .lightbox-nav {
    width: 44px;
    height: 44px;
    opacity: 0.8;
  }
  
  .lightbox:hover .lightbox-nav {
    opacity: 1;
  }
  
  .lightbox-nav.prev {
    left: var(--space-2);
  }
  
  .lightbox-nav.next {
    right: var(--space-2);
  }
  
  .lightbox-close {
    top: var(--space-2);
    right: var(--space-2);
    width: 40px;
    height: 40px;
  }
  
  .lightbox-image {
    max-width: 95vw;
    max-height: 80vh;
  }
}