/* ============================================
   RESET & VARIABLES
   ============================================ */
* { 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: #3b82f6;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --green: #2e9e5e;
  --yellow: #eab308;
  --red: #ef4444;
  --blue-avaluo: #1f78b4;
}

/* ============================================
   BASE
   ============================================ */
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%;
}

/* ============================================
   TOP BAR
   ============================================ */
.topbar {
  height: 52px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 1000;
  position: relative;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

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

.topbar-title { font-weight: 600; font-size: 15px; }
.topbar-subtitle { font-size: 12px; color: var(--text-muted); }

/* Título corto: solo se muestra en mobile (ver media query en map.css) */
.topbar-title-short { display: none; }

.topbar-center {
  display: flex;
  align-items: center;
  gap: 14px;
  position: absolute;
  left: 340px;
}

.topbar-brand-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
}

/* Botón de refrescar (en topbar-center, junto al logo AHG).
   Recarga capas/semáforo/lista/ficha sin recargar la página.
   ESTILO ESTANDARIZADO: mismo aspecto que .presentation-btn
   (cuadrado de 30px, fondo transparente, borde, icono mute). */
.btn-refresh {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.18s;
}
.btn-refresh:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.btn-refresh:disabled,
.btn-refresh.refreshing {
  opacity: 0.7;
  cursor: not-allowed;
}
.btn-refresh-icon {
  font-size: 15px;
  line-height: 1;
  display: inline-block;
}
.btn-refresh.refreshing .btn-refresh-icon {
  animation: spin 0.9s linear infinite;
}

/* El botón del dashboard es un <a> con el mismo estilo de los botones
   del topbar (hereda .btn-refresh); solo se quita el subrayado. */
.btn-dashboard { text-decoration: none; }

/* Grupo de acciones a la derecha del topbar (refrescar, dashboard, admin,
   modo presentación y salir), todos juntos. Antes refresh/dashboard/admin
   vivían sueltos en .topbar-center (absoluto), separados del resto. */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  margin-left: 16px;
}

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

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

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

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

/* ============================================
   LAYOUT
   ============================================ */
.main-container {
  display: flex;
  height: calc(100vh - 52px);   /* fallback */
  height: calc(100dvh - 52px);  /* iOS Safari: excluye la URL bar */
}

/* ============================================
   LOADING
   ============================================ */
.loading-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 15, 26, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  transition: opacity 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.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); } }

/* ============================================
   LOGIN SCREEN
   ============================================ */
.login-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 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: 56px;
  width: auto;
  margin-bottom: 24px;
  object-fit: contain;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  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: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  padding: 11px 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-field input::placeholder {
  color: var(--text-muted);
}

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

/* Mensaje informativo de éxito (p.ej. "te enviamos el correo") */
.login-info {
  font-size: 12px;
  color: #2e9e5e;
  min-height: 18px;
  margin-bottom: 8px;
  text-align: left;
}

/* Enlace secundario del login ("¿Olvidaste tu contraseña?" / "Volver") */
.login-link {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.login-link:hover { text-decoration: underline; }

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

.login-btn:hover {
  background: #2563eb;
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-footer {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 28px;
}

/* ============================================
   LOGOUT BUTTON (topbar)
   ============================================ */
.logout-btn {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.logout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
  border-color: var(--red);
  color: var(--red);
}

/* ============================================
   MODO PRESENTACIÓN (topbar)
   Oculta avalúo, valores de negociación y
   complejidad para reuniones con propietarios.
   Solo visible para admin y coordinador.
   ============================================ */
.presentation-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.18s;
}

.presentation-btn:hover {
  border-color: #f59e0b;
  color: #f59e0b;
}

.presentation-btn.active {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #fff;
}

.presentation-btn.active:hover {
  background: #d97706;
  border-color: #d97706;
}

/* ============================================
   RESPONSIVE — Nota importante:
   Las reglas responsive principales estan en
   map.css (se carga despues) para que tengan
   prioridad sobre los estilos base del panel.
   ============================================ */


/* ============================================
   CAMBIO DE ESTADO DE NEGOCIACIÓN (solo admin)
   Dropdown + botón Guardar dentro de la sección
   "Estado Negociación" del panel de detalle.
   ============================================ */
.estado-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.estado-edit select {
  flex: 1;
  min-width: 150px;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.estado-edit select:focus { border-color: var(--accent); }
.estado-save-btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  transition: all 0.15s;
}
.estado-save-btn:hover:not(:disabled) { background: #258050; border-color: #258050; }
.estado-save-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.estado-edit input[type="number"] {
  flex: 1;
  min-width: 130px;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.estado-edit input[type="number"]:focus { border-color: var(--accent); }
.estado-edit-error {
  width: 100%;
  color: var(--red);
  font-size: 12px;
}

.escritura-toggle-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  margin-left: 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.escritura-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }


/* ============================================
   ENLACES PÚBLICOS PARA PROPIETARIOS (panel derecho)
   ============================================ */
.enlace-gen {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.enlace-gen input[type="number"] {
  width: 70px;
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.enlace-gen input[type="number"]:focus { border-color: var(--accent); }
.enlace-gen-label { font-size: 12px; color: var(--text-muted); }
.enlace-codigos {
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
}
.enlace-codigos:focus { border-color: var(--accent); }

.enlace-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
}
.enlace-item-top {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  flex-wrap: wrap;
}
.enlace-meta { color: var(--text-muted); font-size: 11px; flex: 1; }
.enlace-inactivo { opacity: 0.55; }
.enlace-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.enlace-btn:hover { border-color: var(--accent); color: var(--accent); }
.enlace-btn-rev:hover { border-color: var(--red); color: var(--red); }


/* ============================================
   HISTORIAL DE CAMBIOS (panel derecho)
   ============================================ */
.hist-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 4px;
}
.hist-list::-webkit-scrollbar { width: 4px; }
.hist-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.hist-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.hist-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 3px 7px;
  border-radius: 5px;
  border: 1px solid;
  flex-shrink: 0;
  margin-top: 1px;
}
.hist-body { min-width: 0; flex: 1; }
.hist-detalle { font-size: 12px; color: var(--text-secondary); line-height: 1.45; word-break: break-word; }
.hist-detalle b { color: var(--text-primary); }
.hist-meta { font-size: 10px; color: var(--text-muted); margin-top: 3px; }


/* ============================================
   PAGOS DEL PREDIO (panel derecho)
   ============================================ */
.pago-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  margin-bottom: 6px;
}
.pago-item-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.pago-fecha { color: var(--text-muted); font-family: 'JetBrains Mono', monospace; font-size: 11px; flex-shrink: 0; }
.pago-concepto { color: var(--text-primary); font-weight: 600; flex: 1; }
.pago-valor { color: var(--green); font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.pago-obs { font-size: 11px; color: var(--text-secondary); margin-top: 5px; line-height: 1.45; }
.pago-foot { font-size: 10px; color: var(--text-muted); font-style: italic; margin-top: 4px; }
.pago-anulado { opacity: 0.55; }
.pago-anulado .pago-valor { text-decoration: line-through; color: var(--text-muted); }
.pago-anular-btn {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.pago-anular-btn:hover { border-color: var(--red); color: var(--red); }


/* ============================================
   BITACORA DE NEGOCIACION (panel derecho)
   ============================================ */

.bitacora-add-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.bitacora-add-btn:hover {
  border-color: #2e9e5e;
  color: #2e9e5e;
  background: rgba(46, 158, 94, 0.08);
}

.bitacora-list { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }

.bitacora-entry {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  padding: 0;
  overflow: hidden;
}
.bitacora-entry summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 12px;
  color: var(--text-secondary);
}
.bitacora-entry summary::-webkit-details-marker { display: none; }
.bitacora-entry summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--text-muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.bitacora-entry[open] summary::before { transform: rotate(90deg); }
.bitacora-entry[open] summary { border-bottom: 1px solid var(--border); }
.bitacora-entry-date { color: var(--text-secondary); font-weight: 500; flex-shrink: 0; }
.bitacora-entry-relata {
  color: var(--text-primary);
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.bitacora-edit-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
.bitacora-edit-btn:hover { background: var(--border); color: var(--text-primary); }

.bitacora-entry-body {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text-primary);
  white-space: normal;
  word-wrap: break-word;
}
.bitacora-entry-foot {
  padding: 4px 14px 10px;
  font-size: 10px;
  color: var(--text-muted);
  font-style: italic;
}


/* ============================================
   MODAL DE BITACORA
   ============================================ */

.bitacora-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}
.bitacora-modal.open { display: flex; }

.bitacora-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.bitacora-modal-content {
  position: relative;
  width: min(560px, 92vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.bitacora-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.bitacora-modal-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}
.bitacora-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 6px;
}
.bitacora-modal-close:hover { background: var(--border); color: var(--text-primary); }

.bitacora-modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}

.bitacora-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.bitacora-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.bitacora-field input,
.bitacora-field select,
.bitacora-field textarea {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  resize: vertical;
}
.bitacora-field input:focus,
.bitacora-field select:focus,
.bitacora-field textarea:focus { border-color: #3b82f6; }
.bitacora-field select:disabled { opacity: 0.7; cursor: not-allowed; }

.bitacora-error {
  color: var(--red);
  font-size: 12px;
  min-height: 16px;
  margin-top: 4px;
}

.bitacora-modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
}
.bitacora-btn-cancel,
.bitacora-btn-save {
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid var(--border);
}
.bitacora-btn-cancel {
  background: transparent;
  color: var(--text-secondary);
}
.bitacora-btn-cancel:hover { background: var(--border); }
.bitacora-btn-save {
  background: #2e9e5e;
  color: #fff;
  border-color: #2e9e5e;
}
.bitacora-btn-save:hover:not(:disabled) { background: #258050; border-color: #258050; }
.bitacora-btn-save:disabled { opacity: 0.6; cursor: not-allowed; }
