:root {
  --cor-fundo: #f5f5f5;
  --cor-superficie: #ffffff;
  --cor-topo: #1f2937;
  --cor-borda: #cbd5e1;
  --cor-texto: #111827;
  --cor-texto-secundario: #475569;
  --cor-primaria: #1f2937;
  --cor-primaria-hover: #111827;
  --cor-perigo: #991b1b;
  --cor-sucesso: #166534;
  --cor-aviso: #a16207;
  --sombra-card: 0 8px 24px rgba(15, 23, 42, 0.06);
  --sombra-forte: 0 12px 32px rgba(15, 23, 42, 0.18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, sans-serif;
  background: var(--cor-fundo);
}

body {
  overflow: hidden;
}

#app {
  height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  background: var(--cor-topo);
  color: #ffffff;
  padding: 14px 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  flex-shrink: 0;
}

.topbar-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.topbar p {
  margin: 4px 0 0;
  font-size: 14px;
  opacity: 0.9;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-action-button,
.topbar-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  text-decoration: none;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.topbar-action-button:hover,
.topbar-action-link:hover {
  background: rgba(255, 255, 255, 0.16);
}

.topbar-municipio {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: rgba(255, 255, 255, 0.08);
  padding: 10px 12px;
  border-radius: 12px;
}

.topbar-municipio label {
  color: #e5e7eb;
  font-size: 14px;
  font-weight: 600;
}

.topbar-municipio select {
  min-width: 220px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--cor-borda);
  font: inherit;
  background: #ffffff;
  color: var(--cor-texto);
}

.topbar-municipio button {
  padding: 8px 12px;
  border: none;
  border-radius: 8px;
  background: #ffffff;
  color: var(--cor-primaria);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}

.topbar-municipio button:hover {
  background: #e2e8f0;
}

.municipio-home {
  padding: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #eef2ff;
  border-bottom: 1px solid #dbe4ff;
}

.municipio-home-card {
  width: min(920px, 100%);
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 18px;
  box-shadow: var(--sombra-card);
  padding: 24px;
}

.municipio-home-card h2 {
  margin: 0 0 10px;
  font-size: 24px;
}

.municipio-home-card p {
  margin: 0 0 18px;
  color: var(--cor-texto-secundario);
}

.municipio-selector-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.municipio-selector-row select {
  flex: 1;
  min-width: 260px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--cor-borda);
  font: inherit;
}

.municipio-selector-row button {
  padding: 12px 18px;
  border: none;
  border-radius: 10px;
  background: var(--cor-primaria);
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.municipio-selector-row button:hover {
  background: var(--cor-primaria-hover);
}

.municipio-resumo {
  margin-top: 16px;
  color: #334155;
  line-height: 1.5;
}

.area-mapa {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.area-mapa-oculta {
  display: none;
}

.search-wrap {
  background: #f8fafc;
  border-bottom: 1px solid #dddddd;
  z-index: 1000;
  flex-shrink: 0;
}

.search-bar {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
}

.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--cor-borda);
  border-radius: 8px;
  outline: none;
}

.search-bar button {
  padding: 10px 14px;
  font: inherit;
  border: 1px solid var(--cor-borda);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

#map {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.leaflet-container {
  width: 100%;
  height: 100%;
  background: #e5e7eb;
}

.categoria-filtros {
  display: flex;
  gap: 8px;
  padding: 0 14px 10px;
  flex-wrap: wrap;
}

.categoria-chip {
  border: 1px solid var(--cor-borda);
  background: #ffffff;
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
}

.categoria-chip.ativo {
  background: var(--cor-primaria);
  color: #ffffff;
  border-color: var(--cor-primaria);
}

.info-box,
.erro-box {
  position: absolute;
  z-index: 900;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.info-box {
  right: 14px;
  bottom: 14px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #dddddd;
  color: #333333;
  max-width: 340px;
}

.erro-box {
  left: 14px;
  bottom: 14px;
  background: rgba(180, 30, 30, 0.96);
  color: #ffffff;
  max-width: 380px;
  display: none;
}

.toast-container {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  opacity: 0;
  transform: translateY(-8px);
  transition: all 0.2s ease;
  background: #111827;
  color: #ffffff;
  padding: 10px 12px;
  border-radius: 10px;
  min-width: 220px;
  max-width: 360px;
}

.toast strong {
  display: block;
  margin-bottom: 4px;
}

.toast.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast-sucesso {
  background: var(--cor-sucesso);
}

.toast-erro {
  background: var(--cor-perigo);
}

.toast-aviso {
  background: var(--cor-aviso);
}

.popup-title {
  font-weight: bold;
  font-size: 16px;
  margin-bottom: 8px;
}

.popup-description,
.modal-local-description {
  line-height: 1.45;
}

.popup-actions,
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.popup-actions button,
.modal-actions button,
.popup-form button {
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--cor-primaria);
  color: #ffffff;
  cursor: pointer;
  font: inherit;
}

.popup-actions button:hover,
.modal-actions button:hover,
.popup-form button:hover {
  background: var(--cor-primaria-hover);
}

.popup-image-wrap {
  margin: 10px 0;
}

.popup-image,
.historia-image,
.modal-image {
  display: block;
  width: 100%;
  max-width: 320px;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #dddddd;
}

.historia-item {
  border: 1px solid #dddddd;
  background: #fafafa;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}

.historia-titulo {
  font-weight: 700;
  margin-bottom: 6px;
}

.historia-meta {
  font-size: 12px;
  color: #666666;
  margin-top: 8px;
}

.popup-form input,
.popup-form textarea,
.popup-form button,
.popup-form select {
  width: 100%;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 8px;
  font: inherit;
  border: 1px solid var(--cor-borda);
  border-radius: 8px;
}

.popup-form textarea {
  min-height: 80px;
  resize: vertical;
}

.popup-file-label {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  color: #374151;
}

.popup-note {
  margin-top: 8px;
  font-size: 12px;
  color: #666666;
  line-height: 1.4;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 2000;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-dialog {
  position: relative;
  width: min(760px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  padding: 24px;
}

.modal-dialog-lg {
  width: min(900px, 100%);
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 30px;
  cursor: pointer;
  color: #64748b;
}

.modal-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0 0 10px;
  color: #111827;
}

.modal-subtitle {
  margin-bottom: 16px;
  color: #475569;
}

.modal-section-title {
  font-size: 18px;
  font-weight: 700;
  margin: 20px 0 12px;
  color: #111827;
}

.popup-badge {
  background: #e2e8f0;
  color: #1e293b;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
}

.form-loading {
  opacity: 0.8;
  pointer-events: none;
}

.anti-bot-field {
  position: absolute;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
}

.local-marker-wrap {
  background: transparent;
  border: none;
}

.local-marker {
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.2);
}

.mobile-fab,
.mobile-help-card {
  display: none;
}

@media (max-width: 768px) {
  html,
  body {
    background: #edf2f7;
  }

  body {
    overflow: auto;
  }

  #app {
    height: 100dvh;
    min-height: 100dvh;
    padding-top: var(--safe-top);
    background: linear-gradient(180deg, #eef2ff 0%, #f8fafc 18%, #edf2f7 100%);
  }

  .topbar {
    padding: 14px 14px 12px;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 18px;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
  }

  .topbar-header {
    align-items: stretch;
  }

  .topbar h1 {
    font-size: 22px;
    line-height: 1.2;
  }

  .topbar p {
    margin-top: 6px;
    line-height: 1.45;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .topbar-action-button,
  .topbar-action-link {
    min-height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
  }

  .topbar-municipio {
    width: 100%;
    padding: 12px;
    border-radius: 14px;
  }

  .topbar-municipio select,
  .topbar-municipio button {
    width: 100%;
  }

  .municipio-home {
    padding: 14px;
    display: block;
    background: transparent;
    border-bottom: none;
  }

  .municipio-home-card {
    width: 100%;
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
  }

  .municipio-home-card h2 {
    font-size: 22px;
  }

  .municipio-selector-row {
    flex-direction: column;
  }

  .municipio-selector-row select,
  .municipio-selector-row button {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    border-radius: 12px;
  }

  .area-mapa {
    padding: 10px 10px calc(10px + var(--safe-bottom));
    gap: 10px;
  }

  .search-wrap {
    background: transparent;
    border-bottom: none;
    overflow: visible;
  }

  .search-bar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 0;
  }

  .search-bar input,
  .search-bar button {
    min-height: 46px;
    border-radius: 14px;
    border: 1px solid #d6deea;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.05);
  }

  .search-bar button {
    background: var(--cor-primaria);
    border-color: var(--cor-primaria);
    color: #ffffff;
  }

  .categoria-filtros {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 10px 0 2px;
    scrollbar-width: none;
  }

  .categoria-filtros::-webkit-scrollbar {
    display: none;
  }

  .categoria-chip {
    white-space: nowrap;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    padding: 0 14px;
    border-radius: 999px;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
  }

  #map {
    border-radius: 20px;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.1);
  }

  .info-box,
  .erro-box,
  .toast-container {
    position: fixed;
  }

  .info-box {
    left: 10px;
    right: 10px;
    bottom: calc(86px + var(--safe-bottom));
    max-width: none;
    border-radius: 14px;
  }

  .erro-box {
    left: 10px;
    right: 10px;
    bottom: calc(18px + var(--safe-bottom));
    max-width: none;
    border-radius: 14px;
  }

  .toast-container {
    top: calc(10px + var(--safe-top));
    left: 10px;
    right: 10px;
    align-items: stretch;
  }

  .toast {
    min-width: 0;
    max-width: none;
    border-radius: 14px;
    box-shadow: var(--sombra-forte);
  }

  .mobile-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: 18px;
    bottom: calc(18px + var(--safe-bottom));
    z-index: 930;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #1f2937, #334155);
    color: #ffffff;
    font-size: 24px;
    box-shadow: 0 14px 28px rgba(15, 23, 42, 0.28);
  }

  .mobile-help-card {
    display: block;
    position: absolute;
    left: 12px;
    right: 84px;
    bottom: calc(18px + var(--safe-bottom));
    z-index: 920;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid #dbe4ff;
    border-radius: 16px;
    padding: 12px 14px;
    color: #334155;
    line-height: 1.45;
    box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
  }

  .mobile-help-card strong {
    display: block;
    margin-bottom: 4px;
    color: #111827;
  }

  .modal {
    padding: 8px;
    align-items: flex-end;
  }

  .modal-dialog,
  .modal-dialog-lg {
    width: 100%;
    max-height: 90vh;
    border-radius: 18px 18px 0 0;
    padding: 20px 16px calc(20px + var(--safe-bottom));
  }

  .popup-actions,
  .modal-actions {
    display: grid;
  }

  .popup-actions button,
  .modal-actions button {
    width: 100%;
  }
}
