/* ==========================================================================
   Global Property Escape — Custom Select Dropdowns
   Premium dropdown component replacing native <select> appearance.
   ========================================================================== */

/* ---- Wrapper ---- */
.cs-wrap {
  position: relative;
  width: 100%;
}

/* ---- Trigger (the visible field) ---- */
.cs-trigger {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 48px;
  padding: 10px 40px 10px 14px;
  background: var(--white);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  line-height: 1.4;
}

.cs-trigger:hover {
  border-color: #c4ced8;
}

.cs-trigger:focus,
.cs-wrap.cs-open .cs-trigger {
  border-color: var(--accent);
  outline: none;
  box-shadow: var(--ring-accent);
}

/* Placeholder state (value is empty) */
.cs-trigger.cs-placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

/* Chevron arrow */
.cs-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  transition: transform var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.cs-wrap.cs-open .cs-chevron {
  transform: translateY(-50%) rotate(180deg);
  color: var(--accent);
}

/* ---- Dropdown menu ---- */
.cs-menu {
  position: absolute;
  top: auto;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 480px;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast);
  padding: 6px;
  margin: 0;
  list-style: none;
}

/* ---- Search input ---- */
.cs-search-wrap {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 4px 4px 6px;
  background: var(--white);
}

.cs-search {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--text);
  background: var(--bg-light, #f8fafc);
  outline: none;
  transition: border-color var(--transition-fast);
  box-sizing: border-box;
}

.cs-search:focus {
  border-color: var(--accent);
  background: var(--white);
}

.cs-search::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

.cs-wrap.cs-open .cs-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Custom scrollbar */
.cs-menu::-webkit-scrollbar {
  width: 6px;
}
.cs-menu::-webkit-scrollbar-track {
  background: transparent;
}
.cs-menu::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.cs-menu::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ---- Country flag icon (image; Windows cannot render flag emojis) ---- */
.cs-flag {
  width: 20px;
  height: 15px;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0;
  margin-right: 0.4em;
  box-shadow: 0 0 0 1px rgba(16, 42, 67, 0.12);
}

.cs-label {
  min-width: 0;
  flex: 1 1 auto;
}

/* Trigger keeps its single-line ellipsis; the flag sits before the text. */
.cs-trigger .cs-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Larger flag for page headings (e.g. "Explore Properties in ..."). */
.title-flag {
  display: inline-block;
  width: 1.3em;
  height: 0.98em;
  object-fit: cover;
  border-radius: 2px;
  vertical-align: -0.14em;
  margin-right: 0.35em;
  box-shadow: 0 0 0 1px rgba(16, 42, 67, 0.12);
}

/* ---- Options ---- */
.cs-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 450;
  color: var(--text);
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  /* Allow long names to wrap so they are fully readable. */
  white-space: normal;
  overflow: visible;
  line-height: 1.4;
}

.cs-option.cs-hovered {
  background: var(--info-bg);
  color: var(--primary);
}

.cs-option.cs-selected {
  background: rgba(0, 166, 166, 0.1);
  color: var(--accent-dark);
  font-weight: 600;
}

.cs-option.cs-selected.cs-hovered {
  background: rgba(0, 166, 166, 0.16);
}

/* Checkmark for selected option */
.cs-option.cs-selected::after {
  content: '';
  flex-shrink: 0;
  margin-left: auto;
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300A6A6' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 16px;
  margin-left: 10px;
}

/* ---- Form group integration ---- */
.form-group .cs-wrap .cs-trigger {
  min-height: 48px;
  padding: 12px 40px 12px 15px;
}

.filter-group .cs-wrap .cs-trigger {
  min-height: 42px;
  padding: 9px 36px 9px 13px;
  font-size: 0.92rem;
  border-radius: var(--radius-sm);
}

.results-sort .cs-wrap .cs-trigger {
  min-height: 38px;
  padding: 8px 36px 8px 14px;
  font-size: 0.92rem;
  border-radius: var(--radius-sm);
}

/* ---- Hero search integration ---- */
.hero-search-field .cs-wrap .cs-trigger {
  border: none;
  background: none;
  padding: 0 30px 0 0;
  min-height: auto;
  border-radius: 0;
  font-size: 0.92rem;
}

.hero-search-field .cs-wrap .cs-trigger:hover {
  border-color: transparent;
}

.hero-search-field .cs-wrap .cs-trigger:focus,
.hero-search-field .cs-wrap.cs-open .cs-trigger {
  box-shadow: none;
  border-color: transparent;
}

.hero-search-field .cs-wrap .cs-chevron {
  right: 0;
  width: 16px;
  height: 16px;
  color: var(--text-dim);
}

.hero-search-field .cs-wrap .cs-menu {
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
}

/* ---- Admin / status-select integration ---- */
.status-select.cs-wrap .cs-trigger {
  min-height: 32px;
  padding: 5px 30px 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

/* ---- Admin filter bar ---- */
#adminFilterStatus.cs-wrap,
#adminFilterCategory.cs-wrap,
#adminFilterAgent.cs-wrap,
#adminFilterOwner.cs-wrap,
#editPurpose.cs-wrap,
#editPricePeriod.cs-wrap,
#editStatus.cs-wrap,
#editAgent.cs-wrap,
#editOwner.cs-wrap {
  width: 100%;
}

/* ---- Floating menu (portalled to <body> when a clipped/overflow ancestor
        would otherwise cut it off — e.g. the hero, which has overflow:hidden
        and an animated (transformed) wrapper). Position is set in JS from the
        trigger's viewport rect so it always opens directly below the field. ---- */
.cs-menu.cs-menu--floating {
  position: fixed;
  z-index: 9999;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  width: max-content;
  min-width: 0;
  max-height: 480px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ---- Z-index layering for different contexts ---- */
.hero-search-wrap .cs-menu {
  z-index: 9999;
}

.filter-bar .cs-menu {
  z-index: 1050;
}

.modal-box .cs-menu,
.modal-content .cs-menu {
  z-index: 1070;
}

/* ---- Mobile responsive ---- */
@media (max-width: 700px) {
  .cs-trigger {
    min-height: 46px;
    font-size: 0.9rem;
    padding: 10px 36px 10px 12px;
  }

  .cs-menu {
    max-height: 300px;
    padding: 4px;
  }

  .cs-option {
    padding: 11px 12px;
    font-size: 0.9rem;
  }

  .hero-search-field .cs-wrap .cs-trigger {
    font-size: 0.88rem;
  }

  .filter-group .cs-wrap .cs-trigger {
    min-height: 44px;
    padding: 10px 36px 10px 12px;
  }
}

@media (max-width: 480px) {
  .cs-menu {
    max-height: 260px;
  }
}

/* ---- Print: show native select, hide custom ---- */
@media print {
  .cs-wrap { display: none !important; }
  .cs-wrap .cs-trigger + select,
  .cs-wrap select { display: block !important; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .cs-trigger,
  .cs-chevron,
  .cs-menu,
  .cs-option {
    transition: none;
  }
}

/* ---- Focus-visible for keyboard users ---- */
.cs-trigger:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
