:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: #ffffff;
  --panel-soft: #eef2eb;
  --text: #17201a;
  --muted: #667066;
  --line: #d9dfd6;
  --green: #0f6b43;
  --green-soft: #dcece3;
  --amber: #d97921;
  --blue: #2f6f9f;
  --teal: #09907f;
  --shadow: 0 14px 40px rgba(30, 42, 34, 0.14);
}

* {
  box-sizing: border-box;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  transition: grid-template-columns 180ms ease;
}

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

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  padding: 22px;
  overflow: auto;
  min-width: 0;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.sidebar-toggle {
  margin-left: auto;
  font-size: 24px;
}

.app-shell.sidebar-collapsed .sidebar {
  padding: 14px 8px;
  overflow: hidden;
}

.app-shell.sidebar-collapsed .brand {
  justify-content: center;
  margin-bottom: 0;
}

.app-shell.sidebar-collapsed .mark,
.app-shell.sidebar-collapsed .brand > div:not(.mark),
.app-shell.sidebar-collapsed .panel {
  display: none;
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  margin-left: 0;
}

.mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.28), transparent),
    var(--green);
  box-shadow: inset 0 -10px 0 rgba(0, 0, 0, 0.08);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

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

.panel h2,
.detail-panel h2,
.table-header h2 {
  font-size: 13px;
  line-height: 1.2;
  font-weight: 760;
  text-transform: uppercase;
  color: #344036;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 14px;
}

.metrics div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metrics span {
  display: block;
  font-size: 23px;
  line-height: 1;
  font-weight: 780;
  color: var(--green);
}

.metrics label {
  display: block;
  margin-top: 5px;
  font-size: 12px;
  color: var(--muted);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 4px 8px;
  margin: 2px -8px;
  border-radius: 8px;
  font-size: 14px;
  color: #2f392f;
}

.check-row input {
  accent-color: var(--green);
}

.layer-row {
  cursor: pointer;
  border-left: 3px solid transparent;
}

.layer-row:hover {
  background: #f0f4ee;
}

.layer-row.active-layer {
  border-left-color: var(--green);
  background: var(--green-soft);
  font-weight: 760;
}

.layer-row input {
  cursor: pointer;
}

.layer-name {
  flex: 1;
}

.swatch {
  width: 18px;
  height: 12px;
  border-radius: 2px;
  border: 2px solid currentColor;
  background: rgba(255, 255, 255, 0.7);
}

.swatch.swd {
  color: var(--green);
  background: rgba(15, 107, 67, 0.2);
}

.swatch.revoked,
.swatch.revoked-regazetted {
  color: #be123c;
  background: rgba(190, 18, 60, 0.18);
}

.swatch.revoked-only {
  color: #c2410c;
  background: rgba(194, 65, 12, 0.18);
}

.swatch.parcel {
  color: var(--amber);
  background: rgba(217, 121, 33, 0.22);
}

.swatch.protected {
  color: var(--blue);
  background: rgba(47, 111, 159, 0.14);
}

.swatch.prior {
  color: var(--teal);
  background: rgba(9, 144, 127, 0.12);
}

#search {
  width: 100%;
  height: 38px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}

#search:focus {
  outline: 2px solid rgba(15, 107, 67, 0.22);
  border-color: var(--green);
}

.hint {
  margin-top: 9px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.plan-list {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.plan-link {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  background: var(--panel);
}

.plan-link:hover {
  border-color: rgba(15, 107, 67, 0.45);
  background: var(--green-soft);
}

.plan-link strong {
  font-size: 13px;
}

.plan-link span {
  font-size: 11px;
  color: var(--muted);
}

.detail-link {
  display: inline-block;
  margin-top: 3px;
  color: var(--green);
  font-size: 13px;
  font-weight: 720;
  text-decoration: none;
}

.detail-link:hover {
  text-decoration: underline;
}

.detail-plan-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.detail-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.detail-section > label {
  display: block;
  margin-bottom: 4px;
  font-size: 11px;
  color: var(--muted);
}

.detail-plan-block label {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  color: var(--muted);
}

.detail-plan-links {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.detail-plan-links .plan-cell-link {
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}

.map-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

#map {
  height: 100%;
  min-height: 420px;
  background: #dfe8dc;
}

.detail-panel {
  position: absolute;
  top: 18px;
  right: 18px;
  width: min(340px, calc(100% - 36px));
  max-height: calc(100vh - 330px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  z-index: 500;
}

.detail-panel.is-hidden {
  display: none;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: #344036;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.icon-button:hover {
  border-color: rgba(15, 107, 67, 0.45);
  background: var(--green-soft);
}

.icon-button:focus-visible {
  outline: 2px solid rgba(15, 107, 67, 0.28);
  outline-offset: 2px;
}

.empty-state {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.detail-grid div {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.detail-grid label {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.detail-grid span {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 680;
}

.table-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 520;
  height: 270px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
  box-shadow: 0 -12px 30px rgba(30, 42, 34, 0.12);
  transform: translateY(0);
  transition: transform 160ms ease, opacity 160ms ease;
}

.table-panel.is-hidden {
  transform: translateY(calc(100% + 8px));
  opacity: 0;
  pointer-events: none;
}

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

.table-resize-handle {
  position: absolute;
  top: -6px;
  left: 0;
  right: 0;
  height: 12px;
  cursor: ns-resize;
  touch-action: none;
}

.table-resize-handle::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 50%;
  width: 78px;
  height: 4px;
  border-radius: 999px;
  background: rgba(52, 64, 54, 0.36);
  transform: translateX(-50%);
}

.table-panel.is-resizing,
.table-panel.is-resizing * {
  user-select: none;
}

#row-count {
  font-size: 12px;
  color: var(--muted);
}

.table-scroll {
  height: calc(100% - 56px);
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 9px 12px;
  border-bottom: 1px solid #edf0eb;
  text-align: left;
  white-space: nowrap;
}

.plan-cell-link {
  color: var(--green);
  font-weight: 760;
  text-decoration: none;
}

.plan-cell-link:hover {
  text-decoration: underline;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f7f9f5;
  font-size: 11px;
  text-transform: uppercase;
  color: #596459;
}

.type-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}

.type-chip.absorbed {
  color: #5b2600;
  background: #ffe100;
}

.type-chip.mostly-absorbed {
  color: #713f12;
  background: #fde68a;
}

.type-chip.partial-overlap {
  color: #7c2d12;
  background: #ffedd5;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.active {
  background: #fff3e8;
}

tbody tr.active {
  box-shadow: inset 4px 0 0 #ffe100;
  font-weight: 720;
}

.selected-parcel {
  filter: drop-shadow(0 0 4px rgba(250, 204, 21, 0.85));
}

.leaflet-control-layers,
.leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow) !important;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(120px, 24vh) minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 48px minmax(0, 1fr);
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px 18px;
  }

  .app-shell.sidebar-collapsed .sidebar {
    padding: 8px 12px;
  }

  .map-area {
    min-height: 0;
  }

  .detail-panel {
    top: 10px;
    right: 10px;
    width: min(300px, calc(100% - 20px));
    max-height: calc(100% - 300px);
  }

  .table-panel {
    height: 230px;
  }

}
