* {
  box-sizing: border-box;
}

:root {
  --bg: #f8faf7;
  --card: #ffffff;
  --surface: #f5f7f4;
  --surface-feature: #e7f6ec;
  --text: #001e2b;
  --muted: #5c6c75;
  --border: #d9e0dc;
  --border-soft: #e7ece8;
  --primary: #00ed64;
  --primary-pressed: #00c853;
  --brand-teal: #023430;
  --brand-teal-mid: #0b5f57;
  --gold: #c6a35d;
  --shadow: 0 1px 2px rgba(0, 30, 43, 0.04);
  --shadow-card: 0 4px 12px rgba(0, 30, 43, 0.08);
}

/* Fallback essencial do Leaflet. Mantem o mapa correto mesmo se o CSS do CDN falhar. */
.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-container {
  overflow: hidden;
  cursor: grab;
  background: #dbe4ee;
  outline-offset: 1px;
}

.leaflet-container:active {
  cursor: grabbing;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  border: 0;
}

.leaflet-tile-container {
  pointer-events: none;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-map-pane canvas {
  z-index: 100;
}

.leaflet-map-pane svg {
  z-index: 200;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 10px;
}

.leaflet-right {
  right: 10px;
}

.leaflet-bottom {
  bottom: 10px;
}

.leaflet-left {
  left: 10px;
}

.leaflet-control {
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-control-zoom a {
  display: block;
  width: 34px;
  height: 34px;
  line-height: 34px;
  background: #ffffff;
  color: #001e2b;
  border-bottom: 1px solid #d9e0dc;
  text-align: center;
  text-decoration: none;
  font-size: 18px;
  font-weight: 600;
}

.leaflet-control-zoom a:hover {
  background: #f5f7f4;
}

.leaflet-control-layers,
.leaflet-control-attribution {
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #d9e0dc;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(0, 30, 43, 0.08);
}

.leaflet-control-layers label {
  display: block;
  margin: 4px 0;
}

.leaflet-popup {
  position: absolute;
  text-align: center;
}

.leaflet-popup-content-wrapper {
  padding: 1px;
  text-align: left;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 16px 48px -8px rgba(0, 30, 43, 0.16);
}

.leaflet-popup-content {
  margin: 12px;
  line-height: 1.35;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: "Euclid Circular A", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 360px minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  background: var(--bg);
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 24px;
  height: 100vh;
  padding: 22px;
  background: var(--brand-teal);
  color: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #ffffff;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: var(--primary);
  color: var(--text);
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand > span:last-child {
  min-width: 0;
}

.brand small {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.76rem;
  white-space: nowrap;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-list a {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 14px;
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease,
    transform 180ms ease;
}

.nav-list a:hover,
.nav-list a.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.nav-list a.active {
  box-shadow: inset 4px 0 0 var(--primary);
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.88rem;
  line-height: 1.45;
}

.logout-link {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.86);
  font-weight: 600;
  text-decoration: none;
  transition:
    background-color 180ms ease,
    color 180ms ease,
    box-shadow 180ms ease;
}

.logout-link:hover,
.logout-link:focus-visible {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  outline: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  background: var(--card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 500;
  height: 100vh;
  overflow-y: auto;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand-teal-mid);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 1.78rem;
  font-weight: 500;
  line-height: 1.16;
}

h2 {
  margin-bottom: 12px;
  font-size: 0.9rem;
}

.subtitle,
.hint,
.notice {
  line-height: 1.45;
}

p,
.field-label,
.empty-state,
.route-toolbar span {
  font-size: 0.88rem;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
}

.notice {
  padding: 12px;
  margin: 0;
  border-left: 4px solid #eab308;
  background: #fff8db;
  color: #4d3b00;
  border-radius: 6px;
  font-size: 0.92rem;
}

.panel-section {
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.layers-heading {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
}

.layers-heading > div:first-child {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.layers-heading h2 {
  margin-bottom: 0;
}

#active-layer-count {
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-feature);
  color: var(--brand-teal);
  font-size: 0.82rem;
  font-weight: 900;
}

.layer-tools {
  display: flex;
  gap: 8px;
}

.layer-tools button {
  width: auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--surface);
}

.layer-row strong,
.layer-row span {
  display: block;
}

.layer-row span {
  color: var(--muted);
  font-size: 0.88rem;
}

button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  background: var(--primary);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  background: var(--primary-pressed);
}

.secondary-button {
  margin-top: 10px;
  background: var(--brand-teal);
  color: #ffffff;
}

.secondary-button:hover {
  background: var(--brand-teal-mid);
}

.field-label {
  display: block;
  margin: 4px 0 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

select {
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font: inherit;
}

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
}

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

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

.slider::before {
  position: absolute;
  content: "";
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.25);
}

.switch input:checked + .slider {
  background: var(--brand-teal-mid);
}

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

.stats {
  display: grid;
  gap: 10px;
  margin: 0;
}

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.stats dt {
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-weight: 800;
  text-align: right;
}

.section-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-heading-row h2 {
  margin-bottom: 0;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  border-radius: 50%;
  font-size: 1.3rem;
  line-height: 1;
}

.route-editing-tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.routes-list {
  display: grid;
  gap: 10px;
}

.empty-state {
  margin: 0;
  color: #64748b;
  font-size: 0.9rem;
}

.route-item {
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  background: var(--card);
}

.route-item.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(0, 237, 100, 0.16);
}

.route-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.route-main strong,
.route-main span {
  display: block;
}

.route-main span {
  color: var(--muted);
  font-size: 0.84rem;
}

.route-swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 0 1px #cbd5e1;
  flex: 0 0 auto;
}

.route-badges {
  display: flex;
  gap: 6px;
  margin: 8px 0;
}

.route-badges span {
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-feature);
  color: var(--brand-teal);
  font-size: 0.75rem;
  font-weight: 700;
}

.route-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.route-actions button,
.popup-actions button {
  min-height: 30px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.route-actions button:hover,
.popup-actions button:hover {
  background: var(--border);
}

.route-label {
  padding: 2px 6px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  font-weight: 900;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.2);
}

.route-popup dl {
  display: grid;
  gap: 4px;
  margin: 8px 0;
}

.route-popup dl div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.route-popup dt {
  color: #64748b;
}

.route-popup dd {
  margin: 0;
  font-weight: 800;
}

.popup-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.message {
  display: none;
}

.message.error {
  display: none;
}

.map-wrap {
  position: relative;
  width: 100%;
  height: 100vh;
  min-width: 0;
  overflow: hidden;
  padding: 86px 18px 18px;
  background: var(--bg);
}

#map {
  position: absolute;
  inset: 86px 18px 18px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.leaflet-container {
  width: 100%;
  height: 100%;
}

.loading {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 600;
  padding: 10px 14px;
  background: var(--brand-teal);
  color: #ffffff;
  border-radius: 999px;
  box-shadow: var(--shadow-card);
}

.route-toolbar {
  position: absolute;
  top: 18px;
  left: 18px;
  right: 18px;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  padding: 8px 0;
  pointer-events: none;
}

.route-toolbar > div {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.route-toolbar span {
  color: var(--muted);
}

.route-chips,
.route-focus-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.route-chip,
.route-focus-buttons button {
  width: auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
}

.route-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.route-chip span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.route-chip.active {
  border-color: var(--primary);
  color: var(--brand-teal);
  box-shadow: 0 0 0 3px rgba(0, 237, 100, 0.16);
}

.toolbar-empty {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
}

.hidden {
  display: none;
}

.popup-table {
  border-collapse: collapse;
  font-size: 0.82rem;
}

.popup-table th,
.popup-table td {
  padding: 4px 6px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
  vertical-align: top;
}

.popup-table th {
  color: #475569;
}

@media (max-width: 820px) {
  .app-shell {
    height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 70vh;
    overflow-y: auto;
  }

  .main-nav {
    height: auto;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .nav-list a {
    padding: 12px;
    font-size: 0.95rem;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid #d8dee9;
    height: auto;
  }

  .map-wrap {
    height: 70vh;
    min-height: 70vh;
    padding: 116px 12px 12px;
  }

  #map {
    inset: 116px 12px 12px;
  }

  .route-toolbar {
    align-items: flex-start;
    flex-direction: column;
    left: 12px;
    right: 12px;
  }

  .route-focus-buttons {
    display: none;
  }
}
