/* ═══════════════════════════════════════════════════════════════════
   MadiNi Cadastre Tool  — enterprise register aesthetic.
   Hairline borders, tabular numerals, mineral colors carry meaning.
   ═════════════════════════════════════════════════════════════════ */

:root {
  --ink: #0C0A09;
  --ink-2: #292524;
  --muted: #78716C;
  --muted-2: #A8A29E;
  --rule: #E7E5E4;
  --rule-strong: #D6D3D1;
  --canvas: #FAFAF9;
  --surface: #FFFFFF;
  --accent: #065F46;
  --accent-soft: #ECFDF5;
  --flag: #B45309;
  --nav-h: 4rem;
}

.cadastre-tool {
  height: calc(100vh - var(--nav-h));
  min-height: 640px;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
  color: var(--ink);
  font-feature-settings: "tnum" 1, "cv11" 1;
}

/* ─── Ribbon ────────────────────────────────────────────────────── */
.ribbon {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  font-size: 12px;
}
.ribbon__title {
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.ribbon__eyebrow {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.ribbon__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.ribbon__live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.ribbon__live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(6, 95, 70, 0.12);
}
.ribbon__metrics {
  display: flex;
  gap: 28px;
}
.ribbon__metric {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1;
}
.ribbon__metric strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.ribbon__metric span {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ─── Workspace grid ────────────────────────────────────────────── */
.workspace {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 308px 1fr 0;
  min-height: 0;
  transition: grid-template-columns 0.35s cubic-bezier(.2,.8,.2,1);
}
.workspace.has-drawer {
  grid-template-columns: 308px 1fr 360px;
}

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 99px; }

.sbx {
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
}
.sbx:last-child { border-bottom: none; }
.sbx__label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sbx__hint {
  color: var(--muted-2);
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: none;
}

/* Search */
.search-input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 9px 12px 9px 34px;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-input:focus {
  border-color: var(--ink);
  background: var(--surface);
}
.search-wrap {
  position: relative;
}
.search-wrap::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.55;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2378716C' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
}

/* Layer toggles */
.layer-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}
.layer-row + .layer-row {
  border-top: 1px dashed var(--rule);
}
.layer-row input {
  appearance: none;
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: var(--rule-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex: 0 0 auto;
}
.layer-row input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--surface);
  border-radius: 999px;
  transition: transform 0.2s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.layer-row input:checked {
  background: var(--ink);
}
.layer-row input:checked::after {
  transform: translateX(12px);
}
.layer-row__name {
  flex: 1;
  font-weight: 500;
}
.layer-row__count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}

/* Basemap radio */
.basemap-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.basemap-option {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 7px 10px;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
.basemap-option:hover { border-color: var(--rule-strong); }
.basemap-option.is-active {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

/* Commodity + type chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 10px 5px 7px;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  transition: all 0.15s;
  margin: 0 4px 6px 0;
  line-height: 1;
}
.chip:hover { border-color: var(--rule-strong); }
.chip.is-active {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.chip__swatch {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  flex: 0 0 auto;
}
.chip__count {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.chip.is-active .chip__count { color: rgba(255,255,255,0.72); }

/* Legend */
.legend-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12px;
  color: var(--ink-2);
  border-bottom: 1px dashed var(--rule);
}
.legend-row:last-child { border-bottom: none; }
.legend-row__dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 8px;
  vertical-align: middle;
}
.legend-row__name {
  flex: 1;
  display: flex;
  align-items: center;
}
.legend-row__val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
}

/* Footer actions inside sidebar */
.sbx--actions {
  display: flex;
  gap: 6px;
  padding: 14px 20px;
  background: var(--surface);
  border-top: 1px solid var(--rule);
  margin-top: auto;
}
.sbx-btn {
  flex: 1;
  font-size: 12px;
  font-weight: 500;
  padding: 8px 10px;
  background: var(--canvas);
  border: 1px solid var(--rule);
  border-radius: 6px;
  color: var(--ink-2);
  cursor: pointer;
  transition: all 0.15s;
}
.sbx-btn:hover { background: var(--surface); border-color: var(--rule-strong); }
.sbx-btn--primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.sbx-btn--primary:hover { background: var(--ink-2); border-color: var(--ink-2); }

/* ─── Map area ──────────────────────────────────────────────────── */
.map-area {
  position: relative;
  background: var(--canvas);
  min-height: 0;
  overflow: hidden;
}
#cadastre-map {
  position: absolute;
  inset: 0;
  background: var(--canvas);
}
.leaflet-container { font-family: inherit; background: var(--canvas); }
.leaflet-control-zoom {
  border: 1px solid var(--rule) !important;
  border-radius: 6px !important;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04) !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--ink) !important;
  border-bottom: 1px solid var(--rule) !important;
  font-weight: 400 !important;
  width: 28px !important;
  height: 28px !important;
  line-height: 28px !important;
}
.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-scale-line {
  background: rgba(255,255,255,0.88) !important;
  border: 1px solid var(--rule) !important;
  color: var(--ink-2) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  border-radius: 4px !important;
  padding: 2px 6px !important;
}

/* Map status strip (bottom) */
.map-status {
  position: absolute;
  left: 16px;
  bottom: 48px;
  z-index: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--ink-2);
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}
.map-status strong {
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 600;
}
.map-status__sep { color: var(--rule-strong); }

/* Map loading veil */
.map-loading {
  position: absolute;
  inset: 0;
  z-index: 650;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(250, 250, 249, 0.92);
  transition: opacity 0.5s;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.map-loading.is-hidden { opacity: 0; pointer-events: none; }
.map-loading__spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
  margin-right: 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Attribution */
.map-attrib {
  position: absolute;
  right: 8px;
  bottom: 6px;
  z-index: 600;
  font-size: 10px;
  color: var(--muted-2);
  background: rgba(255,255,255,0.82);
  padding: 2px 6px;
  border-radius: 3px;
}
.map-attrib a { color: var(--muted); text-decoration: none; }
.map-attrib a:hover { color: var(--ink); }

/* ─── Details drawer ────────────────────────────────────────────── */
.drawer {
  background: var(--surface);
  border-left: 1px solid var(--rule);
  overflow-y: auto;
  overscroll-behavior: contain;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(.2,.8,.2,1);
}
.workspace.has-drawer .drawer { transform: translateX(0); }
.drawer__head {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.drawer__kind {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}
.drawer__title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.drawer__sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.drawer__close {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  flex: 0 0 auto;
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
}
.drawer__close:hover { background: var(--canvas); border-color: var(--rule-strong); }

.drawer__swatch {
  width: 4px;
  align-self: stretch;
  border-radius: 2px;
}

.drawer__body {
  padding: 16px 20px;
}
.drawer__section {
  margin-bottom: 20px;
}
.drawer__section-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.kv {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.kv__row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--rule);
}
.kv__row:last-child { border-bottom: none; padding-bottom: 0; }
.kv__key {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.kv__val {
  font-size: 13px;
  color: var(--ink);
  font-weight: 500;
}

.match {
  display: block;
  padding: 10px 12px;
  border: 1px solid var(--rule);
  border-radius: 6px;
  margin-bottom: 6px;
  text-decoration: none;
  transition: all 0.15s;
}
.match:hover { border-color: var(--ink); background: var(--canvas); }
.match__title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  display: block;
  margin-bottom: 2px;
}
.match__ref {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.04em;
}
.match__arrow { float: right; color: var(--accent); font-weight: 600; }

.drawer__cta {
  display: block;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--surface);
  border-radius: 6px;
  text-decoration: none;
  margin-top: 8px;
}
.drawer__cta:hover { background: var(--ink-2); }

.drawer__skeleton {
  padding: 24px 20px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.drawer__skeleton-spin {
  width: 14px;
  height: 14px;
  border: 2px solid var(--rule);
  border-top-color: var(--ink);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

/* ─── Leaflet tooltip override ──────────────────────────────────── */
.cad-tt {
  background: var(--ink) !important;
  color: var(--surface) !important;
  border: none !important;
  border-radius: 4px !important;
  padding: 4px 8px !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18) !important;
  display: flex !important;
  align-items: center;
  gap: 6px;
}
.cad-tt::before { border-top-color: var(--ink) !important; }
.cad-tt .tt-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 1px;
}
.cad-tt .tt-area {
  color: rgba(255,255,255,0.68);
  margin-left: 6px;
  font-variant-numeric: tabular-nums;
}

/* Hide default Leaflet attribution control — we render our own */
.leaflet-container .leaflet-control-attribution { display: none; }

/* ─── Responsive ────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .workspace.has-drawer {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .sidebar {
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--rule);
  }
  .drawer {
    transform: translateY(100%);
    border-left: none;
    border-top: 1px solid var(--rule);
    max-height: 60vh;
  }
  .workspace.has-drawer .drawer { transform: translateY(0); }
  .ribbon__metrics { gap: 14px; }
  .ribbon__metric strong { font-size: 13px; }
}

/* ─── Map cockpit additions (colour-by, tool mode, DMS readout) ─────────── */
.colormode-option.is-active, .toolmode-option.is-active {
  background: var(--lx-ink, #1C1A17); color: var(--lx-bg, #F6F2EA);
  border-color: var(--lx-ink, #1C1A17);
}

.map-coord {
  position: absolute;
  right: 14px; bottom: 14px;
  background: rgba(251, 249, 244, 0.94);
  border: 1px solid var(--lx-hairline, #D9D1C1);
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--lx-ink-soft, #3A342C);
  padding: 5px 10px;
  pointer-events: none;
  letter-spacing: .02em;
  white-space: nowrap;
}

/* Measure label — small tag at the end of a measure segment. */
.measure-label {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px; color: var(--lx-bg, #F6F2EA);
  background: var(--lx-ink, #1C1A17);
  padding: 2px 7px;
  border-radius: 2px;
  white-space: nowrap;
  transform: translate(8px, -8px);
}

/* Multi-result popup — used when Identify lands on overlapping parcels. */
.multi-leaflet-popup .leaflet-popup-content-wrapper {
  background: var(--lx-surface, #FBF9F4);
  border-radius: 4px;
  padding: 0;
}
.multi-leaflet-popup .leaflet-popup-content { margin: 0; width: 300px !important; }
.multi-popup__head {
  font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--lx-muted, #6B6355); font-weight: 600;
  padding: 10px 14px; border-bottom: 1px solid var(--lx-hairline, #D9D1C1);
  background: var(--lx-surface-2, #F1ECE1);
}
.multi-popup .multi-row {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px; text-decoration: none; color: inherit;
  border-bottom: 1px solid var(--lx-hairline, #D9D1C1);
  font-size: 13px;
}
.multi-popup .multi-row:last-of-type { border-bottom: none; }
.multi-popup .multi-row:hover { background: var(--lx-surface-2, #F1ECE1); }
.multi-popup .multi-row strong { color: var(--lx-ink, #1C1A17); font-weight: 600; }
.multi-popup .multi-row span   { color: var(--lx-muted, #6B6355); font-size: 11.5px; }
.multi-popup__more { padding: 8px 14px; color: var(--lx-faint, #9C9280); font-size: 11.5px; font-style: italic; }
