/*
 * PLOT engine — © Dustin / KzNetTech. All rights reserved.
 * TEST COPY for client evaluation. NOT client work, not part of the client's
 * site deliverable, and not licensed. See public/plot-engine/README.md.
 *
 * Derived from PLOT public/style.css (v0.8.0): phone-first, map underneath
 * everything, controls on a right-hand rail. Differences from PLOT: every
 * class is plot-prefixed and tokens are scoped to .plot-app so the engine can
 * sit inside another site without colliding with it; overlays are absolute
 * inside the root instead of fixed to the viewport. The host page sizes the
 * root and may override the --plot-* tokens.
 */
.plot-app {
  --plot-ink: #1b2a41;
  --plot-paper: #ffffff;
  --plot-surface: #f1f5f9;
  --plot-line: #cbd5e1;
  --plot-text-2: #374151;
  --plot-muted: #6b7280;
  --plot-accent: #e4572e;
  --plot-ok: #16a34a;
  --plot-me: #2563eb;       /* the 'you are here' dot + pulse ring while tracking */
  --plot-me-idle: #64748b;  /* same dot, not tracking */
  --plot-chrome: rgba(27, 42, 65, .9); /* rail, HUD, status pill — dark in both themes */
  --plot-page: #dddddd;     /* behind the map while tiles load */
  --plot-shadow: 0 6px 24px rgba(0, 0, 0, .25);
  --plot-rail-w: 64px;
  position: relative; width: 100%; height: 100%; overflow: hidden;
  color: var(--plot-ink); background: var(--plot-page); color-scheme: light;
  font: 16px/1.4 system-ui, -apple-system, sans-serif;
}
.plot-app[data-theme="dark"] {
  --plot-ink: #e5e7eb;
  --plot-paper: #16202e;
  --plot-surface: #22304a;
  --plot-line: #3b4a63;
  --plot-text-2: #cbd5e1;
  --plot-muted: #9ca3af;
  --plot-me: #60a5fa;       /* lighter blue reads better on inverted tiles */
  --plot-page: #0b1220;
  --plot-shadow: 0 6px 24px rgba(0, 0, 0, .6);
  color-scheme: dark;
}
/* Dark map without a second tile provider: invert the raster tiles and spin
   the hue back so water stays blue-ish. Only the tile pane — markers, circles
   and the dot keep their real colours. */
.plot-app[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.7); }
.plot-app[data-theme="dark"] .leaflet-control-attribution { background: var(--plot-chrome); color: var(--plot-muted); }
.plot-app[data-theme="dark"] .leaflet-control-attribution a { color: #93c5fd; }
.plot-app[data-theme="dark"] .leaflet-tooltip { background: var(--plot-paper); color: var(--plot-ink); border-color: var(--plot-line); }
.plot-app[data-theme="dark"] .leaflet-tooltip-top::before { border-top-color: var(--plot-line); }
.plot-app [hidden] { display: none !important; } /* the attribute must beat any display: rule */
.plot-map { position: absolute; inset: 0; }

/* ---- status pill ---- */
.plot-status {
  position: absolute; left: 50%; transform: translateX(-50%); z-index: 1000;
  top: 10px; background: var(--plot-chrome); color: #fff;
  padding: 6px 14px; border-radius: 999px; font-size: 13px; max-width: calc(100% - var(--plot-rail-w) - 24px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---- control rail ---- */
.plot-rail {
  position: absolute; right: 0; top: 50%; transform: translateY(-50%); z-index: 1004;
  width: var(--plot-rail-w); display: flex; flex-direction: column; gap: 6px; padding: 8px 6px;
  background: var(--plot-chrome); border-radius: 18px 0 0 18px; box-shadow: var(--plot-shadow);
}
.plot-rail-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  width: 52px; height: 52px; border: 0; border-radius: 14px; cursor: pointer;
  background: rgba(255,255,255,.08); color: #fff; font: inherit;
}
.plot-rail-btn .glyph { font-size: 20px; line-height: 1; }
.plot-rail-btn .lbl { font-size: 10px; letter-spacing: .02em; opacity: .85; }
.plot-rail-pair { display: flex; flex-direction: column; gap: 2px; }
.plot-rail-btn.half { height: 32px; border-radius: 8px; }
.plot-rail-btn.half .glyph { font-size: 22px; font-weight: 600; }
/* Short screens: the rail is taller than the viewport, so drop labels, shrink
   buttons, and let it scroll. */
@media (max-height: 640px) {
  .plot-rail { max-height: 100%; overflow-y: auto; gap: 4px; padding: 6px 6px; scrollbar-width: none; }
  .plot-rail::-webkit-scrollbar { display: none; }
  .plot-rail-btn { height: 40px; flex: none; }
  .plot-rail-btn .lbl { display: none; }
  .plot-rail-btn.half { height: 28px; }
}
.plot-rail-btn[aria-pressed="true"] { background: #fff; color: var(--plot-ink); }
.plot-rail-btn.primary { background: var(--plot-accent); }
.plot-rail-btn.primary.on { background: var(--plot-ok); color: #fff; }
.plot-rail-btn.busy { opacity: .6; }
.plot-rail-btn.flash { background: var(--plot-ok); color: #fff; }

/* ---- tracking HUD + approach banner ---- */
.plot-hud {
  position: absolute; left: 10px; right: calc(var(--plot-rail-w) + 10px); z-index: 1000;
  bottom: calc(22px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 6px;
}
.plot-hud-line { background: var(--plot-chrome); color: #fff; padding: 8px 12px; border-radius: 12px; font-size: 14px; }
.plot-hud-line.ahead { background: #1d4ed8; font-weight: 600; }
.plot-hud-line.fix { font-size: 12px; opacity: .85; padding: 5px 10px; }
.plot-approach {
  position: absolute; left: 10px; right: calc(var(--plot-rail-w) + 10px); z-index: 1001;
  top: 48px; background: var(--plot-accent); color: #fff; padding: 10px 14px; border-radius: 12px; font-weight: 600;
  box-shadow: var(--plot-shadow); animation: plot-rise .2s ease-out;
}

/* ---- place card ---- */
.plot-card {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 1005;
  background: var(--plot-paper); border-radius: 18px 18px 0 0; box-shadow: var(--plot-shadow);
  max-height: 70%; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom);
  animation: plot-rise .25s ease-out;
}
@keyframes plot-rise { from { transform: translateY(100%); } to { transform: none; } }
/* Wide screen: a bottom sheet would span the whole window, so the card is a
   left panel (viewOffset() reads the geometry and keeps the map centred). */
@media (min-width: 900px) {
  .plot-card { top: 0; right: auto; width: 380px; max-height: none; border-radius: 0; animation: none; }
  .plot-card-photo { border-radius: 0; }
  /* The HUD and banner share the left edge with the panel: slide them past it. */
  .plot-app:has(.plot-card:not([hidden])) .plot-hud,
  .plot-app:has(.plot-card:not([hidden])) .plot-approach { left: 390px; }
}
/* Landscape phone: a bottom sheet covers the whole map, so the card becomes a
   side panel. JS sets data-side to the side the place is on, so the map stays
   visible on the other side. Height cap = "phone on its side". */
@media (orientation: landscape) and (max-height: 500px) {
  .plot-card {
    top: 0; bottom: 0; max-height: none; width: min(360px, 42vw);
    border-radius: 0; animation: none;
  }
  .plot-card[data-side="left"] { right: auto; left: 0; padding-left: env(safe-area-inset-left); }
  .plot-card[data-side="right"] { left: auto; right: var(--plot-rail-w); } /* the control rail owns the edge */
  .plot-card-photo { height: 140px; border-radius: 0; }
  .plot-app:has(.plot-card[data-side="left"]:not([hidden])) .plot-hud,
  .plot-app:has(.plot-card[data-side="left"]:not([hidden])) .plot-approach { left: calc(min(360px, 42vw) + 10px); }
  .plot-app:has(.plot-card[data-side="right"]:not([hidden])) .plot-hud,
  .plot-app:has(.plot-card[data-side="right"]:not([hidden])) .plot-approach { right: calc(var(--plot-rail-w) + min(360px, 42vw) + 10px); }
}
.plot-card-close {
  position: absolute; top: 10px; right: 10px; z-index: 1;
  width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer;
}
.plot-card-photo { height: 220px; background: var(--plot-line) center/cover no-repeat; border-radius: 18px 18px 0 0; position: relative; }
.plot-staged { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
.plot-card-body { padding: 14px 16px 18px; }
.plot-card-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; color: var(--plot-accent); }
.plot-card-title { margin: 0 0 4px; font-size: 20px; color: var(--plot-ink); }
.plot-card-more { display: inline-block; margin: 0 0 8px; padding: 4px 10px; border: 0; border-radius: 999px; background: #1d4ed8; color: #fff; font-size: 13px; font-weight: 600; cursor: pointer; }
.plot-card-sub { margin: 0 0 8px; color: var(--plot-muted); font-size: 14px; }
.plot-card-stats { margin: 0 0 10px; font-weight: 600; }
.plot-card-desc { margin: 0; font-size: 15px; color: var(--plot-text-2); }
.plot-card-links { margin: 10px 0 0; display: flex; gap: 14px; flex-wrap: wrap; }
.plot-card-links a { color: var(--plot-accent); font-weight: 600; text-decoration: none; }

/* ---- map markers ---- */
/* "You are here". Idle (one-shot locate, or tracking off) = grey, no motion: a
   last-known spot, not a live one. Tracking = blue with two pulsing rings so
   the eye finds it on a busy map and you can SEE tracking is on. */
.plot-me-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--plot-me-idle); border: 3px solid #fff; box-shadow: 0 0 0 2px color-mix(in srgb, var(--plot-me-idle) 33%, transparent); position: relative; }
.tracking .plot-me-dot { background: var(--plot-me); box-shadow: 0 0 0 2px color-mix(in srgb, var(--plot-me) 33%, transparent); }
.tracking .plot-me-dot::before, .tracking .plot-me-dot::after {
  content: ''; position: absolute; inset: -3px; border-radius: 50%;
  border: 2px solid var(--plot-me); opacity: 0; animation: plot-pulse 2.4s ease-out infinite;
}
.tracking .plot-me-dot::after { animation-delay: 1.2s; }
@keyframes plot-pulse { 0% { transform: scale(1); opacity: .9; } 100% { transform: scale(4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tracking .plot-me-dot::before, .tracking .plot-me-dot::after { animation: none; opacity: .5; transform: scale(2); } }
.plot-pin { background: none; border: 0; }
.plot-pin svg { display: block; filter: drop-shadow(0 2px 2px rgba(0,0,0,.35)); }

/* ---- about ---- */
.plot-about { border: 0; border-radius: 18px; padding: 18px; width: min(460px, calc(100% - 32px)); color: var(--plot-ink); background: var(--plot-paper); box-shadow: var(--plot-shadow); }
.plot-about::backdrop { background: rgba(0, 0, 0, .45); }
.plot-about h2 { margin: 0 0 10px; font-size: 22px; color: var(--plot-ink); }
.plot-about p { margin: 0 0 10px; font-size: 15px; color: var(--plot-text-2); }
.plot-about a { color: var(--plot-accent); }
.plot-about .plot-muted { font-size: 13px; color: var(--plot-muted); }
.plot-btn { border: 0; border-radius: 12px; background: var(--plot-ink); color: var(--plot-paper); font: inherit; font-weight: 600; padding: 10px 18px; cursor: pointer; }
