/**
 * XEGHEP FIXED SEARCH PANEL — PROMPT 02
 * 
 * Replaces all floating dropdown behavior with a fixed-position
 * Search Panel that never moves, never resizes, never recalculates.
 * 
 * Panel is NOT an overlay. It is part of the application UI.
 * Only the result list scrolls. Input is always fixed at top.
 * 
 * @package   XOS\Presentation\Search
 * @version   v1.0.0 — PROMPT 02
 * @since     Sprint 12.22G.4
 */

/* ════════════════════════════════════════════════════
   SEARCH PANEL — FIXED, NEVER MOVES
   ════════════════════════════════════════════════════ */
.xsp-panel {
  position: fixed;
  top: 56px; /* immediately below header */
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  width: 100%;
  max-width: 480px;
  height: 70vh;
  z-index: 950;
  background: #FFFFFF;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12), 0 8px 32px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  /* Safe area: top is handled by `top`; bottom padding inside */
}

.xsp-panel--open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}

/* ════════════════════════════════════════════════════
   SEARCH INPUT — FIXED, ALWAYS VISIBLE
   ════════════════════════════════════════════════════ */
.xsp-input-wrap {
  flex-shrink: 0;
  padding: 12px 16px;
  border-bottom: 1px solid #E5E7EB;
  display: flex;
  align-items: center;
  gap: 10px;
  background: #FFFFFF;
  border-radius: 16px 16px 0 0;
  z-index: 2;
}

.xsp-input-icon {
  flex-shrink: 0;
  color: #9CA3AF;
  display: flex;
  align-items: center;
}

.xsp-input {
  flex: 1;
  height: 44px;
  border: none;
  outline: none;
  font-size: 16px;
  font-family: inherit;
  color: #1F2937;
  background: transparent;
}

.xsp-input::placeholder {
  color: #9CA3AF;
}

.xsp-input-clear {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 50%;
  color: #9CA3AF;
}

.xsp-input-clear--visible {
  display: flex;
}

/* ════════════════════════════════════════════════════
   RESULT LIST — ONLY THIS SCROLLS
   ════════════════════════════════════════════════════ */
.xsp-results {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 16px;
}

/* ════════════════════════════════════════════════════
   RESULT ITEM — LARGE ICON + TITLE + SUBTITLE
   ════════════════════════════════════════════════════ */
.xsp-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 8px;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: 10px;
  text-align: left;
  font-family: inherit;
  min-height: 56px;
  transition: background 100ms ease;
}

.xsp-item:hover,
.xsp-item--highlighted {
  background: #F0F5FF;
}

.xsp-item:active {
  background: #E0EBFF;
}

.xsp-item-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F3F6FA;
  border-radius: 10px;
  color: #1F4E8C;
}

.xsp-item-icon--history {
  background: #FEF3C7;
  color: #92400E;
}

.xsp-item-text {
  flex: 1;
  min-width: 0;
}

.xsp-item-name {
  display: block;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #1F2937;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.xsp-item-region {
  display: block;
  font-size: 0.75rem;
  color: #9CA3AF;
  line-height: 1.3;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ════════════════════════════════════════════════════
   SECTION HEADER
   ════════════════════════════════════════════════════ */
.xsp-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 8px 4px;
  color: #6B7280;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ════════════════════════════════════════════════════
   BOTTOM ACTIONS — FIXED
   ════════════════════════════════════════════════════ */
.xsp-bottom {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  background: #FFFFFF;
  border-top: 1px solid #E5E7EB;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
}
.xsp-bottom-label {
  font-size: 0.75rem;
  color: #6B7280;
}

.xsp-close-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: 1px solid #E5E7EB;
  border-radius: 8px;
  background: #FFFFFF;
  color: #374151;
  font-size: 0.8125rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  min-height: 44px;
  transition: background 100ms ease;
}

.xsp-close-btn:hover {
  background: #F3F4F6;
}

.xsp-close-btn:active {
  background: #E5E7EB;
}

/* ════════════════════════════════════════════════════
   EMPTY STATE
   ════════════════════════════════════════════════════ */
.xsp-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
  text-align: center;
  color: #9CA3AF;
  font-size: 0.875rem;
}

.xsp-empty strong {
  display: block;
  color: #6B7280;
  margin-bottom: 4px;
}

/* ════════════════════════════════════════════════════
   LOADING
   ════════════════════════════════════════════════════ */
.xsp-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  color: #6B7280;
  font-size: 0.8125rem;
}

.xsp-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #E5E7EB;
  border-top: 2px solid #3B82F6;
  border-radius: 50%;
  animation: xsp-spin 0.6s linear infinite;
}

@keyframes xsp-spin {
  to { transform: rotate(360deg); }
}

/* ════════════════════════════════════════════════════
   BACKDROP — prevents map/background interaction
   ════════════════════════════════════════════════════ */
.xsp-backdrop {
  position: fixed;
  inset: 0;
  z-index: 940;
  background: rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms ease;
}

.xsp-backdrop--visible {
  opacity: 1;
  pointer-events: auto;
}

/* ════════════════════════════════════════════════════
   KEYWORD HIGHLIGHT (reuse existing class)
   ════════════════════════════════════════════════════ */
.xsp-item-name .xeghep-highlight {
  background: #FFF3CD;
  color: #856404;
  font-weight: 700;
  border-radius: 2px;
  padding: 0 2px;
}

/* ════════════════════════════════════════════════════
   MOBILE RESPONSIVENESS
   ════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  .xsp-panel {
    top: 52px;
    left: 0;
    right: 0;
    transform: translateY(12px);
    max-width: 100%;
    height: 65vh;
    border-radius: 16px 16px 0 0;
  }

  .xsp-panel--open {
    transform: translateY(0);
  }
}

/* Landscape phones */
@media (max-width: 920px) and (orientation: landscape) {
  .xsp-panel {
    height: 75vh;
    max-width: 480px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
  }

  .xsp-panel--open {
    transform: translateX(-50%) translateY(0);
  }
}

/* ════════════════════════════════════════════════════
   BUG 02 HOTFIX: MAP OVERLAY — FLEX COLUMN + STICKY FOOTER
   Ensures "Lưu vị trí" button stays at bottom on mobile,
   never hidden behind the dropdown.
   ════════════════════════════════════════════════════ */
/* ════════════════════════════════════════════════════
   BUG 02 HOTFIX: MAP OVERLAY — FULL FIX MOBILE VIEWPORT
   ════════════════════════════════════════════════════ */
.ep12-map-overlay {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* Dùng height động theo dvh (Dynamic Viewport Height) để tự co giãn khi bàn phím ảo xuất hiện */
  height: 100dvh;
  z-index: 1000;
  background: #FFFFFF;
  box-sizing: border-box;
}

.ep12-map-overlay-header {
  flex: 0 0 auto;
  z-index: 10;
}

.ep12-map-overlay-body {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  z-index: 1;
}

.ep12-map-overlay-footer {
  flex: 0 0 auto;
  position: relative;
  z-index: 10;
  background: #FFFFFF;
  border-top: 1px solid #E5E7EB;
  padding: 10px 16px;
}

/* BUG FIX: MAP OVERLAY FOOTER SAFE AREA
   Creates a permanent safe gap below the footer using a ::after pseudo-element.
   This flex child shrinks only the map body (flex: 1), keeping the footer at the
   bottom with a 72px + safe-area-inset-bottom gap before the App Bottom Tab. */
.ep12-map-overlay::after {
  content: '';
  display: block;
  flex: 0 0 auto;
  height: calc(72px + env(safe-area-inset-bottom, 0px));
  background: #FFFFFF;
}
/* Dropdown (portaled to body via JS) — z-index from inline JS */
