/* Professional-mode region finder + bounded selection card.
 * Reuses the established GIS tokens from gis-regions.css. */

/* Lives in the place panel's search slot (gis-place-panel.js), which fixes
 * where it sits — top left, above the place column, in every map style. */
.gis-region-search {
  position: relative;
  width: 100%;
  color: var(--gisr-ink);
  font-family: var(--gisr-font);
}

.gis-region-search[hidden],
.gis-region-search-results[hidden] {
  display: none !important;
}

.gis-region-search-field {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 48px;
  background: var(--gisr-paper);
  border: 2px solid var(--gisr-green);
  box-shadow: 0 8px 22px rgba(20, 23, 20, 0.2);
}

.gis-region-search-field:focus-within {
  border-color: var(--gisr-gold);
  box-shadow:
    0 0 0 3px rgba(196, 152, 31, 0.24),
    0 8px 22px rgba(20, 23, 20, 0.2);
}

.gis-region-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  color: var(--gisr-green);
  pointer-events: none;
}

.gis-region-search-icon svg {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

.gis-region-search-input {
  width: 100%;
  height: 48px;
  min-width: 0;
  margin: 0;
  padding: 0 44px 0 46px;
  appearance: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--gisr-ink);
  font-family: var(--gisr-font);
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
}

.gis-region-search-input::placeholder {
  color: var(--gisr-muted);
  opacity: 1;
  font-weight: 700;
}

/* The field has its own clear button (which also closes the open place);
 * the browser's built-in one beside it was a second ✕ that did less. */
.gis-region-search-input::-webkit-search-cancel-button,
.gis-region-search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
  display: none;
}

.gis-region-search-clear {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--gisr-muted);
  cursor: pointer;
  transition: color var(--duration-fast) var(--ease-out);
}

.gis-region-search-clear[hidden] {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .gis-region-search-clear:hover {
    color: var(--gisr-ink);
  }
}

.gis-region-search-clear:focus-visible {
  color: var(--gisr-ink);
  outline: 2px solid var(--gisr-gold);
  outline-offset: -4px;
}

.gis-region-search-results {
  max-height: min(340px, calc(var(--gis-search-viewport-height, 100dvh) - 92px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--gisr-paper);
  border: 2px solid var(--gisr-line);
  border-top: 0;
  box-shadow: 0 12px 26px rgba(20, 23, 20, 0.22);
}

/* Category chips ride beside the search field on a wide screen, floating over
 * the map in one row, and drop beneath it on a phone. */
.gis-region-search-chips {
  position: absolute;
  top: 5px;
  left: calc(100% + 28px);
  display: flex;
  gap: 7px;
  width: max-content;
  max-width: calc(100vw - var(--gis-place-width, 408px) - 40px);
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.gis-region-search-chips[hidden] {
  display: none !important;
}

.gis-region-search-chip {
  appearance: none;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 6px;
  min-height: 38px;
  padding: 0 11px;
  border: 2px solid var(--gisr-line);
  border-radius: 0;
  background: var(--gisr-paper);
  color: var(--gisr-ink);
  font-family: var(--gisr-font);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
  transition:
    border-color var(--duration-fast) var(--ease-out),
    background var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out);
}

.gis-region-search-chip:focus-visible {
  border-color: var(--gisr-gold);
  outline: 0;
}

/* Gated: on touch there is no hover, and a chip left looking hovered after a
   tap reads as a second active filter beside the real one. */
@media (hover: hover) and (pointer: fine) {
  .gis-region-search-chip:hover {
    border-color: var(--gisr-gold);
    outline: 0;
  }
}

.gis-region-search-chip:active {
  transform: scale(0.96);
}

.gis-region-search-chip[aria-pressed="true"] {
  border-color: var(--gisr-green);
  background: var(--gisr-green);
  color: var(--gisr-paper);
}

.gis-region-search-chip-icon {
  display: block;
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.gis-region-search-result {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  padding: 9px 14px;
  border: 0;
  border-left: 4px solid transparent;
  border-bottom: 1px solid var(--gisr-line);
  background: var(--gisr-paper);
  color: var(--gisr-ink);
  font-family: var(--gisr-font);
  text-align: left;
  cursor: pointer;
}

.gis-region-search-kind {
  color: var(--gisr-gold);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.gis-region-search-result:last-child {
  border-bottom: 0;
}

.gis-region-search-result:hover,
.gis-region-search-result:focus-visible {
  border-left-color: var(--gisr-gold);
  outline: 0;
  background: #faf6ea;
}

.gis-region-search-name {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}

.gis-region-search-meta {
  overflow: hidden;
  color: var(--gisr-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gis-region-search-empty {
  padding: 14px;
  color: var(--gisr-muted);
  font-size: 13px;
  font-weight: 800;
}

.gis-region-search-status {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* iOS can pan the visual viewport while the software keyboard is open without
 * moving the layout viewport. Keep map editor overlays inside the actually
 * visible rectangle; zero-offset desktop/Classic behavior is unchanged. */
.gis-editor-overlay {
  inset: auto;
  top: var(--gis-visual-viewport-offset-top, 0px);
  left: var(--gis-visual-viewport-offset-left, 0px);
  width: var(--gis-visual-viewport-width, 100vw);
  height: var(--gis-visual-viewport-height, 100dvh);
  box-sizing: border-box;
}

@media (pointer: coarse) {
  .gis-region-search-field,
  .gis-region-search-input,
  .gis-region-search-result {
    min-height: 48px;
  }

  .gis-region-search-result {
    min-height: 56px;
  }

  .gis-region-search-chip {
    min-height: 44px;
  }

  .gis-professional-mode .gis-popup-close {
    width: 44px;
    height: 44px;
    top: 2px;
    right: 2px;
  }
}

@media (max-width: 720px) {
  .gis-region-search-chips {
    position: static;
    width: 100%;
    max-width: none;
    padding-top: 8px;
  }

  .gis-region-search-results {
    max-height: min(40dvh, calc(var(--gis-search-viewport-height, 100dvh) - 136px));
  }
}


@media (prefers-reduced-motion: reduce) {
  .gis-region-search-chip {
    transition: none;
  }
  .gis-region-search-chip:active {
    transform: none;
  }
}
