/**
 * Reusable City selector — shared combobox styling.
 *
 * Used by Patient Saved Address, Request Care location and Practitioner
 * Primary Service City. Values come from Design.md tokens (m3-tokens.css)
 * so the control matches the rest of the application.
 *
 * Mobile: the suggestion list is anchored to the control, bounded in height,
 * scrolls internally, and stacks ABOVE the fixed bottom navigation
 * (which sits at z-index 45). It is positioned absolutely so it can never
 * create page overflow, and the component clamps its height to the space
 * actually visible in the viewport — opening upward when dropping down would
 * run off the bottom of the screen.
 */

.city-selector {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: relative;
  margin-bottom: 1rem;
}

.city-selector-label {
  font-family: var(--m3-font-label);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--m3-on-surface);
}

.city-selector-control {
  position: relative;
}

.city-selector-input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-family: var(--m3-font-body);
  font-size: 1rem;
  color: var(--m3-on-surface);
  background: var(--m3-surface-container-lowest);
  border: 1px solid var(--m3-outline-variant);
  border-radius: 0.75rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.city-selector-input:focus-visible,
.city-selector-input:focus {
  outline: none;
  border-color: var(--m3-primary);
  box-shadow: 0 0 0 3px rgba(10, 108, 71, 0.18);
}

.city-selector-input[aria-invalid='true'] {
  border-color: var(--m3-error);
}

.city-selector-list {
  /* Bounded, internally scrolling dropdown anchored below the input. */
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  max-height: min(320px, 45vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--m3-surface-container-lowest);
  border: 1px solid var(--m3-outline-variant);
  border-radius: 0.75rem;
  box-shadow: 0 12px 28px rgba(12, 31, 22, 0.14);
  /* Above the fixed Patient/Practitioner bottom navigation (z-index 45). */
  z-index: 60;
}

/* Not enough room below the input — open upward instead of off-screen. */
.city-selector--drop-up .city-selector-list {
  top: auto;
  bottom: calc(100% + 0.35rem);
}

.city-selector-option {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.65rem 0.7rem;
  border-radius: 0.5rem;
  cursor: pointer;
  min-height: 44px; /* comfortable touch target */
}

.city-selector-option-name {
  font-weight: 600;
  color: var(--m3-on-surface);
}

.city-selector-option-state {
  font-size: 0.86rem;
  color: var(--m3-on-surface-variant);
}

.city-selector-option:hover,
.city-selector-option.is-active {
  background: var(--m3-surface-container-high);
}

.city-selector-option.is-active {
  outline: 2px solid var(--m3-primary);
  outline-offset: -2px;
}

.city-selector-empty {
  padding: 0.75rem 0.7rem;
  color: var(--m3-on-surface-variant);
  font-size: 0.92rem;
}

.city-selector-derived {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.9rem;
  color: var(--m3-on-surface-variant);
}

.city-selector-derived-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.city-selector-derived-value {
  color: var(--m3-on-surface);
  font-weight: 600;
}

.city-selector-help {
  margin: 0;
  font-size: 0.82rem;
  color: var(--m3-on-surface-variant);
}

/* Desktop: keep the control from stretching across very wide forms. */
@media (min-width: 1024px) {
  .city-selector {
    max-width: 460px;
  }
}

/* Small screens: shorter by default. The component further clamps this to the
   measured visible space (and whether the list opens down or up). */
@media (max-width: 767px) {
  .city-selector-list {
    max-height: min(260px, 38vh);
  }
}
