/* ==========================================================================
   CAC Market Intelligence — Interactive Neighbourhood Map
   Self-contained styles for the reusable map component (Market Intelligence
   section only). Reuses the global brand tokens from styles.css
   (--navy, --gold, --sand, --slate, --cloud) with safe fallbacks.
   All classes are namespaced `cac-mi-` to avoid collisions.
   ========================================================================== */

.cac-mi {
  --mi-navy: var(--navy, #1A1F36);
  --mi-gold: var(--gold, #D4872C);
  --mi-sand: var(--sand, #E8E8EA);
  --mi-slate: var(--slate, #8A8478);
  --mi-cloud: var(--cloud, #F4F5F7);
  --mi-line: rgba(0,0,0,0.10);
  --mi-white: #ffffff;
  --mi-radius: 14px;
  --mi-shadow: 0 10px 30px rgba(0,0,0,0.12);
  --mi-shadow-sm: 0 2px 10px rgba(0,0,0,0.10);
  font-family: 'DM Sans',system-ui,-apple-system,'Segoe UI',sans-serif;
}

/* ---- Official citywide anchor strip --------------------------------------- */
.cac-mi-anchors {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: stretch;
  margin: 0 0 18px;
}
.cac-mi-anchors-label {
  flex: 1 1 100%;
  font-size: 9.9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--mi-slate); font-weight: 700; margin-bottom: 2px;
  display: flex; align-items: center; gap: 8px;
}
.cac-mi-badge-official {
  display: inline-block; font-size: 8.55px; letter-spacing: 0.08em;
  text-transform: uppercase; font-weight: 700; color: #2f7d4f;
  background: rgba(47,125,79,0.10); border: 1px solid rgba(47,125,79,0.30);
  padding: 2px 7px; border-radius: 999px;
}
.cac-mi-anchor {
  flex: 1 1 150px; background: var(--mi-white);
  border: 1px solid var(--mi-line); border-radius: 12px;
  padding: 12px 14px; box-shadow: var(--mi-shadow-sm);
}
.cac-mi-anchor .v { font-size: 18px; font-weight: 700; color: var(--mi-navy); line-height: 1.1; }
.cac-mi-anchor .l { font-size: 10.35px; color: var(--mi-slate); margin-top: 4px; line-height: 1.3; }

/* ---- Map shell ------------------------------------------------------------ */
.cac-mi-map-wrap {
  position: relative;
  width: 100%;
  height: 620px;
  border-radius: var(--mi-radius);
  overflow: hidden;
  box-shadow: var(--mi-shadow);
  border: 1px solid var(--mi-line);
  background: #E8E8EA;
}
.cac-mi-map { position: absolute; inset: 0; }
.cac-mi-map:focus { outline: none; }

/* MapLibre canvas font */
.cac-mi-map-wrap .maplibregl-ctrl-attrib { font-size: 9px; }

/* ---- Metric selector (segmented control) ---------------------------------- */
.cac-mi-toolbar {
  position: absolute; top: 14px; left: 14px; z-index: 5;
  display: flex; flex-direction: column; gap: 8px; max-width: calc(100% - 28px);
}
.cac-mi-seg {
  display: inline-flex; background: var(--mi-white);
  border: 1px solid var(--mi-line); border-radius: 999px;
  padding: 4px; box-shadow: var(--mi-shadow-sm); flex-wrap: wrap;
}
.cac-mi-seg button {
  border: none; background: transparent; cursor: pointer;
  font-family: inherit; font-size: 11.25px; font-weight: 600; color: var(--mi-slate);
  padding: 7px 13px; border-radius: 999px; transition: all .15s ease; white-space: nowrap;
}
.cac-mi-seg button:hover { color: var(--mi-navy); }
.cac-mi-seg button[aria-pressed="true"] {
  background: var(--mi-navy); color: #fff;
}
.cac-mi-seg-title {
  font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--mi-navy); font-weight: 700; background: rgba(255,255,255,0.85);
  padding: 4px 10px; border-radius: 999px; box-shadow: var(--mi-shadow-sm);
  align-self: flex-start;
}

/* ---- Legend --------------------------------------------------------------- */
.cac-mi-legend {
  position: absolute; left: 14px; bottom: 14px; z-index: 5;
  background: var(--mi-white); border: 1px solid var(--mi-line);
  border-radius: 12px; padding: 12px 14px; box-shadow: var(--mi-shadow-sm);
  max-width: 250px;
}
.cac-mi-legend h4 {
  font-size: 10.8px; color: var(--mi-navy); margin: 0 0 2px; font-weight: 700;
}
.cac-mi-legend .sub { font-size: 9.45px; color: var(--mi-slate); margin: 0 0 9px; line-height: 1.3; }
.cac-mi-legend-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.cac-mi-legend-sw { width: 16px; height: 12px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,0.08); }
.cac-mi-legend-row span { font-size: 10.35px; color: var(--mi-navy); }
.cac-mi-legend-indic {
  margin-top: 9px; padding-top: 8px; border-top: 1px dashed var(--mi-line);
  font-size: 9px; color: var(--mi-slate); line-height: 1.3;
}

/* ---- Reset / controls ----------------------------------------------------- */
.cac-mi-reset {
  background: var(--mi-white); border: 1px solid var(--mi-line);
  width: 29px; height: 29px; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--mi-navy);
  box-shadow: 0 1px 2px rgba(0,0,0,0.10);
}
.cac-mi-reset:hover { background: var(--mi-sand); }
.cac-mi-reset svg { width: 16px; height: 16px; }

/* ---- Hover tooltip -------------------------------------------------------- */
.cac-mi-tooltip {
  position: absolute; z-index: 7; pointer-events: none;
  background: var(--mi-navy); color: #fff; border-radius: 9px;
  padding: 8px 11px; box-shadow: var(--mi-shadow); transform: translate(-50%, -120%);
  min-width: 120px; max-width: 220px; opacity: 0; transition: opacity .12s ease;
}
.cac-mi-tooltip.show { opacity: 1; }
.cac-mi-tooltip .t-name { font-size: 11.7px; font-weight: 700; line-height: 1.2; }
.cac-mi-tooltip .t-metric { font-size: 9.9px; color: rgba(255,255,255,0.72); margin-top: 2px; }
.cac-mi-tooltip .t-val { color: var(--mi-gold); font-weight: 700; font-size: 13.5px; margin-top: 3px; }
.cac-mi-tooltip .t-hint { font-size: 8.55px; color: rgba(255,255,255,0.55); margin-top: 4px; }

/* ---- Detail panel (side on desktop, bottom-sheet on mobile) --------------- */
.cac-mi-panel {
  position: absolute; top: 0; right: 0; z-index: 8;
  width: 340px; max-width: 86%; height: 100%;
  background: var(--mi-white); box-shadow: -12px 0 30px rgba(0,0,0,0.12);
  transform: translateX(105%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; overflow: hidden;
}
.cac-mi-panel.open { transform: translateX(0); }
.cac-mi-panel-head {
  padding: 18px 20px 14px; border-bottom: 1px solid var(--mi-line);
  background: var(--mi-navy); color: #fff; position: relative;
}
.cac-mi-panel-head .eyebrow { font-size: 9px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--mi-gold); font-weight: 700; }
.cac-mi-panel-head h3 { color: #fff; font-size: 19.8px; margin: 4px 0 0; font-weight: 600; line-height: 1.15; }
.cac-mi-panel-head .tier { font-size: 10.35px; color: rgba(255,255,255,0.65); margin-top: 4px; text-transform: capitalize; }
.cac-mi-panel-close {
  position: absolute; top: 14px; right: 14px; width: 30px; height: 30px;
  border-radius: 50%; border: none; background: rgba(255,255,255,0.14); color: #fff;
  font-size: 16.2px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.cac-mi-panel-close:hover { background: rgba(255,255,255,0.26); }
.cac-mi-panel-body { padding: 6px 20px 18px; overflow-y: auto; flex: 1; }
.cac-mi-row {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--mi-line);
}
.cac-mi-row:last-child { border-bottom: none; }
.cac-mi-row .k { font-size: 11.25px; color: var(--mi-slate); line-height: 1.3; flex: 1; }
.cac-mi-row .val-wrap { text-align: right; flex: 0 0 auto; max-width: 58%; }
.cac-mi-row .val { font-size: 14.4px; font-weight: 700; color: var(--mi-navy); line-height: 1.15; }
.cac-mi-row .val.muted { font-size: 10.8px; font-weight: 500; color: var(--mi-slate); }
.cac-mi-row .src { font-size: 8.55px; color: var(--mi-slate); margin-top: 3px; line-height: 1.25; }
.cac-mi-chip {
  display: inline-block; font-size: 8.1px; letter-spacing: 0.06em; text-transform: uppercase;
  font-weight: 700; padding: 1.5px 6px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}
.cac-mi-chip.indicative { color: #9a6a16; background: rgba(196,136,58,0.12); border: 1px solid rgba(196,136,58,0.34); }
.cac-mi-chip.official  { color: #2f7d4f; background: rgba(47,125,79,0.10); border: 1px solid rgba(47,125,79,0.30); }
.cac-mi-panel-note {
  font-size: 10.35px; color: var(--mi-slate); line-height: 1.45; padding: 12px 0 0; font-style: italic;
}
.cac-mi-srcline {
  font-size: 9.45px; color: var(--mi-slate); line-height: 1.4; padding-top: 8px; margin-top: 8px;
  border-top: 1px dashed var(--mi-line); letter-spacing: 0.01em;
}

/* ---- Loading / error overlays --------------------------------------------- */
.cac-mi-overlay {
  position: absolute; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center;
  background: #E8E8EA; color: var(--mi-slate); font-size: 12.6px; text-align: center; padding: 24px;
}
.cac-mi-overlay.hidden { display: none; }
.cac-mi-spinner {
  width: 26px; height: 26px; border: 3px solid rgba(0,0,0,0.12); border-top-color: var(--mi-gold);
  border-radius: 50%; animation: cac-mi-spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes cac-mi-spin { to { transform: rotate(360deg); } }

/* ---- Methodology & sources note ------------------------------------------- */
.cac-mi-method {
  margin-top: 18px; background: var(--mi-cloud); border: 1px solid var(--mi-line);
  border-radius: 12px; padding: 16px 18px;
}
.cac-mi-method summary {
  cursor: pointer; font-size: 11.7px; font-weight: 700; color: var(--mi-navy);
  display: flex; align-items: center; gap: 9px; list-style: none;
}
.cac-mi-method summary::-webkit-details-marker { display: none; }
.cac-mi-method summary .as-of { font-weight: 500; color: var(--mi-slate); font-size: 10.35px; margin-left: auto; }
.cac-mi-method[open] summary { margin-bottom: 12px; }
.cac-mi-method .m-body { font-size: 11.25px; color: #4a4a4a; line-height: 1.6; }
.cac-mi-method .m-body p { margin: 0 0 10px; }
.cac-mi-method .m-sources { margin: 8px 0 0; padding: 0; list-style: none; }
.cac-mi-method .m-sources li { font-size: 10.35px; margin: 5px 0; line-height: 1.35; }
.cac-mi-method .m-sources a { color: var(--mi-navy); text-decoration: underline; }
.cac-mi-method .m-disclaimer {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--mi-line);
  font-size: 9.9px; color: var(--mi-slate); font-style: italic; line-height: 1.5;
}

/* ---- Responsive: bottom sheet on small screens ---------------------------- */
@media (max-width: 768px) {
  .cac-mi-map-wrap { height: 78vh; min-height: 460px; }
  .cac-mi-panel {
    position: fixed; width: 100%; max-width: 100%; height: auto; max-height: 70vh;
    top: auto; bottom: 0; left: 0; right: 0; border-radius: 18px 18px 0 0;
    transform: translateY(105%); box-shadow: 0 -12px 30px rgba(0,0,0,0.18);
  }
  .cac-mi-panel.open { transform: translateY(0); }
  .cac-mi-panel-head { border-radius: 18px 18px 0 0; }
  .cac-mi-panel::before {
    content: ""; position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 999px; background: rgba(255,255,255,0.4); z-index: 2;
  }
  .cac-mi-toolbar { top: 10px; left: 10px; }
  .cac-mi-seg button { padding: 7px 11px; font-size: 10.8px; }
  .cac-mi-legend { left: 10px; bottom: 10px; padding: 10px 12px; max-width: 180px; }
  .cac-mi-legend .sub { display: none; }
  .cac-mi-anchor { flex: 1 1 44%; }
  .cac-mi-anchor .v { font-size: 15.3px; }
}
@media (max-width: 480px) {
  .cac-mi-seg-title { display: none; }
}
