/* 
 * Optimotive Design System
 * A cohesive, professional design system for light and dark modes
 * Based on 8px grid spacing system
 */

:root {
  /* ===========================================
     SPACING SYSTEM (8px grid)
     Use these for all margins, padding, gaps
     =========================================== */
  --space-0: 0;
  --space-1: 0.5rem;   /* 8px */
  --space-2: 1rem;     /* 16px */
  --space-3: 1.5rem;   /* 24px */
  --space-4: 2rem;     /* 32px */
  --space-5: 2.5rem;   /* 40px */
  --space-6: 3rem;     /* 48px */
  --space-7: 3.5rem;   /* 56px */
  --space-8: 4rem;     /* 64px */
  --space-10: 5rem;    /* 80px */
  --space-12: 6rem;    /* 96px */
  --space-16: 8rem;    /* 128px */

  /* Compact spacing for dense UI */
  --space-0-5: 0.25rem; /* 4px - use sparingly */

  /* ===========================================
     TYPOGRAPHY SCALE
     Consistent font sizes
     =========================================== */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.25rem;    /* 20px */
  --text-2xl: 1.5rem;    /* 24px */
  --text-3xl: 1.875rem;  /* 30px */
  --text-4xl: 2.25rem;   /* 36px */
  --text-5xl: 3rem;      /* 48px */

  /* Line heights */
  --leading-none: 1;
  --leading-tight: 1.25;
  --leading-snug: 1.375;
  --leading-normal: 1.5;
  --leading-relaxed: 1.625;
  --leading-loose: 2;

  /* Font weights */
  --font-normal: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;

  /* ===========================================
     BORDER RADIUS (8px based)
     =========================================== */
  --radius-none: 0;
  --radius-sm: 0.125rem;  /* 2px */
  --radius-base: 0.25rem; /* 4px */
  --radius-md: 0.375rem;  /* 6px */
  --radius-lg: 0.5rem;    /* 8px */
  --radius-xl: 0.75rem;   /* 12px */
  --radius-2xl: 1rem;     /* 16px */
  --radius-3xl: 1.5rem;   /* 24px */
  --radius-full: 9999px;

  /* ===========================================
     SHADOWS
     Consistent elevation
     =========================================== */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-base: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --shadow-inner: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
  --shadow-none: none;

  /* ===========================================
     TRANSITIONS
     Consistent animations
     =========================================== */
  --transition-none: none;
  --transition-all: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-fast: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 300ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-colors: background-color, border-color, color, fill, stroke 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-opacity: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-shadow: box-shadow 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-transform: transform 150ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ===== COLOR SYSTEM ===== */
  /* Brand Colors */
  --brand-purple: #8b5cf6;
  --brand-purple-dark: #7c3aed;
  --brand-purple-light: #a78bfa;
  --brand-purple-faint: rgba(139, 92, 246, 0.1);
  
  /* Neutral Colors - Light Mode */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  
  /* Semantic Colors */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #3b82f6;
  
  /* Light Mode Palette */
  --bg-primary: #ffffff;
  --bg-secondary: #f9fafb;
  --bg-tertiary: #f3f4f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border-color: #e5e7eb;
  --border-hover: #d1d5db;
  
  /* Form Field Colors - Light Mode */
  --input-bg: #ffffff;
  --input-border: #d1d5db;
  --input-focus-border: var(--brand-purple);
  --input-placeholder: #9ca3af;
}

/* Dark Mode Palette */
html.dark-mode {
  /* Sophisticated Dark Colors */
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-tertiary: #1a1a1a;
  --text-primary: #e5e5e5;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
  --border-color: #262626;
  --border-hover: #404040;
  
  /* Adjusted Semantic Colors for Dark Mode */
  --color-success: #22c55e;
  --color-warning: #a16207;  /* Muted amber instead of bright yellow */
  --color-danger: #dc2626;
  --color-info: #6366f1;
  
  /* Form Field Colors - Dark Mode */
  --input-bg: #0a0a0a;
  --input-border: #262626;
  --input-focus-border: var(--brand-purple-light);
  --input-placeholder: #525252;
}

/* ===== BUTTON SYSTEM ===== */

/* Base Button Reset */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: var(--leading-tight);
  border-radius: var(--radius-md);
  transition: var(--transition-all);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  min-height: 44px;
  min-width: 44px;
  border: 2px solid transparent;
  background-color: transparent;
  position: relative;
  overflow: hidden;
}

/* Outline Style (Primary Design Pattern) */
.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}

.btn-outline:hover {
  background-color: var(--bg-secondary);
  border-color: var(--border-hover);
}

.btn-outline:active {
  background-color: var(--bg-tertiary);
}

/* Brand Outline */
.btn-outline-primary {
  border-color: var(--brand-purple);
  color: var(--brand-purple);
}

.btn-outline-primary:hover {
  background-color: var(--brand-purple-faint);
  border-color: var(--brand-purple-dark);
  color: var(--brand-purple-dark);
}

/* Solid Style (For Primary CTAs Only) */
.btn-solid-primary {
  background-color: var(--brand-purple);
  border-color: var(--brand-purple);
  color: white;
}

.btn-solid-primary:hover {
  background-color: var(--brand-purple-dark);
  border-color: var(--brand-purple-dark);
}

/* Semantic Outline Buttons */
.btn-outline-success {
  border-color: var(--color-success);
  color: var(--color-success);
}

.btn-outline-success:hover {
  background-color: rgba(16, 185, 129, 0.1);
}

.btn-outline-danger {
  border-color: var(--color-danger);
  color: var(--color-danger);
}

.btn-outline-danger:hover {
  background-color: rgba(239, 68, 68, 0.1);
}

.btn-outline-warning {
  border-color: var(--color-warning);
  color: var(--color-warning);
}

.btn-outline-warning:hover {
  background-color: rgba(245, 158, 11, 0.1);
}

/* Ghost Button (No Border) */
.btn-ghost {
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background-color: var(--bg-secondary);
  color: var(--text-primary);
}

/* Button Sizes */
.btn-sm {
  padding: calc(var(--space-1) * 0.75) var(--space-1);
  font-size: var(--text-xs);
  min-height: 36px;
}

.btn-lg {
  padding: calc(var(--space-1) * 1.5) var(--space-3);
  font-size: var(--text-base);
  min-height: 48px;
}

/* Button Icons */
.btn i {
  font-size: var(--text-lg);
}

.btn i:first-child:not(:last-child) {
  margin-right: var(--space-1);
}

.btn i:last-child:not(:first-child) {
  margin-left: var(--space-1);
}

/* ===== FORM FIELDS ===== */

.form-control,
.form-select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: calc(var(--space-1) * 1.25) calc(var(--space-1) * 1.75);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  background-color: var(--input-bg);
  background-image: none;
  border: 2px solid var(--input-border);
  border-radius: var(--radius-md);
  transition: var(--transition-colors);
}

.form-control:focus,
.form-select:focus,
input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--input-focus-border);
  box-shadow: 0 0 0 3px var(--brand-purple-faint);
}

.form-control::placeholder,
input::placeholder,
textarea::placeholder {
  color: var(--input-placeholder);
  opacity: 1;
}

/* Dark Mode Form Adjustments */
html.dark-mode .form-control,
html.dark-mode .form-select,
html.dark-mode input,
html.dark-mode textarea,
html.dark-mode select {
  background-color: var(--bg-primary);
  border-color: var(--border-color);
}

html.dark-mode .form-control:focus,
html.dark-mode input:focus,
html.dark-mode textarea:focus,
html.dark-mode select:focus {
  border-color: var(--brand-purple-light);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.1);
}

/* ===== CARD SYSTEM ===== */

.card {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-sm);
}

html.dark-mode .card {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3);
}

.card-header {
  margin: calc(var(--space-3) * -1) calc(var(--space-3) * -1) var(--space-3);
  padding: var(--space-2) var(--space-3);
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  font-weight: var(--font-semibold);
}

html.dark-mode .card-header {
  background-color: var(--bg-tertiary);
}

/* ===== LAYOUT SYSTEM ===== */

.page-container {
  min-height: 100vh;
  background-color: var(--bg-primary);
}

.page-header {
  padding: var(--space-4) 0;
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border-color);
}

.page-title {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  margin: 0;
}

.page-subtitle {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

.content-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* ===== SEMANTIC COLOR APPLICATIONS ===== */

/* Replace bright yellow alerts with subtle versions */
.alert-warning {
  background-color: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--color-warning);
  color: var(--text-primary);
}

html.dark-mode .alert-warning {
  background-color: rgba(161, 98, 7, 0.1);
  border-color: var(--color-warning);
}

.badge-warning {
  background-color: var(--color-warning);
  color: white;
}

html.dark-mode .badge-warning {
  background-color: var(--color-warning);
  color: var(--text-primary);
}

/* ===== TYPOGRAPHY HIERARCHY ===== */

h1, h2, h3, h4, h5, h6 {
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  line-height: var(--leading-tight);
  margin-top: 0;
  margin-bottom: calc(var(--space-1) * 1.5);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

/* ===== UTILITY CLASSES ===== */

.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-primary { color: var(--text-primary) !important; }

.bg-secondary { background-color: var(--bg-secondary) !important; }
.bg-tertiary { background-color: var(--bg-tertiary) !important; }

.border { border: 1px solid var(--border-color) !important; }
.border-top { border-top: 1px solid var(--border-color) !important; }
.border-bottom { border-bottom: 1px solid var(--border-color) !important; }

/* ===== TRANSITIONS ===== */

* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}

/* ===== BOOTSTRAP OVERRIDES ===== */

/* Ensure our button styles override Bootstrap */
.btn:not(.btn-link) {
  font-weight: 500 !important;
}

.btn-sm {
  font-size: 0.75rem !important;
}

.btn-lg {
  font-size: 1rem !important;
}

/* Override Bootstrap's focus styles */
.btn:focus,
.form-control:focus,
.form-select:focus {
  box-shadow: 0 0 0 3px var(--brand-purple-faint) !important;
}

/* Fix Bootstrap badges */
.badge {
  font-weight: var(--font-medium);
  padding: var(--space-0-5) var(--space-1);
}

/* Override Bootstrap card styles */
.card {
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05) !important;
}

html.dark-mode .card {
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.3) !important;
}

/* Fix Bootstrap table styles for dark mode */
html.dark-mode .table > :not(caption) > * > * {
  background-color: inherit !important;
}

/* Override Bootstrap alert styles */
.alert {
  border-width: 1px !important;
  font-weight: 500;
}

/* Ensure modals work in dark mode */
html.dark-mode .modal-content {
  background-color: var(--bg-secondary);
  border-color: var(--border-color);
  color: var(--text-primary);
}

html.dark-mode .modal-header {
  border-bottom-color: var(--border-color);
}

html.dark-mode .modal-footer {
  border-top-color: var(--border-color);
}

/* Fix close buttons in dark mode */
html.dark-mode .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* ===========================================
   RESPONSIVE SPACING
   Adjust spacing on smaller screens
   =========================================== */
@media (max-width: 768px) {
  :root {
    /* Slightly reduce spacing on mobile */
    --space-1: 0.375rem;  /* 6px */
    --space-2: 0.875rem;  /* 14px */
    --space-3: 1.25rem;   /* 20px */
    --space-4: 1.75rem;   /* 28px */
    --space-5: 2.25rem;   /* 36px */
    --space-6: 2.75rem;   /* 44px */
  }
}