/* ============================================================
   SellPilot Platform Shell — Global Navigation Bar
   Injected via <link> into ALL sub-apps (Flask, React, etc.)
   All classes prefixed with sp- to avoid host app conflicts
   ============================================================ */

/* ── Fonts ── */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── Variables ── */
/* 톤: ADR-29 잉크 크롬 — tokens.css --color-chrome(#16211E) 계열 + 코랄 accent.
   셸은 전 앱 공통 크롬이라 순차 전환 예외로 일괄 재도색됨 (구 니어블랙 #111318 + 초록 #1D9E75 대체). */
:root {
  --sp-shell-h: 56px;
  --sp-shell-bg: #16211E;
  --sp-shell-glass: rgba(22, 33, 30, 0.82);
  --sp-shell-highlight: rgba(255, 255, 255, 0.13);
  --sp-shell-depth: 0 18px 60px rgba(0, 0, 0, 0.36);
  --sp-shell-border: rgba(255, 255, 255, 0.06);
  --sp-shell-text: #93A29C;
  --sp-shell-text-hover: #F2F1EA;
  --sp-shell-text-active: #FFFFFF;
  --sp-shell-accent: #D9553D;
  --sp-dd-bg: #1C2A26;
  --sp-dd-border: rgba(255, 255, 255, 0.07);
  --sp-dd-shadow: 0 16px 48px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --sp-ebay: #E53238;
  --sp-amazon: #FF9900;
  --sp-biz: #6366F1;
  --sp-route-green: #1D9E75;
  --sp-route-red: #E53238;
  --sp-route-purple: #8B5CF6;
  --sp-route-blue: #378ADD;
  --sp-route-amber: #FF9900;
  --sp-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --sp-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Body offset ── */
body.sp-shell-active {
  padding-top: var(--sp-shell-h) !important;
}

/* 호스트 앱의 sticky 헤더용 공용 클래스 — 셸 밑으로 말려 들어가지 않게 셸 높이만큼 내려 고정 */
body.sp-shell-active .sp-under-shell {
  top: var(--sp-shell-h) !important;
}

/* ── Shell bar ── */
#sp-shell {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--sp-shell-h);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.045), rgba(255,255,255,0)),
    var(--sp-shell-glass);
  border-bottom: 1px solid var(--sp-shell-border);
  box-shadow: var(--sp-shell-depth);
  backdrop-filter: blur(18px) saturate(1.25);
  -webkit-backdrop-filter: blur(18px) saturate(1.25);
  z-index: 99999;
  display: flex;
  align-items: center;
  padding: 0 24px;
  box-sizing: border-box;
  font-family: 'Plus Jakarta Sans', 'Pretendard Variable', 'Pretendard', sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* Subtle noise texture overlay */
#sp-shell::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none;
}

/* ── Logo ── */
.sp-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-right: 36px;
  text-decoration: none;
  cursor: pointer;
  flex-shrink: 0;
}

.sp-logo-mark {
  width: 30px; height: 30px;
  background: linear-gradient(135deg, #D9553D, #C24730);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
  color: #FFF;
  letter-spacing: -0.5px;
  box-shadow: 0 2px 8px rgba(217, 85, 61, 0.3);
}

.sp-logo-text {
  font-weight: 600;
  font-size: 17px;
  color: #FFF;
  letter-spacing: -0.4px;
}

.sp-logo-text span {
  color: var(--sp-shell-accent);
}

/* ── Navigation ── */
.sp-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
  height: 100%;
}

.sp-nav-item {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--sp-shell-text);
  cursor: pointer;
  transition: color 0.2s var(--sp-ease-out);
  user-select: none;
  white-space: nowrap;
}

.sp-nav-item:hover {
  color: var(--sp-shell-text-hover);
}

.sp-nav-item.sp-active {
  color: var(--sp-shell-text-active);
}

/* Active indicator bar — bottom edge */
.sp-nav-item.sp-active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px; right: 16px;
  height: 2px;
  background: var(--sp-shell-accent);
  border-radius: 2px 2px 0 0;
}

/* Hover glow — subtle underline */
.sp-nav-item:not(.sp-active)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px; right: 16px;
  height: 2px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform 0.25s var(--sp-ease-out);
}

.sp-nav-item:not(.sp-active):hover::after {
  transform: scaleX(1);
}

/* Chevron arrow */
.sp-chevron {
  margin-left: 5px;
  font-size: 9px;
  opacity: 0.5;
  transition: transform 0.25s var(--sp-ease-spring);
}

.sp-nav-item.sp-open .sp-chevron {
  transform: rotate(180deg);
}

/* Channel dot indicator */
.sp-channel-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 7px;
  flex-shrink: 0;
}

/* ── Dropdown ── */
.sp-dropdown {
  position: absolute;
  top: calc(var(--sp-shell-h) - 1px);
  left: 0;
  min-width: 280px;
  background: var(--sp-dd-bg);
  border: 1px solid var(--sp-dd-border);
  border-radius: 0 0 14px 14px;
  box-shadow: var(--sp-dd-shadow);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s var(--sp-ease-out),
              transform 0.25s var(--sp-ease-spring),
              visibility 0.2s;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.sp-dropdown.sp-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Channel accent stripe at top */
.sp-dropdown-accent {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
}

/* ── Dropdown items ── */
.sp-dd-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: background 0.15s, transform 0.15s var(--sp-ease-out);
}

.sp-dd-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sp-dd-item:active {
  transform: scale(0.98);
}

.sp-dd-item.sp-soon {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.sp-dd-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.sp-dd-info {
  flex: 1;
  min-width: 0;
}

.sp-dd-name {
  font-size: 13px;
  font-weight: 500;
  color: #F2F1EA;
  line-height: 1.3;
}

.sp-dd-desc {
  font-size: 11px;
  color: var(--sp-shell-text);
  margin-top: 1px;
}

.sp-dd-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: #7D7F8A;
  flex-shrink: 0;
}

.sp-dd-badge.sp-live {
  background: rgba(78, 180, 150, 0.15);
  color: #4EB496;
}

.sp-dd-badge.sp-live::before {
  content: '';
  display: inline-block;
  width: 5px; height: 5px;
  background: #4EB496;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  animation: sp-pulse 2s ease-in-out infinite;
}

.sp-dd-separator {
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 4px 12px;
}

/* ── Right section ── */
.sp-right {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
}

/* User button */
.sp-user-btn {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.sp-user-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sp-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--sp-shell-accent), #C24730);
  color: #FFF;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Plus Jakarta Sans', sans-serif;
}

.sp-user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--sp-shell-text);
  transition: color 0.15s;
}

.sp-user-btn:hover .sp-user-name {
  color: var(--sp-shell-text-hover);
}

.sp-user-chevron {
  font-size: 9px;
  color: var(--sp-shell-text);
  opacity: 0.5;
}

/* User dropdown */
.sp-user-dd {
  position: absolute;
  top: calc(var(--sp-shell-h) - 1px);
  right: 0;
  min-width: 200px;
  background: var(--sp-dd-bg);
  border: 1px solid var(--sp-dd-border);
  border-radius: 0 0 14px 14px;
  box-shadow: var(--sp-dd-shadow);
  padding: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px);
  transition: opacity 0.2s var(--sp-ease-out),
              transform 0.25s var(--sp-ease-spring),
              visibility 0.2s;
  backdrop-filter: blur(16px);
}

.sp-user-dd.sp-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.sp-user-dd-header {
  padding: 8px 12px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 4px;
}

.sp-user-dd-name {
  font-size: 14px;
  font-weight: 600;
  color: #FFF;
}

.sp-user-dd-email {
  font-size: 11px;
  color: var(--sp-shell-text);
  margin-top: 2px;
}

.sp-user-dd-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--sp-shell-text-hover);
  transition: background 0.15s;
  text-decoration: none;
}

.sp-user-dd-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.sp-user-dd-item svg {
  width: 16px; height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.sp-user-dd-item.sp-danger {
  color: var(--sp-ebay);
}

/* ── Animations ── */
@keyframes sp-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Dropdown staggered entrance */
.sp-dropdown.sp-open .sp-dd-item {
  animation: sp-dd-enter 0.25s var(--sp-ease-out) both;
}
.sp-dropdown.sp-open .sp-dd-item:nth-child(2) { animation-delay: 0.03s; }
.sp-dropdown.sp-open .sp-dd-item:nth-child(3) { animation-delay: 0.06s; }
.sp-dropdown.sp-open .sp-dd-item:nth-child(4) { animation-delay: 0.09s; }
.sp-dropdown.sp-open .sp-dd-item:nth-child(5) { animation-delay: 0.12s; }

@keyframes sp-dd-enter {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  #sp-shell { padding: 0 12px; }
  .sp-logo-text { display: none; }
  .sp-nav-item { padding: 0 10px; font-size: 13px; }
  .sp-user-name { display: none; }
  .sp-dropdown { min-width: 240px; }
}

@media (max-width: 480px) {
  .sp-channel-dot { display: none; }
  .sp-nav { gap: 0; }
  .sp-nav-item { padding: 0 8px; }
}

.sp-route-egg {
  position: fixed;
  inset: 0;
  z-index: 100000;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 24%, rgba(29,158,117,0.18), transparent 28%),
    radial-gradient(circle at 72% 30%, rgba(229,50,56,0.16), transparent 30%),
    radial-gradient(circle at 55% 78%, rgba(55,138,221,0.16), transparent 34%),
    rgba(8, 10, 14, 0.62);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  animation: spEggFadeIn 220ms var(--sp-ease-out) both;
}

.sp-route-egg-map {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(820px, calc(100vw - 40px));
  height: min(420px, calc(100vh - 80px));
  transform: translate(-50%, -50%);
}

.sp-route-egg-title {
  position: absolute;
  left: 50%;
  top: calc(50% - min(260px, 38vh));
  transform: translateX(-50%);
  color: #fff;
  font: 800 14px/1.2 'Plus Jakarta Sans', sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 8px 30px rgba(0,0,0,0.55);
}

.sp-route-node {
  position: absolute;
  display: grid;
  place-items: center;
  width: 112px;
  height: 44px;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  color: #fff;
  font: 800 12px/1 'Plus Jakarta Sans', sans-serif;
  background: rgba(255,255,255,0.1);
  box-shadow: 0 20px 55px rgba(0,0,0,0.32), inset 0 1px 0 rgba(255,255,255,0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  animation: spNodePop 700ms var(--sp-ease-spring) both;
}

.sp-route-node::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 18px;
  border: 1px solid var(--node-color);
  border-color: color-mix(in srgb, var(--node-color), transparent 35%);
  opacity: 0.72;
  animation: spNodePulse 1.4s ease-in-out infinite;
}

.sp-route-node.portal { --node-color: var(--sp-route-green); left: 4%; top: 12%; }
.sp-route-node.pricing { --node-color: var(--sp-route-red); right: 8%; top: 18%; animation-delay: 80ms; }
.sp-route-node.lister { --node-color: var(--sp-route-purple); right: 18%; bottom: 14%; animation-delay: 160ms; }
.sp-route-node.shipping { --node-color: var(--sp-route-blue); left: 14%; bottom: 18%; animation-delay: 240ms; }
.sp-route-node.finance { --node-color: var(--sp-route-green); left: 42%; top: 44%; animation-delay: 320ms; }

.sp-route-path {
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 2px;
  background: linear-gradient(90deg, var(--sp-route-green), var(--sp-route-red), var(--sp-route-purple), var(--sp-route-blue), var(--sp-route-amber));
  transform-origin: left center;
  animation: spRouteDraw 1.2s var(--sp-ease-out) both;
  box-shadow: 0 0 24px rgba(255,255,255,0.3);
}

.sp-route-packet {
  position: absolute;
  left: 10%;
  top: calc(50% - 5px);
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 0 24px #fff;
  animation: spPacket 1.45s var(--sp-ease-out) infinite;
}

@keyframes spEggFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes spRouteDraw { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes spPacket { from { transform: translateX(0); } to { transform: translateX(64vw); } }
@keyframes spNodePop { from { opacity: 0; transform: translateY(14px) scale(0.92); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes spNodePulse { 0%, 100% { transform: scale(1); opacity: 0.45; } 50% { transform: scale(1.08); opacity: 0.9; } }

@media (prefers-reduced-motion: reduce) {
  .sp-route-egg,
  .sp-route-node,
  .sp-route-node::before,
  .sp-route-path,
  .sp-route-packet {
    animation: none !important;
  }
}
