:root {
  color-scheme: light;
  --font-inter: "Inter", ui-sans-serif, system-ui, sans-serif;
  --font-be-vietnam-pro: "Be Vietnam Pro", ui-sans-serif, system-ui, sans-serif;
  --font-jakarta: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
  --font-crimson-text: "Crimson Text", ui-serif, Georgia, "Times New Roman", serif;
  --font-sans: var(--font-inter);
  --font-header: var(--font-be-vietnam-pro);
  --font-accent: var(--font-jakarta);
  --font-body: var(--font-crimson-text);
  --text: #171717;
  --muted: #666666;
  --soft: #8a8a8a;
  --surface: #ffffff;
  --surface-soft: #fafafa;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.16);
  --blue: #0a72ef;
  --blue-soft: #ebf5ff;
  --green: #067647;
  --canopy: #0f8a4b;
  --shadow-card: 0 0 0 1px var(--line), 0 2px 2px rgba(0, 0, 0, 0.04), 0 18px 48px rgba(0, 0, 0, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body,
.map-shell,
.map-canvas {
  width: 100%;
  height: 100%;
  min-height: 480px;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--surface-soft);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
a {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.map-shell {
  position: relative;
  overflow: hidden;
}

.map-canvas {
  position: absolute;
  inset: 0;
  background: #edf0ed;
}

.map-loader {
  position: absolute;
  z-index: 900;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(250, 250, 250, 0.34);
  backdrop-filter: blur(2px);
}

.map-loader-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--text);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-card);
  font-family: var(--font-accent);
  font-size: 13px;
  font-weight: 800;
}

.map-loader-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(6, 118, 71, 0.18);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: loader-spin 820ms linear infinite;
}

.map-loader.is-error .map-loader-spinner {
  border-color: rgba(180, 35, 24, 0.18);
  border-top-color: #b42318;
}

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

.status-panel {
  position: absolute;
  z-index: 500;
  top: 16px;
  left: 16px;
  width: min(380px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  display: grid;
  gap: 14px;
  padding: 16px;
  overflow: auto;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(16px);
}

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

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

h1 {
  margin: 0;
  font-family: var(--font-header);
  font-size: 24px;
  line-height: 1.08;
  font-weight: 700;
  letter-spacing: 0;
}

.source-badge {
  flex: 0 0 auto;
  padding: 4px 9px;
  border-radius: 9999px;
  color: #0068d6;
  background: var(--blue-soft);
  font-size: 12px;
  font-family: var(--font-accent);
  font-weight: 700;
  line-height: 1.3;
}

.status-text {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--line);
  box-shadow: 0 0 0 1px var(--line);
}

.stats-grid > div {
  min-width: 0;
  padding: 10px;
  background: var(--surface);
}

.stats-grid dt {
  margin: 0 0 6px;
  color: var(--soft);
  font-family: var(--font-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.stats-grid dd {
  margin: 0;
  color: var(--text);
  font-family: var(--font-accent);
  font-size: 22px;
  line-height: 1;
  font-weight: 800;
}

.map-shell.is-project-view .stats-grid {
  grid-template-columns: 1fr;
}

.map-shell.is-project-view .stat-projects,
.map-shell.is-project-view .stat-zones,
.map-shell.is-project-view .stat-features,
.map-shell.is-project-view .project-list {
  display: none;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.panel-actions button,
.panel-actions a {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  font-size: 13px;
  font-family: var(--font-accent);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.panel-actions button:hover,
.panel-actions a:hover {
  background: var(--surface-soft);
}

.panel-actions button:focus-visible,
.panel-actions a:focus-visible,
.project-main:focus-visible,
.project-icon-button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

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

.project-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}

.project-item:hover {
  box-shadow: 0 0 0 1px var(--line-strong), 0 8px 20px rgba(0, 0, 0, 0.06);
}

.project-item.is-active {
  background: color-mix(in srgb, var(--surface) 88%, rgba(15, 138, 75, 0.14));
  box-shadow: 0 0 0 1px rgba(15, 138, 75, 0.42), 0 10px 24px rgba(0, 0, 0, 0.08);
}

.project-main {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px;
  border: 0;
  border-radius: 6px;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.project-main:hover {
  background: rgba(0, 0, 0, 0.03);
}

.project-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(6, 118, 71, 0.12);
}

.project-dot.has-trees {
  background: var(--canopy);
  box-shadow: 0 0 0 4px rgba(15, 138, 75, 0.18);
}

.project-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-accent);
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-meta {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.project-icon-button {
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  box-shadow: 0 0 0 1px var(--line);
  text-decoration: none;
  cursor: pointer;
}

.project-icon-button:hover {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.project-icon-button[aria-pressed="true"] {
  color: #ffffff;
  background: var(--green);
  box-shadow: 0 0 0 1px var(--green);
}

.project-icon-button svg {
  width: 16px;
  height: 16px;
}

.detail-panel {
  position: absolute;
  z-index: 1200;
  top: 16px;
  right: 16px;
  width: min(430px, calc(100% - 32px));
  height: calc(100% - 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(16px);
}

.detail-panel[hidden] {
  display: none;
}

.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-header h2 {
  margin: 0;
  font-family: var(--font-header);
  font-size: 22px;
  line-height: 1.12;
  font-weight: 700;
  letter-spacing: 0;
}

.detail-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.detail-header-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
}

.detail-header-button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  color: var(--text);
  background: var(--surface-soft);
  box-shadow: 0 0 0 1px var(--line);
  font-size: 12px;
  font-family: var(--font-accent);
  font-weight: 700;
  cursor: pointer;
}

.detail-header-button:hover,
.detail-header-button[aria-expanded="true"] {
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.detail-header-button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.detail-section {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.detail-section[hidden] {
  display: none;
}

.detail-section h3 {
  margin: 0;
  color: var(--soft);
  font-family: var(--font-accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-list {
  display: grid;
  grid-template-columns: minmax(92px, 0.42fr) minmax(0, 1fr);
  gap: 1px;
  margin: 0;
  overflow: hidden;
  border-radius: 8px;
  background: var(--line);
  box-shadow: 0 0 0 1px var(--line);
}

.detail-list dt,
.detail-list dd {
  min-width: 0;
  margin: 0;
  padding: 9px 10px;
  background: var(--surface);
  font-size: 12px;
  line-height: 1.35;
}

.detail-list dt {
  color: var(--soft);
  font-family: var(--font-accent);
  font-weight: 700;
}

.detail-list dd {
  color: var(--text);
  overflow-wrap: anywhere;
}

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

.media-card {
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  text-decoration: none;
}

.media-card:only-child {
  grid-column: 1 / -1;
}

.media-card:hover {
  box-shadow: 0 0 0 1px var(--line-strong), 0 10px 24px rgba(0, 0, 0, 0.1);
}

.media-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: 220px;
  object-fit: cover;
  background: #edf0ed;
}

.media-caption {
  display: block;
  padding: 8px 9px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--font-accent);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-raw {
  min-height: 156px;
  max-height: 280px;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border-radius: 8px;
  color: #1f2937;
  background: #f6f8f7;
  box-shadow: 0 0 0 1px var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.leaflet-control-zoom,
.leaflet-control-attribution {
  border: 0 !important;
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px rgba(0, 0, 0, 0.08) !important;
}

.leaflet-control-zoom a {
  color: var(--text) !important;
  border-color: var(--line) !important;
}

.error-state {
  color: #b42318;
}

@media (max-width: 680px) {
  html,
  body,
  .map-shell,
  .map-canvas {
    min-height: 620px;
  }

  .status-panel {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    width: auto;
    max-height: 54%;
    padding: 14px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .detail-panel {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    height: 58%;
    padding: 14px;
  }

  .map-shell.has-detail .status-panel {
    max-height: 30%;
  }

  .detail-header h2 {
    font-size: 20px;
  }

  h1 {
    font-size: 21px;
  }
}
