/**
 * Janarth's AI Portfolio Guide - Chatbox Styles
 * Seamlessly matches portfolio's dark aesthetic, yellow accent (#ffb800),
 * glassmorphism, typography, and responsive breakpoints.
 */

/* ==========================================================================
   1. Floating Chat Button & Breathing Glow
   ========================================================================== */

.portfolio-chat-trigger {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom, 20px));
  right: max(20px, env(safe-area-inset-right, 20px));
  height: 52px;
  padding: 4px 16px 4px 6px;
  border-radius: 30px;
  background: rgba(14, 14, 14, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid rgba(255, 184, 0, 0.55);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.65), 0 0 22px rgba(255, 184, 0, 0.3);
  cursor: pointer;
  z-index: 2500;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  transition: transform 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.2), box-shadow 0.28s ease, border-color 0.28s ease, background 0.28s ease;
  animation: chatBreathingGlow 3.6s infinite ease-in-out;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.portfolio-chat-trigger:hover {
  transform: scale(1.06);
  border-color: var(--yellow-accent, #ffb800);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.75), 0 0 28px rgba(255, 184, 0, 0.48);
}

.portfolio-chat-trigger:active {
  transform: scale(0.96);
}

@keyframes chatBreathingGlow {
  0%, 100% {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65), 0 0 16px rgba(255, 184, 0, 0.22);
  }
  50% {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.75), 0 0 28px rgba(255, 184, 0, 0.45);
  }
}

/* Cat Face Avatar Container */
.chat-trigger-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #222222 0%, #101010 100%);
  border: 1.5px solid rgba(255, 184, 0, 0.5);
  box-shadow: 0 0 10px rgba(255, 184, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cat-avatar-svg {
  width: 28px;
  height: 28px;
  display: block;
}

/* Muthu Name and AI Badge Visible Outside */
.chat-trigger-content {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-trigger-name {
  font-size: 0.98rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.4px;
}

.chat-trigger-badge {
  font-size: 0.65rem;
  font-weight: 700;
  color: #111111;
  background: var(--yellow-accent, #ffb800);
  padding: 1px 6px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Status Indicator Dot */
.chat-trigger-status {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
  flex-shrink: 0;
  margin-left: 1px;
}

/* Close icon toggle when chat is open */
.chat-trigger-close-icon {
  width: 18px;
  height: 18px;
  display: none;
  stroke: var(--yellow-accent, #ffb800);
  align-items: center;
  justify-content: center;
}

.portfolio-chat-trigger.is-open .chat-trigger-status {
  display: none;
}

.portfolio-chat-trigger.is-open .chat-trigger-close-icon {
  display: flex;
}

.portfolio-chat-trigger.is-open {
  border-color: rgba(255, 184, 0, 0.8);
}

/* Notification badge */
.chat-unread-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 12px;
  height: 12px;
  background: var(--yellow-accent, #ffb800);
  border: 2px solid #070707;
  border-radius: 50%;
  opacity: 1;
  transition: transform 0.25s ease, opacity 0.25s ease;
  animation: unreadPulse 2s infinite ease-in-out;
}

.chat-unread-badge.hidden {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

@keyframes unreadPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

/* ==========================================================================
   2. Chat Window Container
   ========================================================================== */

.portfolio-chat-window {
  position: fixed;
  bottom: calc(max(20px, env(safe-area-inset-bottom, 20px)) + 65px);
  right: max(20px, env(safe-area-inset-right, 20px));
  width: min(400px, calc(100vw - 40px));
  height: min(600px, calc(100dvh - 120px));
  max-height: calc(86vh - 20px);
  max-height: calc(86dvh - 20px);
  background: rgba(12, 12, 12, 0.88);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85), 0 0 1px rgba(255, 255, 255, 0.2);
  display: flex;
  flex-direction: column;
  z-index: 2500;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1), transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

.portfolio-chat-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.portfolio-chat-window.is-minimized {
  height: 64px !important;
  max-height: 64px !important;
  transform: translateY(0) scale(1);
}

.portfolio-chat-window.is-minimized .chat-messages-container,
.portfolio-chat-window.is-minimized .chat-suggestions-wrapper,
.portfolio-chat-window.is-minimized .chat-input-container,
.portfolio-chat-window.is-minimized .chat-context-bar {
  display: none !important;
}

/* ==========================================================================
   3. Header
   ========================================================================== */

.chat-header {
  height: 64px;
  min-height: 64px;
  padding: 0 16px;
  background: rgba(18, 18, 18, 0.75);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar-wrap {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #222222 0%, #101010 100%);
  border: 1.5px solid rgba(255, 184, 0, 0.5);
  box-shadow: 0 0 10px rgba(255, 184, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-avatar-wrap .cat-avatar-svg {
  width: 28px;
  height: 28px;
}

.chat-status-dot-mini {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #10b981;
  border: 2px solid #0c0c0c;
  box-shadow: 0 0 6px #10b981;
}

.chat-title-group {
  display: flex;
  flex-direction: column;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title-text {
  font-size: 0.96rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}

.chat-status-badge {
  font-size: 0.68rem;
  font-weight: 600;
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  padding: 2px 6px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chat-status-indicator {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.chat-subtitle-text {
  font-size: 0.75rem;
  color: var(--gray-text, #9e9e9e);
  font-weight: 400;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-ctrl-btn {
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  color: #9e9e9e;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
  transition: background-color 0.2s ease, color 0.2s ease;
  outline: none;
}

.chat-ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

/* ==========================================================================
   4. Live Context Bar (Viewing section / project)
   ========================================================================== */

.chat-context-bar {
  padding: 7px 14px;
  background: rgba(255, 184, 0, 0.08);
  border-bottom: 1px solid rgba(255, 184, 0, 0.16);
  font-size: 0.74rem;
  color: #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-context-text {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-context-icon {
  color: var(--yellow-accent, #ffb800);
  font-size: 0.8rem;
  flex-shrink: 0;
}

.chat-context-name {
  color: var(--yellow-accent, #ffb800);
  font-weight: 600;
}

.chat-context-action-btn {
  background: rgba(255, 184, 0, 0.15);
  color: var(--yellow-accent, #ffb800);
  border: 1px solid rgba(255, 184, 0, 0.3);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.chat-context-action-btn:hover {
  background: var(--yellow-accent, #ffb800);
  color: #111111;
}

/* ==========================================================================
   5. Message Stream
   ========================================================================== */

.chat-messages-container {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* Custom Sleek Scrollbar */
.chat-messages-container::-webkit-scrollbar {
  width: 5px;
}

.chat-messages-container::-webkit-scrollbar-track {
  background: transparent;
}

.chat-messages-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 10px;
}

.chat-messages-container::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 184, 0, 0.4);
}

.chat-message-row {
  display: flex;
  width: 100%;
  animation: messageFadeIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes messageFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-message-row.user {
  justify-content: flex-end;
}

.chat-message-row.assistant {
  justify-content: flex-start;
}

.chat-bubble {
  max-width: 86%;
  padding: 11px 15px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.52;
  word-break: break-word;
}

/* User Message */
.chat-message-row.user .chat-bubble {
  background: #1c1a14;
  color: #ffffff;
  border: 1px solid rgba(255, 184, 0, 0.4);
  border-bottom-right-radius: 3px;
}

/* Assistant Message */
.chat-message-row.assistant .chat-bubble {
  background: rgba(24, 24, 24, 0.78);
  color: #e5e5e5;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom-left-radius: 3px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* Formatted Content inside Assistant Message */
.chat-bubble h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--yellow-accent, #ffb800);
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 184, 0, 0.2);
}

.chat-bubble strong {
  color: #ffffff;
  font-weight: 600;
}

.chat-bubble p {
  margin-bottom: 8px;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble ul {
  margin: 6px 0 10px 16px;
}

.chat-bubble li {
  margin-bottom: 4px;
}

.chat-bubble a {
  color: var(--yellow-accent, #ffb800);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chat-bubble a:hover {
  color: #ffd043;
}

/* Structured Section Highlights */
.section-badge-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  margin-bottom: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--yellow-accent, #ffb800);
}

/* Message Action Buttons */
.chat-message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.chat-action-btn.primary {
  background: var(--yellow-accent, #ffb800);
  color: #111111;
  border-color: var(--yellow-accent, #ffb800);
}

.chat-action-btn.primary:hover {
  background: #ffc424;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 184, 0, 0.3);
}

.chat-action-btn:not(.primary):hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--yellow-accent, #ffb800);
  border-color: rgba(255, 184, 0, 0.3);
}

/* ==========================================================================
   5b. Embedded Video Card & Downloadable Option
   ========================================================================== */

.chat-video-card {
  margin: 12px 0 14px 0;
  border-radius: 10px;
  overflow: hidden;
  background: #0d0d0d;
  border: 1px solid rgba(255, 184, 0, 0.28);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.55), 0 0 12px rgba(255, 184, 0, 0.12);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.chat-video-card:hover {
  border-color: rgba(255, 184, 0, 0.45);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.65), 0 0 16px rgba(255, 184, 0, 0.2);
}

.chat-video-wrapper {
  position: relative;
  width: 100%;
  background: #050505;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 0;
}

.chat-embedded-video {
  width: 100%;
  max-height: 220px;
  display: block;
  background: #000000;
  object-fit: contain;
  outline: none;
}

.chat-video-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(20, 20, 20, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.chat-video-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.chat-video-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chat-video-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-video-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #111111;
  background: var(--yellow-accent, #ffb800);
  border: 1px solid var(--yellow-accent, #ffb800);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(255, 184, 0, 0.28);
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  -webkit-tap-highlight-color: transparent;
}

.chat-video-download-btn:hover {
  background: #ffc424;
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(255, 184, 0, 0.45);
  color: #000000;
}

.chat-video-download-btn:active {
  transform: translateY(0);
}

.chat-video-download-btn svg {
  display: block;
  flex-shrink: 0;
}

/* ==========================================================================
   6. Typing Indicator
   ========================================================================== */

.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--yellow-accent, #ffb800);
  opacity: 0.4;
  animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ==========================================================================
   7. Quick Question Suggestion Chips
   ========================================================================== */

.chat-suggestions-wrapper {
  padding: 8px 14px;
  background: rgba(14, 14, 14, 0.85);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.chat-suggestions-wrapper::-webkit-scrollbar {
  display: none;
}

.chat-suggestion-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cfcfcf;
  font-size: 0.74rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  flex-shrink: 0;
}

.chat-suggestion-chip:hover {
  background: rgba(255, 184, 0, 0.12);
  border-color: rgba(255, 184, 0, 0.4);
  color: var(--yellow-accent, #ffb800);
  transform: translateY(-1px);
}

/* ==========================================================================
   8. Input Bar
   ========================================================================== */

.chat-input-container {
  padding: 10px 14px;
  background: rgba(18, 18, 18, 0.92);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-input-field {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 9px 12px;
  color: #ffffff;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s ease, background-color 0.2s ease;
  font-family: inherit;
}

.chat-input-field:focus {
  border-color: var(--yellow-accent, #ffb800);
  background: rgba(255, 255, 255, 0.08);
}

.chat-input-field::placeholder {
  color: #707070;
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--yellow-accent, #ffb800);
  border: none;
  color: #111111;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
  background: #ffd043;
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

.chat-send-icon {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

/* ==========================================================================
   9. Mobile Responsiveness (Under 600px)
   ========================================================================== */

@media (max-width: 600px) {
  .portfolio-chat-trigger {
    bottom: max(16px, env(safe-area-inset-bottom, 16px));
    right: max(16px, env(safe-area-inset-right, 16px));
    height: 48px;
    padding: 3px 14px 3px 5px;
    gap: 7px;
  }

  .chat-trigger-avatar {
    width: 36px;
    height: 36px;
  }

  .cat-avatar-svg {
    width: 24px;
    height: 24px;
  }

  .chat-trigger-name {
    font-size: 0.9rem;
  }

  .portfolio-chat-window {
    right: max(10px, env(safe-area-inset-right, 10px));
    left: max(10px, env(safe-area-inset-left, 10px));
    bottom: calc(max(16px, env(safe-area-inset-bottom, 16px)) + 58px);
    width: auto;
    height: calc(100dvh - 90px);
    max-height: calc(100dvh - 90px);
    border-radius: 16px;
  }

  .chat-bubble {
    max-width: 92%;
    font-size: 0.88rem;
  }

  .chat-header {
    height: 56px;
    min-height: 56px;
  }

  .chat-avatar-wrap {
    width: 34px;
    height: 34px;
  }

  .chat-title-text {
    font-size: 0.9rem;
  }
}
