* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden;
}

#map {
  width: 100vw;
  height: 100vh;
}

/* Toolbar */
#toolbar {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 1000;
  background: white;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  min-width: 220px;
}

#toolbar h1 {
  font-size: 1.2rem;
  color: #2d5016;
  margin-bottom: 8px;
}

.toolbar-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

#categoryFilter,
#mapStyle {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.85rem;
}

#btnLocate,
#btn3D {
  background: white;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
}

#btnLocate:hover,
#btn3D:hover {
  background: #f0f0f0;
}

#btn3D.active {
  background: #4a9e2f;
  color: white;
  border-color: #4a9e2f;
}

.hint {
  font-size: 0.75rem;
  color: #888;
  margin-top: 6px;
}

/* Geology toggle & offline */
.toggle-inline {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  color: #555;
}

.toggle-inline input[type="checkbox"] {
  accent-color: #4a9e2f;
}

.opacity-slider {
  flex: 1;
  height: 4px;
  accent-color: #4a9e2f;
}

.btn-small {
  padding: 4px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: white;
  font-size: 0.78rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-small:hover {
  background: #f0f0f0;
}

.btn-small:active {
  background: #ddd;
}

/* Legend panel - draggable */
.legend-panel {
  position: absolute;
  top: 60px;
  right: 50px;
  z-index: 1100;
  background: white;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  width: 350px;
  height: 60vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  resize: both;
  min-width: 250px;
  min-height: 200px;
  max-height: 85vh;
  max-width: 90vw;
}

.legend-panel.hidden {
  display: none;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: #eef3ea;
  font-size: 0.9rem;
  font-weight: 600;
  color: #2d5016;
  border-bottom: 1px solid #ddd;
  cursor: grab;
  user-select: none;
}

.legend-header:active {
  cursor: grabbing;
}

.btn-zoom-legend {
  background: none;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.85rem;
  cursor: pointer;
  color: #555;
  padding: 1px 8px;
  font-weight: 700;
}

.btn-zoom-legend:hover {
  background: #eee;
}

.legend-body img {
  display: block;
  width: 100%;
}

.btn-close-sm {
  background: none;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: #999;
  padding: 0 4px;
}

.btn-close-sm:hover {
  color: #333;
}

.legend-search {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}

.legend-search input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
}

.legend-search input:focus {
  border-color: #4a9e2f;
  box-shadow: 0 0 0 2px rgba(74,158,47,0.15);
}

.legend-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.legend-loading {
  padding: 20px;
  text-align: center;
  color: #999;
  font-size: 0.85rem;
}

.legend-item {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: default;
}

.legend-item:hover {
  background: #f5f9f3;
}

.legend-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.legend-code {
  display: inline-block;
  background: #8b6914;
  color: white;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  font-family: monospace;
}

.legend-era {
  font-size: 0.7rem;
  color: #999;
}

.legend-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #2d5016;
}

.legend-desc {
  font-size: 0.75rem;
  color: #666;
  line-height: 1.3;
  margin-top: 2px;
}

.legend-zona {
  font-size: 0.7rem;
  color: #999;
  margin-top: 2px;
}

.legend-no-results {
  padding: 20px;
  text-align: center;
  color: #999;
  font-size: 0.85rem;
}

.offline-badge {
  font-size: 0.7rem;
  background: #e74c3c;
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}

.online-badge {
  background: #4a9e2f;
}

/* Altitude field */
.altitude-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.altitude-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 0.9rem;
  background: white;
}

.altitude-row input:focus {
  outline: none;
  border-color: #4a9e2f;
  box-shadow: 0 0 0 2px rgba(74,158,47,0.15);
}

/* Search Bar */
#searchBar {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: 340px;
}

.search-input-wrap {
  position: relative;
}

#searchInput {
  width: 100%;
  padding: 10px 36px 10px 14px;
  border: none;
  border-radius: 24px;
  font-size: 0.95rem;
  box-shadow: 0 2px 12px rgba(0,0,0,0.15);
  outline: none;
}

#searchInput:focus {
  box-shadow: 0 2px 16px rgba(0,0,0,0.25);
}

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 1.2rem;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
}

.search-results {
  margin-top: 4px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  max-height: 300px;
  overflow-y: auto;
}

.search-results.hidden {
  display: none;
}

.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.9rem;
  color: #333;
}

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

.search-result-item:hover {
  background: #f5f9f3;
}

.search-result-item small {
  display: block;
  color: #999;
  font-size: 0.75rem;
  margin-top: 2px;
}

/* Map markers */
.map-marker {
  cursor: pointer;
}

.map-marker svg {
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.3));
}

/* Popup (MapLibre) */
.maplibregl-popup-content {
  border-radius: 10px !important;
  padding: 0 !important;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2) !important;
  max-width: 300px;
}

.maplibregl-popup-close-button {
  font-size: 1.2rem;
  padding: 4px 8px;
  color: #999;
  z-index: 1;
}

.point-popup {
  padding: 14px;
  min-width: 220px;
}

.point-popup h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  color: #2d5016;
  padding-right: 20px;
}

.point-popup .popup-category {
  font-size: 0.75rem;
  color: white;
  background: #4a9e2f;
  padding: 2px 8px;
  border-radius: 10px;
  display: inline-block;
  margin-bottom: 6px;
}

.point-popup .popup-detail {
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 2px;
}

.point-popup .popup-detail strong {
  color: #444;
}

.point-popup .popup-description {
  font-size: 0.85rem;
  color: #555;
  margin-top: 6px;
  margin-bottom: 8px;
  line-height: 1.4;
}

.point-popup .popup-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.point-popup .popup-photos img {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.15s;
}

.point-popup .popup-photos img:hover {
  transform: scale(1.05);
}

.point-popup .popup-actions {
  display: flex;
  gap: 8px;
}

.point-popup .popup-actions button {
  padding: 4px 10px;
  font-size: 0.8rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.popup-btn-edit {
  background: #3498db;
  color: white;
}

.popup-btn-delete {
  background: #e74c3c;
  color: white;
}

/* Modal Panel (slide-in style like the reference image) */
.modal-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 2000;
  width: 400px;
  height: 100vh;
  background: #eef3ea;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.modal-panel.hidden {
  display: none;
}

.modal-panel-content {
  padding: 0 20px 30px;
}

.modal-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  position: sticky;
  top: 0;
  background: #eef3ea;
  z-index: 1;
}

.btn-back {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #d4ddd0;
  color: #2d5016;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-back:hover {
  background: #c0ccba;
}

.modal-panel-header h2 {
  font-size: 1.1rem;
  color: #333;
  font-weight: 600;
}

.btn-confirm {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #c0a080;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-confirm:hover {
  background: #a88868;
}

/* Form */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: #777;
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  background: white;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: #4a9e2f;
  box-shadow: 0 0 0 2px rgba(74,158,47,0.15);
}

.form-group input[type="file"] {
  font-size: 0.85rem;
}

.info-display {
  padding: 12px 14px;
  background: white;
  border-radius: 10px;
  font-size: 0.85rem;
  color: #666;
  border: 1px solid #e8e8e8;
}

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid #e8e8e8;
}

.toggle-row span {
  font-size: 0.9rem;
  color: #555;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.3s;
}

.toggle-slider:before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
  background: #4a9e2f;
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(22px);
}

/* Photo preview */
.photo-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.photo-preview-item {
  position: relative;
  display: inline-block;
}

.photo-preview-item img {
  width: 70px;
  height: 70px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #ddd;
}

.photo-gps-badge {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: #4a9e2f;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.6rem;
  padding: 2px 5px;
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.photo-gps-badge:hover {
  background: #3d8526;
}

/* Existing photos in edit mode */
.existing-photos {
  margin-bottom: 14px;
}

.existing-photos h3 {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 8px;
}

.existing-photo-item {
  display: inline-block;
  position: relative;
  margin: 4px;
}

.existing-photo-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}

.existing-photo-item .delete-photo {
  position: absolute;
  top: -6px;
  right: -6px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Buttons */
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 500;
}

.btn-primary {
  background: #4a9e2f;
  color: white;
}

.btn-primary:hover {
  background: #3d8526;
}

.btn-secondary {
  background: #ddd;
  color: #555;
}

.btn-secondary:hover {
  background: #ccc;
}

.btn-danger {
  background: #e74c3c;
  color: white;
}

.btn-danger:hover {
  background: #c0392b;
}

.hidden {
  display: none !important;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 3000;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox.hidden {
  display: none;
}

.lightbox img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 4px;
}

.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: none;
  border: none;
  color: white;
  font-size: 2rem;
  cursor: pointer;
  padding: 10px;
  opacity: 0.7;
}

.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover {
  opacity: 1;
}

.lightbox-close {
  top: 10px;
  right: 20px;
  font-size: 2.5rem;
}

.lightbox-prev {
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-next {
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
}

.lightbox-caption {
  position: absolute;
  bottom: 20px;
  text-align: center;
  width: 100%;
  color: white;
  font-size: 0.9rem;
}

/* Grid/Table View */
.grid-view {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: #f5f7f3;
  display: flex;
  flex-direction: column;
}

.grid-view.hidden {
  display: none;
}

.grid-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #eef3ea;
  border-bottom: 1px solid #ddd;
}

.grid-header h2 {
  font-size: 1.1rem;
  color: #2d5016;
  white-space: nowrap;
}

.grid-search-wrap {
  flex: 1;
}

.grid-search-wrap input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 0.85rem;
  outline: none;
}

.grid-search-wrap input:focus {
  border-color: #4a9e2f;
}

.grid-body {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.grid-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.grid-table th {
  position: sticky;
  top: 0;
  background: #eef3ea;
  padding: 10px 8px;
  text-align: left;
  font-size: 0.75rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #ddd;
}

.grid-table td {
  padding: 10px 8px;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}

.grid-table tr {
  cursor: pointer;
}

.grid-table tr:hover td {
  background: #e8f0e4;
}

.grid-table .cell-title {
  font-weight: 600;
  color: #2d5016;
}

.grid-table .cell-category {
  display: inline-block;
  background: #4a9e2f;
  color: white;
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 0.7rem;
}

.grid-table .cell-photos {
  font-size: 0.75rem;
  color: #999;
}

.grid-empty {
  text-align: center;
  padding: 40px;
  color: #999;
}

/* Grid Detail Panel */
.grid-detail {
  position: absolute;
  inset: 0;
  background: #f5f7f3;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.grid-detail.hidden {
  display: none;
}

.grid-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: #eef3ea;
  border-bottom: 1px solid #ddd;
}

.grid-detail-header h2 {
  flex: 1;
  font-size: 1.1rem;
  color: #2d5016;
}

.grid-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section label {
  display: block;
  font-size: 0.75rem;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.detail-section .detail-value {
  font-size: 0.9rem;
  color: #333;
  padding: 8px 12px;
  background: white;
  border-radius: 8px;
  border: 1px solid #e8e8e8;
}

.detail-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-photos img {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid #ddd;
  transition: transform 0.15s;
}

.detail-photos img:hover {
  transform: scale(1.03);
}

/* Responsive */
@media (max-width: 600px) {
  #toolbar {
    left: 10px;
    right: 10px;
    min-width: auto;
  }

  #searchBar {
    left: 10px;
    right: 10px;
    width: auto;
    transform: none;
    top: auto;
    bottom: 20px;
  }

  .modal-panel {
    width: 100%;
  }
}
