/* Geofence search canvas — served by alert.search_open.
   Loaded from alerts.html. No HTML lives here.

   Pre-column-builder: the search canvas lands in #alerts-col-list-body
   (takes over the list slot). Once the backend adopts hide_col/show_col,
   it will land in #alerts-col-search-body. Both targets need the same
   flex-column treatment so .alert-search's `height: 100%` resolves. */
#alerts-col-list-body,
#alerts-col-search-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#alerts-col-list-body > *,
#alerts-col-search-body > * {
  flex: 1 1 auto;
  min-height: 0;
}

.alert-search {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  gap: var(--spacing-3);
  padding: var(--spacing-4);
  background: var(--color-bg, #fff);
}

/* Ensure the search header row is always visible at the top of the canvas. */
.alert-search .search-header {
  flex: 0 0 auto;
  min-height: 48px;
}

.alert-search .search-header {
  display: flex;
  gap: var(--spacing-3);
  align-items: center;
  flex-wrap: wrap;
}

.alert-search .search-header .table-search {
  flex: 1 1 280px;
  min-width: 240px;
}

.alert-search .tier-pills {
  display: flex;
  gap: var(--spacing-2);
}

.alert-search .tier-pill {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-neutral-200, #e5e7eb);
  color: var(--color-neutral-700, #374151);
}

/* HTMX sets .htmx-request on the target during an in-flight POST. We key the
   loading affordance on that class so JS never toggles spinner state. */
#gf-search-tbody.htmx-request {
  opacity: 0.5;
}

#tier-pill-trgm.htmx-request::before {
  content: "⟳ ";
  display: inline-block;
  animation: gfTierSpin 0.9s linear infinite;
}

#tier-pill-trgm:not(.htmx-request)::before {
  content: "✓ ";
  color: var(--color-success, #22c55e);
}

@keyframes gfTierSpin {
  to { transform: rotate(360deg); }
}

.alert-search .search-actions {
  margin-left: auto;
  display: flex;
  gap: var(--spacing-2);
}

.alert-search .search-results-wrap {
  flex: 1 1 55%;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 6px);
  background: var(--color-surface, #fff);
}

.alert-search .search-results-wrap table {
  width: 100%;
}

.alert-search .gf-result-row {
  cursor: pointer;
}

.alert-search .gf-result-row:hover {
  background: var(--color-neutral-100, #f3f4f6);
}

/* Row highlights when its checkbox is ticked — CSS-only, no JS state. */
.alert-search .gf-result-row:has(.gf-row-check:checked) {
  background: var(--color-accent-100, #dbeafe);
}

.alert-search .gf-check-cell {
  width: 36px;
  text-align: center;
}

.alert-search .gf-context-cell .badge {
  margin-right: 4px;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--color-neutral-200, #e5e7eb);
}

.alert-search .gf-context-cell .badge-alerts {
  background: #fee2e2;
  color: #991b1b;
}

.alert-search .gf-context-cell .badge-hazards {
  background: #fef3c7;
  color: #92400e;
}

.alert-search .gf-context-cell .badge-infra {
  background: #dbeafe;
  color: #1e40af;
}

.alert-search .search-preview,
.alert-search #gf-preview {
  flex: 1 1 40%;
  min-height: 240px;
  max-height: 45vh;
  aspect-ratio: 5 / 3;         /* matches svg_fragment render aspect (800x480) */
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 6px);
  overflow: hidden;
  background: var(--color-neutral-50, #f9fafb);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-inline: auto;
}

.alert-search #gf-preview svg,
.alert-search #gf-preview .map-svg-fragment {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: auto;       /* let browser pick best upscaling */
}

.alert-search .search-preview-empty {
  padding: var(--spacing-5);
  color: var(--color-text-muted, #6b7280);
  text-align: center;
  font-size: 0.875rem;
}

.alert-search .search-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--spacing-3);
  padding-top: var(--spacing-2);
  border-top: 1px solid var(--color-border, #e5e7eb);
}

.alert-search .search-footer #gf-selected-count {
  font-weight: 500;
}

/* Use Selected button enable/disable driven by checkbox state — no JS. */
#gf-search-form:not(:has(.gf-row-check:checked)) button[type="submit"] {
  opacity: 0.5;
  pointer-events: none;
}
