/* ============================================================
   PANEL DE EDICIÓN MANUAL — BOTTOM DRAWER A 3 COLUMNAS
   ============================================================ */

.manual-editor-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 380px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -10px 40px rgba(0,0,0,0.12);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  font-family: system-ui, -apple-system, sans-serif;
}

/* --- Header --- */
.manual-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 1px solid #e2e8f0;
  background: #ffffff;
  border-radius: 16px 16px 0 0;
  flex-shrink: 0;
}
.manual-editor-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: -0.2px;
}
.manual-editor-close {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  color: #94a3b8;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.15s;
}
.manual-editor-close:hover { background: #fee2e2; color: #ef4444; }

/* --- Body: 3 columnas --- */
.manual-editor-body {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 220px;
  gap: 20px;
  padding: 16px 24px 20px;
  flex: 1;
  overflow-y: auto;
  align-items: start;
  min-height: 0;
}

.manual-col {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* --- Secciones (tarjetas) --- */
.manual-section {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.manual-section-actions { background: #ffffff; border-color: #e2e8f0; }

.manual-section-label {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.manual-section-hint {
  font-size: 11px;
  color: #94a3b8;
  line-height: 1.4;
  margin-top: 2px;
}

/* --- Columna 1: Cómo usar --- */
.manual-col-help { gap: 8px; }

.manual-hint {
  font-size: 12px;
  color: #334155;
  line-height: 1.55;
  padding: 12px 14px;
  background: #eff6ff;
  border-radius: 10px;
  border-left: 3px solid #3b82f6;
}
.manual-hint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.manual-hint-list li {
  position: relative;
  padding-left: 14px;
  font-size: 12px;
}
.manual-hint-list li::before {
  content: '•';
  position: absolute;
  left: 0;
  top: -1px;
  color: #3b82f6;
  font-weight: 900;
  font-size: 14px;
  line-height: 1.3;
}
.manual-hint em { font-style: italic; color: #1e40af; font-weight: 600; }

/* --- Columna 2: Pincel + Categorías --- */
.manual-active-list { display: flex; flex-wrap: wrap; gap: 6px; }

.manual-active-btn {
  padding: 6px 11px;
  border-radius: 8px;
  border: 2px solid transparent;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
  font-family: inherit;
  letter-spacing: 0.1px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.manual-active-btn:hover { transform: translateY(-1px); }

.manual-active-btn.is-active {
  border-color: #fbbf24;
  box-shadow:
    0 0 0 3px rgba(251, 191, 36, 0.55),
    0 4px 12px rgba(0, 0, 0, 0.15);
  transform: scale(1.05);
  font-weight: 800;
}

.manual-empty {
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
  padding: 4px 0;
}

.manual-categories-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 130px;
  overflow-y: auto;
  padding-right: 2px;
}

.manual-categories-empty {
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
  text-align: center;
  padding: 10px;
  background: #f8fafc;
  border-radius: 6px;
  border: 1px dashed #e2e8f0;
}

.manual-category-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 5px 7px;
  transition: border-color 0.15s;
}
.manual-category-row:hover { border-color: #cbd5e1; }

.manual-color-input {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 2px solid #e2e8f0;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  background: #fff;
  transition: border-color 0.15s;
}
.manual-color-input:hover { border-color: #94a3b8; }

.manual-name-input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 4px 6px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 5px;
  color: #1e293b;
  font-family: inherit;
  transition: all 0.15s;
}
.manual-name-input:hover { background: #fff; border-color: #e2e8f0; }
.manual-name-input:focus {
  outline: none;
  background: #fff;
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.manual-cat-count {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  background: #e2e8f0;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.manual-del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #94a3b8;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 5px;
  line-height: 1;
  transition: all 0.15s;
  flex-shrink: 0;
}
.manual-del-btn:hover { background: #fee2e2; color: #ef4444; }

.manual-categories-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}

/* --- Columna 3: Stats + Datos --- */
.manual-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.manual-stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px;
  background: #f1f5f9;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

.manual-stat-value {
  font-size: 20px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1;
}

.manual-stat-label {
  font-size: 9px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  text-align: center;
}

/* --- Botones --- */
.manual-btn {
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.2;
  letter-spacing: 0.1px;
}
.manual-btn-icon { font-size: 13px; line-height: 1; }

.manual-btn-secondary {
  background: #ffffff;
  color: #475569;
  border-color: #e2e8f0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.manual-btn-secondary:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #cbd5e1;
  color: #1e293b;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.manual-btn-danger {
  background: #ef4444;
  color: #ffffff;
  border-color: #ef4444;
}
.manual-btn-danger:hover:not(:disabled) { background: #dc2626; border-color: #dc2626; }

.manual-btn-danger-outline {
  background: #ffffff;
  color: #b91c1c;
  border-color: #fecaca;
}
.manual-btn-danger-outline:hover:not(:disabled) {
  background: #fee2e2;
  border-color: #fca5a5;
}

.manual-btn-block { width: 100%; }
.manual-btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.3); }

/* --- Toggle "Guardar entre sesiones" --- */
.manual-editor-panel .manual-autosave-toggle {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  box-sizing: border-box;
  user-select: none;
}
.manual-editor-panel .manual-autosave-toggle:hover {
  border-color: #cbd5e1;
  background: #ffffff;
}
.manual-editor-panel .manual-autosave-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 2px;
  accent-color: #3b82f6;
  cursor: pointer;
  flex-shrink: 0;
}
.manual-editor-panel .manual-autosave-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.manual-editor-panel .manual-autosave-title {
  font-size: 12px;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.3;
}
.manual-editor-panel .manual-autosave-hint {
  font-size: 10px;
  color: #94a3b8;
  line-height: 1.35;
}

/* ============================================================
   ESTADOS DEL CUERPO EN MODO EDICIÓN
   ============================================================ */

body.manual-editing #map-container svg { cursor: crosshair; }

body.manual-editing #map-container svg [id]:not(#legend-group):not(#export-clip):not(#map-background) {
  transition: filter 0.15s ease;
}
body.manual-editing #map-container svg [id]:not(#legend-group):not(#export-clip):not(#map-background):hover {
  filter: brightness(0.85);
}
body.manual-editing .st-marker,
body.manual-editing .st-callout {
  pointer-events: auto;
  cursor: crosshair;
}
body.manual-editing .pais-pintado:hover { filter: brightness(0.85); }

/* ============================================================
   LAYOUT: dejar espacio al drawer
   ============================================================ */

@media (min-width: 901px) {
  body.manual-editing .app-container { padding-bottom: 400px; }
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 900px) {
  .manual-editor-panel { height: 70vh; border-radius: 16px 16px 0 0; }
  .manual-editor-body {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 14px 16px;
  }
  .manual-categories-list { max-height: 100px; }
}

/* ============================================================
   BOTTOM-SHEET MÓVIL (<1024px)
   ============================================================ */

/* Título + resumen colapsado */
.manual-editor-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.manual-editor-collapsed-summary {
  display: none;
  font-size: 11px;
  color: #94a3b8;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Botón de colapsar (solo móvil) */
.manual-editor-collapse-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: #64748b;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.15s;
}

.manual-editor-collapse-toggle:hover {
  background: #f1f5f9;
  color: #1e293b;
}

@media (max-width: 1023px) {
  /* Mostrar botón y resumen */
  .manual-editor-collapse-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .manual-editor-collapsed-summary { display: block; }

  /* Panel colapsado: solo se ve el header */
  .manual-editor-panel.is-collapsed {
    max-height: 60px !important;
    overflow: hidden !important;
  }
  .manual-editor-panel.is-collapsed .manual-editor-body {
    display: none !important;
  }
  .manual-editor-panel.is-collapsed .manual-editor-header {
    border-bottom: none !important;
    cursor: pointer;
  }
  .manual-editor-panel.is-collapsed .manual-editor-header:hover {
    background: #f8fafc !important;
  }

  /* En móvil, evitar el padding-bottom grande del app-container */
  body.manual-editing .app-container {
    padding-bottom: 80px;
  }
}

/* ============================================================
   FORZAR OCULTACIÓN DEL BOTÓN DE COLAPSAR EN DESKTOP
   (por si el estado residual de móvil se queda pegado)
   ============================================================ */

@media (min-width: 1024px) {
  .manual-editor-collapse-toggle,
  .manual-editor-collapsed-summary {
    display: none !important;
  }
  .manual-editor-panel.is-collapsed {
    max-height: none !important;
    overflow: visible !important;
  }
  .manual-editor-panel.is-collapsed .manual-editor-body {
    display: grid !important;
  }
  .manual-editor-panel.is-collapsed .manual-editor-header {
    cursor: default !important;
  }
}