/* =========================================================
   MAPA DOS TERRITÓRIOS (tela cheia)
========================================================= */
.tmap{ position: fixed; inset: 0; z-index: 500; display: none; background: var(--paper); }
.tmap.show{ display: block; }
body.tmap-open{ overflow: hidden; }
#tmapCanvas{ position: absolute; inset: 0; z-index: 1; }

.tmap-top{
  position: absolute; z-index: 20; top: calc(10px + env(safe-area-inset-top, 0px)); left: 10px; right: 10px;
  display: flex; gap: 8px; align-items: flex-start;
}
.tmap-icon{
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .96);
  font-size: 18px; color: var(--ink); cursor: pointer;
  box-shadow: 0 6px 16px rgba(28, 36, 48, .16);
}
.tmap-search-wrap{ position: relative; flex: 1; }
#tmapSearch{
  width: 100%; height: 44px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 14px;
  background: rgba(255, 255, 255, .96); font-size: 15px; font-family: var(--font-ui);
  box-shadow: 0 6px 16px rgba(28, 36, 48, .16); outline: none;
}
#tmapSearch:focus{ border-color: var(--brand); box-shadow: var(--focus); }
.tmap-results{
  display: none; position: absolute; top: 50px; left: 0; right: 0;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-float); max-height: 50vh; overflow-y: auto;
}
.tmap-results.show{ display: block; }
.tmap-result{ padding: 12px 14px; font-size: 14px; line-height: 1.4; border-bottom: 1px solid var(--line); cursor: pointer; }
.tmap-result:last-child{ border-bottom: none; }
.tmap-result:hover{ background: var(--paper); }

.tmap-title{
  position: absolute; z-index: 15; top: calc(64px + env(safe-area-inset-top, 0px)); left: 50%; transform: translateX(-50%);
  margin: 0; padding: 6px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, .95); border: 1px solid var(--line);
  font-size: 14px; font-weight: 700; white-space: nowrap; max-width: 80%; overflow: hidden; text-overflow: ellipsis;
}
.tmap-hint{
  display: none; position: absolute; z-index: 15; left: 50%; transform: translateX(-50%);
  top: calc(108px + env(safe-area-inset-top, 0px));
  margin: 0; padding: 8px 14px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 6px 16px rgba(11, 42, 99, .3);
}

/* Cartões de baixo */
.tmap-info, .tmap-form{
  display: none; position: absolute; z-index: 20; left: 10px; right: 10px;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  background: #fff; border-radius: var(--radius-lg); border: 1px solid var(--line);
  box-shadow: var(--shadow-float); padding: 16px 18px;
  max-height: 55vh; overflow-y: auto;
}
.tmap-info.show, .tmap-form.show{ display: block; animation: ch-rise .3s ease both; }
.tmap-info-head, .tmap-form-head{ display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.tmap-info-name{ margin: 0 0 6px; font-size: 17px; font-weight: 700; }
.tmap-info-line{ margin: 4px 0 0; font-size: 14px; color: var(--ink-soft); }
.tmap-warn{ color: var(--amber); font-weight: 600; }
.tmap-info .btn, .tmap-form .btn{ width: 100%; margin-top: 12px; }
.tmap-form .wp-field{ margin-top: 10px; }

.tmap-bottom{
  position: absolute; z-index: 20; left: 10px; right: 10px;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, .97); border: 1px solid var(--line); box-shadow: var(--shadow-float);
}
.tmap-bottom .btn{ min-height: 44px; }
.tmap-view-only .btn{ width: 100%; }
.tmap-count{ font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }
.tmap-draw-actions{ display: flex; gap: 8px; flex: 1; justify-content: flex-end; flex-wrap: wrap; }
.tmap[data-mode="view"] .tmap-draw-only{ display: none; }
.tmap[data-mode="draw"] .tmap-view-only{ display: none; }
.tmap[data-mode="form"] .tmap-bottom{ display: none; }
.tmap[data-mode="form"] .tmap-form{ bottom: calc(14px + env(safe-area-inset-bottom, 0px)); max-height: 72vh; }
.tmap[data-mode="form"] .tmap-hint{ display: none; }
.tmap[data-mode="draw"] #tmapCanvas{ cursor: crosshair; }

.territory-name .has-map{ font-size: 13px; }
.leaflet-container{ font-family: var(--font-ui); }

@media (max-width: 480px){
  .tmap-draw-actions{ justify-content: space-between; }
  .tmap-draw-actions .btn{ flex: 1 1 calc(50% - 8px); }
  .tmap-count{ width: 100%; }
}
