/*
 * Custom Utilities for SWAPRIDE
 * Specific utility classes not covered by materialish.css
 * materialish.css is the primary design system - this file only adds specific utilities
 */

/* HTMX Loading Indicators - Specific utility */
.htmx-indicator {
  display: none;
  font-size: 0.875rem;
  margin-left: 0.5rem;
}

.htmx-indicator.htmx-request {
  display: inline;
}

/* ============================================================
 * Unified Vehicle Spec Field Styling
 * Ensures consistent appearance in:
 * - Initial load (readonly mode with form-control-plaintext)
 * - Edit mode (editable with form-control)
 * - After Save (readonly mode restored)
 * - HTMX reload (after vehicle selection change)
 * ============================================================ */

/* Base styling: Make form-control-plaintext look similar to form-control */
.form-control-plaintext.vehicle-spec-field {
  border: 1px solid var(--md-border);
  padding: 0.375rem 0.75rem;
  background-color: var(--md-background);
  border-radius: 0.25rem;
  min-height: calc(1.5em + 0.75rem + 2px);
  display: block;
  width: 100%;
}

/* Unified: Highlight empty or unknown spec fields */
.vehicle-spec-field.empty-field,
.vehicle-spec-field.missing-spec {
  border-color: #dc3545 !important; /* Bootstrap danger red */
  background-color: #fff5f5 !important; /* Light red background */
}

/* Specific styling for plaintext inputs when empty */
.form-control-plaintext.vehicle-spec-field.empty-field,
.form-control-plaintext.vehicle-spec-field.missing-spec {
  border-color: #dc3545 !important;
  background-color: #fff5f5 !important;
  /* Add subtle indicator that field is empty */
  font-style: italic;
  color: var(--md-text-muted);
}

/* Editable mode: Keep consistent styling with Bootstrap defaults */
.form-control.vehicle-spec-field.empty-field,
.form-control.vehicle-spec-field.missing-spec {
  border-color: #dc3545 !important;
  background-color: #fff5f5 !important;
}

/* Vehicle details section */
#vehicle-details-container .alert-info {
  font-size: 0.875rem;
}

/* Loading states */
.loading-placeholder {
  background-color: var(--md-background);
  border: 1px dashed var(--md-border);
  padding: 2rem;
  text-align: center;
  color: var(--md-text-muted);
}

/* Vehicle selection form improvements */
.form-row .form-group {
  margin-bottom: 1rem;
}

.vehicle-specs-container {
  background-color: var(--md-surface);
  border: 1px solid var(--md-border);
  border-radius: 0.375rem;
  padding: 1.5rem;
  margin-top: 1rem;
}

.vehicle-specs-container h5 {
  margin-bottom: 1rem;
  color: var(--md-on-surface-variant);
}

/* Landing Page Utilities */
#hero {
  position: relative;
  z-index: 100;
}

#hero.bg-gradient.hero-with-image {
  background-size: cover;
  background-position: center;
  min-height: 45vh;
}

.min-vh-50 {
  min-height: 50vh;
}

.min-vh-60 {
  min-height: 60vh;
}

.feature-icon {
  width: 4rem;
  height: 4rem;
}

#search-results-section {
  position: relative;
  z-index: 10;
}

/* Compact floating controls utility (used by homepage search) */
.form-floating-sm {
  position: relative;
}
.form-floating-sm > .form-control,
.form-floating-sm > .form-select {
  height: calc(3.5rem + 2px);
  line-height: 1.25;
}
.form-floating-sm > label {
  padding: 1rem 0.75rem;
}
@media (max-width: 768px) {
  .form-floating-sm > .form-control,
  .form-floating-sm > .form-select {
    height: calc(3rem + 2px);
  }
}

/* Advanced Filters - Specific layout */
#advanced-filters {
  margin-top: 1rem;
}

#advanced-filters .card-body {
  background: var(--md-background);
  border-radius: 0.5rem;
  padding: 1.5rem;
}

#advanced-filters .form-floating {
  margin-bottom: 0;
}

/* Micro-interactions utilities */
.mi-hover-lift {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.mi-hover-lift:hover {
  transform: translateY(-3px);
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.12);
}
.mi-press {
  transition: transform 0.05s ease;
}
.mi-press:active {
  transform: translateY(1px);
}

/* Icon utilities */
.icon-48 {
  width: 48px;
  height: 48px;
}

/* Search Form utilities */
.search-form-container {
  max-width: 100%;
}

#search-loading.d-none {
  display: none !important;
}

.htmx-request #search-loading.d-none {
  display: block !important;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .search-form-container .row {
    margin-bottom: 0.5rem;
  }

  .search-form-container .form-floating {
    margin-bottom: 0.75rem;
  }

  .display-4 {
    font-size: 2.5rem;
  }

  .feature-icon {
    width: 3rem;
    height: 3rem;
  }
}

/* Loading Animation */
@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

.loading-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Small inline spinner for search loading indicator */
.search-loading-spinner {
  width: 1rem;
  height: 1rem;
}

/* Create listing: loading overlay and utilities */
.form-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1050; /* above modals if needed */
  display: flex;
  align-items: center;
  justify-content: center;
}
.form-loading-overlay .loading-content {
  background: var(--md-surface);
  border-radius: 0.5rem;
  padding: 1.5rem;
  width: min(560px, 92vw);
  box-shadow: 0 0.75rem 2rem rgba(0, 0, 0, 0.2);
}
.form-loading-overlay .loading-spinner {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 0.75rem;
}
.form-loading-overlay .spinner-ring {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  animation: pulse 1.2s ease-in-out infinite;
}
.form-loading-overlay .spinner-ring:nth-child(2) {
  animation-delay: 0.15s;
}
.form-loading-overlay .spinner-ring:nth-child(3) {
  animation-delay: 0.3s;
}
.form-loading-overlay .loading-text h5 {
  margin: 0 0 0.25rem 0;
}
.form-loading-overlay .loading-progress {
  height: 6px;
  background: #f1f3f5;
  border-radius: 999px;
  overflow: hidden;
}
.form-loading-overlay .loading-progress .progress-bar {
  width: 35%;
  height: 100%;
  background: var(--color-accent);
  transition: width 0.3s ease;
}

/* Utility to toggle hidden state replacing inline style="display:none" */
.d-none {
  display: none !important;
}

/* Debug panel inline-style replacements */
.live-debug-section {
  margin-top: 15px;
}
.live-debug-section h6 {
  color: #dc3545;
  margin: 0 0 8px 0;
  text-decoration: underline;
}
.live-debug-section .section-title {
  margin-top: 8px;
  font-weight: 600;
}
.live-debug-section .kv {
  margin-left: 10px;
}

/* Inline style replacement classes */
.main-layout-vh {
  min-height: 100vh;
}

.hero-subtitle {
  font-size: 0.85rem;
}

.search-subtitle {
  font-size: 0.75rem;
}

.btn-xs {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.featured-subtitle {
  font-size: 0.8rem;
}

/* Utility: max-height 280px (replaces inline style in templates) */
.max-h-280px {
  max-height: 280px;
}

/* Utility classes */
.d-inline {
  display: inline !important;
}

/* Hero specific */
#hero.bg-gradient {
  color: var(--md-surface);
}

/* Badge utilities */
.bg-success-subtle {
  background-color: #d1e7dd !important;
}
.text-success-emphasis {
  color: #0f5132 !important;
}

/* Equipment Form - Specific layout styles */
.equipment-grid {
  max-height: 300px;
  overflow-y: auto;
}

.equipment-item {
  border: none;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.2s ease;
}

.equipment-item .equipment-icon {
  width: 20px;
  height: 20px;
  margin-right: 0.5rem;
  opacity: 0.7;
}

.equipment-item .equipment-name {
  flex: 1;
  font-size: 0.875rem;
}

.equipment-item .equipment-category {
  font-size: 0.75rem;
  color: var(--md-text-muted);
  text-transform: uppercase;
}

/* Multiselect checkbox layout */
.multiselect-checkbox-container {
  border: 1px solid var(--md-border);
  border-radius: 0.25rem;
  height: 300px;
  overflow-y: auto;
  padding: 0.5rem;
  background-color: var(--md-surface);
}

.multiselect-checkbox-item {
  gap: 0.5rem;
  padding: 0.25rem;
  cursor: pointer;
  border-radius: 0.25rem;
  transition: background-color 0.2s;
  var(--md-surface)-space: nowrap;
}

.multiselect-checkbox-item input[type="checkbox"] {
  margin-right: 0.5rem;
}

.multiselect-checkbox-item label {
  margin: 0;
  cursor: pointer;
  user-select: none;
}

/* Multiselect search input */
.multiselect-search-wrapper {
  position: relative;
  margin-bottom: 0.5rem;
}

.multiselect-search-input {
  width: 100%;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  border: 1px solid var(--md-border);
  border-radius: 0.25rem;
  font-size: 0.875rem;
}

.multiselect-search-input:focus {
  border-color: #80bdff;
  outline: 0;
  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.multiselect-search-clear {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--md-text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
}

.multiselect-search-clear:hover {
  color: var(--md-on-surface-variant);
}

.multiselect-checkbox-item.hidden {
  display: none;
}

.multiselect-no-results {
  text-align: center;
  padding: 1rem;
  color: var(--md-text-muted);
  font-size: 0.875rem;
}
