/* ============================================================
   TOOLBAR — Desktop (>1024px): 3 filas etiquetadas
   ============================================================ */

.map-view-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 20px;
}

.toolbar-close-row {
  display: none;   /* solo móvil */
}

.toolbar-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f1f5f9;
}
.toolbar-row:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.toolbar-section-label {
  flex-shrink: 0;
  width: 80px;
  padding-top: 18px;
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.toolbar-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  flex: 1;
  min-width: 0;
  align-items: flex-end;
}

/* ============================================================
   CONTROLES GENÉRICOS
   ============================================================ */

.map-view-toolbar .control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 0 1 auto;
  min-width: 110px;
}

.map-view-toolbar .control-group label {
  font-size: 10px;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.map-view-toolbar select,
.map-view-toolbar input {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  font-size: 13px;
  background: #fff;
  height: 36px;
}

/* ============================================================
   BOTONES DEL TOOLBAR (todos por clase, sin estilos inline)
   ============================================================ */

.map-view-toolbar .btn-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s;
  white-space: nowrap;
}

.map-view-toolbar .btn-action:hover  { filter: brightness(1.08); }
.map-view-toolbar .btn-action:active { filter: brightness(0.95); }

.map-view-toolbar .btn-save   { background: #10b981; }
.map-view-toolbar .btn-load   { background: #3b82f6; }
.map-view-toolbar .btn-share  { background: #0ea5e9; }
.map-view-toolbar .btn-export { background: #8b5cf6; }

/* Paleta */
.palette-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

#palette-preview {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  height: 20px;
  border-radius: 4px;
  overflow: hidden;
  flex: 1;
  min-width: 60px;
  border: 1px solid #e2e8f0;
  background: #fff;
}
#palette-preview span { flex: 1; }

/* ============================================================
   SELECTOR DE NIVEL NUTS (modo manual)
   ============================================================ */

.nuts-level-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.nuts-level-row select { flex: 1; min-width: 140px; }

.nuts-level-lock {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #64748b;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.nuts-level-lock:hover { border-color: #94a3b8; background: #f8fafc; }
.nuts-level-lock.is-locked {
  background: #fef3c7;
  border-color: #fbbf24;
  color: #92400e;
}
.nuts-level-lock.is-locked:hover { background: #fde68a; }

#nuts-level-select:disabled {
  background: #f1f5f9;
  color: #94a3b8;
  cursor: not-allowed;
  opacity: 0.85;
}

.nuts-level-notice {
  font-size: 10.5px;
  line-height: 1.35;
  color: #64748b;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 5px;
  padding: 4px 7px;
  margin-top: 4px;
  max-width: 260px;
}

/* ============================================================
   BLOQUE INFO NUTS (modo CSV): versión + auto-detección
   ============================================================ */

.nuts-info-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.nuts-version-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: #eff6ff;
  color: #2563eb;
  border: 1px solid #dbeafe;
  letter-spacing: 0.3px;
  white-space: nowrap;
  line-height: 1;
}

.nuts-version-badge.is-uk {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

.nuts-autodetect-notice {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 8px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 5px;
  font-size: 10.5px;
  line-height: 1.4;
  color: #075985;
  max-width: 380px;
}

.nuts-autodetect-icon {
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.nuts-autodetect-text { flex: 1; }

/* ============================================================
   BARRA COMPACTA + OVERLAY (solo móvil, ocultos por defecto)
   ============================================================ */

.mobile-toolbar { display: none; }
.toolbar-overlay { display: none; }

/* ============================================================
   TABLET (769 – 1024px)
   ============================================================ */

@media (max-width: 1024px) and (min-width: 769px) {
  .map-view-toolbar { padding: 12px; }

  .toolbar-section-label {
    width: auto;
    padding-top: 0;
    padding-bottom: 4px;
    flex-basis: 100%;
    margin-bottom: -4px;
  }

  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .toolbar-controls { gap: 8px 12px; }
}

/* ============================================================
   MÓVIL (<1024px): barra compacta + drawer
   ============================================================ */

@media (max-width: 1024px) {

  /* Barra compacta arriba */
  .mobile-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    margin-bottom: 12px;
    position: sticky;
    top: 8px;
    z-index: 100;
  }

  .mobile-toolbar select {
    flex: 1;
    height: 44px;
    font-size: 16px;                /* 🆕 FIX: 16px evita auto-zoom iOS */
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: #fff;
    min-width: 0;
    touch-action: manipulation;     /* 🆕 FIX: mejor respuesta al tap */
  }

  .mobile-toolbar button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.15s;
    touch-action: manipulation;     /* 🆕 FIX */
  }
  .mobile-toolbar button:hover,
  .mobile-toolbar button:active {
    background: #eff6ff;
    border-color: #3b82f6;
  }
  .mobile-toolbar button[disabled] { opacity: 0.4; cursor: not-allowed; }

  /* ═══════════════════════════════════════════════════════════════
     Toolbar principal → drawer lateral
     🆕 FIX MÓVIL REAL: usamos `left` en lugar de `transform`.
     Motivo: `transform` crea un nuevo stacking context y en móviles
     reales (iOS Safari muy especialmente, y algunos Chrome Android)
     el overlay de 9998 "gana" los toques aunque el drawer sea 9999.
     Al usar `left`, no se crea stacking context y el z-index apila
     de forma clásica → los toques llegan al drawer.
     ═══════════════════════════════════════════════════════════════ */
  .map-view-toolbar {
    position: fixed;
    top: 0;
    left: -100%;                    /* 🆕 FIX: era transform: translateX(-100%) */
    bottom: 0;
    width: min(400px, 90vw);
    margin: 0;
    border-radius: 0 16px 16px 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);   /* 🆕 FIX */
    z-index: 9999;
    box-shadow: 4px 0 24px rgba(0,0,0,0.2);
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;   /* 🆕 FIX: scroll fluido iOS */
    pointer-events: auto;                /* 🆕 FIX: garantía */
    isolation: isolate;                  /* 🆕 FIX: stacking aislado */
  }

  .map-view-toolbar.is-open { left: 0; }  /* 🆕 FIX: era transform: translateX(0) */

  /* Fila de cierre (solo móvil) */
  .toolbar-close-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .toolbar-close-title {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
  }
  #mobile-settings-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #fff;
    color: #64748b;
    font-size: 16px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;     /* 🆕 FIX */
  }
  #mobile-settings-close:hover { background: #fee2e2; color: #ef4444; }

  /* Filas dentro del drawer */
  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 16px 20px;
    border-bottom: 1px solid #f1f5f9;
  }
  .toolbar-row:last-child { border-bottom: none; }

  .toolbar-section-label {
    width: auto;
    padding: 0;
    font-size: 10px;
    margin-bottom: 2px;
  }

  .toolbar-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .map-view-toolbar .control-group {
    min-width: 0;
    width: 100%;
  }
  .map-view-toolbar select,
  .map-view-toolbar input,
  .map-view-toolbar .btn-action {
    height: 44px;
    min-height: 44px;
    width: 100%;
    font-size: 16px;                 /* 🆕 FIX: 16px evita auto-zoom iOS */
    touch-action: manipulation;      /* 🆕 FIX: mejor respuesta al tap */
  }
  .map-view-toolbar textarea {
    min-height: 44px;
    font-size: 16px;                 /* 🆕 FIX */
    width: 100% !important;
    touch-action: manipulation;
  }

  #palette-preview { height: 24px; }

  .palette-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  #share-controls-group,
  #export-controls-group {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .toolbar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s ease;
    touch-action: manipulation;      /* 🆕 FIX: respuesta de tap consistente */
  }
  .toolbar-overlay.is-open {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  /* ═══════════════════════════════════════════════════════════════
     🆕 FIX MÓVIL REAL: bloqueo robusto del scroll del body.
     En iOS Safari `overflow: hidden` no siempre funciona (el body
     sigue scrolleando detrás). `position: fixed` + `touch-action: none`
     lo bloquea de verdad.
     ═══════════════════════════════════════════════════════════════ */
  body.drawer-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    touch-action: none;
  }
}
.map-view-toolbar .btn-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
  text-decoration: none;
  align-self: flex-end;
  margin-bottom: 7px;
  transition: background 0.15s;
}
.map-view-toolbar .btn-help-icon:hover { background: #2563eb; }