/* ==========================================================
   Portfolio Chat Widget — chat-widget.css
   Light-themed, matching the portfolio design system.
   ========================================================== */

/*
  Fix: Bootstrap sets body { overflow-x: hidden } which creates a scroll
  container and breaks position:fixed in Chrome. overflow-x:clip has the
  same visual clipping effect but does NOT create a scroll container, so
  position:fixed elements stay anchored to the viewport on scroll.
*/
body {
  overflow-x: clip !important;
}

#chat-widget-root {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 0;
  height: 0;
  overflow: visible;
  z-index: 99995;
  pointer-events: none;
}

/*
  On mobile, when the panel is CLOSED the root's invisible overflow area
  can block taps on the navbar. Drop z-index below Bootstrap's navbar (1030)
  when the panel is not open so all page interactions work normally.
*/
@media (max-width: 600px) {
  #chat-widget-root:not(.cw-panel-open) {
    z-index: 1020;
  }
}

#chat-widget-root,
#chat-widget-root * {
  box-sizing: border-box;
  margin: 0;
  font-family: inherit;
}

#chat-widget-root button,
#chat-widget-root textarea,
#chat-widget-root a,
#chat-widget-root [id^="chat"],
#cw-tooltip {
  pointer-events: auto;
}

/* Prevent portfolio global CSS from setting larger font-sizes inside the widget */
#chat-widget-root p,
#chat-widget-root li,
#chat-widget-root span,
#chat-widget-root b,
#chat-widget-root strong,
#chat-widget-root em,
#chat-widget-root a {
  font-size: inherit;
}

/* ---- Tooltip bubble ---- */
#cw-tooltip {
  position: fixed;
  bottom: 88px;
  right: 24px;
  background: #fff;
  color: rgba(0, 22, 38, 0.85);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  border-radius: 12px;
  border: 1px solid rgba(0, 60, 102, 0.12);
  box-shadow: 0 2px 12px rgba(20, 81, 116, 0.12);
  white-space: nowrap;
  pointer-events: none;
  z-index: 99996;
  transition: opacity 0.3s;
  font-family: inherit;
  animation: cw-float-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.7s both;
}

/* Arrow pointing down-right toward the button */
#cw-tooltip::after {
  content: '';
  position: absolute;
  bottom: -7px;
  right: 18px;
  width: 12px;
  height: 12px;
  background: #fff;
  border-right: 1px solid rgba(0, 60, 102, 0.12);
  border-bottom: 1px solid rgba(0, 60, 102, 0.12);
  transform: rotate(45deg);
}

#cw-tooltip.cw-tooltip-left {
  right: auto;
  left: 24px;
}

#cw-tooltip.cw-tooltip-left::after {
  right: auto;
  left: 18px;
}

#cw-tooltip.cw-hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---- Entrance + float animations ---- */
@keyframes cw-float-in {
  0% {
    opacity: 0;
    transform: translateY(24px) scale(0.88);
  }

  60% {
    opacity: 1;
    transform: translateY(-6px) scale(1.02);
  }

  100% {
    transform: translateY(0) scale(1);
  }
}

@keyframes cw-bob {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-5px);
  }
}

/* ---- Toggle button ---- */
#chat-toggle-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgb(20, 81, 116);
  border: 1px solid rgba(0, 60, 102, 0.15);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99998;
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(20, 81, 116, 0.15);
  animation: cw-float-in 0.4s ease-out 0.3s both;
}

#chat-toggle-btn:hover {
  border-color: rgba(20, 81, 116, 0.45);
  transform: scale(1.06);
  box-shadow: 0 6px 28px rgba(20, 81, 116, 0.22);
}

#chat-toggle-btn svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

#chat-toggle-btn.is-open .icon-chat {
  display: none;
}

#chat-toggle-btn:not(.is-open) .icon-close {
  display: none;
}

/* ---- Panel ---- */
#chat-panel {
  position: fixed;
  bottom: 88px;
  right: 24px;
  width: 360px;
  height: 520px;
  background: #fff;
  border: 1px solid rgba(0, 60, 102, 0.1);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 99997;
  box-shadow: 0 8px 40px rgba(20, 81, 116, 0.14);
  overflow: hidden;
  transition: opacity 0.2s, transform 0.2s;
  transform-origin: bottom right;
}

#chat-panel.cw-hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.93) translateY(10px);
}

/* Left-side variant */
#chat-panel.position-left {
  right: auto;
  left: 24px;
  transform-origin: bottom left;
}

#chat-toggle-btn.position-left {
  right: auto;
  left: 24px;
}

/* ---- Standalone full-screen mode (mobile new-tab flow) ---- */
body.cw-standalone-fullscreen {
  background: #fff;
}

body.cw-standalone-fullscreen #chat-widget-root {
  z-index: 2147483000;
  pointer-events: auto;
}

body.cw-standalone-fullscreen #chat-toggle-btn,
body.cw-standalone-fullscreen #cw-tooltip {
  display: none !important;
}

body.cw-standalone-fullscreen #chat-panel {
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: 100dvh;
  max-height: none;
  border-radius: 0;
  border: none;
  box-shadow: none;
  transform: none !important;
}

body.cw-standalone-fullscreen #chat-panel.cw-hidden {
  opacity: 1;
  pointer-events: auto;
}

body.cw-standalone-fullscreen #chat-header {
  padding-top: calc(10px + env(safe-area-inset-top));
}

body.cw-standalone-fullscreen #chat-input-area {
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

/* ---- Header ---- */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid rgba(0, 60, 102, 0.08);
  flex-shrink: 0;
  background: rgba(20, 81, 116, 0.03);
}

.cw-header-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cw-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(20, 81, 116, 0.08);
  border: 1px solid rgba(20, 81, 116, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cw-avatar svg {
  width: 18px;
  height: 18px;
  color: rgb(20, 81, 116);
}

.cw-header-text .cw-name {
  font-size: 13px;
  font-weight: 600;
  color: rgba(0, 22, 38, 0.9);
  line-height: 1.3;
}

.cw-header-text .cw-tagline {
  font-size: 11px;
  color: rgba(0, 30, 51, 0.55);
  line-height: 1.3;
}

.cw-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
}

.cw-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
}

#chat-header-reset {
  background: none;
  border: none;
  color: rgba(0, 30, 51, 0.35);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

#chat-header-reset:hover {
  color: rgba(0, 22, 38, 0.7);
}

#chat-header-reset svg {
  width: 15px;
  height: 15px;
}

/* X close button (panel top-left) */
#chat-panel-close {
  background: none;
  border: none;
  color: rgba(0, 30, 51, 0.4);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

#chat-panel-close:hover {
  color: rgba(0, 22, 38, 0.8);
}

#chat-panel-close svg {
  width: 16px;
  height: 16px;
}

/* ---- Messages area ---- */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  background: #fff;
  scrollbar-width: none;
}

#chat-messages::-webkit-scrollbar {
  display: none;
}

/* Welcome screen */
#cw-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 12px 8px 4px;
  gap: 8px;
}

#cw-welcome .cw-welcome-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(20, 81, 116, 0.06);
  border: 1px solid rgba(20, 81, 116, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
}

#cw-welcome .cw-welcome-icon svg {
  width: 22px;
  height: 22px;
  color: rgb(20, 81, 116);
}

#cw-welcome .cw-welcome-msg {
  font-size: 13px;
  color: rgba(0, 30, 51, 0.6);
  line-height: 1.6;
  max-width: 260px;
}

/* ---- Message bubbles ---- */
.cw-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 88%;
}

.cw-msg.cw-user {
  align-self: flex-end;
  align-items: flex-end;
}

.cw-msg.cw-ai {
  align-self: flex-start;
  align-items: flex-start;
}

.cw-bubble {
  padding: 8px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.65;
  word-wrap: break-word;
}

.cw-msg.cw-user .cw-bubble {
  background: rgb(20, 81, 116);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.cw-msg.cw-ai .cw-bubble {
  background: rgba(20, 81, 116, 0.05);
  color: rgba(0, 22, 38, 0.9);
  border-bottom-left-radius: 4px;
  border: 1px solid rgba(20, 81, 116, 0.1);
}

/* HTML content inside AI bubble */
.cw-bubble b,
.cw-bubble strong {
  color: rgba(0, 22, 38, 0.95);
  font-weight: 600;
}

.cw-bubble ul,
.cw-bubble ol {
  padding-left: 18px;
  margin: 6px 0;
}

.cw-bubble li {
  margin-bottom: 20px;
  line-height: inherit;
}

.cw-bubble hr {
  border: none;
  border-top: 1px solid rgba(0, 60, 102, 0.1);
  margin: 10px 0;
}

.cw-bubble a {
  color: rgb(20, 81, 116);
}

/* Project link buttons inside AI bubbles */
.cw-bubble .cw-link-btn {
  display: inline-block;
  margin-top: 12px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  color: rgb(20, 81, 116);
  border: 1px solid rgba(20, 81, 116, 0.4);
  border-radius: 20px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.cw-bubble .cw-link-btn:hover {
  background: rgba(20, 81, 116, 0.08);
  border-color: rgb(20, 81, 116);
  text-decoration: none;
}

.cw-bubble p {
  margin-bottom: 6px;
}

.cw-bubble p:last-child {
  margin-bottom: 0;
}

/* Typing indicator */
.cw-typing .cw-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
}

.cw-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(20, 81, 116, 0.35);
  animation: cw-bounce 1.2s infinite ease-in-out;
}

.cw-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.cw-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes cw-bounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
  }

  40% {
    transform: translateY(-5px);
  }
}

/* ---- Suggested questions ---- */
#cw-suggestions {
  padding: 0 14px 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
  background: #fff;
}

.cw-suggestion-chip {
  background: rgba(20, 81, 116, 0.05);
  border: 1px solid rgba(20, 81, 116, 0.18);
  color: rgb(20, 81, 116);
  font-size: 11.5px;
  padding: 8px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.cw-suggestion-chip:hover {
  background: rgba(20, 81, 116, 0.12);
  border-color: rgba(20, 81, 116, 0.4);
  color: rgb(20, 81, 116);
}

/* ---- Input area ---- */
#chat-input-area {
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(0, 60, 102, 0.08);
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}

#chat-input {
  flex: 1;
  background: rgba(20, 81, 116, 0.04);
  border: 1px solid rgba(0, 60, 102, 0.15);
  border-radius: 10px;
  color: rgba(0, 22, 38, 0.9);
  font-size: 13px;
  line-height: 1.5;
  padding: 8px 11px;
  resize: none;
  outline: none;
  font-family: inherit;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color 0.15s;
}

#chat-input::placeholder {
  color: rgba(0, 30, 51, 0.35);
}

#chat-input:focus {
  border-color: rgba(20, 81, 116, 0.4);
}

#chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid rgb(20, 81, 116);
  color: rgb(20, 81, 116);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

#chat-send-btn:hover:not(:disabled) {
  background: rgba(20, 81, 116, 0.08);
  border-color: #377599;
}

#chat-send-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#chat-send-btn svg {
  width: 16px;
  height: 16px;
}

/* ---- Mobile ---- */
@media (max-width: 600px) {

  /* Compact vertical stick at bottom-right to save space */
  #chat-toggle-btn {
    bottom: 12px;
    right: 0;
    width: 24px;
    height: 70px;
    border-radius: 10px 0 0 10px;
    padding: 0;
  }

  #chat-toggle-btn svg {
    display: none;
  }

  #chat-toggle-btn::before {
    content: "Chatbot";
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    line-height: 1;
    color: #fff;
  }

  #chat-toggle-btn.position-left {
    left: 0;
    right: auto;
    border-radius: 0 10px 10px 0;
  }

  #chat-toggle-btn.position-left::before {
    writing-mode: vertical-lr;
  }

  /* Hide tooltip on mobile to keep corner minimal */
  #cw-tooltip {
    display: none;
  }

  /* Keep inline panel disabled on mobile pages so it never blocks nav taps.
     Standalone chat page still uses the full-screen panel. */
  body:not(.cw-standalone-fullscreen) #chat-panel {
    display: none !important;
  }

  /* Panel — full width, keyboard-safe height */
  #chat-panel {
    width: calc(100vw - 24px);
    right: 12px;
    left: 12px;
    bottom: 80px;
    /*
      dvh shrinks when the virtual keyboard appears so the panel
      is never hidden behind it. Capped at 520px on tall phones.
    */
    height: min(520px, calc(100dvh - 112px));
    max-height: calc(100dvh - 112px);
    border-radius: 16px;
  }

  /* When panel is hidden, it must not block touches — pointer-events already
     handled by .cw-hidden, but make sure the root never intercepts touches
     outside the visible toggle button area on mobile */
  #chat-panel.cw-hidden {
    pointer-events: none !important;
  }

  #chat-panel.position-left {
    left: 12px;
    right: auto;
  }

  /* ---- Larger, mobile-friendly text ---- */
  .cw-bubble {
    font-size: 15px;
    line-height: 1.7;
    padding: 10px 14px;
  }

  /* 16px prevents iOS Safari from auto-zooming on textarea focus */
  #chat-input {
    font-size: 16px;
    padding: 10px 12px;
  }

  .cw-suggestion-chip {
    font-size: 13px;
    padding: 9px 13px;
  }

  .cw-header-text .cw-name {
    font-size: 14px;
  }

  .cw-header-text .cw-tagline {
    font-size: 12px;
  }

  #cw-welcome .cw-welcome-msg {
    font-size: 14px;
    max-width: 100%;
  }

  /* Bigger send button hit area */
  #chat-send-btn {
    width: 40px;
    height: 40px;
  }

  /* More breathing room in input area */
  #chat-input-area {
    padding: 10px 12px 14px;
  }
}