/* =========================================================
   Aicorvia — Chat widget (built by chatbot.js) + full chat page
   (chat.html / chat-page.js). Message bubbles, typing indicator
   and input row are shared by both.
   Uses the same design tokens as style.css.
   ========================================================= */

.chat-widget-launcher {
  position: fixed;
  bottom: 24px;
  inset-inline-end: 24px;
  width: 58px;
  height: 58px;
  border-radius: var(--radius-pill);
  background: #000;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  z-index: 900;
  transition: transform var(--transition-fast), background var(--transition-fast);
}
.chat-widget-launcher:hover { transform: translateY(-2px); background: #333; }
.chat-widget-launcher svg { position: absolute; transition: opacity var(--transition-fast), transform var(--transition-fast); }
.chat-widget-launcher .icon-close { opacity: 0; transform: scale(0.6); }
.chat-widget-launcher .icon-chat { opacity: 1; transform: scale(1); }
.chat-widget.is-open .chat-widget-launcher .icon-chat { opacity: 0; transform: scale(0.6); }
.chat-widget.is-open .chat-widget-launcher .icon-close { opacity: 1; transform: scale(1); }

.chat-widget-panel {
  position: fixed;
  bottom: 96px;
  inset-inline-end: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: min(600px, calc(100vh - 140px));
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 901;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity var(--transition-med), transform var(--transition-med);
}
.chat-widget-panel[hidden] { display: none; }
.chat-widget.is-open .chat-widget-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-widget-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-dark);
  background: #000;
  color: #fff;
  flex-shrink: 0;
}
.chat-widget-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-widget-header-text { flex: 1; min-width: 0; }
.chat-widget-title { font-weight: 600; font-size: 15px; margin: 0; }
.chat-widget-status {
  font-size: 12.5px;
  color: rgba(255, 255, 255, 0.65);
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
}
.chat-widget-status-dot { width: 7px; height: 7px; border-radius: 50%; background: #34c759; flex-shrink: 0; }
.chat-widget-close {
  background: transparent;
  border: none;
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast);
}
.chat-widget-close:hover { background: rgba(255, 255, 255, 0.14); }

.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg-white);
}
.chat-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.chat-msg-bot {
  align-self: flex-start;
  background: var(--bg-dark-2);
  color: var(--text-on-light);
  border-end-start-radius: 4px;
}
.chat-msg-user {
  align-self: flex-end;
  background: #000;
  color: #fff;
  border-end-end-radius: 4px;
}

.chat-feedback {
  align-self: flex-start;
  display: flex;
  gap: 2px;
  margin-top: -8px;
}
.chat-feedback-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-on-dark-muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.chat-feedback-down svg { transform: rotate(180deg); }
.chat-feedback-btn:hover { background: var(--bg-dark-2); color: var(--text-on-light); }
.chat-feedback-btn:focus-visible { outline: 2px solid currentColor; outline-offset: 1px; }
.chat-feedback-btn[aria-pressed="true"] { color: var(--text-on-light); }
.chat-feedback-btn[aria-pressed="true"] svg path { fill: currentColor; }

.chat-widget-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-dark-2);
  border-radius: 16px;
  border-end-start-radius: 4px;
}
.chat-widget-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-secondary);
  animation: chatTypingBounce 1.2s infinite ease-in-out;
}
.chat-widget-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-widget-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-widget-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border-dark);
  background: var(--bg-white);
  flex-shrink: 0;
}
.chat-widget-input {
  flex: 1;
  border: 1px solid var(--border-dark);
  border-radius: 18px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  max-height: 90px;
  min-height: 40px;
  line-height: 1.4;
  transition: border-color var(--transition-fast);
}
.chat-widget-input:focus { border-color: rgba(0, 0, 0, 0.35); }
.chat-widget-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #000;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
}
.chat-widget-send:hover:not(:disabled) { background: #333; transform: translateY(-1px); }
.chat-widget-send:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

@media (max-width: 480px) {
  .chat-widget-panel {
    inset-inline: 12px;
    bottom: 88px;
    width: auto;
    height: min(70vh, 560px);
  }
  .chat-widget-launcher { bottom: 16px; inset-inline-end: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .chat-widget-panel,
  .chat-widget-launcher,
  .chat-widget-launcher svg,
  .chat-widget-typing span { transition: none; animation: none; }
}

/* ---------- Full chat page (chat.html) ---------- */
.chat-page-container { max-width: 860px; }
.chat-page-back {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-on-dark-muted);
  margin-bottom: 28px;
  transition: color var(--transition-fast);
}
.chat-page-back:hover { color: var(--text-on-dark); }
.chat-page-back::before {
  content: "";
  width: 8px;
  height: 8px;
  border-inline-start: 2px solid currentColor;
  border-block-start: 2px solid currentColor;
  transform: rotate(-45deg);
}
[dir="rtl"] .chat-page-back::before { transform: rotate(135deg); }

.chat-page-card {
  margin-top: 32px;
  background: var(--bg-white);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  height: min(720px, calc(100vh - 140px));
  min-height: 480px;
  overflow: hidden;
}
.chat-page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px 4px;
}
.chat-page-memory {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.chat-page-memory input { width: 16px; height: 16px; accent-color: #000; }
.chat-page-new {
  background: transparent;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-on-light);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.chat-page-new:hover { background: var(--bg-light); }
.chat-page-memory-hint {
  margin: 0;
  padding: 0 18px 12px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-on-light-muted);
  border-bottom: 1px solid var(--border-dark);
}
.chat-page-memory-hint a { text-decoration: underline; color: inherit; }

.chat-page-messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.chat-page-messages .chat-msg { max-width: 76%; font-size: 15px; }

.chat-page-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 18px 12px;
}
.chat-page-suggestions[hidden] { display: none; }
.chat-page-chip {
  background: var(--bg-light);
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  font: inherit;
  font-size: 13.5px;
  color: var(--text-on-light);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.chat-page-chip:hover { background: var(--bg-white); border-color: rgba(0, 0, 0, 0.3); }
.chat-page-form { padding: 14px 18px; }
.chat-page-form .chat-widget-input { max-height: 160px; font-size: 15px; }
.chat-page-disclaimer { margin-top: 14px; color: var(--text-on-dark-muted); }

@media (max-width: 480px) {
  .chat-page-card { height: calc(100vh - 120px); min-height: 420px; }
  .chat-page-messages .chat-msg { max-width: 88%; }
}
