/* ============ CHAT WIDGET ============ */
/* Floating button + panel for the portfolio chat assistant.
   Uses the same tokens (--paper, --ink, --navy, --brass, --radius, fonts)
   defined in style.css so the widget sits naturally in the existing design. */

/* ============ FAB (floating action button) ============ */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--navy);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 70;
  transition:
    transform 0.18s ease,
    background 0.2s,
    color 0.2s,
    box-shadow 0.2s;
  animation: chat-pulse 2.5s infinite;
}

@keyframes chat-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(168, 118, 62, 0.4);
  } /* subtle brass pulse */
  70% {
    box-shadow: 0 0 0 12px rgba(168, 118, 62, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(168, 118, 62, 0);
  }
}

.chat-fab:hover {
  background: var(--paper-alt);
  color: var(--navy);
  transform: translateY(-2px) scale(1.05);
  box-shadow:
    0 1px 2px rgba(33, 29, 23, 0.06),
    0 14px 32px -12px rgba(33, 29, 23, 0.22);
  animation: none;
}

.chat-fab:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
}

.chat-fab svg {
  width: 24px;
  height: 24px;
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.chat-fab .chat-avatar {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
  transition:
    transform 0.3s ease,
    opacity 0.2s;
}

.chat-fab:hover .chat-avatar {
  transform: scale(1.1);
}

.chat-fab-text-badge {
  position: absolute;
  right: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--navy);
  color: var(--paper);
  padding: 6px 14px;
  border-radius: 18px;
  font-family: var(--sans);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
  z-index: 2;
}

.chat-fab-text-badge::after {
  content: "";
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%);
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 5px solid var(--navy);
}

.chat-fab-text {
  transition: opacity 0.3s ease;
}

.typing-dots {
  display: inline-flex;
  margin-left: 4px;
}

.typing-dots span {
  animation: typing-bounce 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) {
  animation-delay: -0.32s;
}
.typing-dots span:nth-child(2) {
  animation-delay: -0.16s;
}

@keyframes typing-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-3px);
  }
}

.chat-fab .chat-fab-icon-close {
  display: none;
}

.chat-fab.open .chat-fab-icon-open,
.chat-fab.open .chat-fab-text-badge {
  opacity: 0;
  transform: translateY(-50%) scale(0.8);
  pointer-events: none;
}

.chat-fab.open {
  animation: none;
}

.chat-fab.open .chat-fab-icon-close {
  display: block;
}

/* ============ PANEL ============ */
.chat-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: min(560px, calc(100vh - 140px));
  max-height: calc(100vh - 140px);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow:
    0 1px 2px rgba(33, 29, 23, 0.05),
    0 24px 60px -16px rgba(33, 29, 23, 0.32);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 70;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============ HEADER ============ */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
}

.chat-title {
  font-family: var(--serif);
  font-size: 15.5px;
  color: var(--navy);
  font-weight: 500;
}

.chat-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-50);
  letter-spacing: 0.02em;
  margin-top: 2px;
}

.chat-close {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-50);
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

.chat-close:hover {
  background: var(--paper-alt);
  color: var(--navy);
}

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

/* ============ MESSAGES ============ */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 3px;
}

.chat-message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
}

.chat-row-user {
  justify-content: flex-end;
}

.chat-row-assistant {
  justify-content: flex-start;
}

.chat-message-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-alt);
  border: 1px solid var(--line);
  flex-shrink: 0;
  transform: scaleX(-1); /* horizontally flip */
}

.chat-bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 13.5px;
  line-height: 1.55;
  word-wrap: break-word;
}

.chat-bubble-body p {
  margin: 0;
}

.chat-bubble-body p + p,
.chat-bubble-body ul {
  margin-top: 6px;
}

.chat-bubble-body ul {
  margin-bottom: 0;
  padding-left: 18px;
}

.chat-bubble-body li {
  margin-bottom: 3px;
}

.chat-bubble-body li:last-child {
  margin-bottom: 0;
}

.chat-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--paper-alt);
  padding: 1px 5px;
  border-radius: 2px;
}

.chat-bubble-user {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
  background: var(--paper-alt);
  color: var(--ink);
  border-left: 2px solid var(--brass);
  border-bottom-left-radius: 4px;
}

.chat-bubble-assistant.chat-bubble-error {
  border-left-color: #a04a3a;
  color: var(--ink-70);
  font-style: italic;
}

.chat-caret {
  display: inline-block;
  width: 6px;
  height: 14px;
  background: var(--brass);
  margin-left: 2px;
  vertical-align: -2px;
  animation: chat-blink 1s steps(2) infinite;
}

@keyframes chat-blink {
  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-caret {
    animation: none;
    opacity: 0.5;
  }
}

/* ============ EMPTY STATE ============ */
.chat-empty {
  padding: 20px 4px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-empty-text {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-70);
  margin: 0;
}

.chat-starters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-starter {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 6px 12px;
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--navy);
  cursor: pointer;
  transition:
    background 0.15s,
    border-color 0.15s,
    color 0.15s;
}

.chat-starter:hover {
  background: var(--paper-alt);
  border-color: var(--brass);
  color: var(--brass);
}

/* ============ INPUT ============ */
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--card);
}

.chat-input {
  flex: 1;
  resize: none;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 38px;
  max-height: 140px;
  overflow-y: auto;
  transition:
    border-color 0.15s,
    box-shadow 0.15s;
}

.chat-input:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(168, 118, 62, 0.15);
}

.chat-input::placeholder {
  color: var(--ink-30);
}

.chat-send,
.chat-stop {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.chat-send {
  background: var(--navy);
  color: var(--brass-soft);
}

.chat-send:hover {
  background: var(--brass);
  color: var(--card);
}

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

.chat-stop {
  background: var(--paper-alt);
  color: var(--ink-70);
  border-color: var(--line-strong);
}

.chat-stop:hover {
  background: var(--card);
  color: var(--ink);
}

.chat-stop svg {
  width: 12px;
  height: 12px;
}

/* ============ MOBILE ============ */
@media (max-width: 720px) {
  .chat-fab {
    bottom: 16px;
    right: 16px;
    width: 52px;
    height: 52px;
  }

  .chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
    transform: translateY(100%);
  }

  .chat-panel.open {
    transform: translateY(0) scale(1);
  }

  /* On mobile, keep the nav from sitting on top of the FAB */
  .chat-fab {
    margin-bottom: env(safe-area-inset-bottom, 0);
  }
}
