body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f4f9;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background-color: #333;
  color: white;
  text-align: center;
  display: flex;

  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
}

#connection-status {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.status-online {
  background-color: #4caf50;
  color: white;
}

.status-offline {
  background-color: #ff9800;
  color: white;
}

.status-local {
  background-color: #2196f3;
  color: white;
}

.ai-architecture-panel {
  background: #ffffff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}

.ai-architecture-title {
  font-size: 12px;
  font-weight: 700;
  color: #0c4a6e;
  margin-bottom: 8px;
}

.ai-architecture-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 12px;
  color: #334155;
}

.ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 9px;
  border: 1px solid transparent;
}

.ai-badge-azure {
  background: #ecfeff;
  color: #155e75;
  border-color: #67e8f9;
}

.ai-badge-local {
  background: #eef2ff;
  color: #3730a3;
  border-color: #a5b4fc;
}

.ai-badge-firestore {
  background: #fffbeb;
  color: #92400e;
  border-color: #fcd34d;
}

.ai-badge-hybrid {
  background: #f5f3ff;
  color: #6d28d9;
  border-color: #c4b5fd;
}

.ai-badge-neutral {
  background: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}

.ai-flow-summary {
  margin-top: 2px;
  font-size: 11px;
  color: #475569;
  font-style: normal;
}


.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

.map-container {
  flex-grow: 1;
  height: 100%;
}

#map {
  height: 100%;
  width: 100%;
}

.controls-panel {
  width: 350px;
  padding: 20px;
  background-color: #ffffff;
  box-shadow: -2px 0 5px rgba(0, 0, 0, 0.1);
  overflow-y: auto;
  flex-shrink: 0;
  transition: width 0.28s ease, padding 0.28s ease, opacity 0.22s ease, box-shadow 0.22s ease;
}

.control-group {
  background-color: #fdfdfd;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 20px;
}

h3 {
  margin-top: 0;
  color: #333;
  border-bottom: 1px solid #eee;
  padding-bottom: 10px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: 500;
  color: #555;
}

input[type="text"],
input[type="file"] {
  width: 100%;
  padding: 8px;
  margin-bottom: 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}

/* Preset Buttons */
.preset-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.preset-btn {
  padding: 12px 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
}

.preset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.preset-btn:active {
  transform: translateY(0);
}

.preset-btn:focus-visible {
  outline: 2px solid #0056b3;
  outline-offset: 2px;
}

/* Parameter Controls */
.param-control {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.param-control:last-child {
  border-bottom: none;
}

.param-control label {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
}

.param-icon {
  font-size: 18px;
  margin-right: 8px;
}

.param-name {
  flex: 1;
  font-size: 14px;
}

.input-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
}

input[type="range"] {
  flex: 1;
  cursor: pointer;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #ddd;
  border-radius: 3px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  background: #007bff;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
  background: #0056b3;
  transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #007bff;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
  background: #0056b3;
  transform: scale(1.1);
}

.number-input {
  width: 70px;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  font-weight: 600;
  color: #007bff;
}

.number-input.scientific {
  width: 85px;
  font-size: 11px;
}

.number-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.unit {
  font-size: 12px;
  color: #666;
  font-weight: 600;
  min-width: 25px;
}

small {
  display: block;
  color: #666;
  font-size: 11px;
  line-height: 1.4;
  font-style: italic;
}

.button-row {
  display: flex;
  gap: 8px;
  margin-top: 15px;
}

.map-search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.map-search-input {
  flex: 1;
  margin-bottom: 0;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 13px;
}

.map-search-input:focus {
  outline: none;
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.1);
}

.map-search-btn {
  width: auto;
  min-width: 84px;
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 4px;
}

.secondary-btn {
  flex: 1;
  padding: 10px;
  background: #6c757d;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.2s;
}

.secondary-btn:hover {
  background: #5a6268;
  transform: translateY(-1px);
}

/* Mode toggle buttons (Auto / Manual) */
.mode-btn {
  flex: 1;
  padding: 10px 8px;
  background: #e5e7eb;
  color: #374151;
  border: 2px solid #d1d5db;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  width: auto;
  box-shadow: none;
}

.mode-btn:hover {
  background: #d1d5db;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.mode-btn-active {
  background: #7c3aed !important;
  color: white !important;
  border-color: #5b21b6 !important;
  box-shadow: 0 2px 6px rgba(124,58,237,0.3) !important;
}

.mode-btn-active:hover {
  background: #6d28d9 !important;
}

button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.3s;
  font-weight: 600;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:hover {
  background: linear-gradient(135deg, #0056b3 0%, #004085 100%);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:disabled {
  background: #ccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#stats p {
  margin: 8px 0;
  padding: 8px;
  background: #f8f9fa;
  border-left: 3px solid #007bff;
  border-radius: 3px;
}

#loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 10000;
  display: none;
  justify-content: center;
  align-items: center;
  color: white;
  font-size: 1.5em;
}

/* ===== MELHORIAS NA UI DO MAPA ===== */

/* Toolbar Leaflet Draw - Polígono */
.leaflet-draw-toolbar {
  background-color: white !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  padding: 4px !important;
}

.leaflet-draw-toolbar a {
  background-color: white !important;
  border: none !important;
  border-radius: 6px !important;
  width: 36px !important;
  height: 36px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 2px 0 !important;
  transition: all 0.2s ease !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: #f0f0f0 !important;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-draw-toolbar a.leaflet-draw-draw-polygon {
  background-color: #007bff !important;
  color: white !important;
}

.leaflet-draw-toolbar a.leaflet-draw-draw-polygon:hover {
  background-color: #0056b3 !important;
}

/* Controles de Zoom */
.leaflet-control-zoom {
  background-color: white !important;
  border-radius: 8px !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15) !important;
  border: none !important;
}

.leaflet-control-zoom a {
  background-color: white !important;
  border: none !important;
  color: #333 !important;
  font-weight: bold !important;
  font-size: 18px !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  border-radius: 6px !important;
  margin: 2px 4px !important;
  transition: all 0.2s ease !important;
}

.leaflet-control-zoom a:hover {
  background-color: #f0f0f0 !important;
  box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-control-zoom a:first-child {
  border-bottom: none !important;
}

/* Handles de edição menores para ajuste fino de polígonos */
.leaflet-editing-icon {
  width: var(--edit-handle-size, 4px) !important;
  height: var(--edit-handle-size, 4px) !important;
  margin-left: calc(-1 * var(--edit-handle-offset, 2px)) !important;
  margin-top: calc(-1 * var(--edit-handle-offset, 2px)) !important;
}

/* Remover estilos padrão conflitantes */
.leaflet-control {
  box-shadow: none !important;
}

/* ===== INTEGRAÇÃO DE ABAS ===== */
:root {
  --tab-active: #007bff;
  --tab-inactive: #e0e0e0;
}

.unified-header {
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4000;
  transform: translateY(calc(-100% + 8px));
  transition: transform 0.25s ease;
}

.header-hover-zone {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  z-index: 4001;
}

.header-hover-zone:hover + .unified-header,
.unified-header:hover,
.unified-header:focus-within {
  transform: translateY(0);
}

.unified-header #connection-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.unified-tabs {
  display: flex;
  gap: 8px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

.tab-btn {
  width: auto;
  padding: 10px 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  border-radius: 10px;
  transition: all 0.3s ease;
  box-shadow: none;
}

.tab-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}

.tab-btn.active {
  color: #0f172a;
  background: #ffffff;
  border-color: #ffffff;
}

.tab-content {
  display: none;
  width: 100%;
  flex: 1;
  min-height: 0;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#pdfsplitter-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: white;
  flex: 1;
}

.main-container {
  display: flex;
  flex: 1;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.controls-panel {
  height: 100%;
  overflow-y: auto;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: calc(350px + 18px);
  transform: translateY(-50%);
  width: 22px;
  height: 56px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(17, 24, 39, 0.72);
  color: #ffffff;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 600;
  opacity: 0.78;
  transition: right 0.28s ease, background 0.2s ease, opacity 0.2s ease, transform 0.2s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.16);
}

.sidebar-toggle:hover {
  background: rgba(17, 24, 39, 0.9);
  opacity: 1;
  transform: translateY(-50%);
}

.main-container.sidebar-collapsed .controls-panel {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  box-shadow: none;
  overflow: hidden;
}

.main-container.sidebar-collapsed .sidebar-toggle {
  right: 6px;
}

.app-footer {
  background: #111827;
  color: #e5e7eb;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.app-footer-main {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.portfolio-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 8px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
}

.portfolio-link:hover {
  filter: brightness(1.08);
}

.app-footer-contact {
  display: flex;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
}

.app-footer-contact a {
  color: #93c5fd;
  text-decoration: none;
}

.app-footer-contact a:hover {
  text-decoration: underline;
}

/* Portfolio page styles (scoped to avoid impacting the app shell) */
.portfolio-page {
  --portfolio-bg: #0b1020;
  --portfolio-panel: #131a2e;
  --portfolio-panel-2: #19233d;
  --portfolio-text: #e6ebff;
  --portfolio-muted: #aeb8d9;
  --portfolio-accent: #4da3ff;
  --portfolio-accent-2: #61d5b8;
  --portfolio-border: rgba(255, 255, 255, 0.12);
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(circle at top right, #1a2546 0%, var(--portfolio-bg) 55%);
  color: var(--portfolio-text);
  line-height: 1.55;
  display: block;
  height: auto;
}

.portfolio-page * {
  box-sizing: border-box;
}

.portfolio-page .wrap {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 36px 0 48px;
}

.portfolio-page .hero {
  background: linear-gradient(145deg, rgba(77, 163, 255, 0.12), rgba(97, 213, 184, 0.1));
  border: 1px solid var(--portfolio-border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.25);
}

.portfolio-page .badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.portfolio-page .badge {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--portfolio-border);
  color: var(--portfolio-muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.portfolio-page h1 {
  margin: 0 0 10px;
  font-size: clamp(26px, 3.2vw, 40px);
  line-height: 1.2;
}

.portfolio-page .subtitle {
  margin: 0;
  font-size: 17px;
  color: var(--portfolio-muted);
  max-width: 880px;
}

.portfolio-page .cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 22px;
}

.portfolio-page .btn {
  text-decoration: none;
  color: #fff;
  background: linear-gradient(135deg, var(--portfolio-accent), #2a7fe0);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 11px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.15s ease, filter 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.portfolio-page .btn.secondary {
  background: linear-gradient(135deg, var(--portfolio-accent-2), #2cb093);
}

.portfolio-page .btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--portfolio-text);
}

.portfolio-page .btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.portfolio-page .grid {
  margin-top: 24px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.portfolio-page .card {
  background: var(--portfolio-panel);
  border: 1px solid var(--portfolio-border);
  border-radius: 14px;
  padding: 18px;
}

.portfolio-page .card h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.portfolio-page .card p {
  margin: 0;
  color: var(--portfolio-muted);
  font-size: 14px;
}

.portfolio-page .kpi {
  display: block;
  margin-bottom: 6px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: #d9e7ff;
}

.portfolio-page .kpi-label {
  display: block;
  color: var(--portfolio-muted);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}

.portfolio-page .section {
  margin-top: 28px;
  background: var(--portfolio-panel-2);
  border: 1px solid var(--portfolio-border);
  border-radius: 14px;
  padding: 22px;
}

.portfolio-page .section h3 {
  margin: 0 0 12px;
  font-size: 20px;
}

.portfolio-page .section p,
.portfolio-page .section li {
  color: var(--portfolio-muted);
}

.portfolio-page .section ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.portfolio-page footer {
  margin-top: 28px;
  color: #93a2d8;
  font-size: 13px;
  text-align: center;
}

.portfolio-page .portfolio-contact {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 14px;
}

.portfolio-page .portfolio-contact a {
  color: #c3d4ff;
  text-decoration: none;
}

.portfolio-page .portfolio-contact a:hover {
  text-decoration: underline;
}

@media (max-width: 680px) {
  .portfolio-page .hero {
    padding: 20px;
  }

  .portfolio-page .btn {
    width: 100%;
    justify-content: center;
  }
}