/* portfolio-chat.css
 * Standalone styles for the floating chat widget — extracted from tech-fx.css
 * so case-study pages can load the chat without the full tech-fx UI surface.
 * Theme variables (--cyan, --line, --brand, etc.) are defined in case-study.css
 * and style.css; both already load on every page.
 */

/* =========================================================================
   PORTFOLIO CHAT — floating "ask me anything" widget. Theme-aware, mobile
   responsive, prefers-reduced-motion respected, no external API.
   ========================================================================= */
.pchat {
  position: fixed;
  bottom: 24px;
  right: 24px;
  /* Above siderail (9996), HUD (9997), tech-tip (10005). Below
     command palette + dialogs which sit at 10000+. */
  z-index: 9998;
  font-family: 'JetBrains Mono', monospace;
}
/* When chat is open, dim the right-side siderail + HUD so their
   labels/tooltips don't show through the chat panel content. */
body.pchat-active .siderail,
body.pchat-active .hud,
body.pchat-active .viewport-hud {
  opacity: 0.18;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

/* -- Bubble -- */
.pchat__bubble {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--cyan);
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--cyan) 22%, transparent),
    color-mix(in srgb, var(--cyan) 8%, transparent));
  color: var(--cyan);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4),
              0 0 22px color-mix(in srgb, var(--cyan) 32%, transparent);
  transition: transform 0.22s, box-shadow 0.22s;
  padding: 0;
  overflow: visible;
}
.pchat__bubble:hover,
.pchat__bubble:focus-visible {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45),
              0 0 32px color-mix(in srgb, var(--cyan) 50%, transparent);
}
.pchat__bubble:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 3px;
}
/* Stack chat-icon + close-icon at the bubble center. Default = chat shown,
   close hidden. When aria-expanded="true" (panel open), they swap. */
.pchat__bubble-icon {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.22s ease, transform 0.22s ease;
  line-height: 1;
  pointer-events: none;
}
.pchat__bubble-icon--chat  { opacity: 1; transform: scale(1) rotate(0deg); }
.pchat__bubble-icon--close { opacity: 0; transform: scale(0.7) rotate(-45deg); }
.pchat__bubble[aria-expanded="true"] .pchat__bubble-icon--chat  { opacity: 0; transform: scale(0.7) rotate(45deg); }
.pchat__bubble[aria-expanded="true"] .pchat__bubble-icon--close { opacity: 1; transform: scale(1) rotate(0deg); }
.pchat__bubble-icon svg { display: block; }
.pchat__bubble-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--cyan) 50%, transparent);
  animation: pchat-pulse 2.4s ease-out infinite;
  pointer-events: none;
}
@keyframes pchat-pulse {
  0%   { transform: scale(0.92); opacity: 0.7; }
  70%  { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}

/* -- Panel -- */
.pchat__panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 380px;
  height: 540px;
  max-height: calc(100vh - 120px);
  background: linear-gradient(180deg, #0b1226 0%, #070a18 100%);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5),
              0 0 30px color-mix(in srgb, var(--cyan) 18%, transparent);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: pchat-pop 0.22s ease-out;
}
.pchat__panel[hidden] { display: none; }
@keyframes pchat-pop {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* -- Header -- */
.pchat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: linear-gradient(180deg, #0d1430, #0a1024);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.pchat__head-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 1.4px;
  color: var(--cyan);
  text-transform: lowercase;
}
.pchat__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #28c840;
  box-shadow: 0 0 6px #28c840;
  animation: pchat-blink 2s ease-in-out infinite;
}
@keyframes pchat-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.pchat__head-actions {
  display: inline-flex;
  gap: 4px;
}
/* Unified icon-button styling for all three header actions
   (browse / reset / close). */
.pchat__icon-btn {
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--cyan) 25%, transparent);
  color: rgba(230, 243, 255, 0.7);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: 0.18s;
  padding: 0;
}
.pchat__icon-btn:hover,
.pchat__icon-btn:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 10%, transparent);
}
.pchat__icon-btn[aria-pressed="true"] {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 16%, transparent);
}
.pchat__close { font-size: 17px; }
.pchat__icon-btn svg { display: block; }

/* Browse view — toggled by header browse button; shows all FAQ entries
   grouped by category for discoverability. Replaces the chat body in
   the same panel space (no separate modal). */
.pchat__browse-view {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  font-size: 12.5px;
  color: rgba(230, 243, 255, 0.88);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--cyan) 40%, transparent) transparent;
}
.pchat__browse-view::-webkit-scrollbar { width: 6px; }
.pchat__browse-view::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--cyan) 40%, transparent); border-radius: 3px; }
.pchat__browse-head {
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: rgba(230, 243, 255, 0.55);
  padding-bottom: 8px;
  border-bottom: 1px dashed color-mix(in srgb, var(--cyan) 22%, transparent);
  margin-bottom: 8px;
}
.pchat__browse-head strong { color: var(--cyan); }

/* Filter input — sticky at the top of the browse view as the user scrolls */
.pchat__browse-search-wrap {
  position: sticky;
  top: -14px;
  margin: 0 -14px 12px;
  padding: 6px 14px 10px;
  background: linear-gradient(180deg, #0b1226 0%, rgba(11, 18, 38, 0.96) 85%, rgba(11, 18, 38, 0));
  z-index: 2;
}
.pchat__browse-search {
  width: 100%;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid color-mix(in srgb, var(--cyan) 22%, transparent);
  color: #e6f3ff;
  padding: 7px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  letter-spacing: 0.3px;
}
.pchat__browse-search::placeholder { color: rgba(230, 243, 255, 0.4); }
.pchat__browse-search:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cyan) 14%, transparent);
}
.pchat__browse-empty {
  display: block;
  font-size: 11px;
  color: rgba(230, 243, 255, 0.5);
  margin-top: 6px;
  font-style: italic;
}
:root[data-theme="light"] .pchat__browse-search-wrap {
  background: linear-gradient(180deg, #ffffff 0%, rgba(255, 255, 255, 0.95) 85%, rgba(255, 255, 255, 0));
}
:root[data-theme="light"] .pchat__browse-search { background: #fff; color: #1a1f2e; border-color: rgba(10, 30, 60, 0.18); }
.pchat__browse-cat {
  margin-bottom: 14px;
}
.pchat__browse-cat-title {
  font-size: 10.5px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan-dim);
  margin: 0 0 6px;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.pchat__browse-cat-title::before { content: '// '; opacity: 0.65; }
.pchat__browse-cat-count {
  font-size: 9.5px;
  color: rgba(230, 243, 255, 0.4);
  font-weight: 400;
  letter-spacing: 0.5px;
}
.pchat__browse-rows {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.pchat__browse-row {
  text-align: left;
  background: transparent;
  border: 1px solid color-mix(in srgb, var(--cyan) 12%, transparent);
  color: rgba(230, 243, 255, 0.82);
  padding: 7px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: 0.15s;
  line-height: 1.4;
}
.pchat__browse-row:hover,
.pchat__browse-row:focus-visible {
  background: color-mix(in srgb, var(--cyan) 8%, transparent);
  border-color: color-mix(in srgb, var(--cyan) 40%, transparent);
  color: var(--cyan);
  transform: translateX(2px);
}

/* Light theme overrides for the browse view */
:root[data-theme="light"] .pchat__browse-view { color: rgba(10, 30, 60, 0.85); }
:root[data-theme="light"] .pchat__browse-head { color: rgba(10, 30, 60, 0.6); }
:root[data-theme="light"] .pchat__browse-cat-title { color: var(--cyan-dim); }
:root[data-theme="light"] .pchat__browse-cat-count { color: rgba(10, 30, 60, 0.4); }
:root[data-theme="light"] .pchat__browse-row { color: rgba(10, 30, 60, 0.8); border-color: rgba(10, 30, 60, 0.1); }

/* -- Body / messages -- */
.pchat__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 8px;
  font-size: 13px;
  line-height: 1.55;
  color: rgba(230, 243, 255, 0.9);
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--cyan) 40%, transparent) transparent;
}
.pchat__body::-webkit-scrollbar { width: 6px; }
.pchat__body::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--cyan) 40%, transparent); border-radius: 3px; }

.pchat__welcome p {
  margin: 0 0 8px;
  color: rgba(230, 243, 255, 0.85);
}
.pchat__welcome-sub {
  font-size: 11.5px;
  color: rgba(230, 243, 255, 0.55) !important;
}
.pchat__welcome-sub a {
  color: var(--cyan);
  border-bottom: 1px dashed color-mix(in srgb, var(--cyan) 40%, transparent);
  text-decoration: none;
}

/* -- Suggestion chips -- */
.pchat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}
.pchat__sugg {
  background: color-mix(in srgb, var(--cyan) 6%, transparent);
  border: 1px solid color-mix(in srgb, var(--cyan) 25%, transparent);
  color: rgba(230, 243, 255, 0.78);
  padding: 5px 10px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 0.4px;
  cursor: pointer;
  transition: 0.18s;
  text-align: left;
}
.pchat__sugg:hover,
.pchat__sugg:focus-visible {
  border-color: var(--cyan);
  color: var(--cyan);
  background: color-mix(in srgb, var(--cyan) 12%, transparent);
}

/* -- Messages -- */
.pchat__msg {
  display: flex;
  margin: 10px 0;
}
.pchat__msg--user { justify-content: flex-end; }
.pchat__msg--bot  { justify-content: flex-start; }
.pchat__msg-bubble {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.55;
}
.pchat__msg--user .pchat__msg-bubble {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--cyan) 24%, transparent),
    color-mix(in srgb, var(--cyan) 12%, transparent));
  border: 1px solid color-mix(in srgb, var(--cyan) 40%, transparent);
  color: #eafdff;
  border-bottom-right-radius: 2px;
}
.pchat__msg--bot .pchat__msg-bubble {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid color-mix(in srgb, var(--cyan) 18%, transparent);
  color: rgba(230, 243, 255, 0.92);
  border-bottom-left-radius: 2px;
}
.pchat__msg--bot .pchat__msg-bubble a {
  color: var(--cyan);
  border-bottom: 1px dashed color-mix(in srgb, var(--cyan) 40%, transparent);
  text-decoration: none;
}
.pchat__msg--bot .pchat__msg-bubble a:hover { border-bottom-style: solid; }
.pchat__msg--bot .pchat__msg-bubble code {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid color-mix(in srgb, var(--cyan) 22%, transparent);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11px;
  color: var(--cyan);
}
.pchat__msg--bot .pchat__msg-bubble strong { color: #fff; }

/* Typing dots (3 pulsing) */
.pchat__dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}
.pchat__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--cyan) 60%, transparent);
  animation: pchat-dots 1.1s ease-in-out infinite;
}
.pchat__dots i:nth-child(2) { animation-delay: 0.18s; }
.pchat__dots i:nth-child(3) { animation-delay: 0.36s; }
@keyframes pchat-dots {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%           { transform: scale(1); opacity: 1; }
}

/* "Did you mean?" suggestions row inside a fallback bot message —
   3 closest non-matching entries shown as clickable chips so a missed
   query has a rebound path. */
.pchat__fallback-related {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 8px 0 4px;
}
.pchat__fallback-related .pchat__sugg {
  width: 100%;
  text-align: left;
}

/* Fallback action buttons (shown when no FAQ match) */
.pchat__fallback-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.pchat__fallback-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border: 1px solid color-mix(in srgb, var(--cyan) 30%, transparent);
  border-radius: 4px;
  color: var(--cyan) !important;
  text-decoration: none !important;
  font-size: 11.5px;
  letter-spacing: 0.6px;
  border-bottom-style: solid !important;
  transition: 0.18s;
}
.pchat__fallback-btn:hover {
  background: color-mix(in srgb, var(--cyan) 12%, transparent);
  border-color: var(--cyan);
}
.pchat__fallback-btn--primary {
  background: linear-gradient(135deg,
    color-mix(in srgb, var(--cyan) 24%, transparent),
    color-mix(in srgb, var(--brand) 14%, transparent));
  color: #fff !important;
  border-color: var(--cyan);
}

/* -- Form -- */
.pchat__form {
  display: flex;
  gap: 6px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
}
.pchat__input {
  flex: 1;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid color-mix(in srgb, var(--cyan) 22%, transparent);
  color: #e6f3ff;
  padding: 8px 10px;
  border-radius: 5px;
  font-family: inherit;
  font-size: 13px;
}
.pchat__input::placeholder { color: rgba(230, 243, 255, 0.35); }
.pchat__input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--cyan) 14%, transparent);
}
.pchat__submit {
  background: linear-gradient(135deg, var(--cyan), var(--brand));
  color: var(--bg-dark);
  border: 0;
  border-radius: 5px;
  width: 38px;
  cursor: pointer;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  transition: 0.18s;
  padding: 0;
  flex-shrink: 0;
}
.pchat__submit:hover,
.pchat__submit:focus-visible {
  filter: brightness(1.1);
  box-shadow: 0 0 14px color-mix(in srgb, var(--cyan) 40%, transparent);
}

/* -- Browse-row search highlight -- */
.pchat__hl {
  background: color-mix(in srgb, var(--cyan) 30%, transparent);
  color: inherit;
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}
:root[data-theme="light"] .pchat__hl {
  background: color-mix(in srgb, var(--brand) 28%, transparent);
  color: #1a1f2e;
}

/* -- Stack the "scroll to top" button above the chat bubble so they don't
   overlap. Chat bubble is 56px tall at bottom:24px; sit gototop 12px above. */
.gototop {
  bottom: 92px !important;
  right: 27px !important;
}

/* -- Mobile -- */
@media (max-width: 640px) {
  .pchat { bottom: 14px; right: 14px; }
  .pchat__bubble { width: 50px; height: 50px; font-size: 20px; }
  .pchat__panel {
    width: calc(100vw - 28px);
    height: calc(100vh - 130px);
    max-height: 600px;
    right: 0;
    bottom: 64px;
  }
  /* Bubble is 50px tall at bottom:14px on mobile — gototop sits above it. */
  .gototop {
    bottom: 74px !important;
    right: 14px !important;
  }
}

/* -- Light theme -- */
:root[data-theme="light"] .pchat__panel {
  background: linear-gradient(180deg, #ffffff 0%, #fbf9f3 100%);
  border-color: rgba(10, 30, 60, 0.18);
  box-shadow: 0 20px 50px rgba(10, 30, 60, 0.15), 0 0 22px color-mix(in srgb, var(--cyan) 15%, transparent);
}
:root[data-theme="light"] .pchat__head { background: linear-gradient(180deg, #f0ece2, #e6e0d2); border-bottom-color: rgba(10, 30, 60, 0.1); }
:root[data-theme="light"] .pchat__body { color: rgba(10, 30, 60, 0.85); }
:root[data-theme="light"] .pchat__welcome p { color: rgba(10, 30, 60, 0.78); }
:root[data-theme="light"] .pchat__welcome-sub { color: rgba(10, 30, 60, 0.55) !important; }
:root[data-theme="light"] .pchat__msg--bot .pchat__msg-bubble {
  background: rgba(10, 30, 60, 0.04);
  border-color: rgba(10, 30, 60, 0.12);
  color: rgba(10, 30, 60, 0.85);
}
:root[data-theme="light"] .pchat__msg--bot .pchat__msg-bubble strong { color: #1a1f2e; }
:root[data-theme="light"] .pchat__msg--bot .pchat__msg-bubble code {
  background: rgba(10, 30, 60, 0.06);
  border-color: rgba(10, 30, 60, 0.15);
  color: #00667a;
}
:root[data-theme="light"] .pchat__sugg { color: rgba(10, 30, 60, 0.75); }
:root[data-theme="light"] .pchat__input { background: #fff; color: #1a1f2e; border-color: rgba(10, 30, 60, 0.2); }
:root[data-theme="light"] .pchat__form { background: rgba(10, 30, 60, 0.03); border-top-color: rgba(10, 30, 60, 0.1); }

/* -- Reduced motion -- */
@media (prefers-reduced-motion: reduce) {
  .pchat__bubble-pulse { animation: none; }
  .pchat__panel { animation: none; }
  .pchat__dot { animation: none; }
  .pchat__dots i { animation: none; opacity: 0.8; }
}

/* -- Print: hide it -- */
@media print {
  .pchat { display: none !important; }
}

/* =========================================================================
   ARCADE — chat widget as in-game dialogue box (theme-arcade only).
   ========================================================================= */
:root.theme-arcade .pchat__panel,
:root.theme-arcade .pchat__bubble,
:root.theme-arcade .pchat__msg-bubble,
:root.theme-arcade .pchat__input,
:root.theme-arcade .pchat__submit,
:root.theme-arcade .pchat__sugg,
:root.theme-arcade .pchat__browse-row,
:root.theme-arcade .pchat__fallback-btn {
  border-radius: 0 !important;
}
:root.theme-arcade .pchat__panel {
  border: 3px solid rgba(255, 204, 0, 0.55) !important;
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.5) !important;
  background: rgba(13, 2, 33, 0.97) !important;
  backdrop-filter: none !important;
}
:root.theme-arcade .pchat__head-title {
  font-family: 'Press Start 2P', 'JetBrains Mono', monospace !important;
  font-size: 9px !important;
  letter-spacing: 1px !important;
}
:root.theme-arcade .pchat__msg-bubble,
:root.theme-arcade .pchat__welcome,
:root.theme-arcade .pchat__input,
:root.theme-arcade .pchat__sugg,
:root.theme-arcade .pchat__browse-row {
  font-family: 'VT323', 'JetBrains Mono', monospace !important;
  font-size: 17px !important;
  line-height: 1.45 !important;
}
:root.theme-arcade .pchat__msg-bubble {
  border: 2px solid rgba(255, 204, 0, 0.35) !important;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45) !important;
}
:root.theme-arcade .pchat__bubble {
  border: 3px solid rgba(255, 204, 0, 0.6) !important;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.55) !important;
}
:root.theme-arcade .pchat__input {
  border: 2px solid rgba(255, 204, 0, 0.4) !important;
  background: rgba(0, 0, 0, 0.45) !important;
  caret-color: #ffcc00;
}
