/* ==========================================================================
   FO-Select — Modern Select Wrapper
   Tek noktadan dağıtım: Tüm `select.pill-input` elementlerini otomatik modernize eder.
   Native <select> display:none yapılır; yerine .fo-select wrapper + trigger + panel
   render edilir. Form value'su bizzat native select'te tutulur (display:none).
   ========================================================================== */

/* CSS değişkenleri — mevcut temaya uyumlu (pill-input referans) */
:root {
  --fo-select-bg:          rgba(255, 255, 255, 0.03);
  --fo-select-border:      rgba(255, 255, 255, 0.08);
  --fo-select-text:        #E4E4E7;     /* ink-100 */
  --fo-select-muted:       #71717A;     /* ink-300 */
  --fo-select-hover:       rgba(10, 132, 255, 0.10);
  --fo-select-active:      rgba(10, 132, 255, 0.22);
  --fo-select-active-text: #64AFFF;
  --fo-select-panel-bg:    #18181B;     /* ink-700 */
  --fo-select-panel-border:rgba(255, 255, 255, 0.10);
  --fo-select-shadow:      0 8px 32px -8px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --fo-select-focus-ring:  rgba(10, 132, 255, 0.30);
  --fo-select-search-bg:   rgba(255, 255, 255, 0.04);
  --fo-select-radius:      12px;
  --fo-select-z:           9999;
}

/* Light mode override (proje :root:not(.dark) kalıbını kullanıyor) */
:root:not(.dark) {
  --fo-select-bg:          #FFFFFF;
  --fo-select-border:      rgba(15, 23, 42, 0.10);
  --fo-select-text:        #0F172A;
  --fo-select-muted:       #64748B;
  --fo-select-hover:       rgba(10, 132, 255, 0.04);
  --fo-select-active:      rgba(10, 132, 255, 0.14);    /* Açık mavi vurgu — light */
  --fo-select-active-text: #0A84FF;                     /* Apple açık mavi vurgu */
  --fo-select-panel-bg:    #FFFFFF;
  --fo-select-panel-border:rgba(15, 23, 42, 0.10);
  --fo-select-shadow:      0 8px 32px -8px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.06);
  --fo-select-search-bg:   rgba(15, 23, 42, 0.04);
}

/* Native select'i gizle — değer hâlâ orada, sadece görünmez */
.fo-select-native {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Wrapper — relative + inline-block yerine block (w-full için) */
.fo-select {
  position: relative;
  display: block;
  width: 100%;
  font: inherit;
  font-size: 13px;
  color: var(--fo-select-text);
}

/* Tetikleyici buton — pill-input görünümü birebir */
.fo-select-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 40px;
  padding: 10px 36px 10px 14px;
  background: var(--fo-select-bg);
  border: 1px solid var(--fo-select-border);
  border-radius: var(--fo-select-radius);
  color: var(--fo-select-text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.fo-select-trigger:hover {
  border-color: rgba(255, 255, 255, 0.14);
}
:root:not(.dark) .fo-select-trigger:hover {
  border-color: rgba(15, 23, 42, 0.18);
}

.fo-select-trigger:focus,
.fo-select.is-open .fo-select-trigger {
  outline: none;
  border-color: #0A84FF;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.30);
}
:root:not(.dark) .fo-select-trigger:focus,
:root:not(.dark) .fo-select.is-open .fo-select-trigger {
  border-color: #0A84FF;
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.22);
}

.fo-select-trigger[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.fo-select-label {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fo-select-label.is-placeholder {
  color: var(--fo-select-muted);
}

.fo-select-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--fo-select-muted);
  transition: transform 160ms ease;
}

.fo-select.is-open .fo-select-icon {
  transform: translateY(-50%) rotate(180deg);
  color: var(--fo-select-active-text);
}

/* Dropdown panel */
.fo-select-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: var(--fo-select-z);
  background: var(--fo-select-panel-bg);
  border: 1px solid var(--fo-select-panel-border);
  border-radius: var(--fo-select-radius);
  box-shadow: var(--fo-select-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 180px;
  opacity: 0;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top center;
  pointer-events: none;
  transition: opacity 140ms cubic-bezier(.2,.7,.3,1),
              transform 140ms cubic-bezier(.2,.7,.3,1);
}

.fo-select.is-open .fo-select-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Arama inputu — sticky üstte */
.fo-select-search {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--fo-select-panel-bg);
  border-bottom: 1px solid var(--fo-select-panel-border);
}

.fo-select-search-input {
  flex: 1;
  min-width: 0;
  background: var(--fo-select-search-bg);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--fo-select-text);
  font: inherit;
  font-size: 13px;
  outline: none;
}

.fo-select-search-input:focus {
  border-color: rgba(10, 132, 255, 0.45);
}
:root:not(.dark) .fo-select-search-input:focus {
  border-color: #0A84FF;
}

.fo-select-search-input::placeholder {
  color: var(--fo-select-muted);
}

.fo-select-search-icon {
  color: var(--fo-select-muted);
  flex-shrink: 0;
}

/* Options listesi */
.fo-select-options {
  flex: 1;
  max-height: 280px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 4px;
  margin: 0;
  list-style: none;
}

/* Özelleştirilmiş ince scrollbar */
.fo-select-options::-webkit-scrollbar { width: 8px; }
.fo-select-options::-webkit-scrollbar-track { background: transparent; }
.fo-select-options::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.10);
  border-radius: 8px;
}
:root:not(.dark) .fo-select-options::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.15);
}

.fo-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--fo-select-text);
  font-size: 13px;
  transition: background-color 80ms ease, color 80ms ease;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fo-select-option:hover,
.fo-select-option.is-highlighted {
  background: var(--fo-select-hover);
}

.fo-select-option.is-selected {
  background: var(--fo-select-active);
  color: var(--fo-select-active-text);
  font-weight: 500;
}

.fo-select-option.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.fo-select-option.is-empty {
  padding: 14px;
  text-align: center;
  color: var(--fo-select-muted);
  cursor: default;
}

.fo-select-option-check {
  margin-left: auto;
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: var(--fo-select-active-text);
  opacity: 0;
}
.fo-select-option.is-selected .fo-select-option-check {
  opacity: 1;
}

/* Footer status (count) */
.fo-select-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--fo-select-panel-border);
  color: var(--fo-select-muted);
  font-size: 11px;
  background: var(--fo-select-panel-bg);
}

/* ==========================================================================
   Responsive — mobil (<640px)
   ========================================================================== */
@media (max-width: 639px) {
  .fo-select-panel {
    position: fixed;
    left: 12px !important;
    right: 12px !important;
    top: auto !important;
    bottom: 12px;
    max-height: 60vh;
    width: auto;
  }
  .fo-select-options {
    max-height: calc(60vh - 120px);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .fo-select-trigger,
  .fo-select-icon,
  .fo-select-option,
  .fo-select-panel {
    transition: none;
  }
  .fo-select-panel {
    transform: none;
  }
}

/* Hidden yardımcı — select[multiple] gibi durumlar için opt-out */
.fo-select-native[data-fo-skip="true"] + .fo-select {
  display: none;
}