/* ==========================================================================
   CAR WebGIS - Estilos Principais e Acessibilidade WCAG AAA
   Conformidade Estrita:
   - Contraste de texto de corpo >= 7:1 (#F1F5F9 sobre #0F291E / #0F172A)
   - Contraste de titulos >= 4.5:1 (#FFFFFF !important)
   - Sem texto escuro sobre fundo escuro e sem texto claro sobre fundo claro
   - Cores canonicas homologadas para camadas ambientais
   ========================================================================== */

:root {
  /* Paleta Base Institucional */
  --bg-dark-primary: #0F291E;      /* Verde Floresta Profundo */
  --bg-dark-secondary: #0F172A;    /* Grafite / Slate 900 */
  --bg-card-dark: #16382B;         /* Container Interno */
  --bg-surface-glass: rgba(15, 41, 30, 0.94);
  --border-glass: rgba(255, 255, 255, 0.15);

  /* Tipografia WCAG AAA */
  --text-pure-white: #FFFFFF;      /* Titulos H1 a H6 e enfase */
  --text-body-bright: #F1F5F9;     /* Corpo de texto (Contraste > 13:1) */
  --text-muted: #CBD5E1;           /* Rotulos secundarios (Contraste > 8:1) */

  /* Cores Canonicas das Camadas Ambientais */
  --layer-perimetro: #FD6600;      /* Laranja Brant */
  --layer-rl: #22C55E;             /* Verde Reserva Legal */
  --layer-app: #EF4444;            /* Vermelho Alerta APP */
  --layer-consolidada: #F59E0B;    /* Âmbar Consolidada */
  --layer-veg-nativa: #10B981;     /* Esmeralda Vegetacao Nativa */
  --layer-hidrografia: #3B82F6;    /* Azul Hidrografia */

  /* Acentos de Acao */
  --color-accent-green: #14532D;
  --color-accent-green-hover: #15803D;
  --color-accent-orange: #C2410C;
  --color-focus-ring: #FFFFFF;

  /* Fontes e Raios */
  --font-family-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-hud: 0 8px 24px -4px rgba(0, 0, 0, 0.5), 0 2px 6px -1px rgba(0, 0, 0, 0.3);
}

/* Reset e Padroes Globais */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  max-width: 100%;
  height: 100%;
  overflow: hidden;
  overflow-x: hidden;
  font-family: var(--font-family-base);
  background-color: var(--bg-dark-primary);
  color: var(--text-body-bright);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.car-webgis-app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

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

/* Blindagem de Tipografia para Conteineres Escuros (Regra ERR-UI-001) */
.car-webgis-app h1,
.car-webgis-app h2,
.car-webgis-app h3,
.car-webgis-app h4,
.car-webgis-app .hud-title,
.car-webgis-app .brand-title,
.car-webgis-app .widget-title {
  color: var(--text-pure-white) !important;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
}

.car-webgis-app p,
.car-webgis-app span,
.car-webgis-app label,
.car-webgis-app .hud-card-value,
.car-webgis-app .layer-name {
  color: var(--text-body-bright) !important;
}

/* ==========================================================================
   Cabecalho da Aplicacao (Header)
   ========================================================================== */
.app-header {
  position: relative;
  flex: 0 0 auto;
  height: 64px;
  min-height: 64px;
  background-color: var(--bg-dark-primary);
  background: linear-gradient(180deg, rgba(15, 41, 30, 0.98) 0%, rgba(11, 25, 44, 0.95) 100%);
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  gap: 16px;
}

.header-brand .brand-link {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand-icon {
  font-size: 24px;
}

.brand-title {
  font-size: 16px;
  letter-spacing: 0.5px;
  margin: 0;
}

.brand-subtitle {
  font-size: 10px;
  color: var(--text-muted) !important;
  text-transform: uppercase;
  letter-spacing: 1px;
  display: block;
}

/* Barra de Busca e Presets */
.search-container {
  flex: 1;
  max-width: 820px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.car-search-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
}

.search-input {
  width: 100%;
  height: 38px;
  padding: 0 34px 0 12px;
  background-color: var(--bg-dark-secondary);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  color: var(--text-pure-white);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.3px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input::placeholder {
  color: #CBD5E1;
}

.search-input:focus {
  border-color: var(--layer-rl);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.3);
}

.btn-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #CBD5E1;
  font-size: 14px;
  cursor: pointer;
  padding: 6px;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-clear:hover {
  color: var(--text-pure-white);
}

.btn-primary {
  height: 38px;
  padding: 0 16px;
  background-color: var(--color-accent-green);
  border: 1px solid #22C55E;
  border-radius: var(--radius-sm);
  color: var(--text-pure-white) !important;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background-color 0.2s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover {
  background-color: var(--color-accent-green-hover);
  border-color: #4ADE80;
}

.btn-primary:focus-visible {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}

/* Pilulas de Exemplos Rapidos */
.quick-demo-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.demo-label {
  font-size: 11px;
  color: var(--text-muted) !important;
}

.demo-buttons-group {
  display: flex;
  gap: 6px;
}

.btn-demo-badge {
  background-color: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 14px;
  padding: 4px 10px;
  min-height: 28px;
  min-width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-pure-white) !important;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-demo-badge:hover {
  background-color: var(--color-accent-green);
  border-color: var(--layer-rl);
  transform: translateY(-1px);
}

.btn-demo-badge:focus-visible {
  outline: 2px solid var(--color-focus-ring);
}

/* Acoes Utilitarias */
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 12px;
  background-color: rgba(255, 255, 255, 0.1);
  font-size: 11px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--layer-rl);
  box-shadow: 0 0 6px var(--layer-rl);
}

.status-contingency .status-dot {
  background-color: var(--layer-consolidada);
  box-shadow: 0 0 6px var(--layer-consolidada);
}

.btn-action-icon {
  width: 36px;
  height: 36px;
  background-color: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-pure-white) !important;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
}

.btn-action-icon:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.btn-secondary-tool {
  height: 36px;
  padding: 0 12px;
  background-color: rgba(253, 102, 0, 0.15);
  border: 1px solid var(--layer-perimetro);
  border-radius: var(--radius-sm);
  color: var(--text-pure-white) !important;
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.btn-secondary-tool:hover {
  background-color: var(--color-accent-orange);
  border-color: #EA580C;
}

/* ==========================================================================
   Conteiner Central e Viewport Cartografico
   ========================================================================== */
.app-main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.map-viewport {
  width: 100%;
  height: 100%;
  background-color: #0B192C;
}

/* Loader Cartografico */
.map-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--bg-surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: 2000;
  box-shadow: var(--shadow-hud);
}

.map-loader.hidden {
  display: none;
}

.loader-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--layer-rl);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader-message {
  font-size: 13px;
  font-weight: 600;
}

/* ==========================================================================
   Painel Informativo HUD (Cards de Resumo do Imovel)
   ========================================================================== */
.property-hud-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 340px;
  background-color: var(--bg-surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(8px);
  z-index: 1000;
  box-shadow: var(--shadow-hud);
  transition: transform 0.3s ease;
}

.hud-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hud-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
}

.hud-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 250px;
}

.badge-status {
  align-self: flex-start;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-idle {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--text-muted) !important;
}

.badge-active {
  background-color: rgba(34, 197, 94, 0.2);
  color: #4ADE80 !important;
  border: 1px solid var(--layer-rl);
}

.badge-pending {
  background-color: rgba(245, 158, 11, 0.2);
  color: #FCD34D !important;
  border: 1px solid var(--layer-consolidada);
}

.badge-suspended {
  background-color: rgba(239, 68, 68, 0.2);
  color: #FCA5A5 !important;
  border: 1px solid var(--layer-app);
}

.btn-hud-collapse {
  background: none;
  border: none;
  color: var(--text-body-bright);
  font-size: 14px;
  cursor: pointer;
  padding: 6px 8px;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hud-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hud-cards-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.hud-card {
  background-color: var(--bg-card-dark);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.hud-card-label {
  font-size: 11px;
  color: var(--text-muted) !important;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-card-value {
  font-size: 15px;
  font-weight: 800;
  margin: 2px 0;
  color: var(--text-pure-white) !important;
}

.hud-card-sub {
  font-size: 10px;
  color: var(--text-muted) !important;
}

/* Barra de Acoes do HUD */
.hud-actions-bar {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.btn-hud-action {
  flex: 1;
  min-height: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.btn-pdf {
  background-color: var(--color-accent-green);
  border: 1px solid #22C55E;
  color: var(--text-pure-white) !important;
}

.btn-pdf:hover:not(:disabled) {
  background-color: var(--color-accent-green-hover);
  border-color: #4ADE80;
}

.btn-pdf:disabled,
.btn-recenter:disabled {
  background-color: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.3) !important;
  cursor: not-allowed;
}

.btn-vector {
  background-color: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text-pure-white) !important;
}

.btn-vector:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

.btn-recenter {
  background-color: rgba(253, 102, 0, 0.2);
  border: 1px solid var(--layer-perimetro);
  color: var(--text-pure-white) !important;
}

.btn-recenter:hover:not(:disabled) {
  background-color: var(--color-accent-orange);
  border-color: #EA580C;
}

/* ==========================================================================
   Seletor de Basemaps Flutuante
   ========================================================================== */
.basemap-selector-widget {
  position: absolute;
  top: 16px;
  right: 16px;
  background-color: var(--bg-surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  z-index: 1000;
  box-shadow: var(--shadow-hud);
}

.widget-title {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  color: var(--text-muted) !important;
}

.basemap-buttons {
  display: flex;
  gap: 4px;
}

.btn-basemap {
  background-color: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  color: var(--text-body-bright) !important;
  padding: 6px 10px;
  min-height: 28px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-basemap.active {
  background-color: #14532D;
  border: 2px solid #22C55E;
  color: var(--text-pure-white) !important;
}

.btn-basemap:hover:not(.active) {
  background-color: rgba(255, 255, 255, 0.16);
}

/* ==========================================================================
   Alternador de Camadas Tematicas Ambientais
   ========================================================================== */
.layers-control-widget {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 250px;
  background-color: var(--bg-surface-glass);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  z-index: 1000;
  box-shadow: var(--shadow-hud);
}

.layers-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.btn-widget-toggle {
  background: none;
  border: none;
  color: var(--text-body-bright);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 8px;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layers-widget-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 3px 0;
  min-height: 28px;
}

.layer-item input[type="checkbox"] {
  accent-color: var(--layer-rl);
  width: 24px;
  height: 24px;
  cursor: pointer;
}

.color-badge {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.layer-name {
  font-size: 12px;
  font-weight: 500;
}

/* ==========================================================================
   Rodape da Aplicacao
   ========================================================================== */
.app-footer {
  position: relative;
  flex: 0 0 auto;
  height: 28px;
  background-color: var(--bg-dark-secondary);
  border-top: 1px solid var(--border-glass);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  font-size: 11px;
}

.footer-left, .footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-sep {
  color: rgba(255, 255, 255, 0.2);
}

.footer-link {
  color: #38BDF8 !important; /* Sky 400 (Contraste > 7:1) */
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 4px;
}

.footer-link:hover {
  text-decoration: underline;
}

.coords-display {
  font-family: monospace;
  color: var(--text-muted) !important;
}

/* ==========================================================================
   Responsividade Mobile (< 768px e < 480px)
   ========================================================================== */
@media (max-width: 768px) {
  .app-header {
    height: auto;
    min-height: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .header-brand {
    order: 1;
    display: flex;
    align-items: center;
  }

  .brand-subtitle {
    display: none !important;
  }

  .header-actions {
    order: 2;
    position: static;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .search-container {
    order: 3;
    width: 100%;
    flex: 1 1 100%;
    max-width: 100%;
    gap: 6px;
  }

  .search-input {
    min-height: 40px;
    height: 40px;
  }

  .btn-primary {
    min-height: 40px;
    height: 40px;
    padding: 0 16px;
  }

  .btn-action-icon {
    min-width: 38px;
    min-height: 38px;
  }

  .btn-secondary-tool {
    min-height: 38px;
    height: 38px;
  }

  .quick-demo-wrapper {
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .app-main {
    position: relative;
    top: auto;
    bottom: auto;
    left: auto;
    right: auto;
  }

  .property-hud-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 50vh;
    overflow-y: auto;
  }

  .btn-hud-action {
    min-height: 40px;
    height: 40px;
  }

  .basemap-selector-widget {
    top: 8px;
    right: 8px;
  }

  .layers-control-widget {
    display: none; /* Recolhido em mobile; acionavel via botao do mapa */
  }
}

@media (max-width: 480px) {
  .app-header {
    gap: 6px;
    padding: 8px 10px;
  }

  .header-brand {
    width: auto;
  }

  .header-actions {
    width: 100%;
    justify-content: flex-end;
    gap: 6px;
  }

  .btn-secondary-tool {
    padding: 0 8px;
    font-size: 11px;
  }

  .app-footer {
    padding: 0 8px;
    font-size: 10px;
  }

  .footer-left span:first-child {
    display: none;
  }

  .footer-right {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
