/* ==========================================================================
   GEOPORTAL PILOTO | WEBGIS
   Layout com mapa em tela cheia e painéis flutuantes
   ========================================================================== */

/* Sistema visual documentado em design-system/geoportal/MASTER.md
   Base: skill "UI UX Pro Max" — Minimalismo suíço + vidro discreto,
   azul de confiança como cor única + dourado só para "selecionado". */
:root {
  --primary: #0077b6;
  --primary-hover: #005f92;
  --primary-light: #e6f1f8;
  --accent: #e0a800;          /* dourado: seleção / filtro ativo */
  --accent-light: #fff6d6;
  --accent-text: #7a5b00;
  --warning: #e0a800;
  --danger: #c2410c;

  /* Tema claro (padrão) */
  --bg-main: #e5e9ef;
  --bg-surface: #ffffff;
  --bg-surface-trans: rgba(255, 255, 255, 0.9);
  --bg-elevated: #f2f4f7;
  --border-color: #e3e7ed;
  --border-glass: rgba(255, 255, 255, 0.6);
  --border-focus: #7cb9db;

  --text-main: #0b1726;
  --text-muted: #556274;     /* 6,1:1 sobre branco */
  --text-light: #6b7889;     /* 4,6:1 sobre branco */

  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, "Cascadia Mono", Consolas, monospace;

  --panel-width: 344px;
  --gap: 12px;

  --shadow-float: 0 1px 2px rgb(11 23 38 / 0.06), 0 8px 24px rgb(11 23 38 / 0.12);
  --shadow-pop: 0 16px 40px rgb(11 23 38 / 0.2);
  --focus-ring: 0 0 0 3px rgba(0, 119, 182, 0.45);

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Tema escuro */
body.dark-mode {
  --primary: #3aa0d8;
  --primary-hover: #63b6e3;
  --primary-light: rgba(58, 160, 216, 0.16);
  --accent-light: rgba(224, 168, 0, 0.16);
  --accent-text: #f5cf5c;

  --bg-main: #0a1019;
  --bg-surface: #111a26;
  --bg-surface-trans: rgba(17, 26, 38, 0.88);
  --bg-elevated: #1a2534;
  --border-color: #253244;
  --border-glass: rgba(255, 255, 255, 0.08);
  --border-focus: #3aa0d8;

  --text-main: #eef2f7;
  --text-muted: #a3afbf;
  --text-light: #8592a3;

  --shadow-float: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.45);
  --focus-ring: 0 0 0 3px rgba(58, 160, 216, 0.5);
}

/* Foco visível para quem navega pelo teclado (sem aparecer no clique do mouse) */
button:focus-visible,
select:focus-visible,
input:focus-visible,
.basemap-card:focus-visible,
.quadra-row:focus-visible,
.upload-box:focus-within {
  outline: none;
  box-shadow: var(--focus-ring);
}

button,
select,
.basemap-card,
.quadra-row,
.upload-box,
.switch {
  cursor: pointer;
}

/* Respeita quem pediu "reduzir movimento" no sistema */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

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

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  overflow: hidden;
  font-size: 14px;
}

button, input, select {
  font-family: inherit;
}

/* Ícones SVG */
.icon-svg {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.icon-svg svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

/* Base comum de todo elemento flutuante sobre o mapa */
.panel,
.top-actions .btn-pill,
.btn-group,
.btn-stack,
.measure-btn,
.measure-menu,
.basemap-toggle,
.basemap-options,
.coords-chip,
.map-hint,
.attribute-drawer,
.active-filter-banner {
  background: var(--bg-surface-trans);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-float);
}

/* ==========================================================================
   MAPA EM TELA CHEIA
   ========================================================================== */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: var(--bg-main);
  outline: none !important;
  -webkit-tap-highlight-color: transparent !important;
  user-select: none;
  -webkit-user-select: none;
}

/* Remove contornos de foco ao clicar/arrastar o mapa */
#map:focus,
#map:focus-visible,
.leaflet-container,
.leaflet-container:focus,
.leaflet-pane,
.leaflet-pane svg,
.leaflet-pane svg path,
path.leaflet-interactive,
path.leaflet-interactive:focus,
path.leaflet-interactive:focus-visible,
.leaflet-interactive,
.leaflet-interactive:focus,
.leaflet-tile {
  outline: none !important;
  -webkit-tap-highlight-color: transparent !important;
}

/* Escala e créditos do Leaflet discretos */
.leaflet-control-scale-line {
  background: var(--bg-surface-trans);
  border-color: var(--text-muted);
  color: var(--text-main);
  font-size: 10px;
}

.leaflet-control-attribution {
  background: var(--bg-surface-trans) !important;
  color: var(--text-muted) !important;
  font-size: 10px;
  border-radius: 6px 0 0 0;
}

.leaflet-control-attribution a {
  color: var(--text-muted) !important;
}

.leaflet-bottom.leaflet-right .leaflet-control-scale {
  margin-right: 64px;
  margin-bottom: 8px;
}

/* ==========================================================================
   PAINEL PRINCIPAL FLUTUANTE
   ========================================================================== */
.panel {
  position: fixed;
  top: var(--gap);
  left: var(--gap);
  width: min(var(--panel-width), calc(100vw - 2 * var(--gap)));
  max-height: calc(100vh - 2 * var(--gap) - 64px);
  border-radius: var(--radius-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: max-height 0.25s ease;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 10px 14px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-info {
  flex: 1;
  min-width: 0;
}

.brand-info h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-info p {
  font-size: 12px;
  color: var(--text-muted);
}

.panel-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

/* Painel recolhido: ficam visíveis só o título e a busca */
.panel.collapsed .sidebar-tabs,
.panel.collapsed .sidebar-content {
  display: none;
}

.panel.collapsed .search-container {
  padding-bottom: 12px;
}

/* Recolhido, o painel é baixinho: deixa a lista de resultados da busca "vazar" para fora */
.panel.collapsed {
  overflow: visible;
}

/* Busca */
.search-container {
  position: relative;
  padding: 0 12px 10px;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrapper .search-icon {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 9px 34px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--bg-elevated);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
  transition: var(--transition);
}

.search-input::placeholder {
  color: var(--text-light);
}

.search-input:focus {
  border-color: var(--primary);
  background: var(--bg-surface);
  box-shadow: var(--focus-ring);
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  padding: 2px;
}

.search-results-dropdown {
  position: absolute;
  top: calc(100% - 4px);
  left: 12px;
  right: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  max-height: 300px;
  overflow-y: auto;
  z-index: 2000;
  display: none;
}

.search-result-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: var(--transition);
}

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

.search-result-item:hover {
  background: var(--bg-elevated);
}

.search-result-title {
  font-size: 13px;
  font-weight: 600;
}

.search-result-desc {
  font-size: 12px;
  color: var(--text-muted);
}

/* Abas em formato "segmentado" */
.sidebar-tabs {
  display: flex;
  gap: 2px;
  margin: 0 12px;
  padding: 3px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
}

.tab-btn {
  flex: 1;
  padding: 6px 2px;
  background: none;
  border: none;
  border-radius: 7px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.tab-btn:hover {
  color: var(--text-main);
}

.tab-btn.active {
  background: var(--bg-surface);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 3px rgb(15 23 42 / 0.12);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  min-height: 0;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Rótulo de seção no estilo suíço: pequeno, caixa-alta, espaçado */
.section-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 16px 0 8px;
}

.section-title:first-child {
  margin-top: 0;
}

/* Textos de orientação (deixam o portal "autoexplicativo") */
.hint-text {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field-select {
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
}

.field-select:focus {
  border-color: var(--primary);
}

/* ==========================================================================
   BOTÕES
   ========================================================================== */
.btn-ghost {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition);
}

.btn-ghost:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.btn-icon:hover {
  background: var(--bg-elevated);
  color: var(--primary);
}

.btn-pill {
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
}

.btn-pill:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-pill.full {
  width: 100%;
}

.btn-pill.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-pill.primary:hover {
  background: var(--primary-hover);
}

.btn-pill.warning {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-pill.danger {
  color: var(--danger);
}

.btn-pill.danger:hover {
  border-color: var(--danger);
}

/* ==========================================================================
   LISTA DE CAMADAS
   ========================================================================== */
.layers-manager-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

.layer-card {
  border-radius: var(--radius-md);
  transition: var(--transition);
}

.layer-card:hover {
  background: var(--bg-elevated);
}

.layer-header {
  padding: 8px 6px 8px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.layer-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.layer-swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 2px solid;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgb(15 23 42 / 0.15);
}

.layer-title {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-badge {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

/* Ações aparecem suavemente ao passar o mouse, sem roubar espaço do nome */
.layer-header {
  position: relative;
}

.layer-actions {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  padding-left: 16px;
  background: linear-gradient(to right, transparent, var(--bg-elevated) 14px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.layer-card:hover .layer-actions,
.layer-card:focus-within .layer-actions {
  opacity: 1;
  pointer-events: auto;
}

.layer-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.layer-btn:hover {
  color: var(--primary);
  background: var(--bg-surface);
}

.layer-btn:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Painel de estilo da camada */
.layer-style-drawer {
  margin: 0 8px 8px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: none;
  flex-direction: column;
  gap: 10px;
}

.layer-style-drawer.open {
  display: flex;
}

.style-control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
}

.style-control-row label {
  color: var(--text-muted);
}

.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-input {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: none;
}

.color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-input::-webkit-color-swatch {
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 50%;
}

.slider-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 58%;
}

.style-slider {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.val-badge {
  font-size: 11px;
  font-weight: 600;
  min-width: 34px;
  text-align: right;
}

/* Chave liga/desliga */
.switch {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 17px;
  flex-shrink: 0;
}

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

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #cbd5e1;
  transition: 0.2s;
  border-radius: 20px;
}

body.dark-mode .slider {
  background-color: #334155;
}

.slider:before {
  position: absolute;
  content: "";
  height: 13px;
  width: 13px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(13px);
}

/* Upload de GeoJSON externo */
.upload-box {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.upload-box:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.upload-title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--primary);
}

.upload-desc {
  font-size: 11px;
  color: var(--text-muted);
}

.upload-box input {
  display: none;
}

.upload-formats {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Mensagem de resultado ao adicionar uma camada */
.upload-status {
  font-size: 12px;
  line-height: 1.45;
  margin-top: 6px;
  color: var(--text-muted);
}

.upload-status:empty {
  display: none;
}

.upload-status.ok { color: #2f855a; }
.upload-status.error { color: var(--danger); }
.upload-status.warn { color: var(--accent-text); }

.upload-note {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 2px;
}

/* Camada DXF usando as cores das layers do CAD: amostra "colorida" */
.layer-swatch.temp.cad {
  background: conic-gradient(#ef4444, #eab308, #22c55e, #3b82f6, #a855f7, #ef4444) !important;
  border-style: solid;
  border-color: var(--border-color) !important;
}
body.dark-mode .upload-status.ok { color: #68d391; }

/* Ortomosaicos: ícone de imagem no lugar da amostra de cor */
.ortho-swatch {
  display: inline-flex;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--primary);
}
.ortho-swatch svg { width: 100%; height: 100%; }

/* --------------------------------------------------------------------------
   CAMADAS TEMPORÁRIAS: visual "provisório" (borda tracejada, mais apagado)
   -------------------------------------------------------------------------- */
.temp-section {
  margin: 4px 0 12px;
}

.layer-card.temp {
  border: 1px dashed var(--border-color);
  background: transparent;
}

.layer-card.temp .layer-title {
  color: var(--text-muted);
  font-style: italic;
}

.layer-card.temp:hover {
  background: var(--bg-elevated);
}

.layer-swatch.temp {
  border-style: dashed;
}

.temp-title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.temp-meta {
  font-size: 11px;
  color: var(--text-light);
}

.layer-btn.danger:hover {
  color: var(--danger);
}

.temp-alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-top: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--accent-light);
  color: var(--accent-text);
  font-size: 11.5px;
  line-height: 1.45;
}

.temp-alert .icon-svg {
  margin-top: 1px;
}

.popup-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 0;
}

/* Tela que aparece ao arrastar um arquivo sobre a página */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 119, 182, 0.18);
  border: 3px dashed var(--primary);
  pointer-events: none;
}

.drop-overlay.show {
  display: flex;
}

.drop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 28px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  box-shadow: var(--shadow-pop);
  color: var(--text-main);
  text-align: center;
}

.drop-card .icon-svg {
  width: 28px;
  height: 28px;
  color: var(--primary);
}

.drop-card b {
  font-size: 15px;
  font-weight: 600;
}

.drop-card small {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   BARRA DE AÇÕES (TOPO DIREITO)
   ========================================================================== */
.top-actions {
  position: fixed;
  top: var(--gap);
  right: var(--gap);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-actions .btn-pill {
  height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-lg);
}

.top-actions .btn-pill:hover {
  background: var(--bg-surface);
}

.top-actions .btn-pill.active {
  background: var(--primary);
  color: #fff;
}

.btn-group {
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius-lg);
}

/* Banner de filtro ativo */
.active-filter-banner {
  position: fixed;
  top: var(--gap);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  border-radius: var(--radius-full);
  padding: 8px 8px 8px 16px;
  font-size: 13px;
  display: none;
  align-items: center;
  gap: 10px;
}

.active-filter-banner button {
  background: var(--bg-elevated);
  border: none;
  border-radius: var(--radius-full);
  padding: 4px 10px;
  color: var(--text-main);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.active-filter-banner button:hover {
  color: var(--danger);
}

/* ==========================================================================
   CONTROLES DE NAVEGAÇÃO (DIREITA, BASE)
   ========================================================================== */
.floating-tools {
  position: fixed;
  right: var(--gap);
  bottom: 36px;
  z-index: 950; /* acima do seletor de mapa de fundo, para o menu "Medir" não ficar por trás */
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-stack {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.map-control-btn {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.map-control-btn + .map-control-btn {
  border-top: 1px solid var(--border-color);
}

.map-control-btn:hover {
  background: var(--bg-elevated);
  color: var(--primary);
}

/* --------------------------------------------------------------------------
   FERRAMENTA DE MEDIÇÃO (botão "Medir" + menu Distância / Área)
   -------------------------------------------------------------------------- */
.measure-tool {
  position: relative;
}

/* Mesmo visual dos outros botões do topo, um pouco mais comprido */
.top-actions .measure-btn {
  padding: 0 18px;
  gap: 6px;
}

a.btn-pill { text-decoration: none; }  /* botão "3D" é um link */

.measure-btn .icon-svg + .icon-svg {
  margin-left: -2px;
}

.top-actions .measure-btn.active,
.top-actions .measure-btn.active:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.measure-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 170px;
  padding: 6px;
  border-radius: var(--radius-md);
  display: none;
  flex-direction: column;
  gap: 2px;
}

.measure-tool.open .measure-menu {
  display: flex;
}

.measure-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-main);
  text-align: left;
  transition: var(--transition);
}

.measure-menu button:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.measure-menu b {
  font-size: 13px;
  font-weight: 600;
}

/* Enquanto mede: cursor em cruz e as camadas não recebem cliques nem popups */
#map.measuring,
#map.measuring .leaflet-grab {
  cursor: crosshair;
}

#map.measuring .leaflet-interactive {
  pointer-events: none !important;
}

/* Barra de vidro no topo com o valor da medição em tempo real (discreta) */
.measure-live {
  position: fixed;
  top: var(--gap);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1050;
  display: none;
  align-items: center;
  gap: 9px;
  height: 46px;
  padding: 0 6px 0 16px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.75);   /* meio-termo: vidro, mas legível */
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 4px 18px rgb(11 23 38 / 0.16);
  white-space: nowrap;
  font-family: var(--font-sans);
}

body.dark-mode .measure-live {
  background: rgba(17, 26, 38, 0.78);
  border-color: rgba(255, 255, 255, 0.12);
}

.measure-live.show {
  display: flex;
}

.measure-live-icon {
  color: #ef4444;
  width: 18px;
  height: 18px;
}

.measure-live-kind {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-muted);
}

.measure-live-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
  padding-right: 4px;
}

.measure-live-help {
  font-size: 13.5px;
  color: var(--text-main);
  padding-right: 4px;
}

/* Botões bem visíveis: ✓ azul cheio (concluir) e ✕ cinza (cancelar, fica vermelho ao passar o mouse) */
.measure-live-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  box-shadow: inset 0 0 0 1px var(--border-color);
}

.measure-live-btn svg {
  width: 17px;
  height: 17px;
}

.measure-live-btn:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: none;
}

.measure-live-btn.ok {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 119, 182, 0.35);
}

.measure-live-btn.ok:hover {
  background: var(--primary-hover);
}

/* --------------------------------------------------------------------------
   OSCILAR: menu de escolha (A e B) e barra de vidro com o controle A ⟷ B
   -------------------------------------------------------------------------- */
.top-actions .measure-btn#btn-swap.active,
.top-actions .measure-btn#btn-swap.active:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.swap-menu {
  min-width: 250px;
  padding: 12px;
  gap: 8px;
}

.swap-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.swap-field .field-select {
  flex: 1;
  margin: 0;
}

.swap-tag {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
}

.swap-tag.b {
  background: #E0A800;
}

.measure-menu button.swap-start {
  justify-content: center;
  margin-top: 2px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
}

.measure-menu button.swap-start:hover {
  background: var(--primary-hover);
  color: #fff;
}

.swap-error:empty {
  display: none;
}

.swap-error,
.swap-empty {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.swap-live {
  top: auto;
  bottom: 84px;   /* embaixo, acima da dica e das coordenadas (não cobre os botões do topo) */
  padding: 0 6px;
  gap: 6px;
}

.swap-side {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px 0 6px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
}

.swap-side:hover {
  background: var(--bg-elevated);
}

.swap-side.on {
  color: var(--text-main);
  font-weight: 600;
}

.swap-side:not(.on) .swap-tag {
  opacity: 0.45;
}

.swap-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.swap-range {
  -webkit-appearance: none;
  appearance: none;
  width: 140px;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--primary), #E0A800);
  cursor: pointer;
}

.swap-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--text-main);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.3);
}

/* Botão "Janela" com cara de botão: contorno e texto azuis (desligado) e azul cheio (ligado) */
.swap-lens-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  height: 34px;
  padding: 0 12px 0 10px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  box-shadow: inset 0 0 0 1.5px var(--primary);
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  transition: var(--transition);
}

.swap-lens-btn svg {
  width: 16px;
  height: 16px;
}

.swap-lens-btn:hover {
  background: var(--primary);
  color: #fff;
}

.swap-lens-btn.on {
  background: var(--primary);
  color: #fff;
  box-shadow: none;
}

/* No modo janela o controle A ⟷ B dá lugar à forma e ao tamanho da janela */
.swap-live.lens-on .swap-side {
  opacity: 0.45;
}

.swap-live.lens-on .swap-range {
  display: none;
}

.swap-lens-opts {
  display: none;
  align-items: center;
  gap: 2px;
}

.swap-live.lens-on .swap-lens-opts {
  display: flex;
}

.swap-shape {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.swap-shape svg {
  width: 16px;
  height: 16px;
}

.swap-shape:hover {
  background: var(--bg-elevated);
}

.swap-shape.on {
  color: var(--primary);
  background: var(--primary-light);
}

.swap-size {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  margin: 0 6px;
  border-radius: 2px;
  background: rgb(11 23 38 / 0.22);
  cursor: pointer;
}

body.dark-mode .swap-size {
  background: rgb(255 255 255 / 0.28);
}

.swap-size::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);
}

.swap-size::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
}

/* Moldura da janela que segue o cursor (o recorte da imagem B é feito no JS) */
.swap-lens-frame {
  position: absolute;
  z-index: 650;
  pointer-events: none;
  border: 2px solid #fff;
  border-radius: 4px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.35), 0 6px 20px rgb(0 0 0 / 0.3);
}

.swap-lens-frame .swap-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.35);
}

.swap-lens-frame.circle {
  border-radius: 50%;
}

.swap-lens-frame.circle .swap-tag {
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
}

#map.swap-lens,
#map.swap-lens .leaflet-grab {
  cursor: crosshair;
}

.swap-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--text-main);
}

/* Rótulo com o valor de cada medição salva (centralizado no ponto) */
.measure-label-icon {
  background: none;
  border: none;
}

.measure-label {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(11, 23, 38, 0.88);
  color: #ffffff;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.3);
  pointer-events: none;
}

/* Lado do rótulo em relação ao meio da linha (para não cobrir o traço) */
.measure-label.center  { transform: translate(-50%, -50%); }
.measure-label.above   { transform: translate(-50%, calc(-100% - 8px)); }
.measure-label.right   { transform: translate(10px, -50%); }
.measure-label.upleft  { transform: translate(calc(-100% - 6px), calc(-100% - 6px)); }
.measure-label.upright { transform: translate(6px, calc(-100% - 6px)); }

/* Medições na lista de camadas temporárias */
.measure-swatch {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  color: #ef4444;
  display: inline-flex;
}

.measure-swatch svg {
  width: 100%;
  height: 100%;
}

.layer-card.measure .temp-meta {
  color: var(--text-muted);
}

.temp-clear-btn {
  display: block;
  margin: 6px 0 0 auto;
  padding: 4px 8px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 12px;
  text-decoration: underline;
}

.temp-clear-btn:hover {
  color: var(--danger);
}

/* ==========================================================================
   SELETOR DE MAPA DE FUNDO (ESQUERDA, BASE)
   ========================================================================== */
.basemap-widget {
  position: fixed;
  left: var(--gap);
  bottom: var(--gap);
  z-index: 900;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.basemap-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 14px 5px 5px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-main);
  text-align: left;
  transition: var(--transition);
}

.basemap-toggle:hover {
  border-color: var(--primary);
}

.basemap-thumb {
  width: 38px;
  height: 38px;
  border-radius: 7px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
}

.basemap-toggle-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.basemap-toggle-text small {
  font-size: 11px;
  color: var(--text-muted);
}

.basemap-toggle-text b {
  font-size: 13px;
  font-weight: 600;
}

.basemap-options {
  display: none;
  grid-template-columns: repeat(3, 76px);
  gap: 6px;
  padding: 6px;
  border-radius: var(--radius-md);
}

.basemap-widget.open .basemap-options {
  display: grid;
}

.basemap-card {
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}

.basemap-card:hover {
  border-color: var(--border-focus);
}

.basemap-card.active {
  border-color: var(--primary);
}

/* Miniatura real (um ladrilho do próprio mapa); a cor de fundo aparece enquanto carrega */
.basemap-preview,
.basemap-thumb {
  background-color: var(--bg-elevated);
  background-size: cover;
  background-position: center;
}

.basemap-preview {
  height: 52px;
}

.basemap-card-label {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 2px 5px;
  background: var(--bg-surface);
  line-height: 1.2;
  display: flex;
  flex-direction: column;
}

.basemap-card-label small {
  font-size: 10px;
  font-weight: 400;
  color: var(--text-muted);
}

/* Miniaturas ilustrativas */
.preview-satellite {
  background: radial-gradient(circle at 70% 30%, #4d7c3a 0%, #2f4f2a 45%, #1c2e1a 100%);
  position: relative;
  overflow: hidden;
}

.preview-satellite::after {
  content: "";
  position: absolute;
  top: 45%; left: -10px; right: -10px; height: 3px;
  background: rgba(226, 232, 240, 0.6);
  transform: rotate(-15deg);
}

.preview-osm {
  background: #f2efe9;
  position: relative;
  overflow: hidden;
}

.preview-osm::before {
  content: "";
  position: absolute;
  top: 35%; left: 0; right: 0; height: 5px;
  background: #fcd6a4;
}

.preview-osm::after {
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 28%;
  background: #aad3df;
}

.preview-osm-road2 {
  position: absolute;
  top: 0; bottom: 0; left: 50%; width: 4px;
  background: #ffffff;
}

.preview-osm-road1,
.preview-osm-water {
  display: none;
}

.preview-positron {
  background: #fafafa;
  position: relative;
  overflow: hidden;
}

.preview-positron-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, #e5e7eb 1px, transparent 1px),
    linear-gradient(to bottom, #e5e7eb 1px, transparent 1px);
  background-size: 12px 12px;
}

.preview-positron-block {
  position: absolute;
  top: 25%; left: 30%; width: 35%; height: 35%;
  background: #eef0f2;
  border: 1px solid #d1d5db;
}

/* ==========================================================================
   DICA E COORDENADAS (CENTRO, BASE)
   ========================================================================== */
.bottom-center {
  position: fixed;
  left: 50%;
  bottom: var(--gap);
  transform: translateX(-50%);
  z-index: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.map-hint {
  border-radius: var(--radius-full);
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}

.map-hint.hidden {
  opacity: 0;
  visibility: hidden;
}

.map-hint b {
  color: var(--danger);
}

/* Botões dentro do aviso (ex.: "Concluir" da medição) */
.hint-btn {
  pointer-events: auto;
  margin-left: 6px;
  padding: 4px 12px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.hint-btn.ghost {
  background: var(--bg-elevated);
  color: var(--text-main);
}

/* Filtro ativo usa o dourado de "selecionado" + um ponto (não depende só da cor) */
.active-filter-banner::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

.active-filter-banner b {
  color: var(--accent-text);
}

.coords-chip {
  border-radius: var(--radius-full);
  padding: 4px 12px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.coords-chip b {
  color: var(--text-main);
  font-weight: 600;
}

.coords-chip .sep {
  color: var(--text-light);
}

/* ==========================================================================
   TABELA DE ATRIBUTOS (GAVETA FLUTUANTE)
   ========================================================================== */
.attribute-drawer {
  position: fixed;
  left: var(--gap);
  right: var(--gap);
  bottom: var(--gap);
  height: 42vh;
  min-height: 260px;
  border-radius: var(--radius-lg);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(calc(100% + 24px));
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: var(--bg-surface);
}

.attribute-drawer.open {
  transform: translateY(0);
}

.drawer-header {
  padding: 10px 10px 6px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.drawer-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.drawer-title {
  font-size: 14px;
  font-weight: 600;
}

.drawer-layer-select,
.drawer-search {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  font-size: 13px;
  outline: none;
}

.drawer-search {
  width: 200px;
}

.drawer-layer-select:focus,
.drawer-search:focus {
  border-color: var(--primary);
}

.drawer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.drawer-hint {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 16px 8px;
}

.table-responsive {
  flex: 1;
  overflow: auto;
  border-top: 1px solid var(--border-color);
}

.attr-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.attr-table th {
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.attr-table td {
  padding: 7px 14px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.attr-table tr:hover td {
  background: var(--primary-light);
  cursor: pointer;
}

/* ==========================================================================
   ESTATÍSTICAS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.stat-card {
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 3px solid var(--primary);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.quadras-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.quadra-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}

.quadra-row b {
  font-weight: 500;
}

.quadra-row:hover {
  background: var(--primary-light);
  color: var(--primary);
}

/* Medição */
.measure-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
  margin-bottom: 12px;
}

#measure-output > div {
  border-radius: var(--radius-md);
}

/* Ajuda */
.help-list {
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.help-list b {
  font-weight: 600;
}

.about-text {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-muted);
}

/* ==========================================================================
   POPUP DO MAPA
   ========================================================================== */
.leaflet-popup-content-wrapper {
  border-radius: 14px !important;
  box-shadow: var(--shadow-pop) !important;
  background: var(--bg-surface) !important;
  color: var(--text-main) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-tip {
  background: var(--bg-surface) !important;
}

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
  font-family: var(--font-sans);
}

.leaflet-container a.leaflet-popup-close-button {
  top: 10px;
  right: 10px;
  color: var(--text-muted);
}

.custom-popup {
  min-width: 250px;
  max-width: 300px;
}

/* Cabeçalho limpo: fundo neutro e um traço colorido identificando a camada */
.popup-header {
  --popup-accent: #0077b6;
  background: var(--bg-surface) !important;
  color: var(--text-main);
  padding: 14px 36px 8px 16px;
  border-left: 4px solid var(--popup-accent);
  margin-top: 12px;
}

.popup-header.quadra { --popup-accent: #1e3a5f; }
.popup-header.app { --popup-accent: #2f855a; }
.popup-header.curso { --popup-accent: #38bdf8; }
.popup-header.implantacao { --popup-accent: #94a3b8; }

.popup-title {
  font-size: 15px;
  font-weight: 600;
}

.popup-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

.popup-body {
  padding: 6px 16px 12px;
}

.popup-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.popup-table tr {
  border-bottom: 1px solid var(--border-color);
}

.popup-table tr:last-child {
  border-bottom: none;
}

.popup-table td {
  padding: 6px 0;
}

.popup-table td.label {
  color: var(--text-muted);
}

.popup-table td.value {
  font-weight: 500;
  text-align: right;
}

.popup-footer {
  padding: 0 16px 14px;
  display: flex;
  gap: 6px;
}

.popup-btn {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.popup-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* Tooltip ao passar o mouse */
.leaflet-tooltip {
  border-radius: 8px;
  border: none;
  box-shadow: var(--shadow-float);
  font-family: var(--font-sans);
  font-size: 12px;
}

/* Rótulos do Mapa */
.map-label {
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  text-align: center;
}

.map-label-quadra {
  background: rgba(11, 37, 64, 0.88);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
}

/* ==========================================================================
   MODAL
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(3px);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-pop);
  overflow: hidden;
}

.modal-header {
  padding: 16px 16px 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 4px 20px 16px;
  max-height: 70vh;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.7;
}

.modal-body b {
  font-weight: 600;
}

.modal-footer {
  padding: 0 20px 16px;
  display: flex;
  justify-content: flex-end;
}

/* Textos diferentes para quem usa mouse e para quem usa o dedo */
.only-touch {
  display: none;
}

/* ==========================================================================
   TELAS DE TOQUE (celular / tablet): botões sempre visíveis e maiores
   ========================================================================== */
@media (hover: none) {
  .only-mouse {
    display: none;
  }

  .only-touch {
    display: inline;
  }

  .layer-actions {
    position: static;
    transform: none;
    opacity: 1;
    pointer-events: auto;
    background: none;
    padding-left: 0;
  }

  .layer-btn {
    padding: 8px;
  }

  .switch {
    width: 38px;
    height: 22px;
  }

  .slider:before {
    height: 18px;
    width: 18px;
  }

  input:checked + .slider:before {
    transform: translateX(16px);
  }

  .quadra-row {
    padding: 12px 10px;
  }
}

/* ==========================================================================
   TELAS PEQUENAS (celular)
   ========================================================================== */
/* Telas médias (celular deitado, tablet em pé): os botões do topo mostram só os ícones,
   para não ficarem em cima da setinha do painel. O nome aparece ao passar o mouse. */
@media (min-width: 721px) and (max-width: 940px) {
  .top-actions .btn-pill > span:not(.icon-svg) {
    display: none;
  }

  .top-actions .btn-pill,
  .top-actions .measure-btn {
    padding: 0 12px;
  }
}

@media (max-width: 720px) {
  :root {
    --gap: 8px;
  }

  /* Painel ocupa a largura toda no topo; aberto, vai até ~70% da tela */
  .panel {
    width: calc(100vw - 2 * var(--gap));
    max-height: 70vh;
    max-height: 70dvh;
  }

  .search-input {
    font-size: 16px; /* evita o zoom automático do iPhone ao digitar */
  }

  .tab-btn {
    padding: 9px 2px;
    font-size: 13px;
  }

  /* Ações: coluna de botões redondos no canto inferior direito */
  .top-actions {
    top: auto;
    bottom: calc(var(--gap) + 100px);
    right: var(--gap);
    flex-direction: column;
    align-items: flex-end;
    z-index: 900;
  }

  .top-actions .btn-pill {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: var(--radius-md);
  }

  .top-actions .btn-pill span:last-child {
    display: none;
  }

  .btn-group {
    flex-direction: column;
    border-radius: var(--radius-md);
  }

  /* Exportar, tela cheia e "sobre" ficam só no computador (a Ajuda está no painel) */
  #btn-export-map,
  #btn-fullscreen,
  #btn-about {
    display: none;
  }

  .btn-icon {
    width: 36px;
    height: 36px;
  }

  /* No celular o zoom é feito com os dedos: mantém só "início" e "minha localização" */
  .floating-tools {
    bottom: var(--gap);
  }

  .floating-tools .zoom-stack {
    display: none;
  }

  /* Cartão da medição logo abaixo do painel recolhido */
  .measure-live {
    top: 132px;
    max-width: calc(100vw - 2 * var(--gap));
  }

  .swap-live {
    top: 132px;
    bottom: auto;
  }

  .swap-range {
    width: 110px;
  }

  /* No celular só as etiquetas A e B (os nomes não cabem) */
  .swap-name {
    display: none;
  }

  .swap-side {
    padding: 0 6px;
  }

  .swap-lens-btn span {
    display: none;
  }

  .swap-size {
    width: 70px;
  }

  /* No celular o menu "Medir" abre para cima, longe do seletor de mapa de fundo */
  .measure-menu {
    top: auto;
    bottom: 0;
    left: auto;
    right: calc(100% + 8px);
  }

  .map-control-btn {
    width: 44px;
    height: 44px;
  }

  .leaflet-bottom.leaflet-right .leaflet-control-scale {
    display: none;
  }

  .coords-chip {
    display: none;
  }

  /* Dica logo abaixo do painel recolhido, longe dos botões da base */
  .bottom-center {
    top: 132px;
    bottom: auto;
    width: calc(100vw - 2 * var(--gap));
  }

  /* Reordenar camadas fica só no computador; no celular sobra espaço para o nome */
  .btn-order {
    display: none !important;
  }

  .map-hint {
    white-space: normal;
    text-align: center;
    max-width: 100%;
  }

  .basemap-toggle {
    padding-right: 10px;
  }

  /* Tabela: ocupa a parte de baixo da tela inteira */
  .attribute-drawer {
    height: 70vh;
    height: 70dvh;
  }

  .drawer-left {
    width: 100%;
  }

  .drawer-title {
    width: 100%;
  }

  .drawer-search {
    flex: 1;
    min-width: 0;
  }

  .drawer-actions {
    position: absolute;
    top: 8px;
    right: 8px;
  }

  /* Popup do lote mais estreito */
  .custom-popup {
    min-width: 0;
    width: min(280px, calc(100vw - 60px));
  }
}
