/* ═══════════════════════════════════════════════════════════
   QINIRUK NODE GRAPH — Overlay Styles
   ═══════════════════════════════════════════════════════════ */

#knowledgeGraphOverlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: #08090e;
  transition: opacity 0.4s ease;
}
#knowledgeGraphOverlay.fade-in { opacity: 1; }
#knowledgeGraphOverlay.fade-out { opacity: 0; pointer-events: none; }

/* Full-viewport WebGL layer; canvas injected here from knowledgeGraph.js */
#kg-webgl-host {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: auto;
}
#kg-webgl-host canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Loading Screen */
#kg-loading-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #08090e;
  z-index: 100;
  transition: opacity 0.8s ease;
}
#kg-loading-screen.fade-out { opacity: 0; pointer-events: none; }

#kg-loading-text {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Consolas', monospace;
  font-size: 11px;
  letter-spacing: 0.3em;
  color: rgba(100, 216, 208, 0.5);
  margin-bottom: 24px;
}

#kg-loading-track {
  width: 200px;
  height: 2px;
  background: rgba(255,255,255,0.06);
  border-radius: 1px;
  margin-top: 24px;
  overflow: hidden;
}

#kg-loading-bar {
  width: 0%;
  height: 100%;
  background: #64d8d0;
  border-radius: 1px;
  transition: width 0.3s ease;
}

/* Overlay UI */
#kg-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  color: #e8e8e8;
}

#kg-header {
  position: absolute;
  top: 20px;
  left: 24px;
  z-index: 2;
  width: min(340px, calc(100vw - 48px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  text-shadow: 0 1px 20px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

/* Brand + carousel stacked in the left rail; carousel stays centered in this column */
.kg-header-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  pointer-events: none;
}

.kg-header-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  align-self: stretch;
  justify-content: center;
}

/* Three.js logo: transparent WebGL canvas (no model-viewer grey panel) */
.kg-header-logo-slot {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#kg-header-logo-canvas {
  display: block;
  width: 46px;
  height: 46px;
  filter: drop-shadow(0 1px 8px rgba(0, 0, 0, 0.55));
}
#kg-header h1 {
  font-size: clamp(0.62rem, 0.58rem + 1.25vw, 0.98rem);
  font-weight: 300;
  letter-spacing: 0.055em;
  text-transform: none;
  color: #e8e8e8;
  opacity: 1;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
}
#kg-header h1 span {
  color: #64d8d0;
  font-weight: 600;
}

#kg-close-hint {
  position: absolute;
  top: 20px;
  right: 28px;
  pointer-events: auto;
}

#kg-close-btn {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 12px 22px;
  min-height: 44px;
  border-radius: 12px;
}

/* Node graph navigation — same glass / convex language as map .map-nav-leaflet */
.kg-nav-leaflet#kg-explore-hint {
  position: absolute;
  top: max(96px, 24vh);
  right: 24px;
  z-index: 6;
  max-width: min(280px, calc(100vw - 48px));
  margin: 0;
  padding: 14px 16px;
  border-radius: 16px;
  border: 1px solid rgba(140, 210, 230, 0.18);
  background:
    radial-gradient(circle at 20% 0%, rgba(120, 220, 255, 0.16), transparent 45%),
    radial-gradient(circle at 80% 120%, rgba(60, 150, 180, 0.2), transparent 55%),
    rgba(14, 16, 22, 0.7);
  box-shadow:
    0 0 28px rgba(120, 220, 255, 0.22),
    0 18px 36px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.22),
    inset 0 -14px 24px rgba(0, 0, 0, 0.38),
    inset 0 0 18px rgba(120, 220, 255, 0.08);
  backdrop-filter: blur(20px) saturate(165%);
  -webkit-backdrop-filter: blur(20px) saturate(165%);
  pointer-events: none;
  text-align: center;
}
.kg-nav-leaflet#kg-explore-hint::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.2), transparent 45%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0) 40%);
  opacity: 0.6;
  pointer-events: none;
  mix-blend-mode: screen;
}
.kg-nav-leaflet#kg-explore-hint::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.06);
  pointer-events: none;
}
.kg-nav-leaflet__inner {
  position: relative;
  z-index: 1;
}
.kg-nav-leaflet__title {
  font-size: 0.72em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.11em;
  color: #8da5a3;
  margin: 0 0 10px 0;
  line-height: 1.3;
}
.kg-nav-leaflet__cues {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.8em;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: rgba(190, 238, 232, 0.95);
}
.kg-nav-leaflet__cues li {
  margin: 0;
  line-height: 1.35;
  white-space: nowrap;
}

/* Graph panel — same glass / convex language as main .stats-panel & map popups */
#kg-dashboard {
  position: relative;
  align-self: stretch;
  width: 100%;
  margin-top: clamp(40px, 9vh, 112px);
  padding: 0;
  pointer-events: auto;
  border-radius: 16px;
  border: 1px solid rgba(140, 210, 230, 0.2);
  background:
    radial-gradient(circle at 20% 0%, rgba(120, 220, 255, 0.18), transparent 46%),
    radial-gradient(circle at 82% 115%, rgba(60, 150, 180, 0.22), transparent 52%),
    rgba(14, 16, 22, 0.58);
  box-shadow:
    0 0 32px rgba(120, 220, 255, 0.28),
    0 18px 40px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.24),
    inset 0 -14px 28px rgba(0, 0, 0, 0.36),
    inset 0 0 20px rgba(120, 220, 255, 0.1);
  backdrop-filter: blur(20px) saturate(165%);
  -webkit-backdrop-filter: blur(20px) saturate(165%);
  overflow: hidden;
  animation: kg-dash-ambient 7.5s ease-in-out infinite;
}
@supports not ((backdrop-filter: blur(2px)) or (-webkit-backdrop-filter: blur(2px))) {
  #kg-dashboard {
    background: rgba(16, 18, 26, 0.88);
  }
}
@keyframes kg-dash-ambient {
  0%,
  100% {
    box-shadow:
      0 0 28px rgba(120, 220, 255, 0.24),
      0 18px 40px rgba(0, 0, 0, 0.42),
      inset 0 1px 0 rgba(255, 255, 255, 0.24),
      inset 0 -14px 28px rgba(0, 0, 0, 0.36),
      inset 0 0 20px rgba(120, 220, 255, 0.1);
  }
  50% {
    box-shadow:
      0 0 40px rgba(120, 220, 255, 0.38),
      0 20px 44px rgba(0, 0, 0, 0.48),
      inset 0 1px 0 rgba(255, 255, 255, 0.28),
      inset 0 -14px 28px rgba(0, 0, 0, 0.38),
      inset 0 0 22px rgba(120, 220, 255, 0.14);
  }
}
#kg-dashboard::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    radial-gradient(circle at 50% -18%, rgba(255, 255, 255, 0.22), transparent 44%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0) 42%);
  opacity: 0.62;
  pointer-events: none;
  mix-blend-mode: screen;
  z-index: 0;
}
#kg-dashboard::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.07);
  pointer-events: none;
  z-index: 0;
}
.kg-dash-scroll {
  position: relative;
  z-index: 1;
  padding: 13px 14px 12px;
  max-height: min(42vh, 340px);
  overflow-x: hidden;
  overflow-y: auto;
}
.kg-dash-scroll::-webkit-scrollbar {
  width: 5px;
}
.kg-dash-scroll::-webkit-scrollbar-thumb {
  background: rgba(100, 216, 208, 0.28);
  border-radius: 3px;
}
@media (prefers-reduced-motion: reduce) {
  #kg-dashboard {
    animation: none;
  }
}
.kg-dash-head {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(100, 216, 208, 0.58);
  margin: 0 0 10px;
}
.kg-dash-stats {
  font-size: 11px;
  line-height: 1.55;
  color: rgba(232, 232, 238, 0.78);
  margin-bottom: 12px;
}
.kg-dash-stats strong {
  color: rgba(232, 232, 238, 0.95);
  font-weight: 600;
}
.kg-dash-substats {
  display: block;
  margin-top: 6px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.42);
  letter-spacing: 0.02em;
}
.kg-dash-block + .kg-dash-block {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.kg-dash-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.38);
  margin-bottom: 6px;
}
.kg-dash-search {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 11px;
  font-size: 12px;
  color: #e8e8ec;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(100, 216, 208, 0.2);
  border-radius: 8px;
  outline: none;
  font-family: inherit;
}
.kg-dash-search::placeholder {
  color: rgba(255, 255, 255, 0.28);
}
.kg-dash-search:focus {
  border-color: rgba(100, 216, 208, 0.45);
  box-shadow: 0 0 0 2px rgba(100, 216, 208, 0.12);
}
.kg-dash-hint {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.38);
  margin-top: 4px;
}
.kg-dash-hint:not(:empty) {
  min-height: 1.15em;
}
.kg-dash-selection {
  font-size: 12px;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.5);
}
.kg-dash-selection.has-selection {
  color: rgba(232, 232, 238, 0.88);
}
.kg-dash-selection .kg-dash-sel-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}
.kg-dash-selection .kg-dash-sel-meta {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.45);
}
@media (max-width: 720px) {
  #kg-header {
    left: 12px;
    width: min(320px, calc(100vw - 24px));
  }
  .kg-dash-scroll {
    max-height: min(44vh, 300px);
  }
  .kg-nav-leaflet#kg-explore-hint {
    top: max(88px, 20vh);
    right: 12px;
    max-width: calc(100vw - 24px);
    padding: 12px 14px;
  }
  .kg-nav-leaflet__cues {
    font-size: 0.75em;
    gap: 5px;
  }
}
@media (max-height: 720px) {
  .kg-dash-scroll {
    max-height: min(38vh, 280px);
  }
}

/* Tooltip */
#kg-tooltip {
  position: fixed;
  display: none;
  pointer-events: none;
  background: rgba(8, 9, 14, 0.92);
  border: 1px solid rgba(100, 216, 208, 0.2);
  border-radius: 6px;
  padding: 10px 14px;
  z-index: 20;
  max-width: 280px;
  backdrop-filter: blur(8px);
}
.kg-tt-name {
  font-size: 13px;
  font-weight: 600;
  color: #e8e8ec;
  margin-bottom: 3px;
}
.kg-tt-meta {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.5;
}

/* Info Panel */
#kg-info-panel {
  position: fixed;
  bottom: 32px;
  left: 32px;
  display: none;
  pointer-events: auto;
  z-index: 20;
  background: rgba(8, 9, 14, 0.92);
  border: 1px solid rgba(100, 216, 208, 0.15);
  border-radius: 8px;
  padding: 18px 22px;
  min-width: 260px;
  max-width: 340px;
  backdrop-filter: blur(12px);
  max-height: 60vh;
  overflow-y: auto;
}
.kg-ip-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.kg-ip-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}
.kg-ip-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.4);
  font-size: 14px;
  cursor: pointer;
  padding: 0 0 0 12px;
}
.kg-ip-close:hover { color: #fff; }
.kg-ip-type {
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 4px;
}
.kg-ip-details {
  margin-top: 12px;
  font-size: 11px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.6);
}
.kg-ip-details .ip-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}
.kg-ip-details .ip-row span { color: #ccc; }
.kg-ip-details .ip-divider {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 10px 0;
}
.kg-ip-details .ip-connections-heading {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: rgba(232, 232, 238, 0.78);
  margin-bottom: 8px;
}
.kg-ip-details .ip-conn-list {
  max-height: 200px;
  overflow-y: auto;
}
.kg-ip-details .ip-conn-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  font-size: 12px;
}
.kg-ip-details .ip-conn-name {
  font-weight: 500;
  min-width: 0;
  word-break: break-word;
}
.kg-ip-details .ip-conn-metric {
  flex-shrink: 0;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: rgba(255, 255, 255, 0.4);
}
.kg-ip-details .ip-conn-list::-webkit-scrollbar { width: 4px; }
.kg-ip-details .ip-conn-list::-webkit-scrollbar-track { background: transparent; }
.kg-ip-details .ip-conn-list::-webkit-scrollbar-thumb { background: rgba(100, 216, 208, 0.2); border-radius: 2px; }

/* ─── Node Graph: CSS 3D rotating photo ring (left rail) ───
   MIT · Nasir Khan · https://codepen.io/insidethediv/pen/WbQjMbp
   Spin matches CodePen: @keyframes on .inner (rAF was skipped when prefers-reduced-motion). */
@-webkit-keyframes kg-ring-spin-y {
  from {
    -webkit-transform: translate(-50%, -50%) rotateX(-15deg) rotateY(0deg);
    transform: translate(-50%, -50%) rotateX(-15deg) rotateY(0deg);
  }
  to {
    -webkit-transform: translate(-50%, -50%) rotateX(-15deg) rotateY(360deg);
    transform: translate(-50%, -50%) rotateX(-15deg) rotateY(360deg);
  }
}
@keyframes kg-ring-spin-y {
  from {
    transform: translate(-50%, -50%) rotateX(-15deg) rotateY(0deg);
  }
  to {
    transform: translate(-50%, -50%) rotateX(-15deg) rotateY(360deg);
  }
}
/* Centered under .kg-header-brand (column flex on #kg-header) */
#kg-ring-carousel {
  position: relative;
  flex-shrink: 0;
  width: min(168px, 20vw);
  height: min(200px, 32vh);
  pointer-events: none;
  visibility: visible;
  opacity: 0.68;
  overflow: visible;
}
#kg-ring-carousel .kg-ring-stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  perspective: 820px;
  perspective-origin: 50% 40%;
  overflow: visible;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
#kg-ring-carousel .kg-ring-inner {
  --card-width: 68px;
  --card-height: 102px;
  --cards-count: 10;
  /* <1 keeps orbit from spilling past header on narrow widths */
  --ring-z-mul: 0.76;
  position: absolute;
  width: var(--card-width);
  height: var(--card-height);
  top: 50%;
  left: 50%;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  will-change: transform;
  -webkit-animation: kg-ring-spin-y 38s linear infinite;
  animation: kg-ring-spin-y 38s linear infinite;
}
#kg-ring-carousel .kg-ring-card {
  position: absolute;
  width: var(--card-width);
  height: var(--card-height);
  border-radius: 9px;
  /* --ring-r/g/b set from /api/photos/mascot-feed ring_color (Nunavut geocoding region) */
  --ring-r: 100;
  --ring-g: 216;
  --ring-b: 208;
  border: 1px solid rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.88);
  overflow: hidden;
  top: 0;
  left: 0;
  --index: 0;
  -webkit-transform-style: preserve-3d;
  transform-style: preserve-3d;
  box-shadow:
    0 0 6px rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.55),
    0 0 16px rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.35),
    0 0 28px rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.14),
    inset 0 0 12px rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.06);
  background:
    radial-gradient(
      circle at 32% 28%,
      rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.2) 0%,
      rgba(8, 9, 14, 0.55) 52%,
      rgba(var(--ring-r), var(--ring-g), var(--ring-b), 0.1) 100%
    );
  -webkit-transform: rotateY(calc((360deg / var(--cards-count)) * var(--index)))
    translateZ(
      calc((var(--card-width) + var(--card-height)) * var(--ring-z-mul))
    );
  transform: rotateY(calc((360deg / var(--cards-count)) * var(--index)))
    translateZ(calc((var(--card-width) + var(--card-height)) * var(--ring-z-mul)));
}
#kg-ring-carousel .kg-ring-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.62;
}
#kg-ring-carousel.kg-ring-loaded .kg-ring-card img {
  opacity: 0.78;
}
@media (prefers-reduced-motion: reduce) {
  #kg-ring-carousel .kg-ring-inner {
    -webkit-animation-duration: 160s;
    animation-duration: 160s;
  }
}
@media (max-width: 900px) {
  #kg-header {
    left: 12px;
    width: min(328px, calc(100vw - 24px));
    gap: 10px;
  }
  #kg-ring-carousel {
    width: min(148px, 28vw);
    height: min(176px, 30vh);
    opacity: 0.65;
  }
  #kg-ring-carousel .kg-ring-inner {
    --card-width: 58px;
    --card-height: 86px;
    --ring-z-mul: 0.74;
  }
}
