/* ==========================================================================
   S.D. ENGINEERING — Client-Side AI Chatbot Widget Styles
   Industrial precision aesthetics matching S.D. Engineering brand
   ========================================================================== */

:root {
  --sd-chat-primary: #294e69;
  --sd-chat-primary-dark: #1b3548;
  --sd-chat-accent: #f59e0b;
  --sd-chat-accent-hover: #d97706;
  --sd-chat-ink: #121820;
  --sd-chat-muted: #5e6875;
  --sd-chat-line: #dce1e6;
  --sd-chat-bg: #ffffff;
  --sd-chat-bubble-bot: #f1f5f9;
  --sd-chat-bubble-user: #294e69;
  --sd-chat-radius: 18px;
  --sd-chat-shadow: 0 16px 40px -8px rgba(18, 24, 32, 0.22), 0 4px 14px -2px rgba(18, 24, 32, 0.08);
}

/* Mini Contact Bar — launcher lives inside the bottom-right bar */
.sd-chat-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  height: 2.6rem;
  padding: 0;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--sd-chat-primary, #294e69);
  cursor: pointer;
  outline: none;
  box-shadow: none;
  transition: background-color 180ms ease, color 180ms ease;
  position: relative;
}

.sd-chat-launcher:hover {
  background: rgba(41, 78, 105, 0.10);
  color: #1b3548;
  transform: none;
  box-shadow: none;
}

.sd-chat-launcher:focus-visible {
  outline: 2px solid var(--sd-chat-accent, #f59e0b);
  outline-offset: 2px;
}

.sd-chat-launcher svg {
  width: 1.4rem;
  height: 1.4rem;
  fill: currentColor;
  display: block;
  transition: transform 180ms ease;
}

.sd-chat-launcher:hover svg {
  transform: scale(1.08);
}

/* Badge dot on launcher */
.sd-chat-launcher-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border: 1.5px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(16, 185, 129, 0.8);
}

/* Tooltip positioned above launcher */
.sd-chat-launcher-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  right: 0;
  left: auto;
  background: #121820;
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 6px 12px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.2);
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 200ms ease, transform 200ms ease;
  letter-spacing: 0.01em;
}

.sd-chat-launcher-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 14px;
  left: auto;
  transform: none;
  border: 5px solid transparent;
  border-top-color: #121820;
}

.sd-chat-launcher:hover .sd-chat-launcher-tooltip {
  opacity: 1;
  transform: translateY(0);
}

/* Main Chat Widget Container — opens from bottom-right */
.sd-chat-container {
  position: fixed;
  z-index: 2000;
  bottom: clamp(1.25rem, 3vw, 1.75rem);
  right: clamp(1.25rem, 3vw, 1.75rem);
  left: auto;
  width: min(420px, calc(100vw - 2rem));
  height: min(640px, calc(100vh - 4.5rem));
  background: var(--sd-chat-bg);
  border-radius: var(--sd-chat-radius);
  box-shadow: var(--sd-chat-shadow);
  border: 1px solid rgba(41, 78, 105, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.97);
  transform-origin: bottom right;
  transition: transform 280ms cubic-bezier(.16, 1, .3, 1), opacity 240ms ease, visibility 240ms ease;
  font-family: var(--font-sans, "Arial", "Helvetica Neue", sans-serif);
}

.sd-chat-container.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.sd-chat-header {
  background: linear-gradient(135deg, var(--sd-chat-primary), var(--sd-chat-primary-dark));
  color: #ffffff;
  padding: 1rem 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--sd-chat-accent);
  flex-shrink: 0;
}

.sd-chat-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sd-chat-avatar {
  width: 2.5rem;
  height: 2.5rem;
  background: rgba(255, 255, 255, 0.16);
  border: 1.5px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  color: #ffffff;
}

.sd-chat-title-wrap h3 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #ffffff;
  line-height: 1.25;
}

.sd-chat-subtitle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 2px;
}

.sd-chat-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #10b981;
  box-shadow: 0 0 6px #10b981;
  display: inline-block;
}

.sd-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.sd-chat-header-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
  padding: 0;
}

.sd-chat-header-btn:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
}

.sd-chat-header-btn:focus-visible {
  outline: 2px solid var(--sd-chat-accent);
  outline-offset: 2px;
}

/* Chat Body / Messages Stream */
.sd-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  background: #f8fafc;
  scroll-behavior: smooth;
}

/* Message Item */
.sd-chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
  animation: sd-msg-in 180ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes sd-msg-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.sd-chat-msg.bot {
  align-self: flex-start;
}

.sd-chat-msg.user {
  align-self: flex-end;
}

.sd-chat-bubble {
  padding: 0.75rem 0.95rem;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.sd-chat-msg.bot .sd-chat-bubble {
  background: #ffffff;
  color: var(--sd-chat-ink);
  border: 1px solid #E2E8F0;
  border-radius: 14px 14px 14px 4px;
  box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.05);
}

.sd-chat-msg.user .sd-chat-bubble {
  background: linear-gradient(135deg, var(--sd-chat-primary), var(--sd-chat-primary-dark));
  color: #ffffff;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 3px 10px -2px rgba(41, 78, 105, 0.28);
}

.sd-chat-msg-time {
  font-size: 0.6875rem;
  color: var(--sd-chat-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.sd-chat-msg.user .sd-chat-msg-time {
  align-self: flex-end;
}

/* Call to Action buttons inside bot messages */
.sd-chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.6rem;
  padding-top: 0.5rem;
  border-top: 1px dashed var(--sd-chat-line);
}

.sd-chat-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0.4rem 0.75rem;
  background: #f1f5f9;
  color: var(--sd-chat-primary);
  border: 1px solid rgba(41, 78, 105, 0.2);
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 160ms ease;
}

.sd-chat-action-btn:hover {
  background: var(--sd-chat-primary);
  color: #ffffff;
  border-color: var(--sd-chat-primary);
}

.sd-chat-action-btn.primary {
  background: var(--sd-chat-accent);
  color: #121820;
  border-color: var(--sd-chat-accent);
}

.sd-chat-action-btn.primary:hover {
  background: var(--sd-chat-accent-hover);
  color: #ffffff;
}

/* Quick Question Pills */
.sd-chat-quick-wrap {
  padding: 0.5rem 1rem 0.75rem;
  background: #f8fafc;
  border-top: 1px solid var(--sd-chat-line);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sd-chat-quick-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--sd-chat-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
}

.sd-chat-quick-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 82px;
  overflow-y: auto;
  padding-right: 2px;
}

.sd-chat-quick-btn {
  background: #ffffff;
  color: var(--sd-chat-ink);
  border: 1px solid var(--sd-chat-line);
  border-radius: 9999px;
  padding: 0.32rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 160ms ease;
}

.sd-chat-quick-btn:hover {
  background: rgba(41, 78, 105, 0.08);
  border-color: var(--sd-chat-primary);
  color: var(--sd-chat-primary);
  transform: translateY(-1px);
}

.sd-chat-quick-btn:focus-visible {
  outline: 2px solid var(--sd-chat-accent);
  outline-offset: 1px;
}

/* Typing Indicator */
.sd-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.6rem 0.9rem;
  background: #ffffff;
  border: 1px solid var(--sd-chat-line);
  border-radius: 14px 14px 14px 4px;
  width: fit-content;
}

.sd-chat-typing-dot {
  width: 6px;
  height: 6px;
  background-color: var(--sd-chat-muted);
  border-radius: 50%;
  animation: sd-bounce 1.2s infinite ease-in-out;
}

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

@keyframes sd-bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* Input Area */
.sd-chat-footer {
  padding: 0.75rem 0.9rem;
  background: #ffffff;
  border-top: 1px solid var(--sd-chat-line);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.sd-chat-input {
  flex: 1;
  border: 1px solid var(--sd-chat-line);
  border-radius: 24px;
  padding: 0.55rem 1rem;
  font-size: 0.875rem;
  color: var(--sd-chat-ink);
  outline: none;
  background: #ffffff;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.sd-chat-input:focus {
  border-color: var(--sd-chat-primary);
  box-shadow: 0 0 0 3px rgba(197, 154, 39, 0.22);
}

.sd-chat-send-btn {
  background: var(--sd-chat-primary);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  width: 2.35rem;
  height: 2.35rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
  flex-shrink: 0;
  padding: 0;
}

.sd-chat-send-btn:hover {
  background: var(--sd-chat-primary-dark);
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(41, 78, 105, 0.35);
}

.sd-chat-send-btn:active {
  transform: scale(0.96);
}

.sd-chat-send-btn:focus-visible {
  outline: 2px solid var(--sd-chat-accent);
  outline-offset: 2px;
}

.sd-chat-send-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: currentColor;
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .sd-chat-launcher,
  .sd-chat-container,
  .sd-chat-msg,
  .sd-chat-quick-btn,
  .sd-chat-typing-dot,
  .sd-chat-launcher-badge {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }
}

/* Responsive Mobile Layout — Preserves compact card design without full-screen takeover */
@media (max-width: 600px) {
  .sd-chat-container {
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
    left: auto;
    width: min(390px, calc(100vw - 1.5rem));
    max-width: calc(100vw - 1.5rem);
    height: min(520px, calc(100dvh - 5.5rem));
    max-height: calc(100dvh - 5.5rem);
    border-radius: var(--sd-chat-radius);
    border: 1px solid rgba(41, 78, 105, 0.18);
    box-shadow: var(--sd-chat-shadow);
  }
  .sd-chat-header {
    padding: 0.85rem 1rem;
  }
  .sd-chat-footer {
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
  .sd-chat-launcher-tooltip {
    display: none;
  }
}
