:root {
  color-scheme: light;
  --bg: #dde5df;
  --panel: #f8f8f4;
  --panel-soft: rgba(248, 248, 244, 0.93);
  --ink: #202821;
  --muted: #687269;
  --line: #d8ded5;
  --accent: #2f6841;
  --accent-strong: #1f4c31;
  --blue: #2f6f96;
  --shadow: 0 18px 50px rgba(31, 42, 35, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.map-stage,
.map {
  position: absolute;
  inset: 0;
}

.map {
  background: #d9e2dc;
}

.sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 12px;
  overflow: auto;
  background: var(--panel-soft);
  border: 1px solid rgba(206, 215, 203, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 2px 2px 5px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 15px;
}

h3 {
  margin-bottom: 8px;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
  text-transform: uppercase;
}

.campo-toggle {
  display: flex;
  gap: 6px;
}

.campo-option {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  background: #e4ecdf;
  border: 1px solid #c9d9c4;
  border-radius: 999px;
  transition:
    background 160ms ease,
    color 160ms ease;
}

.campo-option:hover {
  background: #d9e8d3;
}

.campo-option.is-active {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.campo-option.is-active:hover {
  background: var(--accent);
}

.campo-option.is-disabled {
  color: #a7b0a4;
  cursor: not-allowed;
  background: #eef1ec;
  border-color: #e2e7de;
}

.campo-option.is-disabled:hover {
  background: #eef1ec;
}

.panel {
  padding: 10px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.location-button {
  position: absolute;
  right: 352px;
  bottom: 16px;
  z-index: 9;
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--accent-strong);
  background: #edf4e9;
  border: 1px solid #cbd9c6;
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(31, 42, 35, 0.18);
  cursor: pointer;
}

.location-button:hover {
  background: #e2eddd;
}

.location-button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.location-button.is-active {
  color: #fff;
  background: var(--blue);
  border-color: #245a7d;
}

.location-dot {
  position: relative;
  width: 14px;
  height: 14px;
  background: currentColor;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(47, 111, 150, 0.16);
}

.location-dot::after {
  position: absolute;
  inset: -7px;
  content: "";
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0.28;
}

.location-status {
  position: absolute;
  right: 404px;
  bottom: 19px;
  z-index: 9;
  max-width: min(300px, calc(100vw - 428px));
  padding: 7px 10px;
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  background: rgba(248, 248, 244, 0.92);
  border: 1px solid rgba(203, 217, 198, 0.96);
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(31, 42, 35, 0.14);
  opacity: 1;
  transition:
    opacity 150ms ease,
    transform 150ms ease;
  transform: translateY(0);
  pointer-events: none;
}

.location-status[data-state=""] {
  opacity: 0;
  transform: translateY(4px);
}

.location-status[data-state="pending"] {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  color: var(--accent-strong);
}

.location-status[data-state="pending"]::before {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  content: "";
  border: 2px solid rgba(47, 104, 65, 0.24);
  border-top-color: var(--accent-strong);
  border-radius: 50%;
  animation: location-spin 800ms linear infinite;
}

.location-status[data-state="active"] {
  color: #173d56;
  border-color: rgba(47, 111, 150, 0.36);
}

.location-status[data-state="error"] {
  color: #7b271e;
  border-color: rgba(123, 39, 30, 0.28);
}

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

.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;
}

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

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

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

.layer-group {
  display: grid;
  gap: 6px;
}

.layer-group-list {
  display: grid;
  gap: 7px;
}

.layer-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 7px 8px;
  min-height: 50px;
  padding: 8px;
  background: rgba(246, 248, 244, 0.86);
  border: 1px solid #e0e6dc;
  border-radius: 8px;
}

.layer-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 9px;
}

.swatch {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  background: var(--swatch);
  border: 2px solid color-mix(in srgb, var(--swatch), #000 24%);
  border-radius: 5px;
}

.layer-title {
  min-width: 0;
}

.layer-title strong,
.layer-title span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-title strong {
  font-size: 13px;
}

.layer-title span {
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.switch {
  position: relative;
  align-self: center;
  width: 36px;
  height: 21px;
  flex: 0 0 36px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  background: #c7d0c5;
  border-radius: 999px;
  cursor: pointer;
  transition: background 160ms ease;
}

.switch span::before {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  content: "";
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(30, 36, 26, 0.22);
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::before {
  transform: translateX(15px);
}

.opacity-control {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

.opacity-control input {
  width: 100%;
  accent-color: var(--accent);
}

.base-toggle-labels {
  display: flex;
  grid-column: 1 / -1;
  justify-content: space-between;
  margin-top: -2px;
  font-size: 11px;
  color: var(--muted);
}

.base-toggle-label.is-active {
  color: var(--accent-strong);
  font-weight: 700;
}

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

.map-legend {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 10;
  width: min(280px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow: auto;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.map-legend.is-dragging,
.map-details.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.map-legend.is-collapsed {
  overflow: hidden;
}

.map-legend.is-collapsed .legend-list {
  display: none;
}

.draggable-heading {
  cursor: grab;
  touch-action: none;
}

.draggable-heading h2 {
  user-select: none;
}

.map-details {
  position: absolute;
  right: 16px;
  bottom: 74px;
  z-index: 10;
  width: min(320px, calc(100vw - 32px));
  max-height: min(260px, calc(100vh - 390px));
  overflow: auto;
  background: var(--panel-soft);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.map-details:not(.is-populated) {
  max-height: none;
}

.mini-button {
  min-height: 24px;
  padding: 3px 9px;
  color: var(--accent-strong);
  background: #edf4e9;
  border: 1px solid #cbd9c6;
  border-radius: 7px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
}

.mini-button:hover {
  background: #e2eddd;
}

.icon-mini-button {
  min-width: 58px;
}

.legend-group {
  display: grid;
  gap: 6px;
}

.legend-items {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.legend-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 22px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.2;
}

.legend-item span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-symbol {
  position: relative;
  display: block;
  width: 24px;
  height: 18px;
  color: var(--legend-color);
}

.legend-polygon,
.legend-polygon-hatch {
  background: color-mix(in srgb, var(--legend-color), transparent 34%);
  border: 2px solid color-mix(in srgb, var(--legend-color), #000 24%);
  border-radius: 4px;
}

.legend-polygon-hatch {
  background:
    repeating-linear-gradient(
      135deg,
      color-mix(in srgb, var(--legend-color), #fff 18%) 0,
      color-mix(in srgb, var(--legend-color), #fff 18%) 2px,
      transparent 2px,
      transparent 6px
    ),
    color-mix(in srgb, var(--legend-color), transparent 28%);
}

.legend-line::before,
.legend-line-dash::before,
.legend-line-dot::before,
.legend-road::before,
.legend-road-dash::before {
  position: absolute;
  top: 8px;
  left: 1px;
  width: 22px;
  height: 0;
  content: "";
  border-top: 4px solid var(--legend-color);
  border-radius: 999px;
}

.legend-line-dash::before,
.legend-road-dash::before {
  border-top-style: dashed;
}

.legend-line-dot::before {
  border-top-style: dotted;
}

.legend-road::before,
.legend-road-dash::before {
  top: 7px;
  border-top: 6px solid #6f5136;
}

.legend-road::after,
.legend-road-dash::after {
  position: absolute;
  top: 8px;
  left: 2px;
  width: 20px;
  height: 0;
  content: "";
  border-top: 3px solid var(--legend-color);
  border-radius: 999px;
}

.legend-road-dash::after {
  border-top-style: dashed;
}

.legend-water::before,
.legend-diamond::before,
.legend-windmill::before,
.legend-gate::before,
.legend-corral::before {
  position: absolute;
  content: "";
}

.legend-water::before {
  top: 2px;
  left: 5px;
  width: 14px;
  height: 14px;
  background: var(--legend-color);
  border: 2px solid color-mix(in srgb, var(--legend-color), #000 32%);
  border-radius: 50%;
}

.legend-diamond::before {
  top: 3px;
  left: 6px;
  width: 12px;
  height: 12px;
  background: var(--legend-color);
  border: 2px solid color-mix(in srgb, var(--legend-color), #000 28%);
  transform: rotate(45deg);
}

.legend-windmill::before {
  top: 7px;
  left: 4px;
  width: 16px;
  height: 4px;
  background: var(--legend-color);
  border: 1px solid color-mix(in srgb, var(--legend-color), #000 35%);
  box-shadow:
    0 0 0 0 var(--legend-color),
    0 0 0 0 var(--legend-color);
  transform: rotate(45deg);
}

.legend-windmill::after {
  position: absolute;
  top: 7px;
  left: 4px;
  width: 16px;
  height: 4px;
  content: "";
  background: var(--legend-color);
  border: 1px solid color-mix(in srgb, var(--legend-color), #000 35%);
  transform: rotate(-45deg);
}

.legend-corral::before {
  inset: 2px 3px;
  background:
    linear-gradient(90deg, transparent 30%, var(--legend-color) 30% 42%, transparent 42% 62%, var(--legend-color) 62% 74%, transparent 74%),
    repeating-linear-gradient(0deg, var(--legend-color) 0 3px, transparent 3px 7px);
}

.legend-gate::before {
  top: 4px;
  left: 4px;
  width: 16px;
  height: 9px;
  border-left: 4px solid var(--legend-color);
  border-right: 4px solid color-mix(in srgb, var(--legend-color), transparent 35%);
  border-top: 4px solid var(--legend-color);
  transform: skewY(-16deg);
}

.details {
  color: var(--ink);
  font-size: 12px;
}

.empty-state,
.muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.feature-details {
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.feature-details:first-child {
  padding-top: 0;
  border-top: 0;
}

.feature-details h3 {
  margin-bottom: 6px;
  color: var(--accent-strong);
}

dl {
  display: grid;
  grid-template-columns: minmax(78px, 0.42fr) minmax(0, 1fr);
  gap: 4px 8px;
  margin: 0;
}

dt {
  min-width: 0;
  color: var(--muted);
  font-weight: 700;
}

dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.ol-zoom {
  top: auto;
  right: 16px;
  bottom: 16px;
  left: auto;
}

.ol-zoom button {
  background: rgba(248, 248, 244, 0.92);
  color: var(--ink);
  border-radius: 6px;
}

.mobile-toolbar {
  display: none;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    height: 100dvh;
  }

  .sidebar {
    top: auto;
    right: 10px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    max-height: min(52dvh, 460px);
    padding: 10px;
    border-radius: 8px;
    transition:
      transform 180ms ease,
      opacity 180ms ease;
  }

  .sidebar.mobile-hidden,
  .map-legend.mobile-hidden,
  .map-details.mobile-hidden {
    pointer-events: none;
    opacity: 0;
    transform: translateY(18px);
  }

  .brand {
    padding-bottom: 2px;
  }

  .eyebrow {
    font-size: 10px;
  }

  h1 {
    font-size: 22px;
  }

  h2 {
    font-size: 14px;
  }

  h3 {
    margin-bottom: 5px;
    font-size: 10px;
  }

  .campo-option {
    padding: 7px 10px;
    font-size: 11px;
  }

  .panel {
    padding: 9px;
  }

  .layer-list,
  .layer-group-list {
    gap: 7px;
  }

  .layer-item {
    grid-template-columns: minmax(0, 1fr) 46px;
    min-height: 48px;
    padding: 8px;
  }

  .layer-title strong {
    font-size: 12px;
  }

  .layer-title span,
  .opacity-control,
  .count,
  .details,
  .legend-item,
  .location-status {
    font-size: 11px;
  }

  .switch {
    width: 42px;
    height: 24px;
    flex-basis: 42px;
  }

  .switch span::before {
    width: 18px;
    height: 18px;
  }

  .switch input:checked + span::before {
    transform: translateX(18px);
  }

  .opacity-control {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .map-legend,
  .map-details {
    top: auto !important;
    right: 10px !important;
    bottom: calc(64px + env(safe-area-inset-bottom)) !important;
    left: 10px !important;
    width: auto;
    max-height: min(44dvh, 380px);
    transition:
      transform 180ms ease,
      opacity 180ms ease;
  }

  .map-legend {
    display: grid;
  }

  .map-legend:not(.mobile-hidden) {
    overflow: auto;
  }

  .map-details {
    max-height: min(32dvh, 260px);
  }

  .location-button {
    top: calc(10px + env(safe-area-inset-top));
    right: 10px;
    bottom: auto;
    z-index: 13;
    width: 42px;
    height: 42px;
  }

  .location-status {
    top: calc(13px + env(safe-area-inset-top));
    right: 60px;
    bottom: auto;
    z-index: 13;
    max-width: calc(100vw - 84px);
  }

  .ol-zoom {
    right: 10px;
    bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .mobile-toolbar {
    position: absolute;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    z-index: 12;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 7px;
    background: rgba(248, 248, 244, 0.94);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 14px 34px rgba(31, 42, 35, 0.18);
    backdrop-filter: blur(12px);
  }

  .mobile-tool {
    min-height: 40px;
    padding: 7px 8px;
    color: var(--accent-strong);
    background: #edf4e9;
    border: 1px solid #cbd9c6;
    border-radius: 7px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 800;
  }

  .mobile-tool.is-active {
    color: #fff;
    background: var(--accent);
    border-color: var(--accent-strong);
  }
}

@media (max-width: 480px) {
  .sidebar {
    max-height: min(58dvh, 520px);
  }

  .map-legend,
  .map-details {
    max-height: min(46dvh, 390px);
  }

  .map-details {
    max-height: min(34dvh, 280px);
  }

}
