/* ==========================================================================
   HAND — folha de estilo
   Mesma linguagem visual do MonitorGEO: interface clara e neutra (branco e
   cinzas), o satélite é quem tem cor. A marca AmbGEO fica nos detalhes: o
   ciano nos indicadores e o azul-marinho do logo no botão principal.
   ========================================================================== */

:root {
  color-scheme: light;
  --brand:     #0ad1d1;   /* ciano AmbGEO: marcadores, bordas e fundos */
  --brand-tx:  #0a7a80;   /* ciano legível em fundo claro: textos, links */
  --brand-dk:  #122b40;   /* azul-marinho AmbGEO: botão principal */

  --bg:        #ffffff;
  --bg-2:      #f4f5f6;
  --bg-3:      #eaecee;
  --line:      #d9dde1;
  --line-soft: #e9ebed;

  --txt:       #1f2328;
  --txt-2:     #4f565d;
  --txt-3:     #767d85;

  --agua:      #00bfff;   /* mancha de inundação (mesma cor do GEE) */
  --agua-perm: #1d4ed8;   /* água permanente do JRC (azul-escuro: separa da mancha) */
  --edif:      #ff3b30;   /* edifícios atingidos */
  --aoi:       #fbbf24;   /* área de estudo (âmbar: não se confunde com a mancha azul) */

  --tx-ok: #166a46;   --bg-ok: #e9f6ef;   --bd-ok: #bfe3cf;
  --tx-erro: #9b2c22; --bg-erro: #fdeceb; --bd-erro: #f3c6c1;
  --tx-aviso: #6b5a2e; --bg-aviso: #fbf7ec; --bd-aviso: #efe3c4;
  --tx-info: #075985; --bg-info: #e2f1fa; --bd-info: #c4e2f4;

  --side-w:    356px;
  --radius:    10px;
  --shadow:    0 10px 30px rgba(17, 24, 31, .14);
  --flutuante: rgba(255, 255, 255, .96);
  --mapa-fundo: #e6e8ea;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--txt);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body { display: flex; overflow: hidden; }

button, input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- Painel */
#painel {
  width: var(--side-w);
  flex: none;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line);
  z-index: 1000;
}

.painel-topo {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.painel-topo img { height: 26px; width: auto; display: block; }
.painel-topo h1 {
  margin: 14px 0 2px;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.01em;
}
.painel-topo p { margin: 0; font-size: 12.5px; color: var(--txt-3); }

.painel-corpo {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 20px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(10, 122, 128, .45) rgba(0, 0, 0, .05);
}

/* Passos numerados */
.passo { counter-increment: passo; margin-bottom: 18px; }
.painel-corpo { counter-reset: passo; }
.passo-titulo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
}
.passo-titulo::before {
  content: counter(passo);
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: var(--brand-dk);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
}
.passo.feito .passo-titulo::before { background: var(--brand-tx); }

.dica { margin: 6px 0 0; font-size: 12px; line-height: 1.45; color: var(--txt-3); }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--bg-2); }
.btn:focus-visible { outline: 2px solid var(--brand-tx); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; flex: none; }

.btn-primario {
  width: 100%;
  min-height: 44px;
  border-color: var(--brand-dk);
  background: var(--brand-dk);
  color: #fff;
  font-size: 14px;
}
.btn-primario:hover:not(:disabled) { background: #1b3d59; }

.btn.ativo { border-color: var(--brand); background: #e5f9f9; color: var(--brand-tx); }

.btn-texto {
  border-color: transparent;
  background: transparent;
  color: var(--txt-2);
}
.btn-texto:hover { background: var(--bg-2); color: var(--txt); }

.grade-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Carregando */
.btn .giro {
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: giro .7s linear infinite;
}
@keyframes giro { to { transform: rotate(360deg); } }

/* Envio de arquivo */
.upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-top: 8px;
  padding: 14px 12px;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload:hover, .upload.arrastando { border-color: var(--brand); background: #effcfc; }
.upload:focus-within { outline: 2px solid var(--brand-tx); outline-offset: 2px; }
.upload strong { font-size: 13px; font-weight: 600; }
.upload span { font-size: 11.5px; color: var(--txt-3); }
.upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.area-info {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--tx-ok);
}
.area-info::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok, #1b8a5a);
}
.area-info[hidden] { display: none; }

/* Valor de HAND */
.hand-linha { display: flex; align-items: center; gap: 12px; }
.hand-linha input[type="range"] { flex: 1; accent-color: var(--brand-dk); }
.hand-valor {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}
.hand-valor:focus-within { border-color: var(--brand-tx); box-shadow: 0 0 0 3px rgba(10, 209, 209, .18); }
.hand-valor input {
  width: 58px;
  padding: 8px 4px 8px 10px;
  border: 0;
  outline: 0;
  background: transparent;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.hand-valor span { padding-right: 10px; color: var(--txt-3); font-size: 12.5px; }

/* Resultado */
.resultado {
  margin: 18px 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.resultado[hidden] { display: none; }
.resultado-cab {
  padding: 10px 14px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line-soft);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--txt-2);
}
.metrica {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}
.metrica + .metrica { border-top: 1px solid var(--line-soft); }
.metrica-cor { width: 12px; height: 12px; flex: none; border-radius: 3px; }
.metrica-cor.agua { background: var(--agua); }
.metrica-cor.agua-perm { background: var(--agua-perm); }
.metrica-cor.edif { background: transparent; border: 2px solid var(--edif); }
.metrica-rotulo { flex: 1; font-size: 12.5px; color: var(--txt-2); }
.metrica-valor {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.metrica-valor small { font-size: 12px; font-weight: 600; color: var(--txt-3); margin-left: 2px; }
.metrica-valor.carregando { font-size: 12.5px; font-weight: 500; color: var(--txt-3); }

.acoes { display: flex; flex-direction: column; gap: 8px; }
.acoes[hidden] { display: none; }
.acoes .btn { width: 100%; }

/* Avisos */
.aviso {
  margin-top: 14px;
  padding: 10px 12px;
  border: 1px solid var(--bd-info);
  border-radius: 8px;
  background: var(--bg-info);
  color: var(--tx-info);
  font-size: 12.5px;
  line-height: 1.45;
}
.aviso[hidden] { display: none; }
.aviso.ok { background: var(--bg-ok); border-color: var(--bd-ok); color: var(--tx-ok); }
.aviso.erro { background: var(--bg-erro); border-color: var(--bd-erro); color: var(--tx-erro); }
.aviso.atencao { background: var(--bg-aviso); border-color: var(--bd-aviso); color: var(--tx-aviso); }

.painel-rodape {
  padding: 12px 20px;
  border-top: 1px solid var(--line-soft);
  font-size: 11.5px;
  color: var(--txt-3);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.painel-rodape a, .link { color: var(--brand-tx); text-decoration: none; font-weight: 600; }
.painel-rodape a:hover, .link:hover { text-decoration: underline; }
.painel-rodape button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-tx);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}

/* ---------------------------------------------------------------- Mapa */
#map { flex: 1 1 auto; height: 100%; background: var(--mapa-fundo); }
.leaflet-container { font-family: var(--font); }

.leaflet-control-attribution {
  background: var(--flutuante) !important;
  color: var(--txt-3) !important;
  font-size: 10.5px !important;
}
.leaflet-control-attribution a { color: var(--txt-2) !important; }
.leaflet-control-attribution.atrib-compacta { cursor: pointer; border-radius: 10px; margin: 0 6px 6px 0 !important; }
.atrib-compacta.is-recolhida {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0 !important;
  border-radius: 50%;
  overflow: hidden;
  font-size: 0 !important;
  line-height: 0;
}
.atrib-compacta.is-recolhida::before {
  content: "i";
  font: italic 700 12px/1 Georgia, "Times New Roman", serif;
  color: var(--txt-2);
}
.atrib-compacta.is-recolhida > * { display: none; }

.leaflet-control-scale-line {
  background: var(--flutuante);
  border-color: var(--txt-2);
  color: var(--txt-2);
}

/* Zoom no canto superior direito */
#map .leaflet-top.leaflet-right .leaflet-control-zoom {
  margin-top: 10px;
  margin-right: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(17, 24, 31, .16);
}
#map .leaflet-control-zoom a {
  width: 40px;
  height: 40px;
  line-height: 40px;
  font-size: 20px;
  font-weight: 500;
  background-color: var(--flutuante);
  color: var(--txt);
  border-bottom-color: var(--line);
}
#map .leaflet-control-zoom a:hover { background-color: var(--bg-2); }

/* Seletor de mapa base (mesmo do MonitorGEO) */
#map .lc.leaflet-control {
  margin: 10px 0 0 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: min(280px, calc(100vw - 24px));
}
#map .lc-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--flutuante);
  box-shadow: 0 2px 10px rgba(17, 24, 31, .16);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
#map .lc-toggle:hover { background: var(--bg-2); }
#map .lc-toggle svg { width: 20px; height: 18px; }
#map .lc-painel {
  margin-top: 6px;
  padding: 10px 12px 12px;
  width: min(280px, calc(100vw - 24px));
  max-height: min(70vh, 520px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--flutuante);
  box-shadow: var(--shadow);
  font-size: 12px;
  scrollbar-width: thin;
}
#map .lc-painel[hidden] { display: none; }
#map .lc-sub { display: block; margin: 12px 0 6px; font-size: 10.5px; font-weight: 600; color: var(--txt-2); }
#map .lc-sub:first-child { margin-top: 0; }
#map .lc-bases { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
#map .lc-base {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  font-size: 11px;
  line-height: 1.2;
  color: var(--txt-2);
  text-align: center;
}
#map .lc-base input { position: absolute; opacity: 0; pointer-events: none; }
#map .lc-base img {
  width: 100%;
  aspect-ratio: 4 / 3;
  height: auto;
  object-fit: cover;
  display: block;
  border-radius: 8px;
  border: 2px solid var(--line);
  background: var(--bg-3);
}
#map .lc-base-nomes {
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 3px rgba(0, 0, 0, .8);
}
#map .lc-base:hover img { border-color: var(--txt-3); }
#map .lc-base input:checked ~ img { border-color: var(--brand); }
#map .lc-base input:checked ~ span:last-child { color: var(--txt); font-weight: 700; }
#map .lc-base input:focus-visible ~ img { outline: 2px solid var(--brand-tx); outline-offset: 2px; }
#map .lc-linha { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
#map .lc-linha input { margin: 0; accent-color: var(--brand-tx); }
#map .lc-amostra { width: 12px; height: 12px; flex: none; border-radius: 3px; margin-left: auto; }

/* Busca de lugares (canto superior esquerdo, acima do seletor de mapa base) */
#map .busca.leaflet-control {
  margin: 10px 0 0 10px;
  width: min(340px, calc(100vw - 80px));   /* no celular deixa espaço para o zoom à direita */
}
#map .busca-form {
  display: flex;
  align-items: center;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--flutuante);
  box-shadow: 0 2px 10px rgba(17, 24, 31, .16);
  overflow: hidden;
}
#map .busca-form:focus-within { border-color: var(--brand-tx); box-shadow: 0 0 0 3px rgba(10, 209, 209, .18), 0 2px 10px rgba(17, 24, 31, .16); }
#map .busca-campo {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px 0 14px;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
}
#map .busca-campo::placeholder { color: var(--txt-3); }
#map .busca-campo::-webkit-search-cancel-button { display: none; }
#map .busca-form button {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--txt-2);
  cursor: pointer;
}
#map .busca-form button:hover { color: var(--txt); background: var(--bg-2); }
#map .busca-form button:disabled { opacity: .5; cursor: wait; }
#map .busca-form button[hidden] { display: none; }
#map .busca-form svg { width: 18px; height: 18px; }
#map .busca-ir { border-left: 1px solid var(--line-soft) !important; }
#map .busca-lista {
  margin-top: 6px;
  max-height: min(50vh, 340px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--flutuante);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}
#map .busca-lista[hidden] { display: none; }
#map .busca-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 9px 14px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
#map .busca-item + .busca-item { border-top: 1px solid var(--line-soft); }
#map .busca-item:hover, #map .busca-item:focus-visible { background: var(--bg-2); outline: 0; }
#map .busca-item[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--brand); }
#map .busca-nome { font-size: 13px; font-weight: 600; color: var(--txt); }
#map .busca-nome em { margin-left: 4px; font-style: normal; font-size: 11px; font-weight: 600; color: var(--brand-tx); }
#map .busca-local { font-size: 11.5px; line-height: 1.35; color: var(--txt-3); }
#map .busca-msg { margin: 0; padding: 10px 14px; font-size: 12.5px; color: var(--txt-2); }

/* Barra de desenho sobre o mapa */
#map .barra-desenho {
  position: absolute;
  left: 50%;
  bottom: 28px;
  z-index: 1000;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--flutuante);
  box-shadow: var(--shadow);
  font-size: 12.5px;
  color: var(--txt-2);
}
#map .barra-desenho[hidden] { display: none; }
#map .barra-dica { line-height: 1.35; }
#map .barra-botoes { display: flex; gap: 6px; flex: none; }
#map .barra-botoes button {
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
#map .barra-botoes button:hover { background: var(--bg-2); }
#map .barra-botoes button.primario { border-color: var(--brand-dk); background: var(--brand-dk); color: #fff; }
#map .barra-botoes button[hidden] { display: none; }
#map .resumo-mapa.oculto-desenho { display: none !important; }

/* Resumo do resultado sobre o mapa: só no celular */
#map .resumo-mapa {
  display: none;
  margin: 0 0 10px 10px;
  padding: 8px 12px;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--flutuante);
  box-shadow: 0 2px 10px rgba(17, 24, 31, .16);
  font-size: 12.5px;
  color: var(--txt-2);
}
#map .resumo-mapa span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
#map .resumo-mapa b { color: var(--txt); font-variant-numeric: tabular-nums; }
#map .resumo-mapa i { width: 10px; height: 10px; border-radius: 2px; }
#map .resumo-mapa i.agua { background: var(--agua); }
#map .resumo-mapa i.edif { border: 2px solid var(--edif); }

/* ---------------------------------------------------------------- Tutorial */
dialog.tutorial {
  position: fixed;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(17, 24, 31, .2);
  color: var(--txt);
  overflow: auto;
}
dialog.tutorial::backdrop { background: rgba(24, 28, 32, .45); }
.tut-midia { background: var(--bg-2); border-bottom: 1px solid var(--line-soft); }
.tut-midia img { display: block; width: 100%; height: auto; aspect-ratio: 1280 / 760; object-fit: cover; }
.tut-corpo { padding: 18px 24px 4px; min-height: 132px; }
.tut-contador { font-size: 11.5px; font-weight: 700; color: var(--brand-tx); text-transform: uppercase; letter-spacing: .04em; }
.tut-corpo h2 { margin: 4px 0 8px; font-size: 18px; letter-spacing: -.01em; }
.tut-corpo p { margin: 0; font-size: 13.5px; line-height: 1.55; color: var(--txt-2); }
.tut-limites { margin-top: 14px; padding: 12px 14px; border: 1px solid var(--bd-info); border-radius: var(--radius); background: var(--bg-info); }
.tut-limites[hidden] { display: none; }
.tut-limites-tit { display: block; margin-bottom: 8px; font-size: 11.5px; font-weight: 700; color: var(--tx-info); text-transform: uppercase; letter-spacing: .04em; }
.tut-limites-grade { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.tut-limites-grade div { display: flex; flex-direction: column; gap: 2px; }
.tut-limites-grade b { font-size: 18px; color: var(--txt); letter-spacing: -.01em; }
.tut-limites-grade span { font-size: 12px; line-height: 1.4; color: var(--txt-2); }
.tut-corpo .tut-limites p { font-size: 12.5px; line-height: 1.5; }
.tut-rodape {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 14px 24px 18px;
}
.tut-rodape label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--txt-2); cursor: pointer; }
.tut-rodape input { accent-color: var(--brand-dk); }
.tut-pontos { display: flex; gap: 6px; }
.tut-pontos span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); transition: background .15s, width .15s; }
.tut-pontos span.ativo { width: 18px; border-radius: 4px; background: var(--brand); }
.tut-botoes { display: flex; justify-content: flex-end; gap: 8px; }
.tut-botoes .btn-primario { width: auto; min-height: 38px; padding: 8px 18px; font-size: 13px; }
.tut-fechar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 8px rgba(17, 24, 31, .2);
  color: var(--txt);
  cursor: pointer;
}
.tut-fechar:hover { background: #fff; }
.tut-fechar svg { width: 16px; height: 16px; }

@media (max-width: 600px) {
  .tut-corpo { padding: 14px 16px 4px; }
  .tut-rodape { grid-template-columns: 1fr; gap: 10px; padding: 12px 16px 16px; }
  .tut-pontos { display: none; }
  .tut-botoes { justify-content: space-between; }
}

/* ---------------------------------------------------------------- Celular */
@media (max-width: 768px) {
  body { flex-direction: column-reverse; overflow: auto; height: auto; min-height: 100%; }
  #map { flex: none; width: 100%; height: 58vh; min-height: 320px; }
  #painel { width: 100%; height: auto; border-right: 0; border-top: 1px solid var(--line); }
  .painel-corpo { overflow: visible; }
  #map .resumo-mapa:not([hidden]) { display: flex; }
  #map .barra-desenho { flex-direction: column; align-items: stretch; gap: 8px; bottom: 16px; width: calc(100% - 24px); padding: 10px; }
  #map .barra-botoes button { flex: 1; min-height: 40px; }
  #map .leaflet-control-scale { display: none; }   /* a escala disputaria o canto com o resumo */
  .painel-topo { padding: 14px 20px 12px; }
  .painel-topo h1 { margin-top: 10px; }
}
