html, body {
  height: 100%;
  margin: 0;
}

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.app-header {
  height: 48px;
  display: flex;
  align-items: center;
  padding: 0 1rem;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  flex-shrink: 0;
  z-index: 2;
}

.app-brand {
  font-weight: 600;
  color: #1b1b1b;
  text-decoration: none;
}

.app-brand:hover {
  color: #1b1b1b;
}

.app-main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

#map, #map-compare {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.comparison-container {
  position: absolute;
  inset: 0;
}

.comparison-container.is-drawing-area .mapboxgl-compare {
  pointer-events: none;
  opacity: 0;
}

.comparison-container.is-drawing-area #map-compare {
  pointer-events: none;
}

.comparison-container:not(.is-comparing) #map-compare {
  visibility: hidden;
  pointer-events: none;
}

.map-panel {
  position: absolute;
  z-index: 3;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #d4d4d8;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
  pointer-events: auto;
}

.map-panel h2 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
}

.map-panel-tools {
  top: 12px;
  left: 12px;
  width: 320px;
  max-height: calc(100% - 24px);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.map-panel-tools > h2,
.map-panel-tools > .tools-intro,
.map-panel-tools > .tools-analysis-picker {
  flex-shrink: 0;
  margin-left: 1rem;
  margin-right: 1rem;
}

.tools-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.tools-workspace .tools-form-body {
  flex: 1;
  overflow-y: auto;
}

.tools-workspace .tools-run-btn,
.tools-workspace .risk-status {
  flex-shrink: 0;
  margin-left: 1rem;
  margin-right: 1rem;
}

.map-panel-tools > h2 {
  margin-top: 0.85rem;
}

.tools-intro {
  margin: 0 1rem 0.65rem;
  color: #52525b;
  font-size: 0.82rem;
}

.tools-form-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 1rem 0.75rem;
}

.tools-form-section.hidden {
  display: none;
}

#form-comparison .tools-elevation-field {
  display: none;
}

.tools-workspace.is-overtime #risk-level-fieldset {
  display: none;
}

.overtime-side {
  padding: 0.55rem 0.6rem 0.15rem;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.compare-overlays.is-overtime .compare-elev-select {
  display: none;
}

.compare-elev-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  color: #fff;
}

.compare-elev-card.is-label-only {
  min-width: 148px;
  max-width: 210px;
}

.metrics-chart-title {
  margin: 0.65rem 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #3f3f46;
}

.aal-chart-popup {
  left: calc(336px + (100% - 336px - 274px) / 2);
  bottom: 20px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 630px));
  height: 200px;
  padding: 0.55rem 0.7rem 0.65rem;
  display: flex;
  flex-direction: column;
  z-index: 4;
}

.aal-chart-popup.hidden {
  display: none;
}

.aal-chart-popup h2 {
  margin: 0 0 0.3rem;
  font-size: 0.82rem;
}

.aal-chart-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

.aal-chart-wrap canvas,
#aal-series-chart {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

.tools-fieldset {
  border: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.tools-fieldset legend {
  font-size: 0.78rem;
  font-weight: 600;
  color: #3f3f46;
  margin-bottom: 0.35rem;
}

.tools-field {
  margin-bottom: 0.75rem;
}

.tools-field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3f3f46;
  margin-bottom: 0.25rem;
}

.tools-select {
  width: 100%;
  font-size: 0.82rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid #d4d4d8;
  border-radius: 6px;
  background: #fff;
}

.tools-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.tools-radio,
.tools-check {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: #3f3f46;
  margin-bottom: 0.3rem;
  cursor: pointer;
}

.tools-radio input,
.tools-check input {
  margin-top: 0.15rem;
}

.tools-analysis-picker {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0 1rem 0.85rem;
  padding: 0;
}

.tools-analysis-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0 1rem 0.65rem;
  padding: 0;
}

.tools-analysis-btn {
  display: block;
  width: 100%;
  min-height: 52px;
  padding: 0.65rem 0.85rem;
  border: 2px solid #d4d4d8;
  border-radius: 8px;
  background: #fff;
  color: #18181b;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.tools-analysis-btn:hover {
  border-color: #93c5fd;
  background: #f8fafc;
}

.tools-analysis-btn:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.tools-analysis-btn.is-active {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 0 0 1px #2563eb;
}

.tools-analysis-btn--compact {
  min-height: 40px;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
}

.tools-back-btn {
  flex-shrink: 0;
  align-self: flex-start;
  margin: 0.5rem 1rem 0.35rem;
  padding: 0.25rem 0;
  border: none;
  background: none;
  color: #2563eb;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.tools-back-btn:hover {
  color: #1d4ed8;
  text-decoration: underline;
}

.tools-scenario-group {
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  margin-bottom: 0.75rem;
  background: #fafafa;
}

.tools-scenario-group h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: #18181b;
}

.tools-run-btn {
  flex-shrink: 0;
  margin: 0 1rem 0.85rem;
  padding: 0.45rem 0.75rem;
  border: none;
  border-radius: 6px;
  background: #1d4ed8;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.tools-run-btn:hover {
  background: #1e40af;
}

.risk-status {
  margin: 0 1rem 0.85rem;
  font-size: 0.78rem;
  color: #166534;
  min-height: 1rem;
}

.risk-status.is-error {
  color: #b91c1c;
}

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.map-panel-views {
  top: 12px;
  right: 52px;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.45rem;
  max-width: 280px;
}

.mapboxgl-ctrl-top-right {
  top: 10px;
  right: 10px;
}

.map-btn {
  border: 1px solid #d4d4d8;
  background: #fff;
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  cursor: pointer;
}

.map-btn.is-active {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}

.map-panel-legend {
  right: 12px;
  bottom: 28px;
  width: 250px;
  padding: 0.85rem 1rem;
  max-height: calc(100% - 380px);
  overflow-y: auto;
  z-index: 4;
}

.map-panel-metrics {
  right: 12px;
  top: 108px;
  width: 280px;
  padding: 0.75rem 0.9rem;
  height: auto;
  max-height: calc(100% - 340px);
  overflow-y: auto;
}

.metrics-area-label {
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  color: #52525b;
}

.metrics-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
  color: #3f3f46;
}

.metrics-row strong {
  font-variant-numeric: tabular-nums;
  color: #18181b;
}

.metrics-table {
  width: 100%;
  margin: 0 0 0.55rem;
  font-size: 0.72rem;
  border-collapse: collapse;
}

.metrics-table th,
.metrics-table td {
  padding: 0.2rem 0.25rem;
  text-align: right;
}

.metrics-table th:first-child,
.metrics-table td:first-child {
  text-align: left;
}

.inventory-total {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
}

.legend-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.8rem;
}

.legend-list li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.ground-legend {
  margin-top: 0.15rem;
}

.teafd-legend {
  margin-top: 0.7rem;
  padding-top: 0.55rem;
  border-top: 1px solid #e4e4e7;
}

.legend-section-title,
.teafd-legend-title {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #3f3f46;
}

.teafd-gradient {
  height: 10px;
  border-radius: 4px;
  background: linear-gradient(to right, #fef9c3, #fbbf24, #f97316, #9f1239);
}

.teafd-gradient-labels {
  display: flex;
  justify-content: space-between;
  gap: 0.2rem;
  margin-top: 0.25rem;
  font-size: 0.65rem;
  color: #52525b;
}

.teafd-null-note {
  margin: 0.2rem 0 0;
  font-size: 0.68rem;
  color: #71717a;
}

.mapboxgl-compare {
  z-index: 2;
}

.compare-overlays {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.compare-elev-card {
  pointer-events: auto;
  position: absolute;
  top: 0;
  left: var(--compare-x, 50%);
  min-width: 168px;
  padding: 0.45rem 0.7rem 0.55rem;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);
}

.compare-elev-card--left {
  transform: translateX(calc(-100% - 16px));
}

.compare-elev-card--right {
  transform: translateX(16px);
}

.compare-overlays.is-flush-left .compare-elev-card--left,
.compare-overlays.is-flush-left .compare-elev-card--right {
  transform: translateX(16px);
}

.compare-overlays.is-flush-right .compare-elev-card--left,
.compare-overlays.is-flush-right .compare-elev-card--right {
  transform: translateX(calc(-100% - 16px));
}

.compare-elev-kicker {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #cbd5e1;
  margin-bottom: 0.2rem;
}

.compare-elev-select {
  width: 100%;
  border: none;
  border-radius: 6px;
  background: #1e293b;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.28rem 0.35rem;
}

.map-missing-token {
  padding: 2rem;
  max-width: 40rem;
}

.map-missing-token pre {
  background: #f5f5f5;
  padding: 0.75rem 1rem;
  border-radius: 0.25rem;
}

.mapboxgl-popup-content {
  max-height: 280px;
  overflow: auto;
  font-size: 12px;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
