/* ============================================================
   RD — MAP STYLES
   Castle Fields — Berkhamsted Castle Trust
   Fonts: Cormorant (headings) / Lato (body)
   Colours: Red #d80429 / Green #3C7A38 / Amber #ff9900 / Dark #292E2A
============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Lato', Arial, sans-serif; font-weight: 300; background: #1a1f16; color: #f0ebe0; }

/* ── LAYOUT ── */
.RD-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ── TOP BAR ── */
.RD-topbar { flex-shrink: 0; background: #292E2A; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 1000; }
.RD-topbar__brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.RD-topbar__title { font-family: 'Cormorant', serif; font-size: 20px; font-weight: 600; color: #fff; line-height: 1.2; }
.RD-topbar__title span { display: block; font-size: 10px; font-weight: 400; color: rgba(255,255,255,0.6); letter-spacing: 0.06em; text-transform: uppercase; }

/* ── STATS STRIP ── */
.RD-stats { flex-shrink: 0; background: #1a2018; padding: 6px 16px; display: flex; align-items: center; gap: 16px; overflow-x: auto; border-bottom: 1px solid rgba(255,255,255,0.08); }
.RD-stats__item { display: flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0; }
.RD-stats__dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.RD-stats__label { font-size: 11px; font-weight: 300; color: rgba(255,255,255,0.55); letter-spacing: 0.04em; text-transform: uppercase; }
.RD-stats__value { font-size: 13px; font-weight: 600; color: #fff; }
.RD-stats__divider { width: 1px; height: 16px; background: rgba(255,255,255,0.12); flex-shrink: 0; }
.RD-stats__bar { flex: 1; min-width: 60px; max-width: 180px; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; }
.RD-stats__bar-fill { height: 100%; background: #3C7A38; border-radius: 3px; width: 0%; transition: width 1s ease; }

/* ── SEARCH STRIP ── */
.RD-map-search-strip { flex-shrink: 0; display: flex; background: #1a2018; padding: 6px 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.RD-map-search__input { flex: 1; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15); border-right: none; border-radius: 3px 0 0 3px; padding: 7px 12px; font-size: 13px; color: #fff; outline: none; font-family: 'Lato', Arial, sans-serif; }
.RD-map-search__input::placeholder { color: rgba(255,255,255,0.35); }
.RD-map-search__input:focus { border-color: rgba(255,255,255,0.35); }
.RD-map-search__btn { background: #3C7A38; border: none; border-radius: 0 3px 3px 0; color: #fff; font-size: 13px; font-family: 'Lato', Arial, sans-serif; font-weight: 400; padding: 7px 16px; cursor: pointer; white-space: nowrap; }
.RD-map-search__btn:hover { background: #2a5a26; }

/* ── MAP ── */
#RD-map { flex: 1; width: 100%; min-height: 0; }

/* ── LOADING OVERLAY ── */
.RD-loading { position: absolute; inset: 0; background: #1a1f16; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 2000; transition: opacity 0.4s; }
.RD-loading.hidden { opacity: 0; pointer-events: none; }
.RD-loading__spinner { width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.1); border-top-color: #3C7A38; border-radius: 50%; animation: RD-spin 0.8s linear infinite; }
@keyframes RD-spin { to { transform: rotate(360deg); } }
.RD-loading__text { font-size: 14px; color: rgba(255,255,255,0.7); }
.RD-loading__count { font-size: 12px; color: rgba(255,255,255,0.4); }

/* ── SATELLITE TOGGLE ── */
.RD-sat-toggle { position: absolute; bottom: 28px; right: 10px; z-index: 1000; background: #292E2A; color: #fff; border: 1px solid rgba(255,255,255,0.25); border-radius: 4px; padding: 6px 12px; font-size: 12px; font-family: 'Lato', Arial, sans-serif; cursor: pointer; }
.RD-sat-toggle.active { background: #3C7A38; border-color: #3C7A38; }

/* ── LEAFLET OVERRIDES ── */
.leaflet-popup-content-wrapper { background: #fff !important; border-radius: 8px !important; box-shadow: 0 4px 24px rgba(0,0,0,0.14) !important; padding: 0 !important; overflow: hidden !important; border: 1px solid #e0e0e0 !important; }
.leaflet-popup-content { margin: 0 !important; width: auto !important; font-size: inherit !important; line-height: inherit !important; }
.leaflet-popup-tip { background: #fff !important; box-shadow: none !important; }
.leaflet-popup-close-button { color: rgba(0,0,0,0.35) !important; top: 8px !important; right: 8px !important; font-size: 18px !important; }
.leaflet-touch .leaflet-bar a { background: #292E2A !important; color: #fff !important; }

/* ── POPUP ── */
.RD-popup { font-family: 'Lato', Arial, sans-serif; width: 260px; }

.RD-popup__header { padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.RD-popup__header--at_risk    { background: #d80429; }
.RD-popup__header--supporter  { background: #3C7A38; }
.RD-popup__header--champion   { background: #ff9900; }
.RD-popup__header--ambassador { background: #7B2D8B; }
.RD-popup__header--donor      { background: #3C7A38; }
.RD-popup__header--saviour    { background: #ff9900; }

.RD-popup__icon    { font-size: 22px; line-height: 1; flex-shrink: 0; }
.RD-popup__tier    { font-family: 'Cormorant', serif; font-size: 18px; font-weight: 600; color: #fff; line-height: 1.1; }
.RD-popup__plot-id { font-size: 10px; color: rgba(255,255,255,0.65); margin-top: 2px; letter-spacing: 0.04em; }

.RD-popup__body { overflow: hidden; padding: 14px 16px 16px; background: #fff; }
.RD-popup__name { overflow-wrap: break-word; word-break: break-word; font-family: 'Cormorant', serif; font-size: 20px; font-weight: 600; color: #292E2A; margin: 0 0 8px; line-height: 1.2; }
.RD-popup__msg  { font-size: 13px; color: #555; font-style: italic; line-height: 1.55; margin: 0 0 12px; padding-left: 10px; border-left: 3px solid #3C7A38; }
.RD-popup__w3w  { font-size: 12px !important; color: #d80429 !important; text-decoration: none !important; display: block; margin: 0 0 10px; font-weight: 500; }
.RD-popup__w3w:hover { text-decoration: underline !important; }
.RD-popup__note { font-size: 13px; color: #333; line-height: 1.6; margin: 0 0 14px; }
.RD-popup__cta  { display: block !important; background: #3C7A38 !important; color: #fff !important; text-align: center; font-size: 14px !important; font-weight: 600; padding: 11px 16px; border-radius: 4px; text-decoration: none !important; font-family: 'Lato', Arial, sans-serif; }

/* ── RESPONSIVE ── */
@media (max-width: 500px) {
  .RD-topbar__title span { display: none; }
  .RD-stats { gap: 10px; padding: 6px 10px; }
}

/* ── SIDE PANEL MODAL ── */
.RD-modal-bg {
  position: absolute; inset: 0; z-index: 1000;
  pointer-events: none !important;
}
.RD-modal-bg.open { pointer-events: none !important; }

/* Full width bar across top of map — both desktop and mobile */
.RD-modal {
  position: absolute;
  top: 0; left: 0; right: 0;
  width: 100%;
  background: #fff;
  border-radius: 0;
  border-bottom: 2px solid rgba(0,0,0,0.1);
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  overflow: hidden;
  pointer-events: all;
  transform: translateY(-100%);
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
  z-index: 1001;
}
.RD-modal-bg.open .RD-modal { transform: translateY(0); }

/* Desktop modal — full width bar, two-column layout */
@media (min-width: 600px) {
  .RD-modal {
    display: flex;
    align-items: stretch;
    flex-wrap: nowrap;
    border: none !important;
    outline: none !important;
  }
  /* Left: coloured tier block */
  .RD-modal__header {
    flex-shrink: 0;
    width: 160px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
  }
  .RD-modal__header-left { flex-direction: column; align-items: flex-start; gap: 4px; }
  /* Centre: content block */
  .RD-modal__body {
    flex: 1;
    padding: 10px 20px;
    border-left: 1px solid rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 0;
  }
  /* W3W — big red, own line */
  .RD-modal__w3w {
    font-size: 18px !important;
    font-weight: 700 !important;
    color: #d80429 !important;
    text-decoration: none !important;
    display: block;
    line-height: 1.2;
  }
  .RD-modal__w3w:hover { text-decoration: underline !important; }
  /* Name — own line */
  .RD-modal__name {
    font-size: 15px;
    font-weight: 600;
    color: #292E2A;
    margin: 0;
    line-height: 1.3;
  }
  /* Message — own line, muted */
  .RD-modal__msg {
    font-size: 12px;
    color: #666;
    font-style: italic;
    margin: 0;
    line-height: 1.4;
    border-left: none;
    padding-left: 0;
  }
  /* Note text (at risk) */
  .RD-modal__note { font-size: 13px; color: #333; margin: 0; }
  /* CTA button */
  .RD-modal__cta {
    display: inline-block;
    width: auto !important;
    align-self: flex-start;
    margin-top: 2px;
    padding: 7px 14px;
    font-size: 13px;
  }
  /* Right: CTA or share buttons */
  .RD-modal__share {
    flex-shrink: 0;
    border-left: 1px solid rgba(0,0,0,0.1);
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-width: 140px;
  }
  .RD-modal__share-title { display: none; }
  .RD-modal__share-panel {
    flex-shrink: 0;
    border-left: 1px solid rgba(0,0,0,0.1);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    min-width: 130px;
    max-width: 160px;
  }
  .RD-modal__share-btns { display:flex; flex-direction: column; gap: 5px; }
  .RD-modal__share-title { font-size: 10px; font-weight: 600; color: #999; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 2px; }
  .RD-modal__share-btn { display:flex !important; font-size: 12px; padding: 7px 10px; justify-content: center !important; align-items: center; width: 100%; box-sizing: border-box; text-align: center; }
  /* CTA sits on right for at-risk spaces */
  .RD-modal__cta {
    display: block !important;
    width: 100% !important;
    text-align: center;
    padding: 10px 14px;
    font-size: 14px;
  }
  /* Nav */
  .RD-modal__nav {
    flex-shrink: 0;
    border-left: 1px solid rgba(0,0,0,0.1);
    padding: 0 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    background: #f5f5f5;
    font-size: 12px;
    min-width: 80px;
  }
}

/* Modal header — coloured by tier */
.RD-modal__header { padding: 14px 40px 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.RD-modal__header--at_risk    { background: #d80429; }
.RD-modal__header--supporter  { background: #3C7A38; }
.RD-modal__header--champion   { background: #ff9900; }
.RD-modal__header--ambassador { background: #7B2D8B; }
.RD-modal__header--community  { background: #0891b2; }
.RD-modal__header--donor      { background: #3C7A38; }
.RD-modal__header--saviour    { background: #ff9900; }

.RD-modal__header-left { display: flex; align-items: center; gap: 10px; }
.RD-modal__icon { font-size: 22px; line-height: 1; }
.RD-modal__tier { font-family: 'Cormorant', serif; font-size: 18px; font-weight: 600; color: #fff; line-height: 1.1; }
.RD-modal__id   { font-size: 10px; color: rgba(255,255,255,0.65); margin-top: 2px; letter-spacing: 0.04em; }
.RD-modal__close {
  position: absolute;
  top: 8px; right: 12px;
  background: none; border: none;
  color: rgba(255,255,255,0.8);
  font-size: 22px; cursor: pointer;
  line-height: 1; padding: 4px;
  z-index: 10;
}
.RD-modal__close:hover { color: #fff; }

/* Modal body */
.RD-modal__body { padding: 14px 16px 16px; background: #fff; }
.RD-modal__name { font-family: 'Cormorant', serif; font-size: 20px; font-weight: 600; color: #292E2A; margin: 0 0 8px; line-height: 1.2; overflow-wrap: break-word; }
.RD-modal__msg  { font-size: 13px; color: #555; font-style: italic; line-height: 1.55; margin: 0 0 12px; padding-left: 10px; border-left: 3px solid #3C7A38; }
.RD-modal__w3w  { font-size: 12px; color: #d80429; text-decoration: none; display: block; margin: 0 0 10px; font-weight: 500; }
.RD-modal__note { font-size: 13px; color: #333; line-height: 1.6; margin: 0 0 14px; }
.RD-modal__cta  { display: block; background: #3C7A38; color: #fff !important; text-align: center; font-size: 14px; font-weight: 600; padding: 11px 16px; border-radius: 4px; text-decoration: none !important; font-family: 'Lato', Arial, sans-serif; }

/* Search navigation bar */
.RD-modal__nav { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px; background: #f5f5f5; border-top: 1px solid #e0e0e0; font-size: 12px; color: #555; }
.RD-modal__nav-btn { background: none; border: 1px solid #ccc; border-radius: 3px; padding: 3px 10px; font-size: 12px; cursor: pointer; color: #333; }
.RD-modal__nav-btn:hover { background: #e8e8e8; }
.RD-modal__nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Highlighted plot (stays until modal closed) */
.RD-highlight { transition: none !important; }

/* ── MODAL SHARE BUTTONS ── */
.RD-modal__share { padding: 8px 12px; border-top: 1px solid #f0f0f0; }
.RD-modal__share-title { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #888; margin-bottom: 8px; display: none; }
.RD-modal__share-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.RD-modal__share-btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 10px; border-radius: 4px; font-size: 11px; font-weight: 500; font-family: 'Lato', Arial, sans-serif; text-decoration: none; cursor: pointer; border: none; }
.RD-modal__share-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.RD-modal__share-btn--fb { background: #1877f2; color: #fff; }
.RD-modal__share-btn--tw { background: #000; color: #fff; }
.RD-modal__share-btn--wa { background: #25d366; color: #fff; }
.RD-modal__share-btn--copy { background: #f0ebe0; color: #3d3a2e; }

/* ── HIGHLIGHTED PLOT ── */
.RD-plot-active { animation: RD-pulse 1.5s ease-in-out infinite; }
@keyframes RD-pulse {
  0%, 100% { fill-opacity: 1; }
  50%       { fill-opacity: 0.6; }
}

/* ── FIND MY SPACE BUTTON ── */
.RD-find-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 4px;
  color: #fff;
  font-size: 12px;
  font-family: 'Lato', Arial, sans-serif;
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.RD-find-btn:hover { background: rgba(255,255,255,0.22); }

/* Find modal — centred overlay */
#RD-find-bg.open { pointer-events: all; background: rgba(0,0,0,0.5); }
#RD-find-modal {
  position: absolute !important;
  top: 50% !important; left: 50% !important;
  right: auto !important;
  transform: translate(-50%, -40%) !important;
  transition: opacity 0.2s, transform 0.2s !important;
  opacity: 0;
}
#RD-find-bg.open #RD-find-modal {
  transform: translate(-50%, -50%) !important;
  opacity: 1;
}
@media (max-width: 600px) {
  #RD-find-modal {
    top: auto !important; left: 0 !important;
    right: 0 !important; bottom: 0 !important;
    transform: translateY(100%) !important;
    width: 100% !important; max-width: 100% !important;
    border-radius: 14px 14px 0 0 !important;
  }
  #RD-find-bg.open #RD-find-modal { transform: translateY(0) !important; }
}

/* ── Move zoom controls to bottom left ── */
.leaflet-top.leaflet-left {
  top: auto !important;
  bottom: 40px !important;
}

/* ── FIND MY SPACE MODAL (centred overlay, not full-width bar) ── */
.RD-find-modal-inner {
  position: relative;
  width: calc(100vw - 32px);
  max-width: 340px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  overflow: hidden;
  pointer-events: all;
  transform: translateY(-20px);
  transition: opacity 0.2s, transform 0.2s;
  opacity: 0;
}
#RD-find-bg.open .RD-find-modal-inner {
  transform: translateY(0);
  opacity: 1;
}
#RD-find-bg {
  display: none;
  position: fixed !important; /* use fixed so it covers full viewport */
  inset: 0 !important;
  z-index: 9999 !important;
  pointer-events: none;
}
#RD-find-bg.open {
  display: flex !important;
  align-items: center;
  justify-content: center;
  pointer-events: all !important;
  background: rgba(0,0,0,0.5);
}
@media (max-width: 600px) {
  .RD-find-modal-inner {
    top: auto; left: 0; right: 0; bottom: 0;
    transform: translateY(100%);
    width: 100%; max-width: 100%;
    border-radius: 14px 14px 0 0;
  }
  #RD-find-bg.open .RD-find-modal-inner { transform: translateY(0); }
}

/* Override Leaflet/browser blue links in modal */
.RD-modal a { color: inherit !important; }
.RD-modal a.RD-modal__cta { color: #fff !important; }
.RD-modal a.RD-modal__w3w { color: #d80429 !important; font-size: 18px !important; font-weight: 700 !important; }
.RD-modal__share-btn { color: #fff !important; text-decoration: none !important; }

/* Remove blue focus/border from Leaflet and modal */
.leaflet-container:focus,
.leaflet-container,
#RD-map:focus,
#RD-map { outline: none !important; border: none !important; }
.RD-modal, .RD-modal * { outline: none !important; }
.RD-modal { border: none !important; box-shadow: 0 2px 12px rgba(0,0,0,0.15) !important; }

/* Mobile padding for modal right panel (CTA / share buttons) */
@media (max-width: 600px) {
  #RD-modal-right {
    padding: 12px 16px 28px !important;
    border-left: none !important;
    border-top: 1px solid rgba(0,0,0,0.1);
    min-width: unset !important;
    width: 100%;
  }
  #RD-modal-right a {
    margin-bottom: 4px;
    width: 100%;
    justify-content: center;
  }
  .RD-modal__body {
    padding-bottom: 4px !important;
  }
}
