:root {
  color-scheme: light;
  --ink: #16211e;
  --muted: #5d6a66;
  --line: #d7ded8;
  --panel: #fbfdfb;
  --accent: #1f6f5b;
  --accent-strong: #164f42;
  --warn: #a34d1c;
  --shadow: 0 16px 42px rgba(28, 42, 36, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: #e8eee8;
  color: var(--ink);
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  height: 100dvh;
  min-height: 620px;
}

.app-shell.panel-collapsed {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.panel-collapsed .control-panel {
  display: none;
}

.map-stage {
  position: relative;
  min-width: 0;
}

.map {
  width: 100%;
  height: 100%;
  background: #dbe4de;
}

.topbar,
.status-strip,
.control-panel {
  backdrop-filter: blur(16px);
}

.topbar {
  position: absolute;
  z-index: 600;
  top: max(14px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(560px, calc(100% - 28px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(251, 253, 251, 0.9);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 1.35rem;
}

.status-strip {
  position: absolute;
  z-index: 600;
  left: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  max-width: min(640px, calc(100% - 28px));
  padding: 9px 12px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: rgba(22, 33, 30, 0.86);
  color: #fff;
  font-size: 0.86rem;
}

.panel-toggle {
  position: absolute;
  z-index: 650;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  min-width: 112px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  background: rgba(251, 253, 251, 0.94);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  border-left: 1px solid var(--line);
  background: rgba(251, 253, 251, 0.94);
}

.panel-section {
  display: grid;
  gap: 8px;
}

label,
.section-heading,
.stats span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

select,
input,
button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

select,
input {
  width: 100%;
  padding: 0 11px;
}

button {
  padding: 0 12px;
  cursor: pointer;
  font-weight: 750;
}

button:hover {
  border-color: var(--accent);
}

.grid-actions,
.manual-target {
  grid-template-columns: 1fr 1fr;
}

.manual-target {
  display: none;
  gap: 8px;
}

.manual-target.is-visible {
  display: grid;
}

.manual-target button {
  grid-column: 1 / -1;
  background: var(--accent);
  color: #fff;
}

.stats {
  gap: 10px;
}

.stats div {
  display: grid;
  gap: 3px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.stats strong {
  min-height: 1.25rem;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-heading button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.feature-info,
.debug-log {
  min-height: 180px;
  max-height: 320px;
  margin: 0;
  overflow: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111a17;
  color: #e9f4ef;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.debug-section {
  padding-bottom: 8px;
}

.cadastre-links {
  display: grid;
  gap: 8px;
}

.cadastre-links:empty {
  display: none;
}

.cadastre-link {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 750;
  text-align: left;
  text-decoration: none;
}

.cadastre-link:hover {
  border-color: var(--accent);
}

.debug-log {
  min-height: 150px;
  max-height: 220px;
  background: #1a1f24;
  color: #dce7f5;
}

.cadastre-viewer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 24, 22, 0.58);
}

.cadastre-viewer[hidden] {
  display: none;
}

.cadastre-viewer__window {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1100px, 100%);
  height: min(820px, 100%);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.cadastre-viewer__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.cadastre-viewer__actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cadastre-viewer__actions a {
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 750;
}

.cadastre-viewer__actions button {
  min-height: 34px;
}

.cadastre-viewer iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.cadastre-viewer__fallback {
  align-self: center;
  justify-self: center;
  display: grid;
  gap: 12px;
  max-width: 560px;
  padding: 28px;
  text-align: center;
}

.cadastre-viewer__fallback[hidden] {
  display: none;
}

.cadastre-viewer__fallback strong {
  font-size: 1.1rem;
}

.cadastre-viewer__fallback p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.cadastre-viewer__fallback a {
  justify-self: center;
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  text-decoration: none;
}

.leaflet-control-zoom a {
  color: var(--ink);
}

.current-marker,
.target-marker {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 3px solid #fff;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.22);
}

.current-marker {
  background: #176fca;
}

.target-marker {
  background: var(--warn);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 58dvh) minmax(260px, 42dvh);
    min-height: 100dvh;
  }

  .app-shell.panel-collapsed {
    grid-template-rows: 1fr;
  }

  .control-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .panel-toggle {
    min-width: 102px;
  }

  .cadastre-viewer {
    padding: 8px;
  }

  .cadastre-viewer__window {
    height: 100%;
  }

  .cadastre-viewer__bar {
    align-items: flex-start;
    flex-direction: column;
  }
}
