:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #ccfbf1;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --amber-bg: #fef3c7;
  --amber-text: #92400e;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.sidebar {
  width: 410px;
  min-width: 360px;
  max-width: 100%;
  height: 100%;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 2;
  box-shadow: var(--shadow-sm);
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--primary);
  color: #ffffff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 999px;
  width: fit-content;
}

.filters-section {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.text-input,
.select-input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus,
.select-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.checkbox-input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.actions-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px;
  margin-top: 2px;
}

.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

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

.btn-secondary {
  background: var(--surface-muted);
  color: var(--text);
  border-color: var(--border-strong);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-full {
  width: 100%;
}

.results-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 20px;
  overflow: hidden;
}

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

.section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}

.results-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface-muted);
  padding: 2px 8px;
  border-radius: 999px;
}

.status-banner {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
}

.status-banner.error {
  color: var(--danger-text);
  background: var(--danger-bg);
  border-color: #fecaca;
}

.results-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.result-card {
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.result-card:hover {
  border-color: var(--border-strong);
  background: #f8fafc;
}

.result-card.active {
  border-color: var(--primary);
  background: #f0fdfa;
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.12);
}

.result-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.result-codigo {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}

.result-card-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-clean {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge-overlap {
  background: var(--danger-bg);
  color: var(--danger-text);
}

.badge-neutral {
  background: var(--surface-muted);
  color: var(--text-muted);
}

.detail-panel {
  border-top: 1px solid var(--border);
  background: #f8fafc;
  padding: 14px 20px 16px;
  max-height: 48%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.detail-kicker {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.detail-codigo {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  word-break: break-all;
}

.icon-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--surface-muted);
  color: var(--text);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 11px;
  color: var(--text-subtle);
  font-weight: 600;
}

.metric-value {
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
}

.overlaps-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

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

.overlaps-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
}

.overlap-total {
  font-size: 11px;
  font-weight: 700;
  color: var(--danger-text);
}

.overlaps-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.overlap-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
}

.overlap-source {
  font-weight: 700;
  color: var(--amber-text);
}

.overlap-id {
  color: var(--text-muted);
  font-size: 11px;
  margin-left: 4px;
}

.overlap-area {
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.overlap-empty {
  font-size: 12px;
  color: var(--success-text);
  background: var(--success-bg);
  padding: 8px 10px;
  border-radius: 6px;
  font-weight: 600;
}

.map-container {
  position: relative;
  flex: 1;
  height: 100%;
  min-width: 0;
}

.map-canvas {
  width: 100%;
  height: 100%;
}

.map-overlay-card {
  position: absolute;
  top: 14px;
  left: 14px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 1;
  font-size: 12px;
}

.legend-title {
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-subtle);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-car {
  background: rgba(15, 118, 110, 0.3);
  border: 2px solid #0f766e;
}

.swatch-restricao {
  background: rgba(220, 38, 38, 0.3);
  border: 2px solid #dc2626;
}

.legend-hint {
  font-size: 11px;
  color: var(--text-subtle);
  border-top: 1px solid var(--border);
  padding-top: 6px;
  margin-top: 2px;
}

.map-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: var(--shadow-md);
  z-index: 3;
  pointer-events: none;
}

@media (max-width: 860px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: 52vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .map-container {
    height: 48vh;
  }
}
