/* ═══════════════════════════════════════════════════════════════════
   BIDPOTS DESIGN SYSTEM v2.0
   Modern, accessible, responsive design tokens & components
   WCAG 2.1 AA Compliant | Mobile-First | Dark Mode Ready
   ═══════════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties (Design Tokens) ─────────────────────── */
:root {
  /* Primary Palette */
  --bp-primary: #2563eb;
  --bp-primary-hover: #1d4ed8;
  --bp-primary-light: #dbeafe;
  --bp-primary-dark: #1e40af;

  /* Secondary */
  --bp-secondary: #7c3aed;
  --bp-secondary-hover: #6d28d9;
  --bp-secondary-light: #ede9fe;

  /* Success / Error / Warning / Info */
  --bp-success: #059669;
  --bp-success-light: #d1fae5;
  --bp-error: #dc2626;
  --bp-error-light: #fee2e2;
  --bp-warning: #d97706;
  --bp-warning-light: #fef3c7;
  --bp-info: #0891b2;
  --bp-info-light: #cffafe;

  /* Neutrals */
  --bp-gray-50: #f9fafb;
  --bp-gray-100: #f3f4f6;
  --bp-gray-200: #e5e7eb;
  --bp-gray-300: #d1d5db;
  --bp-gray-400: #9ca3af;
  --bp-gray-500: #6b7280;
  --bp-gray-600: #4b5563;
  --bp-gray-700: #374151;
  --bp-gray-800: #1f2937;
  --bp-gray-900: #111827;

  /* Background & Surface */
  --bp-bg: #ffffff;
  --bp-bg-secondary: var(--bp-gray-50);
  --bp-surface: #ffffff;
  --bp-surface-hover: var(--bp-gray-50);
  --bp-surface-elevated: #ffffff;

  /* Text */
  --bp-text-primary: var(--bp-gray-900);
  --bp-text-secondary: var(--bp-gray-600);
  --bp-text-muted: var(--bp-gray-400);
  --bp-text-inverse: #ffffff;

  /* Borders */
  --bp-border: var(--bp-gray-200);
  --bp-border-hover: var(--bp-gray-300);
  --bp-border-focus: var(--bp-primary);

  /* Spacing (8px grid) */
  --bp-space-1: 0.25rem;  /* 4px */
  --bp-space-2: 0.5rem;   /* 8px */
  --bp-space-3: 0.75rem;  /* 12px */
  --bp-space-4: 1rem;     /* 16px */
  --bp-space-5: 1.25rem;  /* 20px */
  --bp-space-6: 1.5rem;   /* 24px */
  --bp-space-8: 2rem;     /* 32px */
  --bp-space-10: 2.5rem;  /* 40px */
  --bp-space-12: 3rem;    /* 48px */
  --bp-space-16: 4rem;    /* 64px */

  /* Typography */
  --bp-font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --bp-font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --bp-text-xs: 0.75rem;
  --bp-text-sm: 0.875rem;
  --bp-text-base: 1rem;
  --bp-text-lg: 1.125rem;
  --bp-text-xl: 1.25rem;
  --bp-text-2xl: 1.5rem;
  --bp-text-3xl: 1.875rem;
  --bp-text-4xl: 2.25rem;

  --bp-leading-tight: 1.25;
  --bp-leading-normal: 1.5;
  --bp-leading-relaxed: 1.75;

  /* Border Radius */
  --bp-radius-sm: 0.375rem;
  --bp-radius-md: 0.5rem;
  --bp-radius-lg: 0.75rem;
  --bp-radius-xl: 1rem;
  --bp-radius-full: 9999px;

  /* Shadows */
  --bp-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --bp-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --bp-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --bp-shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --bp-transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --bp-transition-base: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --bp-transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Focus Ring (WCAG) */
  --bp-focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.4);
  --bp-focus-ring-error: 0 0 0 3px rgba(220, 38, 38, 0.4);

  /* Z-Index Scale */
  --bp-z-dropdown: 100;
  --bp-z-sticky: 200;
  --bp-z-modal-backdrop: 300;
  --bp-z-modal: 400;
  --bp-z-toast: 500;
}

/* ─── Dark Mode ──────────────────────────────────────────────────── */
[data-theme="dark"],
.bp-dark {
  --bp-bg: #0f172a;
  --bp-bg-secondary: #1e293b;
  --bp-surface: #1e293b;
  --bp-surface-hover: #334155;
  --bp-surface-elevated: #334155;

  --bp-text-primary: #f1f5f9;
  --bp-text-secondary: #94a3b8;
  --bp-text-muted: #64748b;

  --bp-border: #334155;
  --bp-border-hover: #475569;

  --bp-primary-light: #1e3a5f;
  --bp-success-light: #064e3b;
  --bp-error-light: #450a0a;
  --bp-warning-light: #451a03;

  --bp-shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --bp-shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --bp-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
}

/* ─── High Contrast Mode (WCAG) ─────────────────────────────────── */
@media (forced-colors: active) {
  :root {
    --bp-border: CanvasText;
    --bp-focus-ring: 0 0 0 3px Highlight;
  }
}

@media (prefers-contrast: high) {
  :root {
    --bp-text-secondary: var(--bp-gray-800);
    --bp-text-muted: var(--bp-gray-700);
    --bp-border: var(--bp-gray-400);
  }
}

/* ─── Base Reset & Typography ────────────────────────────────────── */
.bp-ui,
.bp-ui * {
  box-sizing: border-box;
}

.bp-ui {
  font-family: var(--bp-font-sans);
  font-size: var(--bp-text-base);
  line-height: var(--bp-leading-normal);
  color: var(--bp-text-primary);
  background-color: var(--bp-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Focus States (WCAG Mandatory) ─────────────────────────────── */
.bp-ui :focus-visible {
  outline: none;
  box-shadow: var(--bp-focus-ring);
  border-radius: var(--bp-radius-sm);
}

.bp-ui a:focus-visible,
.bp-ui button:focus-visible,
.bp-ui input:focus-visible,
.bp-ui select:focus-visible,
.bp-ui textarea:focus-visible,
.bp-ui [tabindex]:focus-visible {
  outline: 2px solid var(--bp-primary);
  outline-offset: 2px;
}

/* Skip to content link (WCAG) */
.bp-skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--bp-primary);
  color: white;
  padding: var(--bp-space-2) var(--bp-space-4);
  z-index: 1000;
  transition: top var(--bp-transition-fast);
  font-weight: 600;
  text-decoration: none;
  border-radius: 0 0 var(--bp-radius-md) 0;
}

.bp-skip-link:focus {
  top: 0;
}

/* ─── Headings ───────────────────────────────────────────────────── */
.bp-h1, .bp-h2, .bp-h3, .bp-h4, .bp-h5, .bp-h6 {
  font-weight: 700;
  line-height: var(--bp-leading-tight);
  color: var(--bp-text-primary);
  margin: 0 0 var(--bp-space-4);
}

.bp-h1 { font-size: var(--bp-text-4xl); }
.bp-h2 { font-size: var(--bp-text-3xl); }
.bp-h3 { font-size: var(--bp-text-2xl); }
.bp-h4 { font-size: var(--bp-text-xl); }
.bp-h5 { font-size: var(--bp-text-lg); }
.bp-h6 { font-size: var(--bp-text-base); }

/* ─── Cards ──────────────────────────────────────────────────────── */
.bp-card {
  background: var(--bp-surface);
  border: 1px solid var(--bp-border);
  border-radius: var(--bp-radius-lg);
  padding: var(--bp-space-6);
  box-shadow: var(--bp-shadow-sm);
  transition: box-shadow var(--bp-transition-base), transform var(--bp-transition-base);
}

.bp-card:hover {
  box-shadow: var(--bp-shadow-md);
}

.bp-card-elevated {
  box-shadow: var(--bp-shadow-lg);
}

.bp-card-interactive:hover {
  transform: translateY(-2px);
  box-shadow: var(--bp-shadow-lg);
}

.bp-card-header {
  padding-bottom: var(--bp-space-4);
  border-bottom: 1px solid var(--bp-border);
  margin-bottom: var(--bp-space-4);
}

.bp-card-footer {
  padding-top: var(--bp-space-4);
  border-top: 1px solid var(--bp-border);
  margin-top: var(--bp-space-4);
}

/* ─── Buttons ────────────────────────────────────────────────────── */
.bp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--bp-space-2);
  padding: var(--bp-space-2) var(--bp-space-4);
  font-family: var(--bp-font-sans);
  font-size: var(--bp-text-sm);
  font-weight: 600;
  line-height: 1.5;
  border-radius: var(--bp-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--bp-transition-fast);
  text-decoration: none;
  white-space: nowrap;
  min-height: 40px; /* touch target WCAG */
}

.bp-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.bp-btn-primary {
  background: var(--bp-primary);
  color: var(--bp-text-inverse);
  border-color: var(--bp-primary);
}
.bp-btn-primary:hover { background: var(--bp-primary-hover); }

.bp-btn-secondary {
  background: var(--bp-surface);
  color: var(--bp-text-primary);
  border-color: var(--bp-border);
}
.bp-btn-secondary:hover { background: var(--bp-surface-hover); border-color: var(--bp-border-hover); }

.bp-btn-success {
  background: var(--bp-success);
  color: var(--bp-text-inverse);
}
.bp-btn-success:hover { background: #047857; }

.bp-btn-danger {
  background: var(--bp-error);
  color: var(--bp-text-inverse);
}
.bp-btn-danger:hover { background: #b91c1c; }

.bp-btn-ghost {
  background: transparent;
  color: var(--bp-primary);
  border-color: transparent;
}
.bp-btn-ghost:hover { background: var(--bp-primary-light); }

.bp-btn-lg { padding: var(--bp-space-3) var(--bp-space-6); font-size: var(--bp-text-base); min-height: 48px; }
.bp-btn-sm { padding: var(--bp-space-1) var(--bp-space-3); font-size: var(--bp-text-xs); min-height: 32px; }
.bp-btn-icon { padding: var(--bp-space-2); min-width: 40px; }

/* ─── Form Inputs ────────────────────────────────────────────────── */
.bp-input {
  display: block;
  width: 100%;
  padding: var(--bp-space-2) var(--bp-space-3);
  font-family: var(--bp-font-sans);
  font-size: var(--bp-text-sm);
  line-height: 1.5;
  color: var(--bp-text-primary);
  background: var(--bp-bg);
  border: 1px solid var(--bp-border);
  border-radius: var(--bp-radius-md);
  transition: border-color var(--bp-transition-fast), box-shadow var(--bp-transition-fast);
  min-height: 40px;
}

.bp-input:hover { border-color: var(--bp-border-hover); }
.bp-input:focus { border-color: var(--bp-border-focus); box-shadow: var(--bp-focus-ring); outline: none; }
.bp-input::placeholder { color: var(--bp-text-muted); }
.bp-input-error { border-color: var(--bp-error); }
.bp-input-error:focus { box-shadow: var(--bp-focus-ring-error); }

.bp-label {
  display: block;
  font-size: var(--bp-text-sm);
  font-weight: 500;
  color: var(--bp-text-primary);
  margin-bottom: var(--bp-space-1);
}

.bp-help-text {
  font-size: var(--bp-text-xs);
  color: var(--bp-text-muted);
  margin-top: var(--bp-space-1);
}

.bp-error-text {
  font-size: var(--bp-text-xs);
  color: var(--bp-error);
  margin-top: var(--bp-space-1);
}

/* ─── Badges ─────────────────────────────────────────────────────── */
.bp-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--bp-space-2);
  font-size: var(--bp-text-xs);
  font-weight: 600;
  border-radius: var(--bp-radius-full);
  line-height: 1.5;
}

.bp-badge-primary { background: var(--bp-primary-light); color: var(--bp-primary-dark); }
.bp-badge-success { background: var(--bp-success-light); color: var(--bp-success); }
.bp-badge-error { background: var(--bp-error-light); color: var(--bp-error); }
.bp-badge-warning { background: var(--bp-warning-light); color: var(--bp-warning); }
.bp-badge-info { background: var(--bp-info-light); color: var(--bp-info); }

/* ─── Toast Notifications ────────────────────────────────────────── */
.bp-toast-container {
  position: fixed;
  top: var(--bp-space-4);
  right: var(--bp-space-4);
  z-index: var(--bp-z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--bp-space-2);
  max-width: 400px;
}

.bp-toast {
  display: flex;
  align-items: flex-start;
  gap: var(--bp-space-3);
  padding: var(--bp-space-4);
  background: var(--bp-surface-elevated);
  border: 1px solid var(--bp-border);
  border-radius: var(--bp-radius-lg);
  box-shadow: var(--bp-shadow-lg);
  animation: bp-slide-in 0.3s ease-out;
}

.bp-toast-success { border-left: 4px solid var(--bp-success); }
.bp-toast-error { border-left: 4px solid var(--bp-error); }
.bp-toast-warning { border-left: 4px solid var(--bp-warning); }
.bp-toast-info { border-left: 4px solid var(--bp-info); }

@keyframes bp-slide-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes bp-fade-out {
  from { opacity: 1; }
  to { opacity: 0; transform: translateX(50px); }
}

/* ─── Skeleton Loaders ───────────────────────────────────────────── */
.bp-skeleton {
  background: linear-gradient(90deg, var(--bp-gray-200) 25%, var(--bp-gray-100) 50%, var(--bp-gray-200) 75%);
  background-size: 200% 100%;
  animation: bp-shimmer 1.5s infinite;
  border-radius: var(--bp-radius-md);
}

.bp-skeleton-text { height: 1rem; margin-bottom: var(--bp-space-2); }
.bp-skeleton-title { height: 1.5rem; width: 60%; margin-bottom: var(--bp-space-3); }
.bp-skeleton-avatar { width: 48px; height: 48px; border-radius: var(--bp-radius-full); }
.bp-skeleton-card { height: 200px; }
.bp-skeleton-btn { height: 40px; width: 120px; }

@keyframes bp-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ─── Empty States ───────────────────────────────────────────────── */
.bp-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--bp-space-16) var(--bp-space-8);
  text-align: center;
}

.bp-empty-state-icon {
  font-size: 3rem;
  color: var(--bp-text-muted);
  margin-bottom: var(--bp-space-4);
}

.bp-empty-state-title {
  font-size: var(--bp-text-lg);
  font-weight: 600;
  color: var(--bp-text-primary);
  margin-bottom: var(--bp-space-2);
}

.bp-empty-state-desc {
  font-size: var(--bp-text-sm);
  color: var(--bp-text-secondary);
  max-width: 320px;
  margin-bottom: var(--bp-space-6);
}

/* ─── Tables ─────────────────────────────────────────────────────── */
.bp-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--bp-text-sm);
}

.bp-table th {
  text-align: left;
  padding: var(--bp-space-3) var(--bp-space-4);
  font-weight: 600;
  color: var(--bp-text-secondary);
  background: var(--bp-bg-secondary);
  border-bottom: 1px solid var(--bp-border);
  font-size: var(--bp-text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bp-table td {
  padding: var(--bp-space-3) var(--bp-space-4);
  border-bottom: 1px solid var(--bp-border);
  color: var(--bp-text-primary);
}

.bp-table tbody tr:hover {
  background: var(--bp-surface-hover);
}

/* ─── Modal ──────────────────────────────────────────────────────── */
.bp-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--bp-z-modal-backdrop);
  animation: bp-fade-in 0.2s ease-out;
}

.bp-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bp-surface);
  border-radius: var(--bp-radius-xl);
  box-shadow: var(--bp-shadow-xl);
  padding: var(--bp-space-8);
  z-index: var(--bp-z-modal);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  animation: bp-scale-in 0.2s ease-out;
}

@keyframes bp-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes bp-scale-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ─── Responsive Grid ────────────────────────────────────────────── */
.bp-grid {
  display: grid;
  gap: var(--bp-space-6);
}

.bp-grid-2 { grid-template-columns: repeat(1, 1fr); }
.bp-grid-3 { grid-template-columns: repeat(1, 1fr); }
.bp-grid-4 { grid-template-columns: repeat(1, 1fr); }

@media (min-width: 640px) {
  .bp-grid-2 { grid-template-columns: repeat(2, 1fr); }
  .bp-grid-3 { grid-template-columns: repeat(2, 1fr); }
  .bp-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 1024px) {
  .bp-grid-3 { grid-template-columns: repeat(3, 1fr); }
  .bp-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ─── Utility Classes ────────────────────────────────────────────── */
.bp-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.bp-flex { display: flex; }
.bp-flex-col { flex-direction: column; }
.bp-items-center { align-items: center; }
.bp-justify-between { justify-content: space-between; }
.bp-justify-center { justify-content: center; }
.bp-gap-2 { gap: var(--bp-space-2); }
.bp-gap-4 { gap: var(--bp-space-4); }
.bp-gap-6 { gap: var(--bp-space-6); }

.bp-text-center { text-align: center; }
.bp-text-right { text-align: right; }
.bp-text-muted { color: var(--bp-text-muted); }
.bp-text-success { color: var(--bp-success); }
.bp-text-error { color: var(--bp-error); }

.bp-mt-2 { margin-top: var(--bp-space-2); }
.bp-mt-4 { margin-top: var(--bp-space-4); }
.bp-mt-6 { margin-top: var(--bp-space-6); }
.bp-mb-4 { margin-bottom: var(--bp-space-4); }
.bp-mb-6 { margin-bottom: var(--bp-space-6); }
.bp-p-4 { padding: var(--bp-space-4); }
.bp-p-6 { padding: var(--bp-space-6); }

.bp-w-full { width: 100%; }
.bp-rounded-full { border-radius: var(--bp-radius-full); }
.bp-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Reduced Motion (WCAG) ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
