/* ============================================================
   Prince Portfolio Chatbot — chatbot.css
   Matches portfolio design: Inter font, white/surface/border palette
   Full responsive: desktop floating panel, mobile full-screen
   ============================================================ */

/* ---------- CSS Custom Properties (matching portfolio) ---------- */
:root {
  --chat-base: #FFFFFF;
  --chat-surface: #FAFAFA;
  --chat-border: #E5E7EB;
  --chat-primary: #111111;
  --chat-secondary: #6B7280;
  --chat-accent: #374151;
  --chat-user-bg: #111111;
  --chat-user-text: #FFFFFF;
  --chat-bot-bg: #F9FAFB;
  --chat-bot-text: #111111;
  --chat-radius: 12px;
  --chat-input-radius: 8px;
  --chat-shadow: 0 4px 24px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
  --chat-shadow-lg: 0 8px 40px rgba(0,0,0,0.14), 0 2px 8px rgba(0,0,0,0.08);
  --chat-z: 9999;
  --chat-panel-width: 420px;
  --chat-panel-max-height: min(640px, calc(100dvh - 100px));
}

/* ---------- Launcher Button ---------- */
#chat-launcher {
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: var(--chat-z);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--chat-primary);
  color: var(--chat-user-text);
  border: none;
  border-radius: 50px;
  padding: 13px 20px 13px 16px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  box-shadow: var(--chat-shadow-lg);
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  white-space: nowrap;
  min-height: 48px; /* accessible touch target */
  outline: none;
}
#chat-launcher:hover {
  background: var(--chat-accent);
  transform: translateY(-2px);
  box-shadow: 0 10px 48px rgba(0,0,0,0.18);
}
#chat-launcher:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 3px;
}
#chat-launcher:active {
  transform: translateY(0);
}
#chat-launcher svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
#chat-launcher .chat-launcher-dot {
  width: 8px;
  height: 8px;
  background: #22C55E;
  border-radius: 50%;
  flex-shrink: 0;
  animation: pulse-dot 2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(0.85); }
}

/* ---------- Chat Panel Container ---------- */
#chat-panel {
  position: fixed;
  z-index: var(--chat-z);
  font-family: 'Inter', sans-serif;
  display: none; /* shown via JS */
  flex-direction: column;
  overflow: hidden;
  background: var(--chat-base);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow-lg);
  /* Default: desktop floating panel */
  bottom: 90px;
  right: 24px;
  width: var(--chat-panel-width);
  max-height: var(--chat-panel-max-height);
  animation: chat-slide-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
#chat-panel.chat-open {
  display: flex;
}

@keyframes chat-slide-in {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Chat Header ---------- */
#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-base);
  flex-shrink: 0;
}
#chat-header-avatar {
  width: 34px;
  height: 34px;
  background: var(--chat-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: white;
}
#chat-header-avatar svg {
  width: 18px;
  height: 18px;
}
#chat-header-info {
  flex: 1;
  min-width: 0;
}
#chat-header-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--chat-primary);
  line-height: 1.2;
  letter-spacing: -0.01em;
}
#chat-header-subtitle {
  font-size: 11px;
  color: var(--chat-secondary);
  margin-top: 1px;
  display: flex;
  align-items: center;
  gap: 5px;
}
#chat-header-subtitle::before {
  content: '';
  width: 7px;
  height: 7px;
  background: #22C55E;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.chat-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.chat-icon-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-secondary);
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.chat-icon-btn:hover {
  background: var(--chat-surface);
  color: var(--chat-primary);
}
.chat-icon-btn:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 1px;
}
.chat-icon-btn svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

/* ---------- Messages Area ---------- */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  min-height: 0; /* critical for flex scroll */
}
#chat-messages::-webkit-scrollbar {
  width: 4px;
}
#chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 4px;
}

/* ---------- Message Bubbles ---------- */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 4px;
  word-break: break-word;
  overflow-wrap: break-word;
}
.chat-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg-bot {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 13.5px;
  line-height: 1.55;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}
.chat-bubble a {
  text-decoration: underline;
  word-break: break-all;
}
.chat-bubble-user {
  background: var(--chat-user-bg);
  color: var(--chat-user-text);
  border-bottom-right-radius: 4px;
}
.chat-bubble-user a {
  color: #9CA3AF;
}
.chat-bubble-bot {
  background: var(--chat-bot-bg);
  color: var(--chat-bot-text);
  border: 1px solid var(--chat-border);
  border-bottom-left-radius: 4px;
}
.chat-bubble-bot a {
  color: var(--chat-primary);
}
.chat-bubble-error {
  background: #FEF2F2;
  color: #DC2626;
  border: 1px solid #FECACA;
  border-bottom-left-radius: 4px;
}
.chat-msg-time {
  font-size: 10px;
  color: var(--chat-secondary);
  padding: 0 4px;
}

/* Typing indicator */
#chat-typing {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--chat-bot-bg);
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
#chat-typing.visible {
  display: flex;
}
.typing-dot {
  width: 7px;
  height: 7px;
  background: var(--chat-secondary);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.30s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Source Citations ---------- */
.chat-sources {
  font-size: 11px;
  color: var(--chat-secondary);
  margin-top: 4px;
  padding: 0 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.chat-source-tag {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 10.5px;
  color: var(--chat-secondary);
}

/* ---------- Quick Suggestion Chips ---------- */
#chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 4px;
  flex-shrink: 0;
}
.chat-chip {
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--chat-primary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-family: 'Inter', sans-serif;
  white-space: nowrap;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
}
.chat-chip:hover {
  background: var(--chat-primary);
  color: white;
  border-color: var(--chat-primary);
}
.chat-chip:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}

/* ---------- Input Area ---------- */
#chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-base);
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-input-radius);
  font-size: 13.5px;
  font-family: 'Inter', sans-serif;
  color: var(--chat-primary);
  background: var(--chat-surface);
  resize: none;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.5;
  overflow-y: auto;
  word-break: break-word;
}
#chat-input::placeholder {
  color: var(--chat-secondary);
}
#chat-input:focus {
  border-color: var(--chat-primary);
  background: var(--chat-base);
}
#chat-send-btn {
  width: 40px;
  height: 40px;
  background: var(--chat-primary);
  color: white;
  border: none;
  border-radius: var(--chat-input-radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
#chat-send-btn:hover {
  background: var(--chat-accent);
}
#chat-send-btn:active {
  transform: scale(0.94);
}
#chat-send-btn:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 2px;
}
#chat-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}
#chat-send-btn svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
}

/* Retry button in error messages */
.chat-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  background: #FEE2E2;
  color: #DC2626;
  border: 1px solid #FECACA;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  transition: background 0.15s;
  font-weight: 500;
}
.chat-retry-btn:hover {
  background: #FECACA;
}

/* ---------- ARIA live region ---------- */
#chat-live-region {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ==========================================================
   MOBILE — Full-screen chat experience
   ========================================================== */
@media (max-width: 600px) {
  #chat-launcher {
    bottom: 20px;
    right: 16px;
    padding: 12px 16px 12px 14px;
    font-size: 13.5px;
  }

  #chat-panel {
    /* Full-screen overlay on mobile */
    inset: 0;
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--chat-border);
    max-height: 100dvh;
    height: 100dvh;
    /* Account for iOS notch / safe areas */
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-top: env(safe-area-inset-top, 0);
  }

  #chat-header {
    padding: 12px 16px;
    /* Make header slightly taller on mobile for comfort */
    min-height: 60px;
  }

  #chat-messages {
    padding: 12px;
    gap: 10px;
  }

  .chat-bubble {
    font-size: 14px; /* slightly larger for readability on small screens */
  }

  #chat-input-area {
    padding: 10px 12px;
    /* Push up above keyboard / home indicator on iOS */
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
  }

  #chat-input {
    font-size: 16px; /* prevents auto-zoom on iOS */
  }

  #chat-suggestions {
    padding: 6px 12px 2px;
  }

  .chat-msg {
    max-width: 92%;
  }
}

/* Tablet adjustments */
@media (min-width: 601px) and (max-width: 1023px) {
  :root {
    --chat-panel-width: min(440px, calc(100vw - 32px));
  }
  #chat-panel {
    right: 16px;
    bottom: 80px;
  }
  #chat-launcher {
    right: 16px;
    bottom: 24px;
  }
}

/* ---------- Accessibility: reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  #chat-panel, #chat-launcher, .typing-dot, .chat-launcher-dot {
    animation: none;
    transition: none;
  }
}
