/* ==========================================================================
   components.css — CIMI Ranking (builds on theme.css)
   Intro · methodology modal · filters · weight sliders · map · legend ·
   mode toggle · ranking table · tooltip.
   ========================================================================== */

main { padding: 22px 0 56px; }
.intro { text-align: center; color: var(--text-muted); font-size: var(--fs-min); line-height: 1.6; max-width: 820px; margin: 0 auto 8px; }
.intro strong { color: var(--cimi-bluedark); }
.smaller-gaps { text-align: center; color: var(--cimi-red); font-weight: 700; font-style: italic; margin: 6px 0 18px; }

/* ---- methodology button + modal ---------------------------------------- */
.method-wrap { display: flex; flex-direction: column; align-items: center; margin: 18px 0; }
.method-btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 700; font-size: var(--fs-min);
  padding: 12px 22px; border: 0; border-radius: var(--radius-sm); background: #4B9E9E; color: #fff;
  min-width: 300px; transition: filter .15s;
}
.method-btn:hover { filter: brightness(.96); }
.method-btn.open { border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
.method-modal {
  display: none; max-width: 720px; width: 100%; text-align: left;
  background: var(--surface-alt); border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm); padding: 18px 22px;
}
.method-modal.active { display: block; }
.method-modal p { font-size: var(--fs-min); color: var(--text); margin: 0 0 12px; line-height: 1.55; }
.method-modal p:last-child { margin-bottom: 0; }
.hl-red { color: var(--cimi-red); font-weight: 700; }

/* ---- filters ------------------------------------------------------------ */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
/* min-height reserves ~2 lines so a 1-line and a 2-line label still line their
   selects up (the label grew to 16px and now wraps at some widths). */
.filters label { display: block; font-size: var(--fs-min); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--cimi-bluedark); margin-bottom: 6px; min-height: 2.5em; }
.filters select {
  width: 100%; appearance: none; font: inherit; font-weight: 600; color: #1e293b;
  padding: 10px 36px 10px 12px; border: 1.5px solid #4B9E9E; border-radius: var(--radius-sm);
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%234B9E9E' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  cursor: pointer;
}
.filters select:focus { outline: none; border-color: #3a7c7c; box-shadow: 0 0 0 3px rgba(75,158,158,.18); }

.exp { font-size: var(--fs-min); color: var(--text); line-height: 1.6; }
.exp strong { color: var(--cimi-bluedark); }

/* ---- weight sliders ----------------------------------------------------- */
.weights { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.weight-card { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px 16px; text-align: center; }
.weight-card .dim-ico { display: block; }
.weight-card .ms-ico { width: 30px; height: 30px; display: block; margin: 0 auto 8px; color: #4B9E9E; }   /* fill = currentColor */
.weight-card .slider-label { display: block; font-size: var(--fs-min); font-weight: 700; color: var(--text-muted); margin-bottom: 10px; min-height: 2.4em; }
.weight-card .row { display: flex; align-items: center; gap: 10px; }
.weight-card .val { font-weight: 800; font-size: var(--fs-min); color: #4B9E9E; width: 46px; text-align: right; }
input[type=range] { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px; background: #d8e1ec; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #4B9E9E; cursor: pointer; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(16,42,75,.3); }
input[type=range]::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #4B9E9E; cursor: pointer; border: 2px solid #fff; }

.status { text-align: center; font-weight: 700; color: #228B22; margin: 18px 0; }
.status.err { color: var(--cimi-red); }

/* ---- map ---------------------------------------------------------------- */
.map-head { background: #4B9E9E; color: #fff; border-radius: var(--radius) var(--radius) 0 0; padding: 14px 18px; }
.map-head .title { font-weight: 800; font-size: var(--fs-lg); }
.map-head .sub { font-size: var(--fs-min); opacity: .9; }
.map-body { border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius); padding: 16px; }
#rank-map { width: 100%; height: 480px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: #f5f8fc; }
.map-legend { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: var(--fs-min); color: var(--text-muted); }
.map-legend .bar { height: 10px; width: 180px; border-radius: 5px; background: linear-gradient(90deg, #003066, #cce0ff, #ffe0cc, #b34700); }
.maplibregl-ctrl-group { box-shadow: var(--shadow) !important; }

/* ---- mode toggle -------------------------------------------------------- */
.mode-toggle { margin-top: 22px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; padding: 16px; background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius-sm); }
.mode-toggle .note { font-size: var(--fs-min); font-style: italic; color: var(--text-muted); flex: 1 1 320px; }
.mode-toggle .opts { display: flex; gap: 18px; }
.mode-toggle label { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: var(--fs-min); cursor: pointer; color: var(--text); }
.mode-toggle input { accent-color: var(--cimi-blue); width: 16px; height: 16px; }

/* ---- ranking table ------------------------------------------------------ */
.table-scroll { overflow-x: auto; margin-top: 24px; scrollbar-width: none; }   /* native bar hidden — replaced by the always-visible .hscroll below */
.table-scroll::-webkit-scrollbar { display: none; }

/* --- custom always-visible horizontal scrollbar (only while the matrix overflows) ---
   macOS overlay scrollbars auto-hide until you scroll and can't be forced visible
   cross-browser, so we draw our own: a slim always-visible track + draggable thumb
   under the matrix, shown only while it overflows. /apps/_shared/hscrollbar.js builds
   the track/thumb and keeps them in sync (scroll · drag · track-click · keyboard). */
.hscroll {
  display: none;                      /* shown by JS only when the matrix overflows */
  height: 12px; margin: 10px 2px 0; border-radius: 999px; overflow: hidden;
  background: var(--border-soft); touch-action: none; cursor: pointer;
}
.hscroll.is-scrollable { display: block; }
.hscroll-thumb {
  width: 40px; height: 100%; border-radius: 999px; background: #9aa7b8;
  cursor: grab; transition: background .15s ease;
}
.hscroll-thumb:hover { background: #8391a5; }
.hscroll-thumb.dragging { background: #7c8ba0; cursor: grabbing; }
.hscroll-thumb:focus-visible { outline: 2px solid var(--cimi-blue); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { .hscroll-thumb { transition: none; } }
.rank-table { width: 100%; border-collapse: collapse; font-size: var(--fs-min); min-width: 620px; }
.rank-table th { background: #4B9E9E; color: #fff; font-weight: 700; padding: 10px 8px; text-align: center; font-size: var(--fs-min); }
.rank-table th:first-child { text-align: left; padding-left: 14px; }
.rank-table th + th { border-left: 1px solid rgba(255,255,255,.22); }   /* subtle header separators */
.rank-table td { padding: 9px 8px; text-align: center; background: #fff; }
.rank-table td.geo { text-align: left; font-weight: 700; color: var(--text); padding-left: 14px; white-space: nowrap; border-bottom: 2px solid #eef2f7; }
.rank-table td.dim { color: var(--text-muted); }
/* colored rank cells separated by white gridlines (vertical + horizontal) */
.rank-table td.rank-cell { font-weight: 800; cursor: default; border: 2px solid #fff; }
.rank-table tbody tr:hover td.geo { background: var(--surface-alt); }

/* ---- city pins (teardrop markers; mirrors the Comparison map) ----------- */
.cma-pin { cursor: pointer; line-height: 0; filter: drop-shadow(0 1px 1.5px rgba(0,0,0,.3)); }
.cma-pin svg { display: block; }

/* ---- map tooltip -------------------------------------------------------- */
.map-tooltip {
  position: fixed; z-index: 70; pointer-events: none; opacity: 0; transition: opacity .1s;
  background: #fff; border: 1px solid var(--border); box-shadow: var(--shadow-md);
  border-radius: 8px; padding: 9px 12px; font-size: var(--fs-min); color: var(--text); min-width: 150px;
}
.map-tooltip .tt-title { font-weight: 800; color: var(--cimi-blue); margin-bottom: 4px; }
.map-tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }
.map-tooltip .tt-row b { color: var(--cimi-bluedark); }
.map-tooltip .tt-score { font-size: var(--fs-min); color: var(--text-soft); text-align: right; }
.map-tooltip .tt-std { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--border-soft); }

@media (max-width: 560px) {
  #rank-map { height: 340px; }
  .mode-toggle { flex-direction: column; align-items: stretch; }
  /* In the column layout the note's `flex: 1 1 320px` basis becomes a 320px
     HEIGHT, leaving a big empty gap above the radios — reset it to content. */
  .mode-toggle .note { flex: 0 0 auto; }
}
