:root {
  --ocean-blue: #0088a8;
  --dark-teal: #006880;
  --bright-cyan: #00b4d8;
  --white: #ffffff;
  --light-bg: #f0f7fa;
  --chat-border: #d0eaf2;
  --text-primary: #1a2e38;
  --chat-text-muted: #6b8fa0;
  --shadow: 0 12px 48px rgba(0, 104, 128, 0.28);
  --radius: 16px;
  --font: "Roboto", sans-serif;
  --chat-panel-width: 400px;
}

.chat-toggle-btn {
  position: fixed;
  bottom: 25px;
  right: 25px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--white);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(0, 104, 128, 0.45);
  z-index: 99999;
  transition:
    transform 0.2s ease,
    opacity 0.2s ease,
    visibility 0.2s ease;
}

.chat-toggle-btn.hidden {
  display: none;
  opacity: 0;
  pointer-events: none;
}

.chat-toggle-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 30px rgba(0, 104, 128, 0.45);
}

.toggle-img-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--white);
}

.chat-badge.hidden {
  display: none;
}

.chat-widget {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: var(--chat-panel-width);
  height: 100vh;
  max-width: 100vw;
  background: var(--white);
  border-radius: 0;
  box-shadow: -8px 0 40px rgba(0, 104, 128, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
  border: none;
  border-left: 1px solid var(--chat-border);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(100%);
  transform-origin: right center;
  transition:
    opacity 0.3s ease,
    transform 0.3s ease,
    visibility 0.3s ease;
}

.chat-widget.open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

.chat-header {
  background: linear-gradient(
    135deg,
    var(--dark-teal) 0%,
    var(--ocean-blue) 100%
  );
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  flex-shrink: 0;
}

.header-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-text {
  flex: 1;
}

.header-text h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  margin: 0;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: 50%;
}

.header-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--light-bg);
}

.message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 90%;
  min-width: 0;
}

.bot-message {
  align-self: flex-start;
}

.user-message {
  flex-direction: row-reverse;
  align-self: flex-end;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.bot-avatar {
  background: linear-gradient(135deg, var(--ocean-blue), var(--bright-cyan));
  color: var(--white);
  object-fit: contain;
  padding: 4px;
  border-radius: 50%;
}

.user-avatar {
  background: var(--dark-teal);
  color: var(--white);
  font-size: 13px;
  font-weight: 600;
}

.message-content {
  background: var(--white);
  border-radius: 14px 14px 14px 4px;
  padding: 12px 16px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
  border: 1px solid var(--chat-border);
  color: var(--text-primary);
  font-family: var(--font);
  max-width: 100%;
  min-width: 0;
  overflow-wrap: break-word;
  word-break: break-word;
  box-sizing: border-box;
}

.user-message .message-content {
  background: linear-gradient(135deg, var(--ocean-blue), var(--dark-teal));
  color: var(--white);
  border-radius: 14px 14px 4px 14px;
  border-color: transparent;
}

.message-content p {
  font-size: 13.5px;
  line-height: 1.4;
  margin: 0 0 2px 0;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
}
.message-content p:last-child {
  margin-bottom: 0;
}

.bot-message .message-content h1,
.bot-message .message-content h2,
.bot-message .message-content h3,
.bot-message .message-content h4,
.bot-message .message-content h5,
.bot-message .message-content h6 {
  color: var(--dark-teal);
  margin: 6px 0 4px 0;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: break-word;
  word-break: break-word;
}

.bot-message .message-content h1 {
  font-size: 15px;
}

.bot-message .message-content h2 {
  font-size: 14.5px;
}

.bot-message .message-content h3 {
  font-size: 14.5px;
}

.bot-message .message-content h4 {
  font-size: 13.5px;
}

.bot-message .message-content h5,
.bot-message .message-content h6 {
  font-size: 13px;
}

.bot-message .message-content strong {
  color: var(--dark-teal);
  font-weight: 700;
}

.bot-message .message-content ul,
.bot-message .message-content ol {
  margin: 4px 0 6px 0;
  padding-left: 18px;
}

.bot-message .message-content li {
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 2px;
  overflow-wrap: break-word;
  word-break: break-word;
}

.bot-message .message-content hr {
  border: none;
  border-top: 1px solid var(--chat-border);
  margin: 8px 0;
}

.bot-message .message-content code {
  background: var(--light-bg);
  border: 1px solid var(--chat-border);
  border-radius: 4px;
  padding: 1px 4px;
  font-family: "Consolas", "Menlo", monospace;
  font-size: 12.5px;
  color: var(--dark-teal);
}

.bot-message .message-content pre {
  background: var(--light-bg);
  border: 1px solid var(--chat-border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: 6px 0;
  overflow-x: auto;
}

.bot-message .message-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
  color: var(--text-primary);
  white-space: pre;
}

.bot-message .message-content blockquote {
  margin: 6px 0;
  padding: 2px 10px;
  border-left: 3px solid var(--ocean-blue);
  color: var(--chat-text-muted);
  font-style: italic;
}

.bot-message .message-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 6px 0;
  font-size: 12.5px;
}

.bot-message .message-content th,
.bot-message .message-content td {
  border: 1px solid var(--chat-border);
  padding: 4px 6px;
  text-align: left;
}

.bot-message .message-content th {
  background: var(--light-bg);
  color: var(--dark-teal);
  font-weight: 700;
}

.bot-message .message-content a {
  color: var(--ocean-blue);
  text-decoration: underline;
  word-break: break-word;
}

.message-time {
  display: block;
  font-size: 10px;
  color: var(--chat-text-muted);
}

.user-message .message-time {
  color: rgba(255, 255, 255, 0.7);
}

.message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
  border: none;
  background: transparent;
  color: var(--chat-text-muted);
  cursor: pointer;
  border-radius: 6px;
  flex-shrink: 0;
}

.copy-btn:hover {
  background: var(--light-bg);
  color: var(--ocean-blue);
}

.copy-btn.copied {
  color: #16a34a;
}

.message.typing-message {
  flex-shrink: 0;
  align-items: center;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
  min-height: 14px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--bright-cyan);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite ease-in-out;
  flex-shrink: 0;
}

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

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

@keyframes typingBounce {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

.quick-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  background: var(--light-bg);
}

.suggestion-chip {
  white-space: nowrap;
  padding: 6px 14px;
  background: var(--white);
  border: 1.5px solid var(--ocean-blue);
  color: var(--ocean-blue);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
}

.suggestion-chip:hover {
  background: var(--ocean-blue);
  color: var(--white);
}

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: var(--white);
  border-top: 1px solid var(--chat-border);
}

.chat-input {
  flex: 1;
  padding: 10px 16px;
  border: 1.5px solid var(--chat-border);
  border-radius: 20px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.4;
  outline: none;
  resize: none;
  overflow-y: hidden;
  max-height: 120px;
  min-height: 40px;
  box-sizing: border-box;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input::placeholder {
  color: var(--chat-text-muted);
}

.chat-input:focus {
  border-color: var(--ocean-blue);
  box-shadow: 0 0 0 3px rgba(0, 136, 168, 0.12);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ocean-blue), var(--dark-teal));
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.send-btn.generating {
  background: var(--dark-teal);
}

body.chatbot-open {
  overflow: hidden;
}

body.chatbot-open > *:not(.chat-widget):not(.chat-toggle-btn):not(.mobile-nav):not(#navbar):not(.scroll-top):not(.cg-modal-overlay) {
  margin-right: var(--chat-panel-width);
  transition: margin-right 0.3s ease;
}

body.chatbot-open #navbar {
  width: calc(100% - var(--chat-panel-width));
  transition: width 0.3s ease;
}

body.chatbot-open .scroll-top {
  right: calc(var(--chat-panel-width) + 28px);
  transition: right 0.3s ease;
}

.chat-toggle-btn.hide-while-open {
  opacity: 0;
  pointer-events: none;
}

.chat-tooltip {
  position: fixed;
  bottom: 92px;
  right: 25px;
  max-width: 220px;
  background: var(--white);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 14px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 104, 128, 0.22);
  border: 1px solid var(--chat-border);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
  z-index: 99998;
  cursor: pointer;
}

.chat-tooltip.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

@keyframes chatIconVibrate {
  0%, 100% { transform: translateX(0) rotate(0); }
  10%, 30%, 50%, 70% { transform: translateX(-3px) rotate(-6deg); }
  20%, 40%, 60%, 80% { transform: translateX(3px) rotate(6deg); }
  90% { transform: translateX(-1px) rotate(-2deg); }
}

.chat-toggle-btn.vibrate {
  animation: chatIconVibrate 0.6s ease-in-out;
}

@media (max-width: 768px) {
  .chat-widget {
    inset: 0;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-width: none;
    max-height: none;
    border-radius: 0;
  }

  .chat-toggle-btn {
    bottom: 18px;
    right: 18px;
  }

  .chat-input {
    font-size: 16px;
  }

  .chat-tooltip {
    bottom: 82px;
    right: 18px;
  }

  body.chatbot-open > *:not(.chat-widget):not(.chat-toggle-btn):not(.mobile-nav):not(#navbar):not(.scroll-top):not(.cg-modal-overlay) {
    margin-right: 0;
  }

  body.chatbot-open #navbar {
    width: 100%;
  }

  body.chatbot-open .scroll-top {
    right: 28px;
  }
}