/* ============================================================
   MAIN.CSS — Layout, paneles y login
   ============================================================

   PROYECTO: Visor Promigas — Titulaciones Prediales
   EMPRESA:  AHG Ingeniero S.A.S.

   Variables CSS centralizadas al inicio (:root).
   El tema es oscuro (igual que Proyecto-SPEC).
   ============================================================ */


/* ============================================================
   RESET Y VARIABLES GLOBALES
   ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-dark:       #0a0f1a;
  --bg-panel:      #111827;
  --bg-card:       #1a2235;
  --bg-card-hover: #1f2a40;
  --border:        #2a3552;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --accent:        #0066cc;       /* Azul Promigas */
  --accent-glow:   rgba(0,102,204,0.15);
  --green:         #2e9e5e;
  --yellow:        #eab308;
  --red:           #ef4444;
}

body {
  font-family: 'DM Sans', -apple-system, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  height: 100vh;       /* fallback navegadores viejos */
  height: 100dvh;      /* iOS Safari: excluye la URL bar dinámicamente */
  overflow: hidden;
  /* Evita el "rubber-band" / bounce de iOS cuando hay overflow accidental */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}


/* ============================================================
   PANTALLA DE LOGIN
   ============================================================ */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.login-logo     { height: 52px; width: auto; margin-bottom: 24px; object-fit: contain; }
.login-title    { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { font-size: 13px; color: var(--text-muted); margin-bottom: 32px; }

.login-field {
  text-align: left;
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
  min-height: 20px;
  font-size: 12px;
  color: var(--red);
  text-align: left;
  margin-bottom: 12px;
}

.login-btn {
  width: 100%;
  padding: 11px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-btn:hover    { opacity: 0.9; }
.login-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.login-footer       { font-size: 11px; color: var(--text-muted); margin-top: 24px; }

/* Mensaje informativo (verde) — confirmación de envío de correo, etc. */
.login-info {
  min-height: 20px;
  font-size: 12px;
  color: #2e9e5e;
  text-align: left;
  margin-bottom: 12px;
}

/* Link secundario debajo del botón de login (ej. "¿Olvidaste tu contraseña?") */
.login-link {
  display: block;
  margin-top: 14px;
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.login-link:hover { color: var(--accent); text-decoration: underline; }


/* ============================================================
   LOADING OVERLAY
   ============================================================ */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(10,15,26,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }


/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  /* La altura crece para acomodar el safe-area-inset-top del notch.
     El padding-top empuja el contenido por debajo del notch, así que el
     bloque visual sigue midiendo 52 px en desktop y 60 px en móvil. */
  height: calc(52px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: calc(16px + env(safe-area-inset-left));
  padding-right: calc(16px + env(safe-area-inset-right));
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  position: relative;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.topbar-logo {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #0099ff);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

.topbar-titles {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;            /* permite que el ellipsis funcione dentro de flex */
}
.topbar-title    { font-weight: 600; font-size: 14px; white-space: nowrap; }
.topbar-subtitle { font-size: 11px; color: var(--text-muted); }

/* Por defecto (desktop) mostramos el título largo */
.topbar-title-short { display: none; }
.topbar-title-full  { display: inline; }

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar-brand-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  margin-left: 14px;  /* separación del título cuando está en topbar-left */
}

/* Botón de refrescar (en topbar-center). Recarga capas/lista sin reload. */
.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-refresh:hover {
  background: var(--bg-panel);
  border-color: var(--accent);
  color: var(--accent);
}
.btn-refresh:disabled,
.btn-refresh.refreshing {
  opacity: 0.7;
  cursor: not-allowed;
}
.btn-refresh-icon {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
}
.btn-refresh.refreshing .btn-refresh-icon {
  animation: spin 0.9s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.topbar-stats {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-left: auto;
  flex-shrink: 0;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-value {
  font-weight: 600;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 14px;
  transition: color 0.2s, border-color 0.2s;
}

.btn-logout:hover { color: var(--red); border-color: var(--red); }

.panel-toggle-btn {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;             /* área de toque más generosa */
  min-width: 36px;
  min-height: 36px;
  border-radius: 6px;
  transition: background 0.12s;
}
.panel-toggle-btn:active,
.panel-toggle-btn:hover { background: rgba(255,255,255,0.06); }

.panel-toggle-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-primary);  /* más visible (era text-secondary) */
  border-radius: 2px;
}


/* ============================================================
   LAYOUT PRINCIPAL
   ============================================================ */
.main-container {
  display: flex;
  height: calc(100vh - 52px - env(safe-area-inset-top));
  height: calc(100dvh - 52px - env(safe-area-inset-top));
  position: relative;
}

.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}

.mobile-overlay.visible { display: block; }


/* ============================================================
   PANEL IZQUIERDO — Lista de predios
   ============================================================ */
.left-panel {
  width: 300px;
  min-width: 300px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 200;
}

.panel-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-search input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.panel-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.panel-filters {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.filter-btn:hover  { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

.panel-section {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-section-grow { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.panel-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Toggle de capas */
.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
}

.layer-toggle:hover { background: var(--bg-card); }

.layer-toggle input {
  width: 14px;
  height: 14px;
  accent-color: var(--accent);
  cursor: pointer;
}

.layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.layer-label { flex: 1; }


/* ============================================================
   LISTA DE PREDIOS
   ============================================================ */
.predio-list {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.list-loading, .list-empty, .list-error {
  padding: 20px 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.list-error { color: var(--red); }

.predio-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.predio-item:hover  { background: var(--bg-card); }
.predio-item.active { background: var(--bg-card-hover); border-left: 3px solid var(--accent); }

.predio-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.predio-codigo {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
}

.estado-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  border: 1px solid;
  white-space: nowrap;
}

.estado-badge.small {
  font-size: 9px;
  padding: 1px 5px;
}

.predio-nombre {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.predio-fti {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 2px;
}


/* ============================================================
   PANEL DERECHO — Ficha de detalle
   ============================================================ */
.right-panel {
  width: 320px;
  min-width: 320px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s;
  z-index: 200;
}

.right-panel.hidden { width: 0; min-width: 0; border-left: none; }


/* ============================================================
   HANDLES DE REDIMENSIONADO (panel izquierdo / derecho)
   ============================================================
   Barra fina entre el panel y el mapa. Al pasar el cursor por
   encima se ilumina; al arrastrar cambia el ancho del panel.
   Ver js/resize.js para la lógica.
   ============================================================ */
.resize-handle {
  width: 5px;
  flex-shrink: 0;
  background: transparent;
  cursor: ew-resize;
  transition: background 0.12s;
  position: relative;
  z-index: 5;
}

.resize-handle:hover,
.resize-handle.resizing {
  background: var(--accent, #0066cc);
}

.resize-handle.resizing {
  box-shadow: 0 0 0 1px var(--accent, #0066cc);
}

/* Oculto en mobile (los paneles ocupan toda la pantalla) */
@media (max-width: 768px) {
  .resize-handle { display: none; }
}


.right-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.right-panel-title {
  font-size: 14px;
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.right-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.right-panel-close:hover { color: var(--text-primary); background: var(--bg-card); }

.right-panel-content {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Secciones de la ficha */
.detail-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.detail-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.estado-indicador {
  padding: 7px 10px;
  border-radius: 6px;
  margin-bottom: 10px;
  font-size: 13px;
}

.detail-grid { display: flex; flex-direction: column; gap: 5px; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
}

.detail-key {
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.detail-val {
  color: var(--text-primary);
  text-align: right;
  word-break: break-word;
}

.detail-val.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
}

.detail-loading, .detail-error {
  padding: 20px 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.detail-error { color: var(--red); }

/* Contactos del predio (primera sección de la ficha) */
.contacto-empty {
  padding: 10px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 8px;
}
.contacto-acciones {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}
.contacto-tel {
  color: #60a5fa;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.contacto-tel:hover { text-decoration: underline; }
.contacto-wa {
  display: inline-flex;
  align-items: center;
  color: #25d366;            /* verde WhatsApp */
  line-height: 0;
}
.contacto-wa:hover { opacity: 0.8; }
.contacto-obs {
  text-align: left;
  font-style: italic;
  font-size: 11px;
  color: var(--text-secondary);
}

/* Sub-cards (servidumbres, titulaciones, propietarios) */
.sub-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.sub-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.sub-card-nombre {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

/* Cadena de tradición */
.cadena-timeline {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Cada anotación de la cadena se renderiza como una tarjeta vertical
   con varios campos. Los actos de cancelación / cierre van con borde
   diferenciado para que se distingan a la vista. */
.cadena-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 10px;
  margin-bottom: 6px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent, #0066cc);
  border-radius: 6px;
}

.cadena-item:last-child { margin-bottom: 0; }

.cadena-item-cancel {
  border-left-color: var(--text-muted, #64748b);
  background: rgba(100, 116, 139, 0.04);
}

/* Encabezado: tipo de acto + fecha en la misma fila */
.cadena-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}

.cadena-acto  {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: none;
}
.cadena-fecha {
  font-size: 11px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  white-space: nowrap;
}

/* Escritura pública + notaría */
.cadena-ep {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Partes intervinientes (De: X · A: Y) */
.cadena-partes {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.45;
}
.cadena-de {
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 3px;
}

/* Observaciones del registro: texto secundario, gris */
.cadena-obs {
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.45;
  margin-top: 2px;
}

/* Pie de trazabilidad: folio + número de anotación (información SNR) */
.cadena-traza {
  font-size: 10px;
  color: var(--text-muted);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 3px;
  padding-top: 4px;
  border-top: 1px dashed rgba(255,255,255,0.07);
  opacity: 0.75;
}

/* Documentos */
.doc-list { display: flex; flex-direction: column; gap: 4px; }

.doc-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.doc-item:last-child { border-bottom: none; }

.doc-tipo  { color: var(--text-muted); font-size: 10px; white-space: nowrap; }
.doc-nombre{ flex: 1; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; }
.doc-fecha { color: var(--text-muted); font-size: 10px; white-space: nowrap; }

/* Documento descargable (anchor) — hover sutil para indicar acción */
a.doc-item {
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s;
}
a.doc-item:hover .doc-nombre { color: #60a5fa; }
a.doc-item:hover { background: rgba(96, 165, 250, 0.06); }

/* Estado de carga mientras se pide el signed URL */
a.doc-item.doc-loading { opacity: 0.5; pointer-events: none; }

/* Mensaje cuando no hay documentos cargados en Storage */
.doc-empty {
  padding: 12px;
  text-align: center;
  font-size: 12px;
  font-style: italic;
  color: var(--text-muted);
  background: rgba(255,255,255,0.02);
  border-radius: 6px;
}

/* ============================================================
   CARPETAS COLAPSABLES en sección Documentos
   ============================================================
   Usa el elemento nativo <details>/<summary>. La flechita rota
   90° cuando la carpeta está abierta (atributo open).
   ============================================================ */
.doc-folder {
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: rgba(255,255,255,0.02);
}

.doc-folder-summary {
  list-style: none;       /* quitar el triángulo nativo del <summary> */
  cursor: pointer;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.03);
  transition: background 0.12s, color 0.12s;
  user-select: none;
}
.doc-folder-summary::-webkit-details-marker { display: none; } /* Safari */

.doc-folder-summary:hover {
  background: rgba(96, 165, 250, 0.06);
  color: var(--text-primary);
}

.doc-folder-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
  display: inline-block;
}
.doc-folder[open] > .doc-folder-summary .doc-folder-arrow {
  transform: rotate(90deg);
}

.doc-folder-name  { flex: 1; }
.doc-folder-count {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  background: var(--bg-card);
  border-radius: 10px;
  color: var(--text-muted);
}

.doc-folder-content {
  padding: 4px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.doc-folder-content .doc-item { border-bottom: none; padding: 5px 0; }

.mono { font-family: 'JetBrains Mono', monospace; font-size: 11px; }


/* ============================================================
   MOBILE (< 768px)
   ============================================================ */
@media (max-width: 768px) {

  /* ---- TOPBAR compacto ----
     Altura total = 60 px de contenido + safe-area del notch. */
  .topbar {
    height: calc(60px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
    gap: 10px;
  }
  .panel-toggle-btn { display: flex; }     /* mostrar hamburguesa */
  .topbar-brand-logo,                       /* ocultar logo AHG */
  .topbar-subtitle { display: none; }       /* ocultar "AHG Ingeniero" */

  /* Cambiar al título corto (solo "Promigas") en mobile */
  .topbar-title-full  { display: none; }
  .topbar-title-short { display: inline; }
  .topbar-title { font-size: 15px; }

  /* ---- STATS COMPACTOS EN MOBILE ----
     Mostramos los 2 stats mas relevantes (en gestion + completados) para
     que el usuario vea el avance sin abrir el panel. "Total predios" se
     oculta — es informacion secundaria y no cambia con el dia a dia.
     Tambien escondemos el texto-etiqueta ("En gestion", "Completados")
     y dejamos solo el circulo de color + el numero, asi caben en la barra. */
  .topbar-stats .stat-item:nth-child(3) { display: none; }   /* Total predios */
  .topbar-stats .stat-item > span:not(.stat-value) { display: none; }
  .topbar-stats .stat-item { gap: 4px; }                     /* dot ↔ numero */
  .topbar-stats { gap: 6px; flex-shrink: 0; }

  /* ---- BOTON REFRESH EN MOBILE ----
     El boton de actualizar capas/lista (recargar sin F5) ahora SI es
     visible en mobile, en forma compacta: solo el icono ↻, sin la
     etiqueta "Refrescar". Mismo touch target que la hamburguesa (36px). */
  .topbar-center {
    display: flex !important;
    align-items: center;
    margin-left: 4px;          /* despegar un poco del titulo */
  }
  .btn-refresh {
    padding: 0;
    width: 36px;
    height: 36px;
    justify-content: center;
  }
  .btn-refresh-label { display: none; }    /* solo icono en mobile */
  .btn-refresh-icon  { font-size: 18px; }  /* icono un poco mas grande */

  /* El contenedor principal debe restar la altura visual del topbar (60 px)
     + el safe-area-inset-top (notch). dvh excluye la URL bar de Safari iOS. */
  .main-container {
    height: calc(100vh  - 60px - env(safe-area-inset-top));
    height: calc(100dvh - 60px - env(safe-area-inset-top));
  }

  /* ---- PANEL IZQUIERDO desplegable ----
     top y bottom respetan los safe-areas para no quedar tapados por el
     notch arriba o el home indicator abajo en iPhones modernos. */
  .left-panel {
    position: fixed;
    left: 0;
    top: calc(60px + env(safe-area-inset-top));
    bottom: env(safe-area-inset-bottom);
    width: 88vw;
    max-width: 360px;
    transform: translateX(-100%);
    transition: transform 0.25s;
    z-index: 300;
    box-shadow: 4px 0 16px rgba(0,0,0,0.5);
    -webkit-overflow-scrolling: touch;
  }
  .left-panel.mobile-open { transform: translateX(0); }

  /* ---- PANEL DERECHO (ficha) ---- */
  .right-panel {
    position: fixed;
    right: 0;
    top: calc(60px + env(safe-area-inset-top));
    bottom: env(safe-area-inset-bottom);
    width: 92vw !important;
    max-width: 360px;
    z-index: 290;
    box-shadow: -4px 0 16px rgba(0,0,0,0.5);
    -webkit-overflow-scrolling: touch;
  }
  .right-panel.hidden { width: 0 !important; min-width: 0 !important; }

  /* Botón de cierre del panel derecho: área de toque más grande en móvil */
  .right-panel-close {
    font-size: 22px;
    padding: 6px 10px;
    min-width: 36px;
    min-height: 36px;
  }
}

/* ============================================================
   MOBILE muy chico (< 400px) — iPhone SE, etc.
   ============================================================ */
@media (max-width: 400px) {
  .topbar-title { max-width: 38vw; font-size: 12px; }
  .topbar-stats .stat-item { font-size: 11px; }
  .stat-value { font-size: 11px; }
}
