/* Phone Input Component Styles */

/* Scoping with ID to ensure specificity without !important */
#phone-input-container .phone-input-container {
  position: relative;
  padding: 0; /* REMOVED padding to fix label spacing issue */
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: stretch;
  z-index: 100;
}

/* Wrapper Group Styling */
#phone-input-container .phone-input-wrapper {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 0;
  position: relative;
  width: 100%;
  height: auto; /* Force consistent height */
  border: 1.5px solid #d1d5db;
  border-radius: 8px; /* Match global radius */
  background-color: #f9fafb;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.03);
  padding: auto;
}

#phone-input-container .phone-input-wrapper:hover {
  border-color: #9ca3af;
  background-color: #ffffff;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

#phone-input-container .phone-input-wrapper:focus-within {
  background-color: #ffffff;
  border-color: #ff7e5f;
  box-shadow: 0 0 0 4px rgba(255, 126, 95, 0.15),
    0 1px 2px 0 rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

/* Country Selector Button */
#phone-input-container .country-selector {
  position: relative;
  padding: auto;
  min-width: 140px; /* Slight adjustment */
  flex: 0 0 auto;
  z-index: 101;
}

#phone-input-container .country-selector.open {
  z-index: 10000;
}

/* Selected Country Button */
#phone-input-container .selected-country {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0.85rem 12px;
  background-color: transparent;
  border: none;
  border-right: none;
  border-radius: 10px 0 0 10px;
  cursor: pointer;
  transition: background-color 0.2s;
  height: 100%; /* Fill height */
  font-family: inherit;
  box-shadow: none;
  outline: none;
}

#phone-input-container .selected-country:hover {
  background-color: #f8f9fa;
}

#phone-input-container .selected-country:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(255, 126, 95, 0.2);
  background-color: #f8f9fa;
  z-index: 2;
}

#phone-input-container .country-selector.open .selected-country {
  background-color: #fff;
  border-right-color: transparent; /* Seamless look when open if desired, or keep specific */
}

#phone-input-container .flag-emoji {
  font-size: 1.25rem;
  line-height: 1;
  margin-right: 8px;
  flex-shrink: 0;
}

#phone-input-container .selected-country .dial-code {
  font-weight: 600;
  color: #1a202c;
  font-size: 0.95rem;
  white-space: nowrap;
}

#phone-input-container .selected-country .arrow {
  display: none !important;
}

#phone-input-container .country-selector.open .arrow {
  transform: rotate(180deg);
}

/* Dropdown */
#phone-input-container .country-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  max-width: 90vw;
  background: #fff;
  border: 1px solid #edf2f7;
  border-radius: 16px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
  z-index: 9999;
  display: none;
  animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

#phone-input-container .country-dropdown.show {
  display: block;
}

@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#phone-input-container .dropdown-search {
  padding: 12px;
  border-bottom: 1px solid #edf2f7;
  background: #fff;
}

#phone-input-container .dropdown-search input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #edf2f7;
  border-radius: 12px;
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s;
  background-color: #f8fafc;
  margin-bottom: 0; /* Override global input margin */
}

#phone-input-container .dropdown-search input:focus {
  border-color: var(--primary-color, #ff7e5f);
  background-color: #fff;
  box-shadow: 0 0 0 3px rgba(255, 126, 95, 0.1);
}

#phone-input-container .country-list {
  max-height: 280px;
  overflow-y: auto;
  list-style: none;
  padding: 4px 0;
  margin: 0;
}

/* Scrollbar Styling */
#phone-input-container .country-list::-webkit-scrollbar {
  width: 6px;
}
#phone-input-container .country-list::-webkit-scrollbar-track {
  background: #f7fafc;
}
#phone-input-container .country-list::-webkit-scrollbar-thumb {
  background: #cbd5e0;
  border-radius: 3px;
}

#phone-input-container .country-option {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  border-bottom: 1px solid transparent;
}

#phone-input-container .country-option:hover,
#phone-input-container .country-option.highlight {
  background-color: #fff5f2;
  padding-left: 20px;
}

#phone-input-container .country-option.active {
  background-color: rgba(255, 126, 95, 0.1);
  font-weight: 600;
}

#phone-input-container .country-option .country-name {
  flex: 1;
  font-size: 0.9rem;
  color: #2d3748;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 12px;
}

#phone-input-container .country-option .country-dial-code {
  color: #718096;
  font-size: 0.85rem;
  font-weight: 500;
}

#phone-input-container .check-icon {
  color: var(--primary-color, #ff7e5f);
  margin-left: 12px;
  font-size: 0.8rem;
  width: auto; /* Prevent stretching */
}

/* Phone Input Field Wrapper */
#phone-input-container .phone-field-wrapper {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0;
  z-index: 10; /* Increased z-index to ensure visibility over any overlaps */
}

/* Specific ID Selector for Input */
#phone-input-container #phone-input-field {
  width: 100%;
  padding: 12px 16px; /* Match global input padding */
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  border-radius: 0 8px 8px 0; /* Match global radius */
  font-size: 1rem;
  height: 100%; /* Fill wrapper height */
  transition: none; /* Managed by wrapper */
  background-color: transparent;
  color: #1a202c;
  font-family: inherit;
  box-shadow: none;
  outline: none;
  margin: 0; /* Remove potential margin */
}

#phone-input-container #phone-input-field::placeholder {
  color: #a0aec0;
  font-size: 0.95rem;
}

#phone-input-container #phone-input-field:focus {
  border: none !important;
  box-shadow: none !important;
}

/* Validation States */
#phone-input-container #phone-input-field.valid {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2348bb78' width='18px' height='18px'%3E%3Cpath d='M0 0h24v24H0z' fill='none'/%3E%3Cpath d='M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

#phone-input-container #phone-input-field.invalid {
  /* We can't change the border of the input comfortably since it has none, 
     so we might need to rely on the wrapper or just text color/background.
     However, the requirement was to clean up !important. 
     The original code changed border-color of the input but had !important on border: none.
     So effectively, it wasn't showing a border. 
     We should probably show invalid state on the WRAPPER or just text. 
     Let's try to style the wrapper based on a class we add to it via JS, 
     OR just accept that the text might be red or add a subtle background.
  */
  color: #e53e3e;
}

/* Better approach for invalid state: 
   Since we can't style the parent based on child class in CSS without :has(),
   and :has() support is good but maybe not 100% everywhere yet (though widely supported in 2024/2025).
   Let's stick to simple visual feedback for now.
*/

#phone-input-container .validation-message {
  position: absolute;
  top: 100%;
  left: 0;
  font-size: 0.75rem;
  color: #f56565;
  margin-top: 6px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(-5px);
  transition: all 0.3s ease;
  pointer-events: none;
  z-index: 10;
}

#phone-input-container #phone-input-field.invalid ~ .validation-message {
  opacity: 1;
  transform: translateY(0);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
  #phone-input-container .country-dropdown {
    width: 280px;
    left: 0;
    right: auto;
  }
}

@media (max-width: 480px) {
  /* 
     On very small screens, keeping them in one row is usually better for phone inputs 
     than stacking 100% width flag on top of 100% width input. 
     The original had flex-direction: row !important.
     Let's allow them to stay row but maybe shrink the country selector a bit or ensure wrapping if REALLY small.
     Actually, standard phone inputs usually stay row.
  */

  #phone-input-container .country-selector {
    min-width: 80px;
    flex: 0 0 80px;
  }

  #phone-input-container .selected-country {
    padding: 12px 0px 12px 10px;
  }

  #phone-input-container .selected-country .dial-code {
    font-size: 0.85rem;
  }

  #phone-input-container .selected-country .arrow {
    margin-left: 4px;
    margin-right: 4px;
  }

  #phone-input-container .flag-emoji {
    margin-right: 4px;
  }

  #phone-input-container #phone-input-field {
    font-size: 0.95rem;
    padding-left: 0.75rem;
  }
}
