/* ============================================================================
   The Kids' Dentist - AI Chat Widget Styles
   Matches the rainforest theme: Leaf greens (#1b5e20, #2e7d32), warm accents,
   clean cards, accessible typography, and mobile-friendly responsive layout.
   ============================================================================ */

:root {
  --kd-chat-primary: #1b5e20;
  --kd-chat-primary-light: #2e7d32;
  --kd-chat-accent: #ffb300;
  --kd-chat-accent-hover: #ffa000;
  --kd-chat-bg: #ffffff;
  --kd-chat-bg-soft: #fbfbf6;
  --kd-chat-bubble-bot: #f3f7f3;
  --kd-chat-border: #e0e8e0;
  --kd-chat-text: #222b23;
  --kd-chat-text-muted: #536b56;
  --kd-chat-shadow: 0 10px 32px rgba(27, 94, 32, 0.18), 0 2px 8px rgba(0, 0, 0, 0.08);
  --kd-chat-radius: 20px;
}

/* Floating Launcher Button */
.kd-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--kd-chat-primary), var(--kd-chat-primary-light));
  color: #ffffff;
  border: 2px solid rgba(255, 255, 255, 0.3);
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(27, 94, 32, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  outline: none;
}

.kd-chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 8px 26px rgba(27, 94, 32, 0.45);
}

.kd-chat-launcher:active {
  transform: scale(0.96);
}

.kd-chat-launcher svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
  transition: transform 0.25s ease;
}

.kd-chat-launcher.is-active svg.kd-icon-chat {
  display: none;
}

.kd-chat-launcher svg.kd-icon-close {
  display: none;
}

.kd-chat-launcher.is-active svg.kd-icon-close {
  display: block;
}

/* Floating Greeting Bubble (Tooltip) */
.kd-chat-teaser {
  position: fixed;
  bottom: 94px;
  right: 24px;
  background: #ffffff;
  color: var(--kd-chat-text);
  padding: 12px 16px;
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.14);
  border: 1px solid var(--kd-chat-border);
  font-size: 0.88rem;
  max-width: 250px;
  line-height: 1.35;
  z-index: 9997;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: kdFadeSlideUp 0.35s ease forwards;
  cursor: pointer;
}

.kd-chat-teaser::after {
  content: "";
  position: absolute;
  bottom: -8px;
  right: 22px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  border-right: 1px solid var(--kd-chat-border);
  border-bottom: 1px solid var(--kd-chat-border);
  transform: rotate(45deg);
}

.kd-chat-teaser-close {
  background: none;
  border: none;
  color: #888;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  margin-left: auto;
}

.kd-chat-teaser-close:hover {
  color: #333;
}

/* Chat Window Container */
.kd-chat-box {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 580px;
  max-height: calc(100vh - 120px);
  background: var(--kd-chat-bg);
  border-radius: var(--kd-chat-radius);
  box-shadow: var(--kd-chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  border: 1px solid rgba(27, 94, 32, 0.12);
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}

.kd-chat-box.kd-hidden {
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px) scale(0.96);
  pointer-events: none;
}

/* Header */
.kd-chat-header {
  background: linear-gradient(135deg, var(--kd-chat-primary), var(--kd-chat-primary-light));
  color: #ffffff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

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

.kd-chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.kd-chat-title {
  font-size: 0.96rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

.kd-chat-subtitle {
  font-size: 0.74rem;
  opacity: 0.9;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
}

.kd-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #69f0ae;
  display: inline-block;
  box-shadow: 0 0 6px #69f0ae;
}

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

.kd-chat-btn-icon {
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.18s ease;
}

.kd-chat-btn-icon:hover {
  background: rgba(255, 255, 255, 0.28);
}

/* Messages Area */
.kd-chat-messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--kd-chat-bg-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Welcome Card */
.kd-chat-welcome {
  background: #ffffff;
  border: 1px solid var(--kd-chat-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.kd-chat-welcome h4 {
  margin: 0 0 6px 0;
  color: var(--kd-chat-primary);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kd-chat-welcome p {
  margin: 0 0 10px 0;
  font-size: 0.85rem;
  color: var(--kd-chat-text-muted);
  line-height: 1.4;
}

/* Quick Suggestion Chips */
.kd-chat-quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.kd-chat-chip {
  background: #ffffff;
  border: 1px solid #c8d8c8;
  color: var(--kd-chat-primary);
  padding: 6px 10px;
  border-radius: 14px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.kd-chat-chip:hover {
  background: var(--kd-chat-bubble-bot);
  border-color: var(--kd-chat-primary-light);
  transform: translateY(-1px);
}

/* Message Rows */
.kd-msg-row {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: kdFadeIn 0.2s ease forwards;
}

.kd-msg-row.kd-user {
  align-self: flex-end;
  align-items: flex-end;
}

.kd-msg-row.kd-bot {
  align-self: flex-start;
  align-items: flex-start;
}

.kd-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.45;
  word-break: break-word;
}

.kd-msg-row.kd-user .kd-msg-bubble {
  background: linear-gradient(135deg, var(--kd-chat-primary), var(--kd-chat-primary-light));
  color: #ffffff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 6px rgba(27, 94, 32, 0.2);
}

.kd-msg-row.kd-bot .kd-msg-bubble {
  background: #ffffff;
  color: var(--kd-chat-text);
  border: 1px solid var(--kd-chat-border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.kd-msg-bubble p {
  margin: 0 0 6px 0;
}

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

.kd-msg-bubble a {
  color: var(--kd-chat-primary);
  font-weight: 600;
  text-decoration: underline;
}

.kd-msg-row.kd-user .kd-msg-bubble a {
  color: #ffffff;
  text-decoration: underline;
}

.kd-msg-bubble ul, .kd-msg-bubble ol {
  margin: 4px 0 6px 18px;
  padding: 0;
}

.kd-msg-bubble li {
  margin-bottom: 3px;
}

.kd-msg-time {
  font-size: 0.68rem;
  color: #8fa091;
  margin-top: 3px;
  padding: 0 4px;
}

/* Typing Indicator */
.kd-typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #ffffff;
  border: 1px solid var(--kd-chat-border);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.kd-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--kd-chat-text-muted);
  opacity: 0.6;
  animation: kdBounce 1.4s infinite ease-in-out;
}

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

/* Interactive In-Chat Appointment Card */
.kd-appt-card {
  background: #ffffff;
  border: 1.5px solid #a5d6a7;
  border-radius: 14px;
  padding: 12px 14px;
  margin-top: 4px;
  box-shadow: 0 4px 12px rgba(27, 94, 32, 0.08);
}

.kd-appt-card h4 {
  margin: 0 0 8px 0;
  font-size: 0.92rem;
  color: var(--kd-chat-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.kd-appt-field {
  margin-bottom: 8px;
}

.kd-appt-field label {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--kd-chat-text-muted);
  margin-bottom: 3px;
}

.kd-appt-field input, .kd-appt-field select {
  width: 100%;
  padding: 6px 9px;
  border: 1px solid #c8d8c8;
  border-radius: 8px;
  font-size: 0.82rem;
  outline: none;
  box-sizing: border-box;
}

.kd-appt-field input:focus, .kd-appt-field select:focus {
  border-color: var(--kd-chat-primary);
}

.kd-appt-submit {
  width: 100%;
  background: linear-gradient(135deg, var(--kd-chat-primary), var(--kd-chat-primary-light));
  color: #ffffff;
  border: none;
  padding: 8px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.18s ease;
}

.kd-appt-submit:hover {
  opacity: 0.94;
}

.kd-appt-success {
  background: #e8f5e9;
  border: 1px solid #81c784;
  color: #1b5e20;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
  margin-top: 6px;
}

/* Input Area */
.kd-chat-footer {
  background: #ffffff;
  border-top: 1px solid var(--kd-chat-border);
  padding: 10px 12px 6px 12px;
}

.kd-chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--kd-chat-bg-soft);
  border: 1.5px solid #d4dfd4;
  border-radius: 24px;
  padding: 4px 6px 4px 12px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.kd-chat-input-row:focus-within {
  border-color: var(--kd-chat-primary-light);
  box-shadow: 0 0 0 3px rgba(46, 125, 50, 0.12);
}

.kd-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 6px 0;
  font-size: 0.88rem;
  color: var(--kd-chat-text);
  outline: none;
}

.kd-chat-input::placeholder {
  color: #8fa091;
}

.kd-chat-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--kd-chat-primary);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.18s ease;
  flex-shrink: 0;
}

.kd-chat-send:hover:not(:disabled) {
  background: var(--kd-chat-primary-light);
  transform: scale(1.05);
}

.kd-chat-send:disabled {
  background: #c2cfc2;
  cursor: not-allowed;
}

.kd-chat-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  margin-left: 2px;
}

.kd-chat-disclaimer {
  font-size: 0.65rem;
  color: #8fa091;
  text-align: center;
  margin: 6px 0 2px 0;
}

/* Animations */
@keyframes kdFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes kdBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .kd-chat-launcher {
    bottom: calc(var(--mobile-bar-height, 64px) + 14px);
    right: 16px;
    width: 54px;
    height: 54px;
  }

  .kd-chat-teaser {
    bottom: calc(var(--mobile-bar-height, 64px) + 78px);
    right: 16px;
  }

  .kd-chat-box {
    bottom: calc(var(--mobile-bar-height, 64px) + 76px);
    right: 12px;
    left: 12px;
    width: auto;
    max-width: none;
    height: 520px;
    max-height: calc(100vh - var(--mobile-bar-height, 64px) - 90px);
  }
}
