/* =============================================================
   PORTFOLIO AI ASSISTANT — chat widget
   Floating "Ask about Saham" chat (bottom-right). Built by
   assets/js/chat-widget.js.

   Styled entirely with the shared design-system tokens
   (--bg, --surface, --line, --text, --muted, --accent), which
   every theme redefines — so the widget recolors automatically
   across all five themes with no per-theme rules here.
   ============================================================= */

.chat {
  position: fixed;
  z-index: 99999;              /* above #scroll-top (also 99999) */
  font-family: var(--default-font, system-ui, sans-serif);
}

/* -------------------------------------------------------------
   Launcher button (collapsed state)
   ------------------------------------------------------------- */
.chat__launch {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
  transition: bottom .35s ease, transform .2s ease, box-shadow .2s ease;
}
.chat__launch i {
  font-size: 24px;
  line-height: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);   /* keeps white legible on lighter accents */
}
.chat__launch:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34); }
.chat__launch:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Lift above #scroll-top once it appears (JS toggles .chat--raised). */
.chat.chat--raised .chat__launch { bottom: 74px; }

/* -------------------------------------------------------------
   Panel (expanded state) — sits above the launcher
   ------------------------------------------------------------- */
.chat__panel {
  position: fixed;
  right: 20px;
  bottom: 92px;                /* clears the 56px launcher at bottom:20px */
  width: 360px;
  max-width: calc(100vw - 40px);
  height: min(70vh, 560px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);       /* solid in every theme */
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
  transform-origin: bottom right;
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease, visibility .22s, bottom .35s ease;
}
.chat.chat--raised .chat__panel { bottom: 146px; }

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

/* -------------------------------------------------------------
   Header
   ------------------------------------------------------------- */
.chat__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.chat__title { display: flex; flex-direction: column; line-height: 1.2; }
.chat__title-name { font-weight: 600; color: var(--head, var(--text)); font-size: 15px; }
.chat__title-sub { font-size: 11px; color: var(--muted); letter-spacing: .02em; }

.chat__close {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}
.chat__close:hover { background: color-mix(in srgb, var(--text) 12%, transparent); color: var(--text); }
.chat__close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------------
   Message log
   ------------------------------------------------------------- */
.chat__log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chat__msg { display: flex; }
.chat__msg--user { justify-content: flex-end; }
.chat__msg--assistant { justify-content: flex-start; }

.chat__bubble {
  max-width: 82%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.chat__msg--assistant .chat__bubble {
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.chat__msg--user .chat__bubble {
  background: var(--accent);
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);   /* legible on lighter accents */
  border-bottom-right-radius: 4px;
}

/* Typing indicator (three bouncing dots) */
.chat__dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin: 0 2px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatDot 1.2s infinite ease-in-out;
}
.chat__dot:nth-child(2) { animation-delay: .15s; }
.chat__dot:nth-child(3) { animation-delay: .3s; }
@keyframes chatDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* -------------------------------------------------------------
   Input row
   ------------------------------------------------------------- */
.chat__form {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.chat__input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .15s ease;
}
.chat__input::placeholder { color: var(--muted); }
.chat__input:focus { border-color: var(--accent); }
.chat__input:disabled { opacity: .6; }

.chat__send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease, opacity .15s ease;
}
.chat__send i { font-size: 16px; line-height: 0; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }
.chat__send:hover { transform: translateY(-1px); }
.chat__send:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chat__send:disabled { opacity: .5; cursor: default; transform: none; }

/* -------------------------------------------------------------
   Mobile — near full-screen sheet
   ------------------------------------------------------------- */
@media (max-width: 480px) {
  .chat__panel {
    right: 12px;
    left: 12px;
    bottom: 12px;
    width: auto;
    max-width: none;
    height: min(78vh, 620px);
  }
  .chat.chat--raised .chat__panel { bottom: 12px; }   /* full-width sheet ignores the raise */
  .chat.chat--open .chat__launch { opacity: 0; pointer-events: none; }   /* avoid overlap with the sheet */
}

/* -------------------------------------------------------------
   Reduced motion — kill transitions/animations
   ------------------------------------------------------------- */
.chat--no-motion .chat__panel,
.chat--no-motion .chat__launch,
.chat--no-motion .chat__send,
.chat--no-motion .chat__close { transition: none; }
.chat--no-motion .chat__dot { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .chat__panel, .chat__launch, .chat__send, .chat__close { transition: none; }
  .chat__dot { animation: none; }
}
