/* Rwanda Plot Finder Web — Notion-Style Editorial GIS Design System */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-tint: #f7f6f3;
  --surface-hover: #efefec;
  --text: #37352f;
  --text-muted: #787774;
  --border: #e9e9e7;
  --primary: #2383e2;
  --primary-fg: #ffffff;
  --primary-soft: rgba(35, 131, 226, 0.12);
  --green: #0f7b6c;
  --green-soft: rgba(15, 123, 108, 0.14);
  --amber: #d9730d;
  --amber-soft: rgba(217, 115, 13, 0.14);
  --red: #e03e3e;
  --red-soft: rgba(224, 62, 62, 0.14);
  --shadow-sm: 0 2px 8px rgba(15, 15, 15, 0.08);
  --shadow-md: 0 6px 24px rgba(15, 15, 15, 0.12);
  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 14px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #191919;
  --surface: #202020;
  --surface-tint: #262626;
  --surface-hover: #2f2f2f;
  --text: #f0f0ee;
  --text-muted: #9b9a97;
  --border: #333333;
  --primary: #529cca;
  --primary-fg: #0d1117;
  --primary-soft: rgba(82, 156, 202, 0.18);
  --green: #4dab9a;
  --green-soft: rgba(77, 171, 154, 0.18);
  --amber: #ffa344;
  --amber-soft: rgba(255, 163, 68, 0.18);
  --red: #ff7369;
  --red-soft: rgba(255, 115, 105, 0.18);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.45);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
}

/* Compact Top Bar */
.topbar {
  height: 50px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  gap: 10px;
}

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

.brand-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, #2383e2 0%, #0f7b6c 100%);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  background: var(--surface-tint);
  border: 1px solid var(--border);
  color: var(--text-muted);
  white-space: nowrap;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-pill {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-pill:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-pill.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(35, 131, 226, 0.25);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  height: 32px;
  padding: 0 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
}

.icon-btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
}

.icon-btn.primary:hover {
  filter: brightness(1.06);
}

/* Main Workspace */
.workspace {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* Fullscreen Map Stage */
.map-stage {
  flex: 1;
  position: relative;
  min-width: 0;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
  background: #141a1f;
  z-index: 1;
}

/* Floating Search Bar over Map */
.floating-search-wrap {
  position: absolute;
  top: 10px;
  left: 12px;
  width: min(440px, calc(100% - 24px));
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 5px 6px 5px 11px;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  min-width: 0;
}

.search-box input::placeholder {
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-weight: 400;
}

.search-btn {
  border: none;
  background: var(--primary);
  color: var(--primary-fg);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  flex-shrink: 0;
}

.search-btn:hover {
  filter: brightness(1.06);
}

.search-dropdown {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 8px;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.search-dropdown.open {
  display: flex;
}

.dropdown-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 2px 4px 6px;
}

.section-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.quick-upi-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 8px;
  border-radius: 7px;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: left;
  width: 100%;
  font-family: inherit;
}

.quick-upi-row:hover {
  background: var(--surface-hover);
}

.quick-upi-code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
}

.quick-upi-meta {
  font-size: 11px;
  color: var(--text-muted);
}

/* Basemap & Scale Strip */
.map-top-controls {
  position: absolute;
  top: 62px;
  left: 12px;
  z-index: 450;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  box-shadow: var(--shadow-sm);
}

.segmented button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
}

.segmented button.active {
  background: var(--primary);
  color: var(--primary-fg);
}

.zoom-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
}

/* Right-Side Compact GIS Stack */
.map-right-stack {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 450;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-ctrl-group {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.map-ctrl-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.map-ctrl-btn:hover {
  background: var(--surface-hover);
}

.map-ctrl-btn + .map-ctrl-btn {
  border-top: 1px solid var(--border);
}

/* Main-Screen Visible Opacity Pill */
.map-opacity-pill {
  position: absolute;
  bottom: 14px;
  left: 12px;
  z-index: 450;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  box-shadow: var(--shadow-sm);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
}

.map-opacity-pill input[type="range"] {
  width: 96px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Layer Tree Checkboxes */
.tree-group {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-tint);
  overflow: hidden;
}

.tree-group-head {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  cursor: pointer;
  user-select: none;
}

.tree-group-head:hover {
  background: var(--surface-hover);
}

.tree-sub-list {
  display: none;
  flex-direction: column;
  border-top: 1px solid var(--border);
  padding: 3px 8px 5px 22px;
  background: var(--surface);
}

.tree-sub-list.open {
  display: flex;
}

.tree-sub-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  cursor: pointer;
  font-size: 11.5px;
}

.tree-sub-row + .tree-sub-row {
  border-top: 1px solid var(--border);
}

.tree-cb {
  width: 15px;
  height: 15px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}

/* Bottom Floating Action Pills over Map */
.map-bottom-pills {
  position: absolute;
  bottom: 14px;
  right: 12px;
  z-index: 450;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tool-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 11px;
  border-radius: 9px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.tool-pill:hover {
  background: var(--surface-hover);
}

.tool-pill.active {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
}

/* Ruler Floating Panel */
.ruler-panel {
  position: absolute;
  top: 106px;
  left: 12px;
  width: min(320px, calc(100% - 72px));
  z-index: 460;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px 12px;
  display: none;
  flex-direction: column;
  gap: 8px;
}

.ruler-panel.open {
  display: flex;
}

/* Neighbor Reference Popover */
.neighbor-popover {
  position: absolute;
  bottom: 58px;
  right: 12px;
  width: min(330px, calc(100% - 24px));
  z-index: 470;
  background: var(--surface);
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 11px 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
}

.neighbor-popover.open {
  display: flex;
}

/* Error Callout */
.error-card {
  background: var(--red-soft);
  border: 1px solid rgba(224, 62, 62, 0.35);
  color: var(--text);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 12px;
  display: none;
  flex-direction: column;
  gap: 6px;
  backdrop-filter: blur(8px);
}

.error-card.open {
  display: flex;
}

/* Side Drawer / Panel (Parcel Details, Layers, Saved, Android App) */
.side-panel {
  width: 390px;
  max-width: 100vw;
  flex-shrink: 0;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 600;
}

.side-panel.hidden {
  display: none;
}

.panel-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Notion-Style Compact Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card.tinted {
  background: var(--surface-tint);
}

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

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-tint);
  border: 1px solid var(--border);
  color: var(--text);
}

.pill.green {
  background: var(--green-soft);
  color: var(--green);
  border-color: transparent;
}

.pill.amber {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: transparent;
}

.pill.red {
  background: var(--red-soft);
  color: var(--red);
  border-color: transparent;
}

.prop-table {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-tint);
}

.prop-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  font-size: 12px;
}

.prop-row + .prop-row {
  border-top: 1px solid var(--border);
}

.prop-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.prop-val {
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

/* Horizontal District Chips */
.chip-row {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 7px;
  cursor: pointer;
}

.chip.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: rgba(35, 131, 226, 0.4);
}

/* Toggle Switch Row */
.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  cursor: pointer;
}

.switch-row + .switch-row {
  border-top: 1px solid var(--border);
}

.switch-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.switch-title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}

.switch-sub {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 99px;
  transition: 0.18s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: 0.18s;
}

.toggle input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* Buttons */
.btn-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  flex: 1;
}

.btn:hover {
  background: var(--surface-hover);
}

.btn.primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: transparent;
}

.btn.sm {
  padding: 5px 9px;
  font-size: 11px;
  flex: initial;
}

/* Accordion */
.accordion-head {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
}

.accordion-body {
  display: none;
  flex-direction: column;
  gap: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.accordion-body.open {
  display: flex;
}

/* Status Toast */
.toast {
  position: fixed;
  bottom: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 99px;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 1;
}

/* Mobile Bottom Bar */
.mobile-bottom-nav {
  display: none;
  height: 58px;
  flex-shrink: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 1000;
}

.mobile-bottom-nav button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}

.mobile-bottom-nav button.active {
  color: var(--primary);
}

/* Responsive Mobile Layout */
@media (max-width: 860px) {
  .topbar-nav, .brand-badge {
    display: none;
  }
  .mobile-bottom-nav {
    display: flex;
  }
  .side-panel {
    position: absolute;
    inset: 0;
    width: 100%;
    border-left: none;
  }
  .side-panel.parcel-drawer {
    top: auto;
    height: 62%;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-md);
  }
  .side-panel.parcel-drawer.collapsed {
    height: 68px;
  }
}

.plot-num-label {
  color: #f8fafc;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.95), 0 0 2px #000;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* On-Map Measure Side & Center Area Labels */
.measure-side-badge {
  background: rgba(16, 20, 26, 0.88);
  color: #00e5ff;
  border: 1px solid rgba(0, 229, 255, 0.65);
  border-radius: 6px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

.measure-area-badge {
  background: rgba(16, 20, 26, 0.92);
  color: #facc15;
  border: 1.5px solid #facc15;
  border-radius: 8px;
  padding: 4px 9px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  transform: translate(-50%, -50%);
}

/* Sub-layer Visibility / Contrast Boost Styles */
.overlay-style-high_contrast {
  filter: contrast(1.45) saturate(1.45) drop-shadow(0 0 1px rgba(0, 0, 0, 0.8));
}

.overlay-style-bold_bright {
  filter: contrast(1.65) brightness(1.18) saturate(1.75) drop-shadow(0 0 1.5px rgba(255, 255, 255, 0.85));
}

/* Leaflet Dark Adjustments */
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(20, 20, 20, 0.65) !important;
  color: #ccc !important;
}
.leaflet-control-attribution a {
  color: #8cc4f0 !important;
}
