/* ========================= */
/* CHATBOT STYLES           */
/* ========================= */

:root {
  --primary-color: #2a3f5f;
  --secondary-color: #e8a51d;
  --text-primary: #1a1a1a;
  --text-secondary: #666;
  --bg-light: #f5f5f5;
  --bg-white: #ffffff;
  --border-color: #e0e0e0;
}

#chatbot-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  font-family: "Gudea", sans-serif;
  pointer-events: auto;
}

@media (min-width: 481px) {
  #chatbot-container {
    bottom: 20px;
    right: 20px;
  }
  
  .chat-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
  }
}

@supports (position: fixed) {
  #chatbot-container {
    position: fixed;
  }
}

/* Chat Window */
.chat-window {
  display: flex;
  flex-direction: column;
  width: 380px;
  height: 600px;
  background: var(--bg-white);
  border-radius: 12px;
  box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
  max-height: 90vh;
  max-height: 90dvh;
  position: absolute;
  bottom: 80px;
  right: 0;
  -webkit-overflow-scrolling: touch;
}

#chatbot-container:not(.chatbot-closed) .chat-window,
#chatbot-container.chat-open .chat-window {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Chat Header */
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #050f1a 0%, #0a1922 100%);
  border-radius: 12px 12px 0 0;
  color: white;
}

.chat-header-content h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  font-family: "Gudea", sans-serif;
}

.chat-header-content p {
  margin: 4px 0 0 0;
  font-size: 12px;
  opacity: 0.9;
  font-family: "Gudea", sans-serif;
}

.close-btn {
  background: none;
  border: none;
  color: #dcc9a3;
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, opacity 0.2s;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  font-size: 20px;
  font-weight: 600;
}

.close-btn:hover {
  color: #f7f5f0;
  opacity: 0.9;
}

.close-btn:active {
  opacity: 0.7;
}

/* Messages Container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #0b1c2d;
}

/* Message Styles */
.chat-message {
  display: flex;
  animation: messageSlideIn 0.3s ease-out;
}

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

.bot-message {
  justify-content: flex-start;
}

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

.message-content {
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  word-break: break-word;
  font-size: 14px;
  font-family: "Gudea", sans-serif;
  line-height: 1.4;
  overflow-wrap: break-word;
}

.message-content p,
.message-content ol,
.message-content ul {
  margin: 8px 0;
  padding: 0;
}

.message-content ol,
.message-content ul {
  padding-left: 20px;
}

.message-content li {
  margin: 4px 0;
  word-break: break-word;
}

.bot-message .message-content {
  background: #0f2438;
  color: #f7f5f0;
  border: 1px solid #1a3a52;
  border-bottom-left-radius: 2px;
}

.user-message .message-content {
  background: #dcc9a3;
  color: #0b1c2d;
  border-bottom-right-radius: 2px;
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #0f2438;
  border: 1px solid #1a3a52;
  border-radius: 12px;
  border-bottom-left-radius: 2px;
}

.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #dcc9a3;
  animation: typingAnimation 1.4s infinite;
}

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

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

@keyframes typingAnimation {
  0%, 60%, 100% {
    opacity: 0.5;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-10px);
  }
}

/* Input Area */
.chat-input-area {
  padding: 16px;
  border-top: 1px solid #1a3a52;
  background: #0b1c2d;
  border-radius: 0 0 12px 12px;
  flex-shrink: 0;
}

#chat-form {
  display: flex;
  gap: 8px;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #1a3a52;
  border-radius: 6px;
  font-family: "Gudea", sans-serif;
  outline: none;
  transition: border-color 0.2s;
  background: #0f2438;
  color: #f7f5f0;
  font-size: 16px;
  min-height: 44px;
  appearance: none;
  -webkit-appearance: none;
  -webkit-border-radius: 6px;
}

#chat-input:focus {
  border-color: #dcc9a3;
}

#chat-input::placeholder {
  color: #8899aa;
}

.send-btn {
  background: #dcc9a3;
  color: #0b1c2d;
  border: none;
  border-radius: 6px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  font-family: "Gudea", sans-serif;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  appearance: none;
  -webkit-appearance: none;
  -webkit-border-radius: 6px;
}

.send-btn:hover {
  background: #f7f5f0;
}

.send-btn:active {
  transform: scale(0.95);
}

/* Toggle Button */
.chat-toggle-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-color) 0%, #1f2e47 100%);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(42, 63, 95, 0.3);
  transition: all 0.3s ease;
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9998;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
  flex-shrink: 0;
}

.chat-toggle-btn:hover {
  transform: scale(1.1);
  -webkit-transform: scale(1.1);
  box-shadow: 0 6px 20px rgba(42, 63, 95, 0.4);
}

.chat-toggle-btn:active,
.chat-toggle-btn:focus {
  transform: scale(0.95);
  -webkit-transform: scale(0.95);
  outline: none;
}

#chatbot-container.chatbot-closed .chat-toggle-btn {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
  display: flex;
}

#chatbot-container:not(.chatbot-closed) .chat-toggle-btn,
#chatbot-container.chat-open .chat-toggle-btn {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  display: none;
}

/* Scrollbar Styling */
.chat-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
  background: #ccc;
}

/* Responsive Design */
@media (max-width: 480px) {
  .chat-toggle-btn {
    width: calc(100% - 0px);
    height: 60px;
    border-radius: 0;
    bottom: 0;
    right: 0;
    left: 0;
    font-size: 16px;
    font-weight: 600;
    font-family: "Castoro Titling", serif;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    background: linear-gradient(
      to bottom,
      rgba(11, 28, 45, 0.95),
      rgba(11, 28, 45, 0.95)
    );
  }

  .chat-toggle-btn svg {
    display: none;
  }

  .chat-toggle-btn::before {
    content: 'CHAT WITH US';
    background: linear-gradient(to right, #c8b379, #f7f5f0 50%, #c8b379 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
  }

  #chatbot-container.chatbot-closed .chat-toggle-btn {
    display: flex;
    pointer-events: auto;
  }

  #chatbot-container:not(.chatbot-closed) .chat-toggle-btn {
    display: none;
  }

  #chatbot-container:not(.chatbot-closed)::after {
    opacity: 0;
    pointer-events: none;
  }

  .chat-window {
    width: 100vw;
    width: 100dvw;
    height: 85vh;
    height: 85dvh;
    max-width: 100vw;
    max-height: 85dvh;
    border-radius: 12px 12px 0 0;
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
  }

  #chatbot-container:not(.chatbot-closed) .chat-window {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
  }

  .message-content {
    max-width: 85%;
  }

  /* KEY FIX: closed state — only 60px tall, no pointer events */
  #chatbot-container {
    bottom: 0;
    right: 0;
    left: 0;
    top: auto;
    height: 60px;
    pointer-events: none;
  }

  #chatbot-container.chatbot-closed {
    top: auto !important;
    height: 60px !important;
    pointer-events: none !important;
  }

  #chatbot-container.chatbot-closed * {
    pointer-events: none !important;
  }

  #chatbot-container.chatbot-closed .chat-toggle-btn {
    pointer-events: auto !important;
  }

  #chatbot-container:not(.chatbot-closed) {
    top: 0 !important;
    height: 100% !important;
    pointer-events: auto !important;
  }

  .chat-header {
    padding: 16px;
  }

  .chat-messages {
    padding: 16px;
    gap: 10px;
  }

  .chat-input-area {
    padding: 12px;
    position: relative;
  }

  #chat-input {
    font-size: 16px;
    padding: 12px;
    min-height: 44px;
  }

  .send-btn {
    min-height: 44px;
    min-width: 44px;
  }
}

/* Ultra-small screens with keyboard */
@media (max-width: 480px) and (max-height: 700px) {
  .chat-window {
    height: 100dvh;
  }

  .chat-messages {
    padding: 12px;
    gap: 8px;
  }

  .message-content {
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* Landscape orientation */
@media (max-width: 768px) and (max-height: 500px) {
  .chat-window {
    height: 90dvh;
    max-height: 90dvh;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .chat-messages {
    padding: 12px;
  }
}

/* Mobile - Reduce height for keyboards */
@media (max-height: 600px) {
  .chat-window {
    height: 85dvh;
    max-height: 85dvh;
  }
}

/* Service Links in Chat Messages */
.chat-service-link {
  color: #DCC9A3;
  text-decoration: none;
  font-weight: 500;
  letter-spacing: 0.04em;
  position: relative;
  display: inline-block;
  margin: 4px 4px 4px 0;
  transition: all 0.25s ease;
  cursor: pointer;
  white-space: nowrap;
}

.chat-service-link::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -2px;
  width: 100%;
  height: 1px;
  background: linear-gradient(to right, transparent, #DCC9A3, transparent);
  opacity: 0.6;
}

.chat-service-link:hover {
  opacity: 0.85;
  text-decoration: underline;
}

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

.message-content {
  word-wrap: break-word;
  word-break: break-word;
}

.message-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.message-content ul li {
  margin: 6px 0;
  line-height: 1.5;
}

.message-content p {
  margin: 8px 0;
  line-height: 1.5;
}

.message-content strong {
  color: #DCC9A3;
}

.message-content a {
  color: #2a3f5f;
  text-decoration: none;
  font-weight: 600;
}

.message-content a:hover {
  text-decoration: underline;
}

.chat-message .message-content a.chat-service-link,
.chat-message .message-content .chat-service-link {
  color: #DCC9A3 !important;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .chat-window,
  .chat-toggle-btn,
  .send-btn,
  .chat-message,
  .chat-service-link {
    transition: none;
    animation: none;
  }
}