/* ==========================================================================
   Nolan's desk: guided support chat. Pairs with assets/js/chatbot.js.
   Uses the site's :root tokens when present, with matching fallbacks.
   ========================================================================== */

#nolan-desk {
  --nd-gold-btn: var(--gold-grad-btn, linear-gradient(135deg, #fff1a8 0%, #ffd84a 35%, #ffc21a 68%, #ffe684 100%));
  --nd-text: var(--text, #f6f1e7);
  --nd-muted: var(--muted, #b3ab9c);
  --nd-dim: var(--dim, #7d766a);
  --nd-line: var(--line, rgba(212, 175, 55, 0.22));
  --nd-line-strong: var(--line-strong, rgba(240, 200, 100, 0.55));
  --nd-gold-2: var(--gold-2, #f6d77e);
  --nd-ink: #1a1100;
  --nd-panel-bg: linear-gradient(160deg, rgba(26, 22, 14, 0.98) 0%, rgba(11, 10, 8, 0.99) 45%, rgba(6, 6, 5, 0.99) 100%);
  --nd-display: var(--font-display, "Jost", "Inter", system-ui, sans-serif);
  --nd-body: var(--font-body, "Inter", system-ui, -apple-system, "Segoe UI", sans-serif);
  --nd-edge: 24px;
  --nd-launcher: 60px;
  --nd-lift: 0px;
  font: 400 15px/1.55 var(--nd-body);
  color: var(--nd-text);
  -webkit-font-smoothing: antialiased;
}
#nolan-desk *, #nolan-desk *::before, #nolan-desk *::after { box-sizing: border-box; }
#nolan-desk [hidden] { display: none !important; }
#nolan-desk button { font: inherit; color: inherit; background: none; border: 0; margin: 0; cursor: pointer; }
#nolan-desk svg { display: block; }
#nolan-desk :focus-visible { outline: 2px solid var(--accent, #ffcc33); outline-offset: 3px; }
#nolan-desk .nd-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.nd-scrim { display: none; }

/* ---------- Launcher ---------- */
.nd-launcher {
  position: fixed;
  right: var(--nd-edge);
  bottom: calc(var(--nd-edge) + var(--nd-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 76;
  width: var(--nd-launcher);
  height: var(--nd-launcher);
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--nd-ink) !important;
  background: var(--nd-gold-btn) !important;
  background-size: 200% 100% !important;
  box-shadow: 0 0 0 1px rgba(255, 236, 170, 0.55) inset, 0 12px 30px rgba(0, 0, 0, 0.55), 0 8px 26px rgba(255, 190, 40, 0.3), 0 0 18px rgba(255, 204, 51, 0.25);
  transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease, bottom 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  animation: ndGoldShift 7s ease-in-out infinite;
}
.nd-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 0 0 1px rgba(255, 236, 170, 0.65) inset, 0 16px 36px rgba(0, 0, 0, 0.55), 0 10px 34px rgba(255, 190, 40, 0.42), 0 0 40px rgba(255, 204, 51, 0.32); }
.nd-launcher:active { transform: scale(0.96); }
.nd-launcher__icon { grid-area: 1 / 1; display: grid; place-items: center; transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.2s ease; }
.nd-launcher__icon svg { width: 26px; height: 26px; }
.nd-launcher__icon--close { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.nd-launcher__icon--close svg { width: 22px; height: 22px; }
.nd--open .nd-launcher__icon--chat { opacity: 0; transform: rotate(90deg) scale(0.6); }
.nd--open .nd-launcher__icon--close { opacity: 1; transform: none; }
.nd-launcher__dot {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--red, #ff5a5a);
  border: 2.5px solid #0a0907;
  transform: scale(0);
  transition: transform 0.3s cubic-bezier(0.3, 1.6, 0.5, 1);
}
.nd--unread:not(.nd--open) .nd-launcher__dot { transform: scale(1); animation: ndPulse 2.4s ease-out 0.4s infinite; }

/* ---------- Teaser bubble ---------- */
.nd-teaser {
  position: fixed;
  right: calc(var(--nd-edge) + var(--nd-launcher) + 12px);
  bottom: calc(var(--nd-edge) + var(--nd-lift) + 8px + env(safe-area-inset-bottom, 0px));
  z-index: 76;
  max-width: min(320px, calc(100vw - var(--nd-launcher) - var(--nd-edge) * 2 - 12px));
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 4px 4px 4px 2px;
  border-radius: 16px 16px 4px 16px;
  background: var(--nd-panel-bg), #0a0907;
  border: 1px solid var(--nd-line-strong);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.6), 0 0 24px rgba(212, 175, 55, 0.16);
  opacity: 0;
  transform: translateX(10px) scale(0.96);
  transform-origin: right bottom;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), bottom 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.nd-teaser--in { opacity: 1; transform: none; }
.nd-teaser__text { flex: 1; padding: 9px 4px 9px 14px; text-align: left; font: 500 14px/1.4 var(--nd-body); color: var(--nd-text); border-radius: 12px; }
.nd-teaser__text:hover { color: var(--nd-gold-2); }
.nd-teaser__close { flex: 0 0 28px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; color: var(--nd-muted); }
.nd-teaser__close:hover { color: var(--nd-text); background: rgba(255, 255, 255, 0.06); }
.nd-teaser__close svg { width: 14px; height: 14px; }

/* ---------- Panel ---------- */
.nd-panel {
  position: fixed;
  right: var(--nd-edge);
  bottom: calc(var(--nd-edge) + var(--nd-launcher) + 14px + var(--nd-lift) + env(safe-area-inset-bottom, 0px));
  z-index: 77;
  width: 360px;
  height: min(540px, calc(100vh - var(--nd-launcher) - var(--nd-edge) * 2 - 30px - var(--nd-lift)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 22px;
  background: var(--nd-panel-bg), #0a0907;
  border: 1px solid var(--nd-line-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 60px rgba(212, 175, 55, 0.14), 0 0 2px rgba(255, 230, 150, 0.5);
  visibility: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: right bottom;
  transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.3s;
}
.nd--open .nd-panel { visibility: visible; opacity: 1; transform: none; transition: opacity 0.22s ease, transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }

.nd-head {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 12px 15px 18px;
  border-bottom: 1px solid var(--nd-line);
  background: radial-gradient(260px 120px at 15% 0%, rgba(255, 204, 51, 0.12), transparent 70%);
}
.nd-head__avatar {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font: 700 18px/1 var(--font-logo, "Cinzel", serif);
  color: var(--nd-ink);
  background: var(--nd-gold-btn);
  box-shadow: 0 0 0 1px rgba(255, 236, 170, 0.5) inset, 0 0 16px rgba(255, 204, 51, 0.28);
}
.nd-head__text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.nd-head__title { font: 600 18px/1.15 var(--nd-display); letter-spacing: 0.01em; color: var(--nd-text); }
.nd-head__sub { font: 400 13px/1.3 var(--nd-body); color: var(--nd-muted); }
.nd-head__close { flex: 0 0 40px; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: var(--nd-muted); transition: background 0.2s ease, color 0.2s ease; }
.nd-head__close:hover { color: var(--nd-text); background: rgba(255, 255, 255, 0.06); }
.nd-head__close svg { width: 18px; height: 18px; }

.nd-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 16px 20px;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 175, 55, 0.3) transparent;
}
.nd-log { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Messages ---------- */
.nd-msg { display: flex; }
.nd-msg--user { justify-content: flex-end; margin-top: 6px; }
.nd-msg--user + .nd-msg--bot { margin-top: 6px; }
#nolan-desk .nd-bubble {
  margin: 0;
  max-width: 86%;
  padding: 10px 14px;
  font: 400 14.5px/1.55 var(--nd-body);
  overflow-wrap: anywhere;
}
.nd-msg--bot .nd-bubble {
  color: var(--nd-text);
  background: rgba(255, 244, 214, 0.045);
  border: 1px solid var(--nd-line);
  border-radius: 16px 16px 16px 5px;
}
.nd-msg--user .nd-bubble {
  color: var(--nd-ink);
  font-weight: 600;
  background: var(--nd-gold-btn);
  border-radius: 16px 16px 5px 16px;
  box-shadow: 0 6px 18px rgba(255, 190, 40, 0.18);
}
.nd-in { animation: ndRise 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.nd-typing { margin-top: 8px; }
.nd-typing .nd-bubble { padding: 13px 16px; }
.nd-dots { display: flex; gap: 5px; }
.nd-dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--nd-gold-2); opacity: 0.35; animation: ndDot 1.1s ease-in-out infinite; }
.nd-dots i:nth-child(2) { animation-delay: 0.15s; }
.nd-dots i:nth-child(3) { animation-delay: 0.3s; }

/* ---------- Option chips ---------- */
.nd-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.nd-chips:empty { display: none; }
#nolan-desk .nd-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 8px 15px;
  border-radius: 999px;
  font: 600 13.5px/1.25 var(--nd-body);
  text-align: left;
  text-decoration: none;
  color: var(--nd-gold-2);
  background: rgba(212, 175, 55, 0.07);
  border: 1px solid var(--nd-line-strong);
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease, color 0.2s ease;
}
#nolan-desk .nd-chip:hover { background: rgba(212, 175, 55, 0.16); box-shadow: 0 0 18px rgba(255, 204, 51, 0.22); transform: translateY(-1px); }
#nolan-desk .nd-chip svg { width: 15px; height: 15px; flex: 0 0 15px; }
#nolan-desk .nd-chip--link {
  color: var(--nd-ink);
  background: var(--nd-gold-btn);
  border-color: rgba(255, 236, 170, 0.6);
  box-shadow: 0 6px 18px rgba(255, 190, 40, 0.2);
}
#nolan-desk .nd-chip--link:hover { background: var(--nd-gold-btn); box-shadow: 0 8px 24px rgba(255, 190, 40, 0.36), 0 0 22px rgba(255, 204, 51, 0.3); }
#nolan-desk .nd-chip--back { color: var(--nd-muted); background: transparent; border-color: var(--nd-line); font-weight: 500; }
#nolan-desk .nd-chip--back:hover { color: var(--nd-text); background: rgba(255, 255, 255, 0.05); box-shadow: none; }
.nd-chips--in .nd-chip { animation: ndRise 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) both; animation-delay: calc(var(--i, 0) * 45ms); }

/* ---------- Phone: full-width bottom sheet ---------- */
@media (max-width: 520px) {
  #nolan-desk { --nd-edge: 16px; --nd-launcher: 56px; }
  .nd-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 86vh;
    height: 86dvh;
    border-radius: 22px 22px 0 0;
    border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(40px);
    transform-origin: center bottom;
  }
  .nd-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 77;
    background: rgba(0, 0, 0, 0.62);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0s linear 0.25s;
  }
  .nd--open .nd-scrim { opacity: 1; visibility: visible; transition: opacity 0.25s ease, visibility 0s; }
  .nd-panel { z-index: 78; }
  .nd--open .nd-launcher, .nd--open .nd-teaser { opacity: 0; visibility: hidden; pointer-events: none; }
  .nd-head { padding: 14px 10px 13px 16px; }
  .nd-head__close { flex-basis: 44px; width: 44px; height: 44px; }
  .nd-body { padding: 16px 14px 22px; }
  #nolan-desk .nd-bubble { font-size: 15px; max-width: 88%; }
  #nolan-desk .nd-chip { min-height: 42px; font-size: 14px; padding: 9px 16px; }
  html.nd-lock, html.nd-lock body { overflow: hidden; }
}

/* ---------- Motion ---------- */
@keyframes ndGoldShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes ndPulse { 0% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.55); } 70%, 100% { box-shadow: 0 0 0 9px rgba(255, 90, 90, 0); } }
@keyframes ndRise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ndDot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  #nolan-desk *, #nolan-desk *::before, #nolan-desk *::after { animation: none !important; transition: none !important; }
  .nd-dots i { opacity: 0.8; }
}

@media print { #nolan-desk { display: none; } }
