/* Hotwire Combobox Consolidated Styles - Updated */

/* =============================================================================
   1. Core Layout & Positioning
   ============================================================================= */

.hw-combobox {
  position: relative !important;
  flex: 1;
  min-width: 0;
}

/* Override default width when using flex-1 class */
.flex-1 .hw-combobox {
  --hw-combobox-width: 100% !important;
}

/* =============================================================================
   2. Main Wrapper - Match form input styling
   ============================================================================= */

.hw-combobox__main__wrapper {
  /* Ensure wrapper displays as flex to allow input to expand */
  display: flex !important;
  align-items: center !important;

  /* Full width in flex containers */
  width: 100% !important;
  min-width: 0 !important;

  /* Match the form's input styling exactly */
  background-color: rgb(249 250 251) !important;
  border: 1px solid rgb(209 213 219) !important;
  color: rgb(17 24 39) !important;
  font-size: 0.875rem !important;
  border-radius: 0.5rem !important;

  /* Ensure consistent padding with other inputs - reserve space for caret */
  padding: 0.5rem 2.25rem 0.5rem 0.75rem !important;
}

.hw-combobox__main__wrapper:focus-within {
  border-color: rgb(59 130 246) !important;
  outline: 2px solid transparent !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 2px rgb(59 130 246 / 0.5) !important;
}

/* Remove focus ring override that was too aggressive */
.hw-combobox__main__wrapper[aria-expanded="true"],
.hw-combobox__main__wrapper:focus,
.hw-combobox__main__wrapper:active {
  border-color: rgb(59 130 246) !important;
  outline: 2px solid transparent !important;
  outline-offset: 2px !important;
}

/* Additional specificity for flex-1 containers */
.flex-1 .hw-combobox__main__wrapper {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* Even more specific override targeting the exact width constraint */
.flex-1 > .hw-combobox > .hw-combobox__main__wrapper {
  width: 100% !important;
  max-width: none !important;
  min-width: 0 !important;
}

/* Override any inline styles */
.flex-1 .hw-combobox__main__wrapper[style*="width"] {
  width: 100% !important;
}

/* =============================================================================
   3. Input - Remove all borders/outlines and ensure full width
   ============================================================================= */

.hw-combobox__input,
input.hw-combobox__input,
.hw-combobox__main__wrapper input[role="combobox"] {
  /* Remove default input styling that conflicts - wrapper handles the border */
  border: none !important;
  border-width: 0 !important;
  outline: none !important;
  box-shadow: none !important;
  background-color: transparent !important;
  background: transparent !important;

  /* Full width expansion */
  width: 100% !important;
  min-width: 0 !important;
  flex: 1 !important;

  /* Remove extra padding - wrapper handles it */
  padding: 0 !important;
  margin: 0 !important;

  /* Inherit color from wrapper */
  color: inherit !important;

  /* Remove border radius that might show through */
  border-radius: 0 !important;
}

.hw-combobox__input:focus,
input.hw-combobox__input:focus,
.hw-combobox__main__wrapper input[role="combobox"]:focus {
  border: none !important;
  border-width: 0 !important;
  outline: none !important;
  box-shadow: none !important;
  ring: 0 !important;
  --tw-ring-shadow: none !important;
}

.hw-combobox__input::placeholder {
  color: rgb(156 163 175) !important;
}

/* Ensure proper input sizing when parent has flex-1 */
.flex-1 .hw-combobox__input {
  width: 100% !important;
  min-width: 0 !important;
  flex: 1 !important;
}

/* =============================================================================
   4. Dropdown Handle/Caret
   ============================================================================= */

.hw-combobox__handle {
  position: absolute !important;
  right: 0.75rem !important;
  top: 50% !important;
  transform: translateY(-50%) !important;
  flex: none !important;
  cursor: pointer !important;
  display: block !important;
  opacity: 1 !important;
  visibility: visible !important;
  width: 1rem !important;
  height: 1rem !important;
}

/* Add the caret icon using ::before pseudo-element */
.hw-combobox__handle::before {
  content: "" !important;
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e") !important;
  background-repeat: no-repeat !important;
  background-position: center !important;
  background-size: contain !important;
}

.flex-1 .hw-combobox__main__wrapper .hw-combobox__handle {
  position: absolute !important;
  flex: none !important;
}

/* =============================================================================
   5. Listbox/Dropdown - Light Mode
   ============================================================================= */

.hw-combobox__listbox {
  background: white !important;
  border: 1px solid rgb(209 213 219) !important;
  color: rgb(17 24 39) !important;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1) !important;

  /* Essential positioning */
  position: absolute !important;
  top: calc(100% + 0.2rem) !important;
  left: 0 !important;
  z-index: 10 !important;
  width: 100% !important;

  /* Flowbite-inspired styling */
  border-radius: 0.5rem !important;
  padding: 0.25rem !important;
}

.hw-combobox__option {
  color: rgb(17 24 39) !important;
  background-color: rgb(255 255 255) !important;

  /* Flowbite-inspired styling */
  border-radius: 0.375rem !important;
  padding: 0.5rem 1rem !important;
  margin: 0.125rem !important;
  transition: all 0.15s ease-in-out !important;
}

.hw-combobox__option:hover,
.hw-combobox__option--selected,
.hw-combobox__option--navigated {
  background-color: rgb(239 246 255) !important;
  color: rgb(17 24 39) !important;
}

/* =============================================================================
   6. Dark Mode - Manual .dark class
   ============================================================================= */

.dark .hw-combobox__main__wrapper {
  background-color: rgb(55 65 81) !important;
  border-color: rgb(75 85 99) !important;
  color: rgb(255 255 255) !important;
}

.dark .hw-combobox__main__wrapper:focus-within {
  border-color: rgb(59 130 246) !important;
  box-shadow: 0 0 0 2px rgb(59 130 246 / 0.5) !important;
}

.dark .hw-combobox__input::placeholder {
  color: rgb(156 163 175) !important;
}

.dark .hw-combobox__listbox {
  background: rgb(55 65 81) !important;
  border-color: rgb(75 85 99) !important;
  color: rgb(249 250 251) !important;
  box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.1) !important;

  /* Ensure positioning is preserved in dark mode */
  position: absolute !important;
  top: calc(100% + 0.2rem) !important;
  left: 0 !important;
  z-index: 10 !important;
  width: 100% !important;
}

.dark .hw-combobox__option {
  color: rgb(249 250 251) !important;
  background-color: rgb(55 65 81) !important;
}

.dark .hw-combobox__option:hover,
.dark .hw-combobox__option--selected,
.dark .hw-combobox__option--navigated {
  background-color: rgb(99 102 241) !important;
  color: rgb(255 255 255) !important;
}

.dark {
  --hw-handle-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
}

/* Dark mode dialog styles */
.dark .hw-combobox__dialog {
  background: rgb(55 65 81) !important;
  border-color: rgb(107 114 128) !important;
}

.dark .hw-combobox__dialog__input {
  background: rgb(75 85 99) !important;
  border-color: rgb(107 114 128) !important;
  color: rgb(249 250 251) !important;
}

.dark .hw-combobox__dialog__input::placeholder {
  color: rgb(156 163 175) !important;
}

/* =============================================================================
   7. Dark Mode - prefers-color-scheme fallback
   ============================================================================= */

@media (prefers-color-scheme: dark) {
  :root {
    --hw-handle-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%239ca3af' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  }

  .hw-combobox__main__wrapper {
    background-color: rgb(55 65 81) !important;
    border-color: rgb(75 85 99) !important;
    color: rgb(255 255 255) !important;
  }

  .hw-combobox__main__wrapper:focus-within {
    border-color: rgb(59 130 246) !important;
    box-shadow: 0 0 0 2px rgb(59 130 246 / 0.5) !important;
  }

  .hw-combobox__input::placeholder {
    color: rgb(156 163 175) !important;
  }

  .hw-combobox__listbox {
    background: rgb(55 65 81) !important;
    border-color: rgb(75 85 99) !important;
    color: rgb(249 250 251) !important;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.1) !important;

    /* Ensure positioning is preserved */
    position: absolute !important;
    top: calc(100% + 0.2rem) !important;
    left: 0 !important;
    z-index: 10 !important;
    width: 100% !important;
  }

  /* Target the listbox more specifically */
  ul.hw-combobox__listbox {
    background: rgb(55 65 81) !important;
    border: 1px solid rgb(107 114 128) !important;

    /* Ensure positioning is preserved for specific selector */
    position: absolute !important;
    top: calc(100% + 0.2rem) !important;
    left: 0 !important;
    z-index: 10 !important;
    width: 100% !important;
  }

  .hw-combobox__option,
  li.hw-combobox__option {
    color: rgb(249 250 251) !important;
    background-color: rgb(55 65 81) !important;
  }

  .hw-combobox__option:hover,
  .hw-combobox__option--selected,
  .hw-combobox__option--navigated,
  li.hw-combobox__option:hover,
  li.hw-combobox__option--selected,
  li.hw-combobox__option--navigated {
    background-color: rgb(99 102 241) !important;
    color: rgb(255 255 255) !important;
  }

  .hw-combobox__dialog {
    background: rgb(55 65 81) !important;
    border-color: rgb(107 114 128) !important;
  }

  .hw-combobox__dialog__input {
    background: rgb(75 85 99) !important;
    border-color: rgb(107 114 128) !important;
    color: rgb(249 250 251) !important;
  }

  .hw-combobox__dialog__input::placeholder {
    color: rgb(156 163 175) !important;
  }
}

/* =============================================================================
   8. CSS Variables for dark mode
   ============================================================================= */

:root.dark,
.dark {
  --hw-component-bg-color: #374151 !important;
  --hw-option-bg-color: #374151 !important;
  --hw-active-bg-color: #6366f1 !important;
  --hw-border-color: #4b5563 !important;
}

@media (prefers-color-scheme: dark) {
  :root {
    --hw-component-bg-color: #374151 !important;
    --hw-option-bg-color: #374151 !important;
    --hw-active-bg-color: #6366f1 !important;
    --hw-border-color: #4b5563 !important;
  }
}
