/* =====================================================================
 * TRAVEL GLOBE — embedded "Places visited" widget (Places tab)
 *
 * Scoped deliberately: every custom property lives on #globe-container
 * itself (not :root), so nothing here can override — or be overridden
 * by — the host app's own theme. The one class name that collided with
 * the host's stylesheet (.panel) is renamed to .gl-panel; everything
 * else here is already namespaced enough (tt-*, trip-*, panel-*) to be
 * safe verbatim.
 * ===================================================================== */

/* Host-side wrapper: makes the widget sit in a plain host .panel card
   like every other panel, with the globe's own dark "space" filling the
   card edge-to-edge below the heading. Collapsible like the ledger's
   category cards, but defaults to expanded. */
.globe-panel{grid-column:1/-1; padding:0; overflow:hidden;}
.globe-panel-head{padding:20px 20px 0;}
.globe-panel-head h3{margin:0 0 2px;}
.globe-panel-desc{margin:0 0 14px; font-size:11.5px; color:var(--ink-faint);}
.globe-panel-warn{margin:0 0 14px; font-size:11.5px; color:var(--warn);}
.globe-panel-warn[hidden]{display:none;}
.globe-panel-head-row{display:flex; align-items:center; justify-content:space-between; gap:10px;}
.globe-panel-head-row h3{margin:0;}
.globe-panel-collapse{
  appearance:none; border:0; background:none;
  display:inline-flex; align-items:center; justify-content:center;
  width:22px; height:22px; padding:0; flex:none;
  border-radius:6px;
  color:var(--ink-faint);
  cursor:pointer;
  transition:color 140ms var(--ease), background-color 140ms var(--ease);
}
.globe-panel-collapse:hover{color:var(--ink); background:var(--bg);}
.globe-panel-collapse:active{transform:scale(.92);}
.globe-panel-collapse svg{width:12px; height:12px; transition:transform 220ms var(--ease-out); transform:rotate(0deg);}
.globe-panel.collapsed .globe-panel-collapse svg{transform:rotate(-90deg);}
.globe-stage-wrap{
  overflow:hidden;
  max-height:620px;
  opacity:1;
  transition:max-height 280ms var(--ease), opacity 220ms var(--ease);
}
.globe-panel.collapsed .globe-stage-wrap{max-height:0; opacity:0;}
.globe-panel.collapsed .globe-panel-desc,
.globe-panel.collapsed .globe-panel-warn{margin-bottom:16px;}
.globe-stage{position:relative; height:560px;}
@media (max-width:640px){ .globe-stage{height:440px;} }

#globe-container{
  /* Surfaces ----------------------------------------------------------- */
  --bg:#0e0e10;
  --bg-deep:#08080a;
  --surface:rgba(23,23,27,.60);
  --surface-hover:rgba(255,255,255,.05);
  --hair:rgba(255,255,255,.085);
  --hair-strong:rgba(255,255,255,.15);

  /* Ink ------------------------------------------------------------ */
  --ink:#f3f3f5;
  --ink-2:#a6a6af;
  --ink-3:#71717c;

  /* Accent --------------------------------------------------------- */
  --accent:#4F46E5;
  --accent-tint:rgba(79,70,229,.13);
  --accent-line:rgba(79,70,229,.38);

  --radius:14px;
  --radius-sm:9px;

  /* Motion --------------------------------------------------------- */
  --ease-out:cubic-bezier(.23,1,.32,1);
  --ease:cubic-bezier(.4,0,.2,1);

  --font:ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI","Inter","Helvetica Neue",Arial,sans-serif;
  --mono:ui-monospace,SFMono-Regular,"SF Mono",Menlo,Consolas,monospace;

  position:relative;
  width:100%;
  height:100%;
  min-height:320px;
  overflow:hidden;
  color:var(--ink);
  font-family:var(--font);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  background:radial-gradient(120% 92% at 50% 44%, #16161a 0%, var(--bg) 48%, var(--bg-deep) 100%);
  touch-action:none;
  cursor:grab;
  user-select:none;
  -webkit-user-select:none;
  -webkit-tap-highlight-color:transparent;
}
#globe-container.is-dragging{cursor:grabbing}
#globe-container.is-hit{cursor:pointer}
#globe-container canvas{display:block;width:100%;height:100%}

#globe-container::after{
  content:"";
  position:absolute;inset:0;
  pointer-events:none;
  background:radial-gradient(120% 90% at 50% 45%,transparent 60%,rgba(0,0,0,.38) 100%);
  transition:background 320ms var(--ease);
}

#globe-container.bg-light{
  /* Apple-style adaptive material: the HUD switches to a light-vibrancy
     family to match the brighter backdrop (dark glass over a night sky,
     light glass over daylight) — not just a darker/lighter tint of the
     same palette, which is how translucent chrome stays legible over a
     backdrop this different rather than reading as muddy or washed out. */
  --bg:#f4f4f6;
  --bg-deep:#e7e7ec;
  --ink:#1c1c22;
  --ink-2:#4c4c58;
  --ink-3:#77778a;
  --surface:rgba(255,255,255,.72);
  --surface-hover:rgba(20,20,26,.06);
  --hair:rgba(20,20,26,.10);
  --hair-strong:rgba(20,20,26,.20);
  --accent-tint:rgba(79,70,229,.10);
  --accent-line:rgba(79,70,229,.34);
  background:radial-gradient(120% 92% at 50% 44%, #ffffff 0%, var(--bg) 52%, var(--bg-deep) 100%);

  /* Hooks for the handful of hand-picked (non-variable) colors above —
     chips and text that were tuned to sit on dark glass specifically and
     need a distinct, not just lighter, value on light glass. */
  --tooltip-bg:rgba(255,255,255,.82);
  --tt-badge-ink:#c8281a;
  --chip-bg:rgba(20,20,26,.055);
  --chip-edge:rgba(20,20,26,.07);
  --chip-edge-strong:rgba(20,20,26,.18);
  --ink-faint-2:rgba(20,20,26,.32);
}
#globe-container.bg-light::after{
  background:radial-gradient(120% 90% at 50% 45%,transparent 62%,rgba(20,20,26,.10) 100%);
}
#globe-container.bg-light .gl-panel{box-shadow:0 10px 28px rgba(20,20,26,.14);}
#globe-container.bg-light #tooltip{box-shadow:0 16px 36px rgba(20,20,26,.20);}

/* ----------------------------- Panels ---------------------------- */
.gl-panel{
  position:absolute;
  z-index:4;
  background:var(--surface);
  -webkit-backdrop-filter:blur(22px) saturate(150%);
  backdrop-filter:blur(22px) saturate(150%);
  border:1px solid var(--hair);
  border-radius:var(--radius);
  box-shadow:0 10px 34px rgba(0,0,0,.42);
  transition:background-color 320ms var(--ease), border-color 320ms var(--ease);
}

.panel-head{
  top:20px;left:20px;
  padding:15px 18px 14px;
}
.ttl{
  margin:0;
  font-size:15px;
  font-weight:600;
  letter-spacing:-.012em;
  line-height:1.2;
}
.stats{display:flex;gap:20px;margin-top:13px}
.stat{display:flex;flex-direction:column;gap:2px}
.stat b{
  font-size:19px;
  font-weight:600;
  line-height:1;
  letter-spacing:-.02em;
  font-variant-numeric:tabular-nums;
}
.stat span{
  font-size:10px;
  letter-spacing:.085em;
  text-transform:uppercase;
  color:var(--ink-3);
}

/* ---------------------------- Trip list -------------------------- */
.panel-trips{
  top:20px;right:20px;
  width:214px;
  padding:12px 10px 10px;
}
.panel-label{
  display:flex;align-items:center;justify-content:space-between;
  gap:8px;
  padding:0 8px 9px;
  font-size:10px;
  letter-spacing:.11em;
  text-transform:uppercase;
  color:var(--ink-3);
}
.panel-label-actions{display:flex;align-items:center;gap:2px}
.reset{
  appearance:none;border:0;background:none;
  font:inherit;font-size:10px;letter-spacing:.06em;
  color:var(--ink-3);
  text-transform:uppercase;
  padding:2px 4px;margin:-2px -4px;
  border-radius:6px;
  cursor:pointer;
  opacity:0;
  pointer-events:none;
  transition:opacity 160ms var(--ease), color 160ms var(--ease), transform 160ms var(--ease-out);
}
.reset[data-show="true"]{opacity:1;pointer-events:auto}
.reset:active{transform:scale(.96)}

.panel-collapse{
  appearance:none;border:0;background:none;
  display:inline-flex;align-items:center;justify-content:center;
  width:18px;height:18px;margin:-2px -4px -2px 0;
  padding:0;border-radius:6px;
  color:var(--ink-3);
  cursor:pointer;
  transition:color 140ms var(--ease), background-color 140ms var(--ease);
}
.panel-collapse:hover{color:var(--ink);background:var(--surface-hover)}
.panel-collapse svg{
  width:11px;height:11px;
  transition:transform 220ms var(--ease-out);
  transform:rotate(0deg);
}
.panel-trips.collapsed .panel-collapse svg{transform:rotate(-90deg)}

.trip-list-wrap{
  overflow:hidden;
  max-height:280px;
  opacity:1;
  transition:max-height 260ms var(--ease), opacity 200ms var(--ease);
}
.panel-trips.collapsed .trip-list-wrap{max-height:0;opacity:0}

.trip-list{
  display:flex;flex-direction:column;gap:1px;
  max-height:280px;
  overflow-y:auto;
  overflow-x:hidden;
  overscroll-behavior:contain;
  /* Minimal, Apple-style scrollbar: a thin, translucent thumb with no
     visible track, rather than the OS default. */
  scrollbar-width:thin;
  scrollbar-color:var(--hair-strong) transparent;
}
.trip-list::-webkit-scrollbar{width:5px}
.trip-list::-webkit-scrollbar-track{background:transparent}
.trip-list::-webkit-scrollbar-thumb{
  background:var(--hair-strong);
  border-radius:999px;
}
.trip-list::-webkit-scrollbar-thumb:hover{background:var(--ink-3)}

.trip{
  display:flex;align-items:center;gap:10px;
  width:100%;
  padding:8px 8px;
  border:0;
  border-radius:var(--radius-sm);
  background:transparent;
  color:var(--ink-2);
  font:inherit;
  font-size:12.5px;
  letter-spacing:-.005em;
  text-align:left;
  cursor:pointer;
  transition:background-color 140ms var(--ease), color 140ms var(--ease), transform 140ms var(--ease-out);
}
.trip:focus-visible{outline:2px solid var(--accent-line);outline-offset:1px}
.trip:active{transform:scale(.985)}
.trip[aria-pressed="true"]{
  background:var(--accent-tint);
  color:var(--ink);
}
@media (hover:hover) and (pointer:fine){
  .trip:hover{background:var(--surface-hover);color:var(--ink)}
  .trip[aria-pressed="true"]:hover{background:var(--accent-tint)}
}

.trip-dot{
  flex:none;
  width:7px;height:7px;border-radius:50%;
  background:var(--ink-3);
  transition:background-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.trip[aria-pressed="true"] .trip-dot{
  background:var(--accent);
  box-shadow:0 0 8px rgba(79,70,229,.7);
}
@media (hover:hover) and (pointer:fine){
  .trip:hover .trip-dot{background:var(--accent);box-shadow:0 0 8px rgba(79,70,229,.7)}
  .reset:hover{color:var(--ink)}
}
.trip-name{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.trip-n{
  flex:none;
  font-family:var(--mono);
  font-size:10.5px;
  color:var(--ink-3);
  font-variant-numeric:tabular-nums;
}

/* ---------------------------- Foot bar --------------------------- */
.footbar{
  position:absolute;
  z-index:4;
  left:20px;bottom:20px;
  display:flex;align-items:center;gap:14px;
  pointer-events:none;
  font-size:11.5px;
  color:var(--ink-3);
}
.hint{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.hint kbd{
  font-family:var(--font);
  font-size:10px;
  font-weight:500;
  letter-spacing:.02em;
  color:var(--ink-2);
  background:var(--chip-bg, rgba(255,255,255,.055));
  border:1px solid var(--hair);
  border-bottom-color:var(--chip-edge, rgba(255,255,255,.05));
  border-radius:5px;
  padding:2px 6px;
  transition:background-color 320ms var(--ease), border-color 320ms var(--ease), color 320ms var(--ease);
}

.controls-br{
  position:absolute;
  z-index:4;
  right:20px;bottom:20px;
  display:flex;flex-direction:column;align-items:flex-end;gap:9px;
}

.spin{
  display:inline-flex;align-items:center;gap:7px;
  font-size:11px;
  letter-spacing:.02em;
  color:var(--ink-3);
  pointer-events:none;
  transition:opacity 300ms var(--ease);
}
.spin[data-on="false"]{opacity:.34}
.spin i{
  width:9px;height:9px;border-radius:50%;
  border:1.5px solid var(--chip-edge-strong, rgba(255,255,255,.16));
  border-top-color:var(--ink-2);
  animation:spin 2.4s linear infinite;
  animation-play-state:paused;
  transition:border-color 320ms var(--ease);
}
.spin[data-on="true"] i{animation-play-state:running}
@keyframes spin{to{transform:rotate(360deg)}}

.bg-toggle{
  appearance:none;
  display:inline-flex;align-items:center;gap:7px;
  border:1px solid var(--hair);
  background:var(--surface);
  -webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px);
  color:var(--ink-2);
  font:inherit;font-size:11px;letter-spacing:.02em;
  padding:6px 11px 6px 9px;
  border-radius:999px;
  cursor:pointer;
  transition:color 140ms var(--ease), border-color 140ms var(--ease), background-color 320ms var(--ease);
}
.bg-toggle:hover{color:var(--ink);border-color:var(--hair-strong)}
.bg-toggle:active{transform:scale(.97)}
.bg-toggle .dot{
  flex:none;
  width:8px;height:8px;border-radius:50%;
  background:var(--ink-3);
  transition:background-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.bg-toggle[aria-pressed="true"] .dot{background:#ffcf5c;box-shadow:0 0 8px rgba(255,207,92,.75)}

.fit-btn{
  appearance:none;
  align-self:flex-end;
  display:inline-flex;align-items:center;justify-content:center;
  width:30px;height:30px;
  border:1px solid var(--hair);
  background:var(--surface);
  -webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px);
  border-radius:999px;
  color:var(--ink-2);
  cursor:pointer;
  transition:color 140ms var(--ease), border-color 140ms var(--ease), background-color 320ms var(--ease);
}
.fit-btn:hover{color:var(--ink);border-color:var(--hair-strong)}
.fit-btn:active{transform:scale(.94)}
.fit-btn svg{width:14px;height:14px}

/* --------------------------- Tooltip ----------------------------- */
/* The anchor tracks the pin every frame and is deliberately NOT
   transitioned — a transition here would smear the card behind the pin
   while the globe rotates. The card owns the enter/exit animation. */
#tooltip-anchor{
  position:absolute;
  z-index:7;
  top:0;left:0;
  transform:translate3d(-9999px,-9999px,0);
  pointer-events:none;
  will-change:transform;
}
#tooltip{
  min-width:180px;
  max-width:256px;
  padding:13px 15px;
  background:var(--tooltip-bg, rgba(20,20,24,.74));
  -webkit-backdrop-filter:blur(22px) saturate(160%);
  backdrop-filter:blur(22px) saturate(160%);
  border:1px solid var(--hair);
  border-radius:var(--radius);
  box-shadow:0 16px 44px rgba(0,0,0,.55);
  opacity:0;
  visibility:hidden;
  transform:scale(.96);
  transition:opacity 150ms var(--ease), transform 190ms var(--ease-out), visibility 0s linear 190ms,
             background-color 320ms var(--ease), border-color 320ms var(--ease), box-shadow 320ms var(--ease);
  pointer-events:none;
  will-change:transform,opacity;
}
#tooltip.visible{
  opacity:1;
  visibility:visible;
  transform:scale(1);
  transition:opacity 150ms var(--ease), transform 190ms var(--ease-out), visibility 0s,
             background-color 320ms var(--ease), border-color 320ms var(--ease), box-shadow 320ms var(--ease);
}
#tooltip.pinned{pointer-events:auto;border-color:var(--accent-line)}

.tt-head{display:flex;align-items:flex-start;justify-content:space-between;gap:12px}
.tt-city{
  margin:0;
  font-size:15px;
  font-weight:600;
  letter-spacing:-.015em;
  line-height:1.2;
}
.tt-country{
  margin:3px 0 0;
  font-size:11.5px;
  color:var(--ink-3);
  letter-spacing:-.005em;
}
.tt-badge{
  flex:none;
  display:inline-flex;align-items:center;
  margin-top:1px;
  padding:3px 8px;
  border-radius:999px;
  background:var(--accent-tint);
  border:1px solid var(--accent-line);
  color:var(--tt-badge-ink, #ff8b83);
  font-size:10.5px;
  font-weight:600;
  letter-spacing:.01em;
  white-space:nowrap;
  transition:background-color 320ms var(--ease), border-color 320ms var(--ease), color 320ms var(--ease);
}
.tt-rule{height:1px;background:var(--hair);margin:12px -15px 11px}
.tt-dates{list-style:none;margin:0;padding:0;display:grid;gap:7px}
.tt-dates li{
  display:flex;align-items:center;gap:9px;
  font-size:11.5px;
  color:var(--ink-2);
  letter-spacing:-.005em;
}
.tt-dates li i{
  flex:none;
  width:4px;height:4px;border-radius:50%;
  background:rgba(79,70,229,.55);
}
.tt-visit-range{flex:1;min-width:0}
/* A real button (opens the trip in the ledger), styled to look like the
   quiet label it replaced until you're actually pointed at it. */
.tt-trip{
  appearance:none;
  flex:none;
  max-width:120px;
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
  padding:3px 7px;
  border:1px solid transparent;
  border-radius:6px;
  background:var(--chip-bg, rgba(255,255,255,.055));
  font:inherit;
  font-size:10px;
  color:var(--ink-3);
  letter-spacing:.01em;
  cursor:pointer;
  transition:background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease-out);
}
#tooltip.pinned .tt-trip:hover{background:var(--accent-tint); border-color:var(--accent-line); color:var(--ink)}
.tt-trip:focus-visible{outline:2px solid var(--accent-line); outline-offset:1px}
.tt-trip:active{transform:scale(.95)}
.tt-esc{
  margin:11px 0 0;
  font-size:10px;
  color:var(--ink-faint-2, rgba(255,255,255,.26));
  letter-spacing:.02em;
}

/* ------------------------- Loader / error ------------------------ */
#status{
  position:absolute;
  z-index:9;
  inset:0;
  display:flex;flex-direction:column;align-items:center;justify-content:center;gap:15px;
  background:var(--bg);
  transition:opacity 500ms var(--ease);
  pointer-events:none;
}
#status.hidden{opacity:0}
.ld-arc{
  width:24px;height:24px;
  border:1.5px solid rgba(255,255,255,.12);
  border-top-color:var(--accent);
  border-radius:50%;
  animation:spin .85s linear infinite;
}
.ld-txt{font-size:11.5px;letter-spacing:.02em;color:var(--ink-3)}
.ld-err{max-width:330px;text-align:center;line-height:1.65;color:#cf9089;font-size:12px}

/* ---------------------------- Responsive ------------------------- */
@media (max-width:760px){
  .panel-head{top:14px;left:14px;padding:12px 14px 11px}
  .ttl{font-size:13.5px}
  .stats{gap:15px;margin-top:10px}
  .stat b{font-size:16px}
  .panel-trips{top:14px;right:14px;width:auto;max-width:44vw;padding:9px 7px 7px}
  .trip{padding:7px;font-size:11.5px;gap:8px}
  .trip-n{display:none}
  .footbar{display:none}
  .controls-br{right:14px;bottom:14px}
  #tooltip{max-width:min(256px,72vw)}
}
/* Below ~520px the two top panels would collide, so the trip filter
   reflows into a horizontally scrollable bar along the bottom. */
@media (max-width:520px){
  .panel-trips{
    top:auto;bottom:14px;left:14px;right:14px;
    width:auto;max-width:none;
    padding:9px 10px 10px;
  }
  .panel-label{padding:0 2px 8px}
  .trip-list{
    flex-direction:row;
    gap:6px;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    scrollbar-width:none;
    -ms-overflow-style:none;
  }
  .trip-list::-webkit-scrollbar{display:none}
  .trip{
    flex:none;width:auto;
    padding:7px 11px;
    background:var(--chip-bg, rgba(255,255,255,.04));
  }
  .trip-name{white-space:nowrap}
  .controls-br{display:none}   /* would sit under the bar */
}

@media (prefers-reduced-motion:reduce){
  .spin i,.ld-arc{animation:none}
  #tooltip{transition:opacity 120ms linear}
  .trip,.reset{transition:none}
}
