/* ===========================================================================
   Sputnik X — Trade Explorer 3D (plan §5 D2-D5)

   Dark premium console, same visual family as /memory-center (glass panels,
   #0a0e16 space background, cyan primary) + /data-chat (LV operator chrome).
   Plain hand-written CSS — no Tailwind build step, no CDN, no webfonts.

   Pieces:
     1. shell + header          — fixed top bar with window/count chips
     2. #te-graph-host          — WebGL host filling the viewport
     3. .te-legend              — top-left glass legend
     4. #te-gate                — auth gate overlay
     5. #te-info                — right slide-in node panel
     6. #te-halos               — anomaly / chat-focus halo rings overlay
     7. .te-chat                — bottom-left chat dock
     8. .te-tip                 — hover tooltip card (FG3D label layer)
   =========================================================================== */

.te-shell {
  --te-bg: #0a0e16;
  --te-surface: #141b28;
  --te-surface-low: #0d1320;
  --te-on: #dde3ea;
  --te-muted: #8b98ab;
  --te-primary: #8aebff;
  --te-primary-deep: #22d3ee;
  --te-warm: #ffa758;
  --te-cool: #4ea0ff;
  --te-danger: #ff6b5e;
  --te-border: rgba(255, 255, 255, 0.1);
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--te-bg);
  color: var(--te-on);
  font-family:
    'Inter',
    -apple-system,
    'Segoe UI',
    system-ui,
    sans-serif;
  overflow: hidden;
}

.te-icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
  flex-shrink: 0;
}
.te-icon-lg {
  width: 34px;
  height: 34px;
}

/* ── 1. Header ─────────────────────────────────────────────────────────── */
.te-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 18px;
  background: color-mix(in srgb, var(--te-surface-low) 82%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--te-border);
  z-index: 50;
  flex-shrink: 0;
}
.te-title-icon {
  width: 20px;
  height: 20px;
  color: var(--te-primary);
}
.te-title {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.te-chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--te-muted);
  border: 1px solid var(--te-border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.te-chip[hidden] {
  display: none;
}
.te-header-spacer {
  flex: 1;
}
.te-operator-tag {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--te-primary);
  border: 1px solid rgba(138, 235, 255, 0.35);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.te-hdr-link {
  font-size: 12px;
  font-weight: 600;
  color: var(--te-muted);
  text-decoration: none;
  white-space: nowrap;
}
.te-hdr-link:hover {
  color: var(--te-on);
}

/* ── 2. Main + WebGL host ──────────────────────────────────────────────── */
.te-main {
  position: relative;
  flex: 1;
  overflow: hidden;
}
#te-graph-host {
  position: absolute;
  inset: 0;
  z-index: 10;
  overflow: hidden;
  background: var(--te-bg);
}
#te-graph-host canvas {
  display: block;
  outline: none;
}

/* ── 3. Legend ─────────────────────────────────────────────────────────── */
.te-legend {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--te-surface-low) 76%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--te-border);
  font-size: 11px;
  color: var(--te-muted);
  pointer-events: none;
}
.te-legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.te-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.te-dot-hs2 {
  background: linear-gradient(135deg, hsl(0, 82%, 60%), hsl(52, 82%, 60%));
}
.te-dot-kn4 {
  width: 7px;
  height: 7px;
  background: hsl(28, 72%, 70%);
}
.te-dot-country {
  background: var(--te-cool);
}
.te-ring {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-sizing: border-box;
}
.te-ring-anomaly {
  border: 2px dashed var(--te-danger);
}
.te-edge {
  display: inline-block;
  width: 14px;
  height: 0;
  border-top: 2px solid;
}
.te-edge-export {
  border-color: var(--te-warm);
}
.te-edge-import {
  border-color: var(--te-cool);
}

/* ── 4. Auth gate ──────────────────────────────────────────────────────── */
.te-gate {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  background: color-mix(in srgb, var(--te-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.te-gate[hidden] {
  display: none;
}
.te-gate h3 {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 700;
}
.te-gate p {
  margin: 0;
  max-width: 460px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--te-muted);
}
.te-gate .te-icon-lg {
  color: var(--te-primary);
}
.te-signin-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 9px 18px;
  border-radius: 10px;
  background: var(--te-primary);
  color: #04141a;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.35);
}
.te-signin-btn:hover {
  background: #a5f0ff;
}

/* ── 5. Node info panel (right slide-in — mc-n3d-info clone) ───────────── */
#te-info {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 40;
  width: 330px;
  max-width: 86vw;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px 20px 24px;
  background: color-mix(in srgb, var(--te-surface) 88%, transparent);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-left: 1px solid var(--te-border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.5);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
}
#te-info.is-open {
  transform: translateX(0);
}
#te-info[hidden] {
  display: none;
}
.te-info-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
#te-info-label {
  display: block;
  font-size: 16px;
  font-weight: 700;
  word-break: break-word;
  line-height: 1.25;
}
#te-info-type {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-primary);
}
#te-info-close {
  flex-shrink: 0;
  appearance: none;
  border: 1px solid var(--te-border);
  background: transparent;
  color: var(--te-muted);
  border-radius: 8px;
  width: 30px;
  height: 30px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#te-info-close:hover {
  color: var(--te-on);
  border-color: var(--te-primary-deep);
  background: rgba(34, 211, 238, 0.08);
}
.te-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid currentColor;
}
.te-badge[hidden] {
  display: none;
}
.te-badge.is-anomaly {
  color: var(--te-danger);
  background: rgba(255, 107, 94, 0.12);
}
.te-badge.is-structural {
  color: var(--te-warm);
  background: rgba(255, 167, 88, 0.12);
  letter-spacing: 0.04em;
  text-transform: none;
  margin-top: 6px;
}
.te-info-rows {
  display: flex;
  flex-direction: column;
  gap: 1px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.te-info-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.02);
}
.te-info-row[hidden] {
  display: none;
}
.te-info-row-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--te-muted);
  flex-shrink: 0;
}
.te-info-row-value {
  font-size: 13px;
  font-weight: 600;
  text-align: right;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}
.te-info-section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-primary);
  margin: 6px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.te-info-section-anomaly {
  color: var(--te-danger);
}
.te-info-partners {
  margin: 0;
  padding: 0 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
}
.te-info-partners li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.te-partner-name {
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.te-partner-meta {
  color: var(--te-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.te-anomaly-card {
  border: 1px solid rgba(255, 107, 94, 0.25);
  border-radius: 10px;
  padding: 9px 12px;
  margin-bottom: 8px;
  background: rgba(255, 107, 94, 0.05);
  font-size: 12px;
}
.te-anomaly-head {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.te-anomaly-body {
  margin-top: 3px;
  color: var(--te-muted);
  font-variant-numeric: tabular-nums;
}
.te-anomaly-label {
  margin-top: 3px;
  color: var(--te-on);
}
.te-info-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.te-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  appearance: none;
  border: 1px solid var(--te-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--te-on);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.te-btn:hover {
  border-color: var(--te-primary-deep);
  background: rgba(34, 211, 238, 0.08);
}
.te-btn[hidden] {
  display: none;
}
.te-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.te-btn-primary {
  background: var(--te-primary);
  color: #04141a;
  border-color: transparent;
}
.te-btn-primary:hover {
  background: #a5f0ff;
}

/* ── 6. Halo rings overlay (anomaly + chat focus) ──────────────────────── */
#te-halos {
  position: absolute;
  inset: 0;
  z-index: 15;
  pointer-events: none;
  overflow: hidden;
}
.te-halo {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-sizing: border-box;
  will-change: left, top;
}
.te-halo.is-anomaly {
  border-color: var(--te-danger);
  border-style: dashed;
  box-shadow:
    0 0 10px rgba(255, 107, 94, 0.6),
    inset 0 0 8px rgba(255, 167, 88, 0.35);
  animation: te-halo-pulse 1.8s ease-in-out infinite;
}
.te-halo.is-chat-focus {
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  border-color: var(--te-primary);
  box-shadow: 0 0 16px rgba(138, 235, 255, 0.75);
  animation: te-halo-pulse 1.4s ease-in-out infinite;
}
@keyframes te-halo-pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.18);
  }
}

/* ── 7. Chat dock (bottom-left) ────────────────────────────────────────── */
.te-chat {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 45;
  width: 360px;
  max-width: calc(100vw - 28px);
  max-height: 46vh;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: color-mix(in srgb, var(--te-surface) 90%, transparent);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid var(--te-border);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.te-chat-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--te-border);
  color: var(--te-primary);
  flex-shrink: 0;
}
.te-chat-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.te-chat-toggle {
  margin-left: auto;
  appearance: none;
  border: 1px solid var(--te-border);
  background: transparent;
  color: var(--te-muted);
  border-radius: 6px;
  width: 24px;
  height: 24px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
}
.te-chat-toggle:hover {
  color: var(--te-on);
}
.te-chat.is-collapsed .te-chat-thread,
.te-chat.is-collapsed .te-chat-composer {
  display: none;
}
.te-chat-thread {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.te-chat-empty p {
  margin: 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--te-muted);
}
.te-msg {
  display: flex;
}
.te-msg-q {
  justify-content: flex-end;
}
.te-msg-a {
  justify-content: flex-start;
}
.te-bubble-q {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px 12px 3px 12px;
  background: rgba(138, 235, 255, 0.14);
  border: 1px solid rgba(138, 235, 255, 0.25);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.te-card {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px 12px 12px 3px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--te-border);
  font-size: 12.5px;
  line-height: 1.5;
}
.te-card-kind {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-warm);
  margin-bottom: 4px;
}
.te-card-refusal .te-card-kind {
  color: var(--te-danger);
}
.te-card-resolved {
  font-size: 11px;
  color: var(--te-muted);
  font-style: italic;
  border-left: 2px solid var(--te-primary-deep);
  padding-left: 8px;
  margin-bottom: 6px;
}
.te-card-text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.te-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 7px;
}
.te-chip-sm {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--te-muted);
  border: 1px solid var(--te-border);
  border-radius: 999px;
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
}
.te-chip-sm.is-sig {
  color: #3ee08a;
  border-color: rgba(62, 224, 138, 0.4);
}
.te-chip-sm.is-nosig {
  color: var(--te-muted);
}
.te-card-disclaimer {
  margin-top: 7px;
  font-size: 10.5px;
  color: var(--te-muted);
  font-style: italic;
}
.te-card-graphref {
  margin-top: 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--te-primary);
}
.te-chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--te-border);
  flex-shrink: 0;
}
.te-chat-input {
  flex: 1;
  resize: none;
  min-height: 34px;
  max-height: 120px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--te-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--te-on);
  font: inherit;
  font-size: 12.5px;
  line-height: 1.4;
  outline: none;
}
.te-chat-input:focus {
  border-color: var(--te-primary-deep);
}
.te-chat-send {
  appearance: none;
  border: none;
  background: var(--te-primary);
  color: #04141a;
  border-radius: 10px;
  width: 36px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.te-chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

/* ── 8. Hover tooltip (FG3D label layer) ───────────────────────────────── */
.te-tip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(10, 14, 22, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  font-family: inherit;
}
.te-tip-id {
  font-size: 12.5px;
  font-weight: 700;
  color: #dde3ea;
  white-space: nowrap;
}
.te-tip-sub {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8aebff;
  white-space: nowrap;
}
.te-tip-anom {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ff6b5e;
}

/* ── Toast ─────────────────────────────────────────────────────────────── */
.te-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  padding: 10px 18px;
  border-radius: 10px;
  background: rgba(20, 27, 40, 0.95);
  border: 1px solid var(--te-border);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  font-size: 12.5px;
  max-width: 80vw;
}
.te-toast[hidden] {
  display: none;
}

/* ── 5b. Country card explorer (#te-card, te-cards.js) ─────────────────── */
#te-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#te-card[hidden] {
  display: none;
}
.te-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.te-card-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-word;
}
.te-card-window {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--te-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* collapsed summary */
.te-card-summary {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.te-card-total-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(138, 235, 255, 0.06);
  border: 1px solid rgba(138, 235, 255, 0.16);
}
.te-card-total-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-muted);
}
.te-card-total-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--te-primary);
  font-variant-numeric: tabular-nums;
}
.te-card-split-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.te-card-split {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--te-on);
  font-variant-numeric: tabular-nums;
}
.te-card-split-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.te-card-split-import .te-card-split-dot {
  background: var(--te-cool);
}
.te-card-split-export .te-card-split-dot {
  background: var(--te-warm);
}
.te-card-subhead {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-primary);
}
.te-card-top {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.te-card-top-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border-left: 3px solid transparent;
}
.te-card-top-item.te-card-dir-export {
  border-left-color: var(--te-warm);
}
.te-card-top-item.te-card-dir-import {
  border-left-color: var(--te-cool);
}
.te-card-top-name {
  font-size: 12.5px;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.te-card-top-meta {
  font-size: 11.5px;
  color: var(--te-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.te-card-backfill-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--te-warm);
  border: 1px solid rgba(255, 167, 88, 0.4);
  border-radius: 999px;
  padding: 1px 6px;
  vertical-align: 1px;
}
.te-card-empty-note {
  font-size: 12px;
  color: var(--te-muted);
  font-style: italic;
}
.te-card-summary-actions,
.te-card-explorer-foot {
  display: flex;
}
.te-card-expand-btn,
.te-card-collapse-btn {
  width: 100%;
}

/* expanded explorer */
.te-card-explorer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.te-card-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.te-card-search {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.te-card-search-label,
.te-card-sort-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--te-muted);
}
.te-card-search-input {
  appearance: none;
  border: 1px solid var(--te-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--te-on);
  border-radius: 9px;
  padding: 8px 10px;
  font: inherit;
  font-size: 12.5px;
  outline: none;
}
.te-card-search-input:focus {
  border-color: var(--te-primary-deep);
}
.te-card-dir-toggle {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--te-border);
}
.te-card-dir-btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--te-muted);
  border-radius: 7px;
  padding: 6px 4px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.te-card-dir-btn:hover {
  color: var(--te-on);
}
.te-card-dir-btn.is-active {
  background: rgba(138, 235, 255, 0.14);
  color: var(--te-primary);
}
.te-card-sort {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.te-card-sort-select {
  appearance: none;
  border: 1px solid var(--te-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--te-on);
  border-radius: 9px;
  padding: 7px 10px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  outline: none;
}
.te-card-sort-select:focus {
  border-color: var(--te-primary-deep);
}
.te-card-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--te-muted);
  font-variant-numeric: tabular-nums;
  padding: 2px 2px 4px;
}
.te-card-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.te-card-sector {
  border-radius: 10px;
  border: 1px solid var(--te-border);
  background: rgba(255, 255, 255, 0.02);
  overflow: hidden;
  border-left-width: 3px;
}
.te-card-sector.te-card-dir-export {
  border-left-color: var(--te-warm);
}
.te-card-sector.te-card-dir-import {
  border-left-color: var(--te-cool);
}
.te-card-sector-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--te-on);
  padding: 9px 11px;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.te-card-sector-head:hover {
  background: rgba(255, 255, 255, 0.03);
}
.te-card-caret {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--te-muted);
  width: 12px;
}
.te-card-dir-tag {
  flex-shrink: 0;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 5px;
  border-radius: 5px;
}
.te-card-dir-tag-export {
  color: var(--te-warm);
  background: rgba(255, 167, 88, 0.14);
}
.te-card-dir-tag-import {
  color: var(--te-cool);
  background: rgba(78, 160, 255, 0.14);
}
.te-card-sector-name {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.te-card-sector-val {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--te-muted);
  font-variant-numeric: tabular-nums;
}
.te-card-kn4 {
  padding: 4px 11px 10px 31px;
}
.te-card-kn4[hidden] {
  display: none;
}
.te-card-kn4-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.te-card-kn4-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 11.5px;
}
.te-card-kn4-code {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--te-primary);
  font-variant-numeric: tabular-nums;
}
.te-card-kn4-label {
  flex: 1;
  min-width: 0;
  color: var(--te-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.te-card-kn4-val {
  flex-shrink: 0;
  color: var(--te-on);
  font-variant-numeric: tabular-nums;
}
.te-card-kn4-empty {
  font-size: 11px;
  color: var(--te-muted);
  font-style: italic;
}

/* ── Small screens ─────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .te-legend {
    display: none;
  }
  .te-hdr-link {
    display: none;
  }
  .te-chat {
    width: calc(100vw - 28px);
    max-height: 40vh;
  }
}

/* ── Reduced motion ────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .te-halo.is-anomaly,
  .te-halo.is-chat-focus {
    animation: none;
    opacity: 0.85;
  }
  #te-info {
    transition: none;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Mode toggle (3D graph ⇄ 2D map) — header segmented control
   ═══════════════════════════════════════════════════════════════════════════ */
.te-mode {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  margin-left: 10px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--te-surface-low) 82%, transparent);
  border: 1px solid var(--te-border);
}
.te-mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--te-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.16s ease,
    color 0.16s ease;
}
.te-mode-btn .te-icon {
  width: 15px;
  height: 15px;
}
.te-mode-btn:hover {
  color: var(--te-on);
}
.te-mode-btn.is-active {
  background: color-mix(in srgb, var(--te-primary) 22%, transparent);
  color: var(--te-primary);
}

/* ═══════════════════════════════════════════════════════════════════════════
   2D map — canvas host + premium glass control card
   ═══════════════════════════════════════════════════════════════════════════ */
#te-map-host {
  position: absolute;
  inset: 0;
  z-index: 12;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #0e1524 0%, var(--te-bg) 70%);
}
#te-map-host[hidden] {
  display: none;
}
#te-map-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.te-map-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--te-surface-low) 78%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--te-border);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.te-map-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--te-muted);
}
.te-map-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.te-map-dot {
  width: 18px;
  height: 3px;
  border-radius: 2px;
  display: inline-block;
}
.te-map-dot-export {
  background: var(--te-warm);
}
.te-map-dot-import {
  background: var(--te-cool);
}
.te-map-dot-hub {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #78e6b4;
}
.te-map-modes {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--te-bg) 60%, transparent);
  border: 1px solid var(--te-border);
}
.te-map-mode-btn {
  border: 0;
  border-radius: 7px;
  padding: 5px 11px;
  background: transparent;
  color: var(--te-muted);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.14s ease,
    color 0.14s ease;
}
.te-map-mode-btn:hover {
  color: var(--te-on);
}
.te-map-mode-btn.is-active {
  background: color-mix(in srgb, var(--te-primary) 20%, transparent);
  color: var(--te-primary);
}

/* Hover tooltip (JS-positioned, escaped textContent). */
.te-map-tip {
  position: absolute;
  z-index: 40;
  max-width: 220px;
  padding: 7px 10px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--te-surface) 92%, transparent);
  border: 1px solid var(--te-border);
  color: var(--te-on);
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.4);
}
.te-map-tip[hidden] {
  display: none;
}

@media (max-width: 640px) {
  .te-mode-btn {
    padding: 6px 9px;
    font-size: 11px;
  }
  .te-map-panel {
    top: 10px;
    left: 10px;
    padding: 10px;
  }
}
