:root {
  --control-opacity: 0.5;
  --control-opacity-hover: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-canvas--rotating {
  cursor: grabbing !important;
}

/* ---------------------------------------------------------------------------
   Loader
--------------------------------------------------------------------------- */
.loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: #f2f2f2;
  transition: opacity 0.5s ease;
}

.loader--hidden {
  opacity: 0;
  pointer-events: none;
}

.loader__spinner {
  width: 48px;
  height: 48px;
  border: 5px solid #d4d4d4;
  border-top-color: #4a90d9;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader__text {
  color: #333;
  font-size: 16px;
}

/* ---------------------------------------------------------------------------
   Panel de error
--------------------------------------------------------------------------- */
.error-panel {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: #f8f8f8;
}

/* El atributo hidden debe ocultar el panel (display:flex lo sobreescribiría). */
.error-panel[hidden] {
  display: none;
}

.error-panel__message {
  margin: 0;
  font-size: 18px;
  color: #333;
  text-align: center;
  max-width: 320px;
}

.error-panel__button {
  padding: 12px 28px;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: #4a90d9;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.error-panel__button:hover {
  background: #3a7cc0;
}

/* ---------------------------------------------------------------------------
   Controles flotantes (desktop)
--------------------------------------------------------------------------- */
.controls {
  position: fixed;
  z-index: 900;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  opacity: var(--control-opacity);
  transition: opacity 0.2s ease;
}

.controls:hover {
  opacity: var(--control-opacity-hover);
}

/* Cámara: arriba-centro */
.controls--camera {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
}

/* Tema: arriba-derecha */
.controls--theme {
  top: 12px;
  right: 12px;
}

/* Capas: derecha, centrado vertical, columna (se rellena en Unidad 3) */
.controls--layers {
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: #333;
}

.control-btn__icon {
  font-size: 22px;
  line-height: 1;
}

/* Pills del switch de capas (panel derecho, columna) */
.layers-title {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #999;
  margin: 2px 6px 4px;
}

.layer-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: none;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  font: inherit;
  color: #777;
  opacity: 0.6;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.layer-pill:hover {
  background: rgba(0, 0, 0, 0.06);
  opacity: 0.85;
}

.layer-pill--on {
  opacity: 1;
  color: #222;
}

.layer-pill__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
}

.layer-pill__label {
  flex: 1;
  text-align: left;
  font-size: 13px;
  line-height: 1;
}

.layer-pill__switch {
  position: relative;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: #d0d0d0;
  flex: none;
  transition: background 0.15s ease;
}

.layer-pill__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: left 0.15s ease;
}

.layer-pill--on .layer-pill__switch {
  background: #4a90d9;
}

.layer-pill--on .layer-pill__knob {
  left: 14px;
}

/* ---------------------------------------------------------------------------
   Barra de búsqueda (Unidad 14)
--------------------------------------------------------------------------- */
.search-container {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 960;
  width: 320px;
  max-width: calc(100vw - 24px);
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  color: #222;
  background: #fff;
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  outline: none;
  transition: box-shadow 0.2s ease;
}

.search-input:focus {
  box-shadow: 0 2px 12px rgba(74, 144, 217, 0.35);
}

.search-input::placeholder {
  color: #999;
}

.logout-btn {
  position: fixed;
  top: 12px;
  right: 64px;
  z-index: 960;
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #fff;
  color: #555;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.logout-btn:hover {
  color: #b33a3a;
  background: #fff7f7;
}

/* Botón de limpieza de la demo: borra storage/cookies/cachés y recarga con
   login limpio. Debajo del "Cerrar sesión", sin solaparse con el toggle de
   tema (arriba-derecha). */
.reset-btn {
  position: fixed;
  top: 48px;
  right: 64px;
  z-index: 959;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  color: #888;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.14);
  cursor: pointer;
  font: inherit;
  font-size: 12px;
}

.reset-btn:hover {
  color: #333;
  background: #f5f7fb;
}

.search-results {
  margin-top: 4px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
  max-height: 320px;
  overflow-y: auto;
}

.search-results[hidden] {
  display: none;
}

.search-results__empty {
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: #999;
}

.search-results__item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  font: inherit;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s ease;
}

.search-results__item:last-child {
  border-bottom: none;
}

.search-results__item:hover {
  background: #f5f8fc;
}

.search-results__partida {
  font-size: 13px;
  font-weight: 600;
  color: #333;
}

.search-results__detail {
  font-size: 12px;
  color: #777;
}

/* ---------------------------------------------------------------------------
   Panel lateral de parcela (Unidad 4)
--------------------------------------------------------------------------- */
.parcel-panel {
  position: fixed;
  top: 56px;
  left: 12px;
  z-index: 980;
  width: 260px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  padding: 14px 16px 16px;
}

.map-navigation-controls {
  position: absolute;
  right: 12px;
  bottom: 72px;
  z-index: 910;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.map-navigation-controls__button {
  width: 42px;
  height: 40px;
  border: 0;
  border-bottom: 1px solid #eee;
  background: #fff;
  color: #333;
  cursor: pointer;
  font-family: inherit;
  font-size: 20px;
  font-weight: 600;
  line-height: 1;
}

.map-navigation-controls__button:last-child { border-bottom: 0; font-size: 18px; }
.map-navigation-controls__button:hover { background: #f3f6fa; }

.parcel-panel[hidden] {
  display: none;
}

.parcel-panel__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  color: #777;
  border-radius: 4px;
}

.parcel-panel__close:hover {
  background: rgba(0, 0, 0, 0.08);
  color: #222;
}

.parcel-panel__title {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin: 0 24px 12px 0;
}

.parcel-panel__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
}

.parcel-panel__row:last-child {
  border-bottom: none;
}

.parcel-panel__field {
  margin: 0;
  font-size: 12px;
  color: #999;
  flex: none;
}

.parcel-panel__value {
  margin: 0;
  font-size: 13px;
  color: #222;
  font-weight: 500;
  text-align: right;
  overflow-wrap: anywhere;
}

.parcel-panel__export {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  font-size: 13px;
  font-weight: 600;
  color: #4a90d9;
  background: #f0f6ff;
  border: 1px solid #d0e0f5;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.parcel-panel__export:hover {
  background: #e0eeff;
}

/* ---------------------------------------------------------------------------
   Bottombar mobile (Unidad 5 — UX mobile)
   Visible solo por debajo de 768px. Por encima del breakpoint se oculta y se
   muestran los 3 paneles flotantes de desktop (layout sin cambios).
--------------------------------------------------------------------------- */
.bottombar {
  display: none;
}

@media (max-width: 767px) {
  /* Los paneles flotantes de desktop se ocultan en mobile. */
  .controls--camera,
  .controls--theme,
  .controls--layers {
    display: none;
  }

  .bottombar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 950;
    height: 60px;
    background: #ffffff;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.18);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0 12px;
  }

  .bottombar__control {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    color: #333;
  }

  .bottombar__control:hover,
  .bottombar__control--active {
    background: rgba(0, 0, 0, 0.06);
  }

  .bottombar__mini {
    font-size: 20px;
    line-height: 1;
  }

  .bottombar__mini-dots {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  .bottombar__mini-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.18);
  }

  .bottombar__drawer {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    right: 0;
    margin: 0 auto;
    width: calc(100% - 24px);
    max-width: 340px;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.22);
    padding: 12px;
  }

  .bottombar__drawer[hidden] {
    display: none;
  }

  .drawer-action {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    color: #222;
    text-align: left;
  }

  .drawer-action:hover {
    background: rgba(0, 0, 0, 0.06);
  }

  .drawer-action .theme-icon,
  .drawer-action .camera-icon {
    font-size: 20px;
    line-height: 1;
  }

  /* Panel de parcela: mantiene posición lateral fija; el alto disponible se
     reduce para dejar lugar a la bottombar y se asegura scroll vertical si el
     contenido (campos base + extra) no entra en pantalla. */
  .parcel-panel {
    max-height: calc(100vh - 84px);
  }

  .map-navigation-controls { bottom: 72px; right: 10px; }

  .logout-btn {
    top: 12px;
    right: 64px;
  }

  .reset-btn {
    top: 48px;
    right: 64px;
  }
}
