/**
 * PaintVault Design System
 * ========================
 * Unified CSS variables and dark theme support
 *
 * USAGE: Load this file BEFORE app.css in base.html
 *
 * Variable Naming Convention:
 * - --pv-color-*  : Brand colors (accent, orange, etc.)
 * - --pv-bg-*     : Background colors
 * - --pv-text-*   : Text colors
 * - --pv-border-* : Border colors
 * - --pv-spacing-*: Spacing scale
 * - --pv-radius-* : Border radius
 * - --pv-shadow-* : Box shadows
 * - --pv-font-*   : Typography
 */

/* ============================================
   1. ROOT VARIABLES - Light Theme (default)
   ============================================ */

:root {
  /* --- Brand Colors --- */
  --pv-color-accent: #2F4C86;
  --pv-color-accent-light: #4A6FA5;
  --pv-color-accent-dark: #1a2a4a;
  --pv-color-orange: #E57C38;
  --pv-color-orange-dark: #d66a28;
  --pv-color-green: #10b981;
  --pv-color-red: #ef4444;
  --pv-color-yellow: #f59e0b;

  /* --- Background Colors --- */
  --pv-bg-base: #F7F6F2;
  --pv-bg-surface: #ffffff;
  --pv-bg-elevated: #f5f7fa;
  --pv-bg-muted: #e9ecef;

  /* --- Text Colors --- */
  --pv-text-primary: #2B2B2B;
  --pv-text-secondary: #6B6B6B;
  --pv-text-muted: #9ca3af;
  --pv-text-inverse: #ffffff;

  /* --- Border Colors --- */
  --pv-border-default: rgba(0, 0, 0, 0.12);
  --pv-border-light: rgba(0, 0, 0, 0.06);
  --pv-border-strong: rgba(0, 0, 0, 0.2);

  /* --- Typography --- */
  --pv-font-heading: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --pv-font-body: 'Lora', Georgia, 'Times New Roman', serif;
  --pv-font-mono: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;

  --pv-font-size-xs: 0.75rem;
  --pv-font-size-sm: 0.875rem;
  --pv-font-size-base: 1rem;
  --pv-font-size-lg: 1.125rem;
  --pv-font-size-xl: 1.25rem;
  --pv-font-size-2xl: 1.5rem;
  --pv-font-size-3xl: 2rem;
  --pv-font-size-4xl: 2.5rem;

  /* --- Spacing Scale --- */
  --pv-spacing-1: 0.25rem;
  --pv-spacing-2: 0.5rem;
  --pv-spacing-3: 0.75rem;
  --pv-spacing-4: 1rem;
  --pv-spacing-5: 1.25rem;
  --pv-spacing-6: 1.5rem;
  --pv-spacing-8: 2rem;
  --pv-spacing-10: 2.5rem;
  --pv-spacing-12: 3rem;
  --pv-spacing-16: 4rem;

  /* --- Border Radius --- */
  --pv-radius-sm: 4px;
  --pv-radius-md: 8px;
  --pv-radius-lg: 12px;
  --pv-radius-xl: 16px;
  --pv-radius-full: 9999px;

  /* --- Shadows --- */
  --pv-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --pv-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --pv-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.12);
  --pv-shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.15);

  /* --- Transitions --- */
  --pv-transition-fast: 0.15s ease;
  --pv-transition-base: 0.2s ease;
  --pv-transition-slow: 0.3s ease;

  /* --- Z-Index Scale --- */
  --pv-z-dropdown: 1000;
  --pv-z-sticky: 1020;
  --pv-z-fixed: 1030;
  --pv-z-modal-backdrop: 1040;
  --pv-z-modal: 1050;
  --pv-z-popover: 1060;
  --pv-z-tooltip: 1070;
}

/* ============================================
   2. DARK THEME VARIABLES
   ============================================ */

.theme-dark,
[data-bs-theme="dark"] {
  /* --- Background Colors --- */
  --pv-bg-base: #05070c;
  --pv-bg-surface: #111827;
  --pv-bg-elevated: #1f2937;
  --pv-bg-muted: #0b1120;

  /* --- Text Colors --- */
  --pv-text-primary: #f3f4f6;
  --pv-text-secondary: #9ca3af;
  --pv-text-muted: #6b7280;
  --pv-text-inverse: #1f2937;

  /* --- Border Colors --- */
  --pv-border-default: #1f2937;
  --pv-border-light: #374151;
  --pv-border-strong: #4b5563;

  /* --- Shadows (darker for dark theme) --- */
  --pv-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
  --pv-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
  --pv-shadow-lg: 0 10px 30px rgba(0, 0, 0, 0.4);
  --pv-shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.5);

  /* --- Legacy variable mapping (for existing code) --- */
  --color-bg: var(--pv-bg-base);
  --color-bg-soft: var(--pv-bg-muted);
  --color-bg-card: var(--pv-bg-surface);
  --color-bg-elevated: var(--pv-bg-elevated);
  --color-text: var(--pv-text-primary);
  --color-text-muted: var(--pv-text-secondary);
  --color-text-dim: var(--pv-text-muted);
  --color-border: var(--pv-border-default);
  --color-border-light: var(--pv-border-light);
}

/* ============================================
   3. BOOTSTRAP DARK THEME OVERRIDES
   ============================================ */

/* --- Cards --- */
.theme-dark .card,
[data-bs-theme="dark"] .card {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .card-header,
[data-bs-theme="dark"] .card-header {
  background-color: var(--pv-bg-elevated);
  border-bottom-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .card-header.bg-light,
[data-bs-theme="dark"] .card-header.bg-light {
  background-color: var(--pv-bg-elevated) !important;
  color: var(--pv-text-primary) !important;
}

.theme-dark .card-body,
[data-bs-theme="dark"] .card-body {
  color: var(--pv-text-primary);
}

.theme-dark .card-footer,
[data-bs-theme="dark"] .card-footer {
  background-color: var(--pv-bg-muted);
  border-top-color: var(--pv-border-default);
}

/* --- Tables --- */
.theme-dark .table,
[data-bs-theme="dark"] .table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--pv-text-primary);
  --bs-table-border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .table-light,
.theme-dark thead.table-light,
[data-bs-theme="dark"] .table-light,
[data-bs-theme="dark"] thead.table-light {
  --bs-table-bg: var(--pv-bg-elevated);
  --bs-table-color: var(--pv-text-primary);
  --bs-table-border-color: var(--pv-border-default);
}

.theme-dark .table-light th,
.theme-dark .table-light td,
[data-bs-theme="dark"] .table-light th,
[data-bs-theme="dark"] .table-light td {
  background-color: var(--pv-bg-elevated) !important;
  color: var(--pv-text-primary) !important;
  border-color: var(--pv-border-default) !important;
}

.theme-dark .table-hover tbody tr:hover,
[data-bs-theme="dark"] .table-hover tbody tr:hover {
  --bs-table-hover-bg: var(--pv-bg-muted);
  background-color: var(--pv-bg-muted);
}

/* --- Forms --- */
.theme-dark .form-control,
.theme-dark .form-select,
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
  background-color: var(--pv-bg-elevated);
  border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .form-control:focus,
.theme-dark .form-select:focus,
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
  background-color: var(--pv-bg-elevated);
  border-color: var(--pv-color-accent-light);
  color: var(--pv-text-primary);
  box-shadow: 0 0 0 0.25rem rgba(47, 76, 134, 0.25);
}

.theme-dark .form-control::placeholder,
[data-bs-theme="dark"] .form-control::placeholder {
  color: var(--pv-text-muted);
}

.theme-dark .form-label,
[data-bs-theme="dark"] .form-label {
  color: var(--pv-text-primary);
}

.theme-dark .form-check-label,
[data-bs-theme="dark"] .form-check-label {
  color: var(--pv-text-primary);
}

.theme-dark .form-text,
[data-bs-theme="dark"] .form-text {
  color: var(--pv-text-secondary);
}

/* --- Accordion --- */
.theme-dark .accordion-item,
[data-bs-theme="dark"] .accordion-item {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default);
}

.theme-dark .accordion-button,
[data-bs-theme="dark"] .accordion-button {
  background-color: var(--pv-bg-surface);
  color: var(--pv-text-primary);
}

.theme-dark .accordion-button:not(.collapsed),
[data-bs-theme="dark"] .accordion-button:not(.collapsed) {
  background-color: var(--pv-bg-elevated);
  color: var(--pv-text-primary);
  box-shadow: inset 0 calc(-1 * var(--bs-accordion-border-width)) 0 var(--pv-border-default);
}

.theme-dark .accordion-button::after,
[data-bs-theme="dark"] .accordion-button::after {
  filter: invert(1) grayscale(100%) brightness(200%);
}

.theme-dark .accordion-body,
[data-bs-theme="dark"] .accordion-body {
  background-color: var(--pv-bg-surface);
  color: var(--pv-text-primary);
}

/* --- List Groups --- */
.theme-dark .list-group-item,
[data-bs-theme="dark"] .list-group-item {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .list-group-item-action:hover,
.theme-dark .list-group-item-action:focus,
[data-bs-theme="dark"] .list-group-item-action:hover,
[data-bs-theme="dark"] .list-group-item-action:focus {
  background-color: var(--pv-bg-elevated);
  color: var(--pv-text-primary);
}

/* --- Modals --- */
.theme-dark .modal-content,
[data-bs-theme="dark"] .modal-content {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .modal-header,
[data-bs-theme="dark"] .modal-header {
  border-bottom-color: var(--pv-border-default);
}

.theme-dark .modal-footer,
[data-bs-theme="dark"] .modal-footer {
  border-top-color: var(--pv-border-default);
}

.theme-dark .btn-close,
[data-bs-theme="dark"] .btn-close {
  filter: invert(1) grayscale(100%) brightness(200%);
}

/* --- Dropdowns --- */
.theme-dark .dropdown-menu,
[data-bs-theme="dark"] .dropdown-menu {
  background-color: var(--pv-bg-elevated);
  border-color: var(--pv-border-default);
  box-shadow: var(--pv-shadow-lg);
}

.theme-dark .dropdown-item,
[data-bs-theme="dark"] .dropdown-item {
  color: var(--pv-text-primary);
}

.theme-dark .dropdown-item:hover,
.theme-dark .dropdown-item:focus,
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
  background-color: var(--pv-bg-muted);
  color: var(--pv-text-primary);
}

.theme-dark .dropdown-divider,
[data-bs-theme="dark"] .dropdown-divider {
  border-top-color: var(--pv-border-default);
}

/* --- Alerts (enhanced) --- */
.theme-dark .alert,
[data-bs-theme="dark"] .alert {
  border-width: 1px;
  border-style: solid;
}

.theme-dark .alert-info,
[data-bs-theme="dark"] .alert-info {
  background-color: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.theme-dark .alert-success,
[data-bs-theme="dark"] .alert-success {
  background-color: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.theme-dark .alert-warning,
[data-bs-theme="dark"] .alert-warning {
  background-color: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fcd34d;
}

.theme-dark .alert-danger,
[data-bs-theme="dark"] .alert-danger {
  background-color: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.theme-dark .alert-primary,
[data-bs-theme="dark"] .alert-primary {
  background-color: rgba(47, 76, 134, 0.15);
  border-color: rgba(47, 76, 134, 0.4);
  color: #93c5fd;
}

.theme-dark .alert-secondary,
[data-bs-theme="dark"] .alert-secondary {
  background-color: rgba(107, 114, 128, 0.15);
  border-color: rgba(107, 114, 128, 0.4);
  color: #d1d5db;
}

/* --- Badges --- */
.theme-dark .badge.bg-light,
[data-bs-theme="dark"] .badge.bg-light {
  background-color: var(--pv-bg-elevated) !important;
  color: var(--pv-text-primary) !important;
}

.theme-dark .badge.bg-secondary,
[data-bs-theme="dark"] .badge.bg-secondary {
  background-color: var(--pv-bg-elevated) !important;
  color: var(--pv-text-secondary) !important;
}

/* --- Pagination --- */
.theme-dark .page-link,
[data-bs-theme="dark"] .page-link {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .page-link:hover,
[data-bs-theme="dark"] .page-link:hover {
  background-color: var(--pv-bg-elevated);
  border-color: var(--pv-border-light);
  color: var(--pv-text-primary);
}

.theme-dark .page-item.active .page-link,
[data-bs-theme="dark"] .page-item.active .page-link {
  background-color: var(--pv-color-accent);
  border-color: var(--pv-color-accent);
}

.theme-dark .page-item.disabled .page-link,
[data-bs-theme="dark"] .page-item.disabled .page-link {
  background-color: var(--pv-bg-muted);
  color: var(--pv-text-muted);
}

/* --- Breadcrumbs --- */
.theme-dark .breadcrumb,
[data-bs-theme="dark"] .breadcrumb {
  --bs-breadcrumb-divider-color: var(--pv-text-muted);
}

.theme-dark .breadcrumb-item + .breadcrumb-item::before,
[data-bs-theme="dark"] .breadcrumb-item + .breadcrumb-item::before {
  color: var(--pv-text-muted);
}

.theme-dark .breadcrumb-item.active,
[data-bs-theme="dark"] .breadcrumb-item.active {
  color: var(--pv-text-secondary);
}

/* --- Progress Bars --- */
.theme-dark .progress,
[data-bs-theme="dark"] .progress {
  background-color: var(--pv-bg-muted);
}

/* --- Navs & Tabs --- */
.theme-dark .nav-tabs,
[data-bs-theme="dark"] .nav-tabs {
  border-bottom-color: var(--pv-border-default);
}

.theme-dark .nav-tabs .nav-link,
[data-bs-theme="dark"] .nav-tabs .nav-link {
  color: var(--pv-text-secondary);
}

.theme-dark .nav-tabs .nav-link:hover,
.theme-dark .nav-tabs .nav-link:focus,
[data-bs-theme="dark"] .nav-tabs .nav-link:hover,
[data-bs-theme="dark"] .nav-tabs .nav-link:focus {
  border-color: var(--pv-border-light) var(--pv-border-light) var(--pv-border-default);
  color: var(--pv-text-primary);
}

.theme-dark .nav-tabs .nav-link.active,
[data-bs-theme="dark"] .nav-tabs .nav-link.active {
  background-color: var(--pv-bg-surface);
  border-color: var(--pv-border-default) var(--pv-border-default) var(--pv-bg-surface);
  color: var(--pv-text-primary);
}

/* ============================================
   4. UTILITY CLASSES
   ============================================ */

/* --- Text Colors --- */
.pv-text-primary { color: var(--pv-text-primary) !important; }
.pv-text-secondary { color: var(--pv-text-secondary) !important; }
.pv-text-muted { color: var(--pv-text-muted) !important; }
.pv-text-accent { color: var(--pv-color-accent) !important; }
.pv-text-orange { color: var(--pv-color-orange) !important; }
.pv-text-success { color: var(--pv-color-green) !important; }
.pv-text-danger { color: var(--pv-color-red) !important; }
.pv-text-warning { color: var(--pv-color-yellow) !important; }

/* --- Background Colors --- */
.pv-bg-base { background-color: var(--pv-bg-base) !important; }
.pv-bg-surface { background-color: var(--pv-bg-surface) !important; }
.pv-bg-elevated { background-color: var(--pv-bg-elevated) !important; }
.pv-bg-muted { background-color: var(--pv-bg-muted) !important; }
.pv-bg-accent { background-color: var(--pv-color-accent) !important; }
.pv-bg-orange { background-color: var(--pv-color-orange) !important; }

/* --- Border Colors --- */
.pv-border { border-color: var(--pv-border-default) !important; }
.pv-border-light { border-color: var(--pv-border-light) !important; }
.pv-border-strong { border-color: var(--pv-border-strong) !important; }
.pv-border-accent { border-color: var(--pv-color-accent) !important; }

/* --- Shadows --- */
.pv-shadow-sm { box-shadow: var(--pv-shadow-sm) !important; }
.pv-shadow-md { box-shadow: var(--pv-shadow-md) !important; }
.pv-shadow-lg { box-shadow: var(--pv-shadow-lg) !important; }
.pv-shadow-xl { box-shadow: var(--pv-shadow-xl) !important; }
.pv-shadow-none { box-shadow: none !important; }

/* --- Border Radius --- */
.pv-rounded-sm { border-radius: var(--pv-radius-sm) !important; }
.pv-rounded-md { border-radius: var(--pv-radius-md) !important; }
.pv-rounded-lg { border-radius: var(--pv-radius-lg) !important; }
.pv-rounded-xl { border-radius: var(--pv-radius-xl) !important; }
.pv-rounded-full { border-radius: var(--pv-radius-full) !important; }

/* ============================================
   5. COMPONENT CLASSES
   ============================================ */

/* --- Card variant for dark theme --- */
.pv-card {
  background-color: var(--pv-bg-surface);
  border: 1px solid var(--pv-border-default);
  border-radius: var(--pv-radius-lg);
  color: var(--pv-text-primary);
}

.pv-card-header {
  background-color: var(--pv-bg-elevated);
  border-bottom: 1px solid var(--pv-border-default);
  padding: var(--pv-spacing-4) var(--pv-spacing-6);
}

.pv-card-body {
  padding: var(--pv-spacing-6);
}

/* --- Button variants --- */
.pv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--pv-spacing-2);
  padding: var(--pv-spacing-3) var(--pv-spacing-4);
  font-family: var(--pv-font-heading);
  font-size: var(--pv-font-size-sm);
  font-weight: 600;
  border-radius: var(--pv-radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--pv-transition-base);
  text-decoration: none;
}

.pv-btn:hover {
  transform: translateY(-1px);
}

.pv-btn:active {
  transform: translateY(0);
}

.pv-btn-primary {
  background: linear-gradient(135deg, var(--pv-color-orange), var(--pv-color-orange-dark));
  color: var(--pv-text-inverse);
  box-shadow: 0 4px 12px rgba(229, 124, 56, 0.3);
}

.pv-btn-primary:hover {
  box-shadow: 0 6px 16px rgba(229, 124, 56, 0.4);
  color: var(--pv-text-inverse);
}

.pv-btn-secondary {
  background-color: var(--pv-bg-elevated);
  color: var(--pv-text-primary);
  border: 1px solid var(--pv-border-light);
}

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

.pv-btn-ghost {
  background-color: transparent;
  color: var(--pv-text-primary);
  border: 1px solid var(--pv-border-default);
}

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

/* --- Input variant --- */
.pv-input {
  width: 100%;
  padding: var(--pv-spacing-3) var(--pv-spacing-4);
  font-size: var(--pv-font-size-base);
  background-color: var(--pv-bg-elevated);
  color: var(--pv-text-primary);
  border: 1px solid var(--pv-border-default);
  border-radius: var(--pv-radius-md);
  transition: all var(--pv-transition-base);
}

.pv-input:focus {
  outline: none;
  border-color: var(--pv-color-accent);
  box-shadow: 0 0 0 3px rgba(47, 76, 134, 0.15);
}

.pv-input::placeholder {
  color: var(--pv-text-muted);
}

/* ============================================
   6. TEXT CONTRAST FIXES
   ============================================ */

/* Fix Bootstrap .text-muted in dark mode */
.theme-dark .text-muted,
[data-bs-theme="dark"] .text-muted {
  color: var(--pv-text-secondary) !important;
}

/* Fix .text-dark class - should use appropriate color */
.theme-dark .text-dark,
[data-bs-theme="dark"] .text-dark {
  color: var(--pv-text-primary) !important;
}

/* Fix small helper text */
.theme-dark small,
.theme-dark .small,
[data-bs-theme="dark"] small,
[data-bs-theme="dark"] .small {
  color: var(--pv-text-secondary);
}

/* Fix hr dividers */
.theme-dark hr,
[data-bs-theme="dark"] hr {
  border-color: var(--pv-border-default);
  opacity: 1;
}

/* ============================================
   7. FOCUS & ACCESSIBILITY
   ============================================ */

/* Enhanced focus states */
.theme-dark *:focus-visible,
[data-bs-theme="dark"] *:focus-visible {
  outline: 2px solid var(--pv-color-accent-light);
  outline-offset: 2px;
}

.theme-dark .btn:focus-visible,
[data-bs-theme="dark"] .btn:focus-visible {
  box-shadow: 0 0 0 0.25rem rgba(74, 111, 165, 0.5);
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   8. AUTOCOMPLETE - FIX OVERLAPPING BUG
   ============================================

   IMPORTANT: These styles fix a bug where autocomplete
   result lines overlap on Safari/Chrome Mac/iOS/Android.
   The issue is caused by inconsistent line-height inheritance
   and missing min-height on list items.

   DO NOT remove min-height, line-height, or box-sizing!
   ============================================ */

/* --- Autocomplete Container (all variants) --- */
#suggestBox,
#catalogSuggest,
#paintSearchResults,
.search-results-dropdown,
.autocomplete-results,
.paint-suggestions {
  /* Reset potential inheritance issues */
  line-height: 1.5;
  font-size: var(--pv-font-size-base, 1rem);

  /* Layout */
  list-style: none;
  margin: 0;
  padding: 0;

  /* Scroll behavior */
  max-height: 350px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */

  /* Appearance */
  background: var(--pv-bg-surface, #ffffff);
  border: 1px solid var(--pv-border-default, rgba(0, 0, 0, 0.12));
  border-radius: var(--pv-radius-lg, 12px);
  box-shadow: var(--pv-shadow-lg, 0 10px 30px rgba(0, 0, 0, 0.12));

  /* Ensure proper stacking */
  z-index: var(--pv-z-dropdown, 1000);
}

/* --- Autocomplete Items - CRITICAL for fixing overlap --- */
#suggestBox > *,
#suggestBox .list-group-item,
#catalogSuggest > *,
#catalogSuggest .list-group-item,
#paintSearchResults > *,
#paintSearchResults .list-group-item,
.search-results-dropdown > *,
.search-results-dropdown .result-item,
.autocomplete-results > *,
.paint-suggestions > * {
  /* MINIMUM HEIGHT - prevents collapse on Safari/iOS */
  min-height: 44px !important;

  /* EXPLICIT LINE-HEIGHT - prevents inheritance bugs */
  line-height: 1.4 !important;

  /* EXPLICIT BOX-SIZING - ensures consistent sizing */
  box-sizing: border-box !important;

  /* Padding - generous for touch targets */
  padding: 0.625rem 0.875rem !important;

  /* Flexbox layout for vertical centering */
  display: flex !important;
  align-items: center !important;
  gap: 0.625rem;

  /* Text handling */
  word-wrap: break-word;
  overflow-wrap: break-word;

  /* Separator */
  border-bottom: 1px solid var(--pv-border-default, rgba(0, 0, 0, 0.08));

  /* Colors */
  color: var(--pv-text-primary, #2B2B2B);
  background: transparent;

  /* Interaction */
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}

/* Last item - no border */
#suggestBox > *:last-child,
#suggestBox .list-group-item:last-child,
#catalogSuggest > *:last-child,
#catalogSuggest .list-group-item:last-child,
#paintSearchResults > *:last-child,
#paintSearchResults .list-group-item:last-child,
.search-results-dropdown > *:last-child,
.autocomplete-results > *:last-child,
.paint-suggestions > *:last-child {
  border-bottom: none;
}

/* Hover state */
#suggestBox > *:hover,
#suggestBox .list-group-item:hover,
#catalogSuggest > *:hover,
#catalogSuggest .list-group-item:hover,
#paintSearchResults > *:hover,
#paintSearchResults .list-group-item:hover,
.search-results-dropdown > *:hover,
.autocomplete-results > *:hover,
.paint-suggestions > *:hover {
  background: var(--pv-bg-elevated, #f5f7fa);
}

/* --- Inner content alignment --- */
#suggestBox .list-group-item > div,
#catalogSuggest .list-group-item > div,
#paintSearchResults .list-group-item > div,
.search-results-dropdown .result-item > div {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0; /* Allow text truncation */
  flex: 1;
}

/* --- Color dot in autocomplete --- */
.dropdown-color-dot,
#suggestBox .pv-swatch,
#catalogSuggest .pv-swatch {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

/* --- Text truncation in autocomplete items --- */
#suggestBox .text-truncate,
#catalogSuggest .text-truncate,
#paintSearchResults .text-truncate,
.search-results-dropdown .paint-info {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* --- Safari/WebKit specific fixes --- */
@supports (-webkit-touch-callout: none) {
  #suggestBox > *,
  #suggestBox .list-group-item,
  #catalogSuggest > *,
  #catalogSuggest .list-group-item,
  #paintSearchResults > *,
  #paintSearchResults .list-group-item,
  .search-results-dropdown > *,
  .autocomplete-results > *,
  .paint-suggestions > * {
    /* Force GPU rendering for stable layout */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);

    /* Prevent text size adjustment issues */
    -webkit-text-size-adjust: 100%;

    /* Ensure proper tap highlight on iOS */
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
  }
}

/* --- iOS touch device optimizations --- */
@media (hover: none) and (pointer: coarse) {
  #suggestBox > *,
  #suggestBox .list-group-item,
  #catalogSuggest > *,
  #catalogSuggest .list-group-item,
  #paintSearchResults > *,
  #paintSearchResults .list-group-item,
  .search-results-dropdown > *,
  .autocomplete-results > *,
  .paint-suggestions > * {
    /* Larger touch targets on mobile */
    min-height: 48px !important;
    padding: 0.75rem 1rem !important;
  }
}

/* --- Dark Theme Overrides for Autocomplete --- */
.theme-dark #suggestBox,
.theme-dark #catalogSuggest,
.theme-dark #paintSearchResults,
.theme-dark .search-results-dropdown,
.theme-dark .autocomplete-results,
.theme-dark .paint-suggestions,
[data-bs-theme="dark"] #suggestBox,
[data-bs-theme="dark"] #catalogSuggest,
[data-bs-theme="dark"] #paintSearchResults,
[data-bs-theme="dark"] .search-results-dropdown,
[data-bs-theme="dark"] .autocomplete-results,
[data-bs-theme="dark"] .paint-suggestions {
  background: var(--pv-bg-elevated, #1f2937);
  border-color: var(--pv-border-light, #374151);
  box-shadow: var(--pv-shadow-lg, 0 10px 30px rgba(0, 0, 0, 0.4));
}

.theme-dark #suggestBox > *,
.theme-dark #suggestBox .list-group-item,
.theme-dark #catalogSuggest > *,
.theme-dark #catalogSuggest .list-group-item,
.theme-dark #paintSearchResults > *,
.theme-dark #paintSearchResults .list-group-item,
.theme-dark .search-results-dropdown > *,
.theme-dark .autocomplete-results > *,
.theme-dark .paint-suggestions > *,
[data-bs-theme="dark"] #suggestBox > *,
[data-bs-theme="dark"] #suggestBox .list-group-item,
[data-bs-theme="dark"] #catalogSuggest > *,
[data-bs-theme="dark"] #catalogSuggest .list-group-item,
[data-bs-theme="dark"] #paintSearchResults > *,
[data-bs-theme="dark"] #paintSearchResults .list-group-item,
[data-bs-theme="dark"] .search-results-dropdown > *,
[data-bs-theme="dark"] .autocomplete-results > *,
[data-bs-theme="dark"] .paint-suggestions > * {
  color: var(--pv-text-primary, #f3f4f6);
  border-bottom-color: var(--pv-border-default, #1f2937);
}

.theme-dark #suggestBox > *:hover,
.theme-dark #suggestBox .list-group-item:hover,
.theme-dark #catalogSuggest > *:hover,
.theme-dark #catalogSuggest .list-group-item:hover,
.theme-dark #paintSearchResults > *:hover,
.theme-dark #paintSearchResults .list-group-item:hover,
.theme-dark .search-results-dropdown > *:hover,
.theme-dark .autocomplete-results > *:hover,
.theme-dark .paint-suggestions > *:hover,
[data-bs-theme="dark"] #suggestBox > *:hover,
[data-bs-theme="dark"] #suggestBox .list-group-item:hover,
[data-bs-theme="dark"] #catalogSuggest > *:hover,
[data-bs-theme="dark"] #catalogSuggest .list-group-item:hover,
[data-bs-theme="dark"] #paintSearchResults > *:hover,
[data-bs-theme="dark"] #paintSearchResults .list-group-item:hover,
[data-bs-theme="dark"] .search-results-dropdown > *:hover,
[data-bs-theme="dark"] .autocomplete-results > *:hover,
[data-bs-theme="dark"] .paint-suggestions > *:hover {
  background: var(--pv-bg-muted, #0b1120);
}

/* --- Dark theme scrollbar --- */
.theme-dark #suggestBox::-webkit-scrollbar,
.theme-dark #catalogSuggest::-webkit-scrollbar,
.theme-dark #paintSearchResults::-webkit-scrollbar,
.theme-dark .search-results-dropdown::-webkit-scrollbar,
[data-bs-theme="dark"] #suggestBox::-webkit-scrollbar,
[data-bs-theme="dark"] #catalogSuggest::-webkit-scrollbar,
[data-bs-theme="dark"] #paintSearchResults::-webkit-scrollbar,
[data-bs-theme="dark"] .search-results-dropdown::-webkit-scrollbar {
  width: 8px;
}

.theme-dark #suggestBox::-webkit-scrollbar-track,
.theme-dark #catalogSuggest::-webkit-scrollbar-track,
.theme-dark #paintSearchResults::-webkit-scrollbar-track,
.theme-dark .search-results-dropdown::-webkit-scrollbar-track,
[data-bs-theme="dark"] #suggestBox::-webkit-scrollbar-track,
[data-bs-theme="dark"] #catalogSuggest::-webkit-scrollbar-track,
[data-bs-theme="dark"] #paintSearchResults::-webkit-scrollbar-track,
[data-bs-theme="dark"] .search-results-dropdown::-webkit-scrollbar-track {
  background: var(--pv-bg-surface, #111827);
  border-radius: 4px;
}

.theme-dark #suggestBox::-webkit-scrollbar-thumb,
.theme-dark #catalogSuggest::-webkit-scrollbar-thumb,
.theme-dark #paintSearchResults::-webkit-scrollbar-thumb,
.theme-dark .search-results-dropdown::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] #suggestBox::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] #catalogSuggest::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] #paintSearchResults::-webkit-scrollbar-thumb,
[data-bs-theme="dark"] .search-results-dropdown::-webkit-scrollbar-thumb {
  background: var(--pv-border-light, #374151);
  border-radius: 4px;
}

.theme-dark #suggestBox::-webkit-scrollbar-thumb:hover,
.theme-dark #catalogSuggest::-webkit-scrollbar-thumb:hover,
.theme-dark #paintSearchResults::-webkit-scrollbar-thumb:hover,
.theme-dark .search-results-dropdown::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] #suggestBox::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] #catalogSuggest::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] #paintSearchResults::-webkit-scrollbar-thumb:hover,
[data-bs-theme="dark"] .search-results-dropdown::-webkit-scrollbar-thumb:hover {
  background: var(--pv-border-strong, #4b5563);
}
