/* =========================================================
   Portfolio assistant — chat panel
   Requires base.css

   chat.js only unhides this once a worker URL is configured, so an
   unconfigured build ships without a chat button at all.
   ========================================================= */

.chat-dock {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: clamp(16px, 3vw, 28px);
  z-index: 51;
}

.chat-dock[hidden] {
  display: none;
}

body.intro-active .chat-dock {
  opacity: 0;
  pointer-events: none;
}

.chat-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 56px;
  padding: 0 22px;
  border-radius: var(--radius-pill);
  color: var(--text-inverse);
  font-size: 14.5px;
  font-weight: 650;
  white-space: nowrap;
  background: var(--grad-cta);
  box-shadow: 0 14px 34px rgba(37, 99, 235, 0.32);
  transition: transform 200ms var(--ease), box-shadow 200ms var(--ease);
}

.chat-toggle:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 42px rgba(37, 99, 235, 0.4);
}

.chat-toggle:active {
  transform: translateY(0);
}

@media (max-width: 767px) {
  .chat-toggle {
    height: 50px;
    padding: 0 18px;
    font-size: 14px;
  }
}

/* ---------------------------------------------------------
   Panel
   --------------------------------------------------------- */
.chat-panel {
  position: fixed;
  right: clamp(16px, 3vw, 28px);
  bottom: calc(clamp(16px, 3vw, 28px) + 68px);
  z-index: 52;
  display: flex;
  flex-direction: column;
  width: min(384px, calc(100vw - 32px));
  height: min(540px, calc(100vh - 140px));
  overflow: hidden;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  background: rgba(var(--surface-rgb), 0.97);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.chat-panel[hidden] {
  display: none;
}

.js .chat-panel {
  transform-origin: 100% 100%;
  animation: chat-panel-in 220ms var(--ease);
}

@keyframes chat-panel-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
}

.chat-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-default);
}

.chat-header .icon3d {
  --icon-size: 44px;
}

.chat-header h2 {
  font-size: 15px;
  font-weight: 650;
}

.chat-header p {
  margin-top: 2px;
  color: var(--text-tertiary);
  font-size: 12px;
  line-height: 1.4;
}

.chat-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin-left: auto;
  border-radius: 10px;
  color: var(--text-tertiary);
  transition: background 160ms var(--ease), color 160ms var(--ease);
}

.chat-close:hover {
  color: var(--primary-700);
  background: var(--primary-50);
}

/* ---------------------------------------------------------
   Log
   --------------------------------------------------------- */
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-msg--bot {
  align-self: flex-start;
  border: 1px solid var(--border-default);
  border-bottom-left-radius: 6px;
  color: var(--text-primary);
  background: var(--surface-blue);
}

.chat-msg--user {
  align-self: flex-end;
  border-bottom-right-radius: 6px;
  color: var(--text-inverse);
  background: var(--grad-cta);
}

.chat-msg--error {
  align-self: stretch;
  max-width: none;
  border: 1px solid rgba(230, 92, 106, 0.28);
  border-radius: var(--radius-sm);
  color: var(--danger-text);
  font-size: 13px;
  background: rgba(230, 92, 106, 0.07);
}

.chat-msg--error a {
  color: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-typing {
  display: inline-flex;
  gap: 4px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary-300);
  animation: chat-blink 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chat-blink {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* ---------------------------------------------------------
   Suggestions + composer
   --------------------------------------------------------- */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 var(--space-5) var(--space-3);
}

.chat-suggestions button {
  padding: 7px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-pill);
  color: var(--primary-700);
  font-size: 12.5px;
  font-weight: 550;
  background: var(--surface);
  transition: background 160ms var(--ease), border-color 160ms var(--ease);
}

.chat-suggestions button:hover {
  border-color: var(--border-strong);
  background: var(--primary-50);
}

.chat-form {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5) var(--space-5);
  border-top: 1px solid var(--border-default);
}

.chat-form input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-default);
  border-radius: 12px;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  transition: border-color 160ms var(--ease);
}

.chat-form input::placeholder {
  color: var(--text-tertiary);
}

.chat-form input:focus {
  border-color: var(--border-strong);
  outline: none;
}

.chat-form input:focus-visible {
  outline: 3px solid rgba(49, 130, 246, 0.36);
  outline-offset: 2px;
}

.chat-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  color: var(--text-inverse);
  background: var(--grad-cta);
  transition: filter 160ms var(--ease), opacity 160ms var(--ease);
}

.chat-send:hover {
  filter: saturate(1.08);
}

.chat-send:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.chat-disclaimer {
  padding: 0 var(--space-5) var(--space-4);
  color: var(--text-tertiary);
  font-size: 11.5px;
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  .js .chat-panel {
    animation: none;
  }

  .chat-typing span {
    animation: none;
    opacity: 0.6;
  }
}
