/* ---------- Reset / base ---------- */
* { 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;
  font-size: 14px;
  color: #1a1a1a;
  background: #f5f5f5;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ---------- Loading overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(255, 255, 255, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}
.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e0e0e0;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.loading-text {
  font-size: 15px;
  color: #444;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}
.toast {
  background: #333;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  animation: toastIn 0.2s ease;
  pointer-events: auto;
  max-width: 480px;
}
.toast.error { background: #c0392b; }
.toast.success { background: #27ae60; }
.toast.info { background: #2c3e50; }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Filter panel (top-left) ---------- */
.filter-panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  width: 280px;
  max-width: calc(100vw - 24px);
  overflow: hidden;
  transition: width 0.2s ease;
}
.filter-panel.collapsed .filter-panel-body {
  display: none;
}
.filter-panel.collapsed {
  width: auto;
}
.filter-panel-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #2c3e50;
  color: #fff;
}
.filter-panel-title {
  font-weight: 600;
  font-size: 14px;
}
.filter-panel-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.search-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus {
  border-color: #3498db;
}
.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  user-select: none;
}
.layer-toggle input[type="checkbox"] {
  margin: 0;
  cursor: pointer;
}
.layer-swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}
.layer-label {
  flex: 1;
  font-size: 14px;
}
.layer-count {
  background: #ececec;
  color: #555;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
  min-width: 24px;
  text-align: center;
}
.filter-panel-hint {
  font-size: 11px;
  color: #888;
  line-height: 1.3;
  padding-top: 4px;
  border-top: 1px solid #eee;
}

/* ---------- Legend (bottom-left) ---------- */
.legend {
  position: absolute;
  bottom: 24px;
  left: 12px;
  z-index: 1000;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  max-width: 240px;
  overflow: hidden;
}
.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #fafafa;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.legend-title {
  font-weight: 600;
  font-size: 13px;
}
.legend-body {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
}
.legend.collapsed .legend-body {
  display: none;
}
.legend-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.legend-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}
.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

/* ---------- Side panel (right) ---------- */
.side-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  background: #fff;
  z-index: 1500;
  box-shadow: -4px 0 18px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
.side-panel.open {
  transform: translateX(0);
}
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #2c3e50;
  color: #fff;
}
.side-panel-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.side-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
}
.field-value {
  font-size: 14px;
  word-break: break-word;
  color: #1a1a1a;
}
.field-value a {
  color: #2980b9;
  text-decoration: none;
}
.field-value a:hover {
  text-decoration: underline;
}
.field-value.empty {
  color: #aaa;
  font-style: italic;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chip {
  display: inline-block;
  background: #ececec;
  color: #333;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  line-height: 1.5;
}

.editable-textarea {
  width: 100%;
  min-height: 80px;
  padding: 8px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}
.editable-textarea:focus {
  border-color: #3498db;
}
.editable-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.editable-input:focus {
  border-color: #3498db;
}
.save-status {
  font-size: 11px;
  color: #888;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 14px;
}
.save-status.saving { color: #888; }
.save-status.saved { color: #27ae60; }
.save-status.error { color: #c0392b; }
.save-spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 1.5px solid #ddd;
  border-top-color: #3498db;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s;
}
.btn-primary {
  background: #2980b9;
  color: #fff;
}
.btn-primary:hover { background: #1f6391; }
.btn-secondary {
  background: #ececec;
  color: #333;
}
.btn-secondary:hover { background: #dcdcdc; }
.btn-danger {
  background: #c0392b;
  color: #fff;
}
.btn-danger:hover { background: #962d22; }
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.icon-button {
  background: transparent;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 18px;
  line-height: 1;
}
.icon-button:hover {
  background: rgba(0, 0, 0, 0.06);
}
.side-panel-header .icon-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal.open {
  display: flex;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.modal-dialog {
  position: relative;
  background: #fff;
  border-radius: 10px;
  width: 420px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 48px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #2c3e50;
  color: #fff;
}
.modal-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}
.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-row > span {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
}
.form-row input,
.form-row textarea,
.form-row select {
  padding: 8px;
  border: 1px solid #d0d0d0;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.form-row input:focus,
.form-row textarea:focus,
.form-row select:focus {
  border-color: #3498db;
}
.coords-row .coords-display {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: #555;
  background: #f7f7f7;
  padding: 6px 8px;
  border-radius: 4px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* ---------- Custom marker (divIcon) ---------- */
.rmap-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.rmap-marker:hover {
  transform: scale(1.18);
}
.rmap-marker-pin {
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.rmap-marker-pin:hover {
  transform: rotate(-45deg) scale(1.18);
}

/* ---------- Mobile / responsive ---------- */
@media (max-width: 600px) {
  .filter-panel {
    width: calc(100vw - 24px);
    top: 8px;
    left: 8px;
  }
  .legend {
    bottom: 8px;
    left: 8px;
    max-width: calc(100vw - 24px);
  }
  .legend-body {
    max-height: 30vh;
  }

  /* Side panel becomes bottom sheet */
  .side-panel {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 70vh;
    max-height: 70vh;
    transform: translateY(100%);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.18);
  }
  .side-panel.open {
    transform: translateY(0);
  }
  .side-panel-header {
    border-radius: 14px 14px 0 0;
  }
}
