/* =========================================
   Chat Widget - Portfolio Chat Assistant
   Light Theme
   ========================================= */

/* --- Chat Bubble (FAB) --- */
.chat-widget-bubble {
  position: fixed;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
  right: max(24px, env(safe-area-inset-right));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #0078D4;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 120, 212, 0.35);
  z-index: 10000;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.chat-widget-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 120, 212, 0.5);
}

.chat-widget-bubble:active {
  transform: scale(0.95);
}

.chat-widget-bubble-icon {
  font-size: 26px;
  line-height: 1;
  color: #fff;
  transition: transform 0.3s ease, opacity 0.2s ease;
}

.chat-widget-bubble.open .chat-widget-bubble-icon--chat {
  transform: rotate(90deg);
  opacity: 0;
  position: absolute;
}

.chat-widget-bubble.open .chat-widget-bubble-icon--close {
  transform: rotate(0deg);
  opacity: 1;
}

.chat-widget-bubble:not(.open) .chat-widget-bubble-icon--close {
  transform: rotate(-90deg);
  opacity: 0;
  position: absolute;
}

/* --- Chat Window --- */
.chat-widget-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.06);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.5) translateY(40px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.25s ease;
}

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

/* --- Header (Bright Gradient) --- */
.chat-widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, #0078D4 0%, #7B2FF7 100%);
  border-bottom: none;
  flex-shrink: 0;
}

.chat-widget-header-title {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  letter-spacing: 0.2px;
}

.chat-widget-header-subtitle {
  color: rgba(255, 255, 255, 0.8);
  font-size: 11px;
  font-weight: 400;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  margin-top: 2px;
}

.chat-widget-header-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: rgba(255, 255, 255, 0.9);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.chat-widget-header-close:hover {
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
}

/* --- Messages Area --- */
.chat-widget-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: #ffffff;
}

/* Scrollbar styling */
.chat-widget-messages::-webkit-scrollbar {
  width: 5px;
}

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

.chat-widget-messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.12);
  border-radius: 4px;
}

.chat-widget-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* --- Message Bubbles --- */
.chat-widget-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  word-wrap: break-word;
  animation: chatMsgFadeIn 0.3s ease;
}

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

.chat-widget-msg--bot {
  align-self: flex-start;
  background: #f0f2f5;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.chat-widget-msg--user {
  align-self: flex-end;
  background: #0078D4;
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Links inside messages */
.chat-widget-msg a {
  color: #0078D4;
  text-decoration: none;
}

.chat-widget-msg a:hover {
  text-decoration: underline;
}

.chat-widget-msg--user a {
  color: #d4e8ff;
}

/* Lists inside messages */
.chat-widget-msg ul {
  margin: 6px 0 2px 0;
  padding-left: 18px;
}

.chat-widget-msg ul li {
  margin-bottom: 3px;
}

/* --- Typing Indicator --- */
.chat-widget-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  background: #f0f2f5;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: chatMsgFadeIn 0.3s ease;
}

.chat-widget-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  animation: chatTypingBounce 1.2s infinite ease-in-out;
}

.chat-widget-typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-widget-typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chatTypingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.3;
  }
  30% {
    transform: translateY(-6px);
    opacity: 0.8;
  }
}

/* --- Quick Reply Buttons --- */
.chat-widget-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 2px 0;
  align-self: flex-start;
  max-width: 100%;
  animation: chatMsgFadeIn 0.3s ease;
}

.chat-widget-quick-btn {
  background: #ffffff;
  border: 1px solid #0078D4;
  color: #0078D4;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
  white-space: nowrap;
}

.chat-widget-quick-btn:hover {
  background: rgba(0, 120, 212, 0.08);
  border-color: #0078D4;
  color: #005a9e;
}

.chat-widget-quick-btn:active {
  background: #0078D4;
  color: #fff;
}

/* --- Input Area --- */
.chat-widget-input-area {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: #fafafa;
  flex-shrink: 0;
}

.chat-widget-input {
  flex: 1;
  background: #ffffff;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 22px;
  padding: 10px 16px;
  color: #1a1a1a;
  font-size: 13.5px;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-widget-input::placeholder {
  color: rgba(0, 0, 0, 0.35);
}

.chat-widget-input:focus {
  border-color: #0078D4;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.15);
}

.chat-widget-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #0078D4;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
  transition: background 0.2s ease, transform 0.15s ease;
}

.chat-widget-send-btn:hover {
  background: #1a86d9;
}

.chat-widget-send-btn:active {
  transform: scale(0.92);
}

.chat-widget-send-btn:disabled {
  background: #e0e0e0;
  color: rgba(0, 0, 0, 0.25);
  cursor: default;
}

/* Send arrow icon (CSS-only) */
.chat-widget-send-icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  position: relative;
}

.chat-widget-send-icon::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 7px 0 7px 12px;
  border-color: transparent transparent transparent #fff;
  transform: translate(-35%, -50%);
}

/* --- Mobile: prevent iOS auto-zoom on input focus --- */
@media (max-width: 768px) {
  .chat-widget-input {
    font-size: 16px;
  }
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
  .chat-widget-window {
    width: calc(100vw - 16px);
    height: calc(100vh - 120px);
    bottom: calc(80px + env(safe-area-inset-bottom, 0px));
    right: 8px;
    border-radius: 14px;
  }

  .chat-widget-bubble {
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
    right: 16px;
  }
}

@media (max-width: 360px) {
  .chat-widget-window {
    width: 100vw;
    height: calc(100vh - 70px);
    bottom: 70px;
    right: 0;
    border-radius: 14px 14px 0 0;
  }
}

/* --- Accessibility: focus-visible --- */
.chat-widget-bubble:focus-visible,
.chat-widget-header-close:focus-visible,
.chat-widget-quick-btn:focus-visible,
.chat-widget-send-btn:focus-visible {
  outline: 2px solid #0078D4;
  outline-offset: 2px;
}

.chat-widget-input:focus-visible {
  border-color: #0078D4;
  box-shadow: 0 0 0 2px rgba(0, 120, 212, 0.25);
}
