/* =========================================================
   Portfolio AI assistant widget (uses theme variables from style.css)
   ========================================================= */

.chat-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  width: 58px;
  height: 58px;
  border-radius: 18px;
  border: 0;
  background: var(--accent-fill);
  color: var(--on-accent);
  font-size: 1.45rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 12px 30px -8px var(--accent-glow), 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.25s, background 0.2s;
}
.chat-launcher:hover { transform: translateY(-3px); background: var(--accent-fill-hover); }
.chat-launcher i { grid-area: 1 / 1; transition: transform 0.3s, opacity 0.2s; }
.chat-launcher .icon-close { opacity: 0; transform: rotate(-90deg); }
.chat.open .chat-launcher .icon-open { opacity: 0; transform: rotate(90deg); }
.chat.open .chat-launcher .icon-close { opacity: 1; transform: none; }

/* Gentle pulse ring until the chat has been opened */
.chat:not(.open) .chat-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--accent-fill);
  animation: chatPulse 2.6s ease-out infinite;
}
@keyframes chatPulse {
  from { transform: scale(1); opacity: 0.6; }
  to   { transform: scale(1.35); opacity: 0; }
}

.chat-panel {
  position: fixed;
  right: 20px;
  bottom: 92px;
  z-index: 60;
  width: 380px;
  height: min(580px, 100vh - 120px);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.25s, transform 0.25s, visibility 0s linear 0.25s;
}
.chat.open .chat-panel {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.25s, transform 0.25s;
}

/* Header */
.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(135deg, var(--accent-tint), transparent 70%);
}
.chat-avatar {
  width: 40px;
  height: 44px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  background: var(--accent-fill);
  color: var(--on-accent);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.85rem;
}
.chat-heading { flex: 1; min-width: 0; }
.chat-heading h2 { font-size: 0.98rem; font-weight: 600; }
.chat-heading p { font-size: 0.74rem; color: var(--text-mute); display: flex; align-items: center; gap: 6px; }
.chat-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-fill); box-shadow: 0 0 0 3px var(--accent-tint); }
.chat-close {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 1rem;
}
.chat-close:hover { border-color: var(--line-strong); color: var(--text); }

/* Messages */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overscroll-behavior: contain;
}
.msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  animation: msgIn 0.25s ease;
}
.msg-user {
  align-self: flex-end;
  background: var(--accent-fill);
  color: var(--on-accent);
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--base);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg p + p, .msg p + ul, .msg ul + p { margin-top: 8px; }
.msg ul { list-style: none; padding: 0; display: grid; gap: 4px; }
.msg li { position: relative; padding-left: 14px; }
.msg li::before { content: "›"; position: absolute; left: 0; color: var(--accent); }
.msg a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }

.typing { display: flex; gap: 5px; padding: 14px 16px; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--slate-light);
  animation: typingDot 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Suggested questions */
.chat-suggest { display: flex; flex-wrap: wrap; gap: 7px; padding: 0 16px 12px; }
.chat-suggest[hidden] { display: none; }
.chat-suggest button {
  font: inherit;
  font-size: 0.78rem;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--chip-bg);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}
.chat-suggest button:hover { border-color: var(--accent); color: var(--accent); }

/* Input */
.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.chat-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--base);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.chat-form button {
  width: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: var(--accent-fill);
  color: var(--on-accent);
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.chat-form button:hover { background: var(--accent-fill-hover); }
.chat-form button:disabled { opacity: 0.5; cursor: wait; }

/* Phones: the panel takes the whole screen */
@media (max-width: 520px) {
  .chat-panel {
    inset: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    transform: translateY(24px);
  }
  .chat.open .chat-launcher { opacity: 0; pointer-events: none; }
  body.chat-open { overflow: hidden; }
  .chat-launcher { width: 54px; height: 54px; right: 16px; bottom: 16px; }
  .to-top { right: 21px; bottom: 82px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat:not(.open) .chat-launcher::after { display: none; }
}
