/* CareMap explorer layout */
body.explore { position: fixed; inset: 0; height: 100vh; overflow: hidden; }
#map { position: absolute; inset: 0; }

.glass {
  background: var(--panel); backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text);
}

/* top bar */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 20; height: 58px;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
#topbar .brand { font-size: 16px; }
#search-wrap { position: relative; flex: 1; max-width: 420px; }
#search-wrap > svg {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 11px;
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}
#search {
  width: 100%; min-width: 0; background: var(--bg-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius); padding: 9px 12px 9px 34px; color: var(--text); font-size: 13px; font-family: var(--font);
}
#search:focus { outline: 2px solid color-mix(in srgb, var(--accent) 28%, transparent); outline-offset: 1px; border-color: var(--accent); }
#search-results {
  position: absolute; top: 44px; left: 0; right: 0; z-index: 30; max-height: 320px; overflow-y: auto;
  background: var(--panel-solid); border: 1px solid var(--border); border-radius: var(--radius); display: none;
}
#search-results .sr {
  padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; font-size: 13px;
}
#search-results .sr:hover { background: var(--control-hover); }
#search-results .sr .meta { color: var(--muted); font-size: 12px; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* control panel */
#controls { position: absolute; top: 72px; left: 14px; z-index: 15; width: 288px; padding: 16px; max-height: calc(100vh - 90px); overflow-y: auto; }
.ctl-group { margin-bottom: 16px; }
.facet-grid { display: grid; gap: 10px; }
.facet-grid label { display: block; }
.facet-grid .label { display: block; margin-bottom: 5px; }
.label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 7px; }
.label .val { color: var(--accent); text-transform: none; letter-spacing: 0; font-weight: 700; }
.seg { display: flex; background: var(--control); border: 1px solid var(--border); border-radius: var(--radius); padding: 3px; gap: 2px; }
.seg-btn { flex: 1; background: transparent; color: var(--muted); border: none; border-radius: 3px; padding: 7px 4px; font-size: 11px; font-weight: 700; cursor: pointer; font-family: var(--font); }
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--bg-2); color: var(--accent); box-shadow: 0 1px 2px rgba(20,48,42,.12); }
select { width: 100%; background: var(--bg-2); color: var(--text); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 8px 10px; font-size: 12px; font-family: var(--font); }
.slider { width: 100%; accent-color: var(--accent); }
.ticks { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted-2); margin-top: 2px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); margin-bottom: 9px; cursor: pointer; }
.check input { accent-color: var(--brand); }
.result-count { font-size: 13px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 12px; }
.result-count b { color: var(--text); }

/* boot overlay */
#boot-overlay {
  position: absolute; inset: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: blur(3px);
  transition: opacity .35s ease;
}
#boot-overlay.hide { opacity: 0; pointer-events: none; }
.boot-card { padding: 24px 30px; text-align: center; max-width: 300px; }
.boot-title { font-size: 15px; font-weight: 700; color: var(--text); margin-top: 14px; }
.boot-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }
.boot-spinner {
  width: 34px; height: 34px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--control); border-top-color: var(--accent);
  animation: boot-spin .8s linear infinite;
}
@keyframes boot-spin { 100% { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .boot-spinner { animation: none; } }

/* drawer skeleton */
.d-skeleton { padding: 4px 0; }
.d-skeleton .sk-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.d-skeleton .sk-grade { width: 46px; height: 46px; border-radius: var(--radius); flex: none; }

/* legend */
#legend { position: absolute; bottom: 14px; left: 316px; z-index: 15; width: 260px; padding: 14px 16px; }
#legend h2 { font-size: 11px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.legend-grades { display: flex; gap: 6px; }
.legend-grades .lg { flex: 1; text-align: center; }
.legend-grades .sw { height: 8px; border-radius: 4px; margin-bottom: 4px; }
.legend-grades span { font-size: 11px; color: var(--muted); }
.grad { height: 10px; border-radius: 5px; background: linear-gradient(to right, rgb(232,218,199), rgb(218,190,147), rgb(207,165,83), rgb(194,141,28), rgb(174,118,0), rgb(145,94,0)); }
.grad-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }

/* tooltip */
#tip { position: absolute; z-index: 40; pointer-events: none; display: none; max-width: 260px; padding: 10px 12px;
  background: var(--panel-solid); border: 1px solid var(--border-strong); border-radius: var(--radius); font-size: 12px; box-shadow: var(--shadow); }
#tip .t-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
#tip .t-name { font-weight: 700; font-size: 13px; }
#tip .t-meta { color: var(--muted); font-size: 11px; line-height: 1.4; }

/* detail drawer */
#drawer { position: absolute; top: 72px; right: 14px; bottom: 14px; z-index: 25; width: 380px; padding: 0; overflow: hidden;
  transform: translateX(420px); transition: transform 0.28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column; }
#drawer.open { transform: translateX(0); }
#drawer-close { position: absolute; top: 12px; right: 12px; z-index: 5; background: var(--control); border: none; color: var(--text);
  width: 30px; height: 30px; border-radius: var(--radius); cursor: pointer; font-size: 18px; }
#drawer-close:hover { background: var(--control-hover); }
#drawer-body { overflow-y: auto; padding: 22px; }
.d-grade-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.d-name { font-size: 20px; font-weight: 800; margin: 0; }
.d-sub { color: var(--muted); font-size: 13px; margin: 2px 0 18px; }
.d-actions { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.d-actions svg, .d-footer-actions svg { width: 15px; height: 15px; flex: none; }
.d-section { border-top: 1px solid var(--border); padding: 16px 0; }
.d-section h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 0 0 10px; }
.service-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.service-chip { border: 1px solid var(--border-strong); border-radius: 3px; padding: 4px 7px; font-size: 11px; color: var(--text); background: var(--control); }
.fact-row { display: flex; justify-content: space-between; gap: 16px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 12px; line-height: 1.35; }
.fact-row span { color: var(--muted); }
.fact-row b { text-align: right; font-weight: 700; }
.fact-note { margin-top: 9px; color: var(--muted-2); font-size: 11px; line-height: 1.45; }
.d-footer-actions { display: flex; margin-top: 14px; }
.d-footer-actions .btn { color: var(--muted); }
.d-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.d-stat { background: var(--control); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.d-stat b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.d-stat span { font-size: 11px; color: var(--muted); }
.d-stat.bad b { color: var(--g-f); }
.d-source-action { margin: 0 0 16px; }
.reasons { list-style: none; padding: 0; margin: 0; }
.reasons li { padding: 6px 0 6px 22px; position: relative; font-size: 13px; line-height: 1.4; color: var(--text); }
.reasons li::before { content: "•"; position: absolute; left: 6px; color: var(--muted); }
.reasons li.good::before { content: "✓"; color: var(--brand); }
.reasons li.bad::before { content: "!"; color: var(--g-f); font-weight: 800; }
.citation-codes { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted);
  background: var(--control); border-radius: var(--radius); padding: 10px 12px; line-height: 1.6; word-break: break-word; }
.price-big { font-size: 26px; font-weight: 800; }
.price-interp { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* locked overlay */
.locked { position: relative; }
.lock-veil { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 18px; text-align: center; background: var(--control); }
.lock-veil .lk-ic { font-size: 22px; }
.lock-veil p { color: var(--muted); font-size: 13px; margin: 8px 0 12px; line-height: 1.4; }
.blur-preview { filter: blur(6px); opacity: 0.5; pointer-events: none; user-select: none; }

/* tagging */
.tag-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tag-chip { font-size: 11px; padding: 5px 9px; border-radius: 3px; border: 1px solid var(--border); background: var(--control); color: var(--muted); cursor: pointer; }
.tag-chip.active { color: #06121a; font-weight: 700; }
.tag-chip.active[data-tag="shortlist"] { background: var(--brand); border-color: var(--brand); }
.tag-chip.active[data-tag="maybe"] { background: var(--g-c); border-color: var(--g-c); }
.tag-chip.active[data-tag="visited"] { background: var(--accent); border-color: var(--accent); }
.tag-chip.active[data-tag="rejected"] { background: var(--g-f); border-color: var(--g-f); }
.note-box { width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
  font-family: var(--font); font-size: 13px; padding: 10px; resize: vertical; min-height: 60px; }

/* saved panel */
#saved-panel { position: absolute; top: 72px; right: 14px; bottom: 14px; z-index: 26; width: 380px; padding: 0;
  transform: translateX(420px); transition: transform 0.28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column; }
#saved-panel.open { transform: translateX(0); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-head button, .panel-foot { }
#saved-panel-close { background: var(--control); border: none; color: var(--text); width: 30px; height: 30px; border-radius: var(--radius); cursor: pointer; font-size: 18px; }
#saved-list { flex: 1; overflow-y: auto; padding: 8px 12px; }
.saved-item { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; }
.saved-item:hover { background: var(--control); border-color: var(--border); }
.saved-item .si-body { flex: 1; min-width: 0; }
.saved-item .si-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-item .si-meta { font-size: 11px; color: var(--muted); }
.panel-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; }
.panel-foot .btn { flex: 1; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 20px; line-height: 1.5; }

/* modal */
#modal-backdrop { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: none; }
#upgrade-modal { position: fixed; z-index: 61; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 440px; max-width: calc(100vw - 32px); padding: 28px; display: none; }
#upgrade-modal.open, #modal-backdrop.open { display: block; }
#upgrade-modal h2 { margin: 0 0 6px; font-size: 22px; }
.modal-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.modal-feats { list-style: none; padding: 0; margin: 0 0 20px; }
.modal-feats li { padding: 7px 0 7px 24px; position: relative; font-size: 14px; }
.modal-feats li::before { content: "✓"; position: absolute; left: 0; color: var(--brand); font-weight: 800; }
.btn.block { width: 100%; }
.modal-anchor { font-size: 13px; color: var(--text); line-height: 1.5; margin: 12px 0 0; text-align: center; }
.modal-anchor b { color: var(--brand); }
.modal-guarantee { font-size: 12px; color: var(--muted); margin: 10px 0 0; text-align: center; }
.modal-guarantee a { color: var(--muted); text-decoration: underline; }
.modal-trust { font-size: 12.5px; color: var(--muted); line-height: 1.5; margin: 12px 0 0; text-align: center; }
#modal-close { position: absolute; top: 14px; right: 14px; background: var(--control); border: none; color: var(--text); width: 30px; height: 30px; border-radius: var(--radius); cursor: pointer; font-size: 18px; }
.key-entry { margin-top: 20px; border-top: 1px solid var(--border); padding-top: 18px; }
.key-row { display: flex; gap: 8px; margin-top: 8px; }
.key-row input { flex: 1; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 12px; color: var(--text); font-family: ui-monospace, monospace; font-size: 13px; }
#key-msg { font-size: 12px; margin-top: 8px; min-height: 16px; }
#key-msg.ok { color: var(--brand); }
#key-msg.err { color: var(--g-f); }

/* comparison overlay */
#compare-backdrop { position: fixed; inset: 0; z-index: 70; background: var(--overlay); display: none; }
#compare-view { position: fixed; z-index: 71; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(1040px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; display: none; flex-direction: column; }
#compare-view.open, #compare-backdrop.open { display: flex; }
#compare-backdrop.open { display: block; }
#compare-close { background: var(--control); border: none; color: var(--text); width: 30px; height: 30px; border-radius: var(--radius); cursor: pointer; font-size: 18px; }
#drawer-close,
#saved-panel-close,
#compare-close,
#modal-close {
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-size: 0;
}
#drawer-close svg,
#saved-panel-close svg,
#compare-close svg,
#modal-close svg {
  width: 17px;
  height: 17px;
}
#compare-body { overflow: auto; padding: 0 20px 8px; }
.cmp-scroll { overflow-x: auto; }
.cmp-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.cmp-table th, .cmp-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.cmp-table thead th { position: sticky; top: 0; background: var(--panel-solid); z-index: 2; border-bottom: 2px solid var(--border-strong); }
.cmp-name { font-weight: 700; font-size: 13px; margin-bottom: 6px; max-width: 180px; }
.cmp-goto { padding: 3px 10px; font-size: 11px; }
.cmp-rowlabel { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
  white-space: nowrap; position: sticky; left: 0; background: var(--panel-solid); z-index: 1; }
.cmp-table td.bad { color: var(--g-f); font-weight: 700; }
.cmp-table td.cmp-best { background: rgba(52,211,153,0.12); font-weight: 700; }
.cmp-table td.cmp-best::after { content: " ✓"; color: var(--brand); }
.cmp-note { font-size: 11px; color: var(--muted-2); padding: 12px 4px; }

@media (max-width: 760px) {
  #topbar {
    height: 94px;
    flex-wrap: wrap;
    align-content: center;
    gap: 7px;
    padding: 7px 8px;
  }
  #topbar .brand { order: 1; width: 21px; overflow: hidden; gap: 0; }
  #topbar .map-scope-switch { order: 2; }
  #search-wrap { order: 4; flex: 0 0 100%; min-width: 0; max-width: none; }
  #search { padding: 9px 9px 9px 34px; font-size: 12px; }
  .topbar-right { order: 3; gap: 5px; }
  #controls { top: 108px; width: calc(100vw - 28px); max-height: 42vh; }
  #legend { display: none; }
  #drawer, #saved-panel {
    top: 108px;
    display: none;
    width: calc(100vw - 28px);
    left: 14px;
    right: auto;
    transform: none;
  }
  #drawer.open, #saved-panel.open { display: flex; }
}
@media (max-width: 520px) {
  #upgrade-btn { display: none; }
}
