/* ============================================================
   LEBANIM — custom-select.css
   Styles du composant custom dropdown MOBILE ONLY (≤767 px).
   TOUTES les règles sont OBLIGATOIREMENT sous
   @media (max-width: 767px) — aucune exception. Le desktop
   (≥768 px) n'est touché par aucune ligne de ce fichier.

   Pendant aux assets/js/custom-select.js (qui pose la garde
   matchMedia côté JS).

   Z-index :
   - Backdrop  : 100000 (au-dessus du bandeau STAGING 99999)
   - Sheet     : 100001
   - Trigger   : flow normal (pas de z-index spécifique)
   ============================================================ */

@media (max-width: 767px) {

  /* ────────────────────────────────────────────────────────────
     1. Cacher visuellement le <select> natif tout en gardant
     l'élément dans le DOM (accessible aux scripts existants
     qui lisent .value, dispatch 'change', etc.).
     visually-hidden pattern (pas display:none ni visibility:hidden).
     ──────────────────────────────────────────────────────────── */
  .custom-select-native-hidden {
    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;
    pointer-events: none !important;
  }

  /* ────────────────────────────────────────────────────────────
     2. Trigger button (rendu fermé) — esthétique alignée avec
     le rendu V5 Section D des selects (background blanc, bordure
     crème, chevron gold à droite, hauteur 48 tactile, font 16
     anti-zoom iOS).
     ──────────────────────────────────────────────────────────── */
  .custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 16px;
    text-align: left;
    background: #ffffff;
    border: 1px solid var(--color-border-soft, #e0d8c8);
    border-radius: 8px;
    color: var(--color-text-primary, #1a1a1a);
    box-sizing: border-box;
    cursor: pointer;
    transition: border-color 150ms ease, box-shadow 150ms ease;
    -webkit-appearance: none;
    appearance: none;
  }

  .custom-select-trigger:hover {
    border-color: var(--color-gold, #c8a04a);
  }

  .custom-select-trigger:focus-visible {
    outline: 2px solid var(--color-gold, #c8a04a);
    outline-offset: 2px;
    border-color: var(--color-gold, #c8a04a);
  }

  .custom-select-trigger:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #f5f1e8;
  }

  .custom-select-trigger-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .custom-select-trigger-label.is-placeholder {
    color: var(--color-text-muted, #888);
  }

  /* Chevron SVG inline rendu en CSS background pour rester
     cohérent avec le SVG des <select> natifs stylés en V5
     (#B8893E gold-dark). */
  .custom-select-trigger-chevron {
    display: inline-block;
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23B8893E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='4 6 8 11 12 6'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 16px 16px;
    transition: transform 200ms ease;
  }

  .custom-select-trigger[aria-expanded="true"] .custom-select-trigger-chevron {
    transform: rotate(180deg);
  }

  /* ────────────────────────────────────────────────────────────
     3. Backdrop (assombrissement page) — couvre tout le viewport,
     z-index au-dessus du bandeau STAGING (99999), animation 250ms.
     ──────────────────────────────────────────────────────────── */
  .custom-select-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 250ms ease-out;
    z-index: 100000;
    cursor: pointer;
  }

  .custom-select-backdrop.is-open {
    opacity: 1;
  }

  /* ────────────────────────────────────────────────────────────
     4. Sheet (bottom sheet glissant depuis le bas)
     position fixed bottom 0, full width, max-height 80vh,
     border-radius 16 px haut, ombre haute marquée, animation
     translateY 100% → 0 sur 250 ms ease-out.
     ──────────────────────────────────────────────────────────── */
  .custom-select-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100vw;
    max-height: 80vh;
    background: #ffffff;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
    z-index: 100001;
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 250ms ease-out;
    overflow: hidden;
    box-sizing: border-box;
    font-family: inherit;
  }

  .custom-select-sheet.is-open {
    transform: translateY(0);
  }

  /* Header sticky — titre + ✕ */
  .custom-select-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border-soft, #e0d8c8);
    background: #ffffff;
    flex-shrink: 0;
  }

  .custom-select-sheet-title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 17px;
    font-weight: 600;
    color: var(--color-text-primary, #1a1a1a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .custom-select-sheet-close {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    color: var(--color-text-secondary, #555);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    transition: background 150ms ease, color 150ms ease;
  }

  .custom-select-sheet-close:hover,
  .custom-select-sheet-close:focus-visible {
    background: var(--color-cream-soft, #f5f1e8);
    color: var(--color-text-primary, #1a1a1a);
  }

  .custom-select-sheet-close:focus-visible {
    outline: 2px solid var(--color-gold, #c8a04a);
    outline-offset: 2px;
  }

  /* Search input (uniquement si > 15 items) */
  .custom-select-sheet-search {
    padding: 10px 16px;
    background: #ffffff;
    border-bottom: 1px solid var(--color-border-soft, #e0d8c8);
    flex-shrink: 0;
  }

  .custom-select-sheet-search-input {
    width: 100%;
    min-height: 44px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 16px;
    background: #ffffff;
    border: 1px solid var(--color-border-soft, #e0d8c8);
    border-radius: 8px;
    color: var(--color-text-primary, #1a1a1a);
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
  }

  .custom-select-sheet-search-input:focus {
    outline: 2px solid var(--color-gold, #c8a04a);
    outline-offset: 2px;
    border-color: var(--color-gold, #c8a04a);
  }

  /* Body scrollable */
  .custom-select-sheet-body {
    flex: 1 1 auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0 16px;
    background: #ffffff;
  }

  /* Optgroups — séparateur visuel marqué */
  .custom-select-sheet-optgroup-label {
    padding: 12px 20px 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-gold-dark, #B8893E);
    background: var(--color-cream-soft, #f5f1e8);
    border-top: 1px solid var(--color-border-soft, #e0d8c8);
  }

  .custom-select-sheet-optgroup:first-child .custom-select-sheet-optgroup-label {
    border-top: none;
  }

  /* Items */
  .custom-select-sheet-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 14px 20px;
    background: transparent;
    border: none;
    text-align: left;
    font-family: inherit;
    font-size: 15px;
    color: var(--color-text-primary, #1a1a1a);
    cursor: pointer;
    transition: background 120ms ease;
    box-sizing: border-box;
  }

  .custom-select-sheet-item:hover:not(.is-disabled),
  .custom-select-sheet-item:focus-visible:not(.is-disabled) {
    background: var(--color-cream-soft, #f5f1e8);
  }

  .custom-select-sheet-item:focus-visible {
    outline: 2px solid var(--color-gold, #c8a04a);
    outline-offset: -2px;
  }

  .custom-select-sheet-item.is-selected {
    background: rgba(200, 160, 74, 0.14);
    color: var(--color-gold-dark, #B8893E);
    font-weight: 600;
  }

  .custom-select-sheet-item.is-disabled {
    opacity: 0.4;
    cursor: not-allowed;
  }

  .custom-select-sheet-item-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .custom-select-sheet-item-check {
    flex-shrink: 0;
    color: var(--color-gold-dark, #B8893E);
    font-size: 18px;
    font-weight: 700;
    line-height: 1;
  }

  /* Edge case : aucune option */
  .custom-select-sheet-empty {
    padding: 28px 20px;
    text-align: center;
    color: var(--color-text-muted, #888);
    font-size: 14px;
    font-style: italic;
  }

  /* ────────────────────────────────────────────────────────────
     5. Décalage sous bandeau STAGING (cohérence avec V4
     Section 2 sur la pop-up IA). Le sheet sort du bas donc
     le bandeau ne le couvre pas, mais on réduit max-height
     pour garantir que rien ne dépasse en haut.
     ──────────────────────────────────────────────────────────── */
  body.lebanim-staging-active .custom-select-sheet {
    max-height: calc(80vh - var(--lebanim-staging-h, 0px));
  }

}
/* FIN @media (max-width: 767px) — aucune règle hors media. */
