/* ==========================================================================
   MS Consulting Group — Site chat assistant
   Uses site design tokens from styles.css when available
   ========================================================================== */

.msc-chat {
  --msc-chat-z: 200;
  --msc-chat-accent: var(--accent, #1a3c34);
  --msc-chat-gold: var(--accent-2, #c4a35a);
  --msc-chat-bg: var(--bg, #f7f5f0);
  --msc-chat-ink: var(--ink, #121212);
  --msc-chat-muted: var(--muted, #5c5c5c);
  --msc-chat-line: var(--line, #e2ddd4);
  --msc-chat-white: var(--white, #fff);
  --msc-chat-display: var(--font-display, "Fraunces", Georgia, serif);
  --msc-chat-body: var(--font-body, "DM Sans", system-ui, sans-serif);
  --msc-chat-radius: 12px;
  --msc-chat-ease: var(--ease, ease);
  --msc-chat-dur: var(--dur, 200ms);

  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: var(--msc-chat-z);
  font-family: var(--msc-chat-body);
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--msc-chat-ink);
  pointer-events: none;
}

.msc-chat *,
.msc-chat *::before,
.msc-chat *::after {
  box-sizing: border-box;
}

.msc-chat button,
.msc-chat a,
.msc-chat input,
.msc-chat .msc-chat-panel {
  pointer-events: auto;
}

/* Launcher ---------------------------------------------------------------- */

.msc-chat-launcher {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 56px;
  min-height: 56px;
  padding: 14px 20px;
  border: 2px solid var(--msc-chat-gold);
  border-radius: 999px;
  background: #1a3c34;
  color: #fff;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow:
    0 10px 36px rgba(18, 18, 18, 0.32),
    0 0 0 4px rgba(196, 163, 90, 0.28);
  transition: background var(--msc-chat-dur) var(--msc-chat-ease),
    transform var(--msc-chat-dur) var(--msc-chat-ease),
    box-shadow var(--msc-chat-dur) var(--msc-chat-ease);
}

.msc-chat-launcher:hover {
  background: #14302a;
  box-shadow:
    0 14px 40px rgba(18, 18, 18, 0.38),
    0 0 0 5px rgba(196, 163, 90, 0.35);
}

.msc-chat-launcher:focus-visible {
  outline: 3px solid var(--msc-chat-gold);
  outline-offset: 3px;
}

.msc-chat-launcher[aria-expanded="true"] {
  background: #14302a;
}

.msc-chat-launcher-icon {
  display: inline-flex;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  color: #fff;
}

.msc-chat-launcher-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.msc-chat-launcher-label {
  white-space: nowrap;
  color: #fff;
}

.msc-chat-launcher-label--short {
  display: none;
}

/* Soft pulse once on load (respect reduced motion) */
.msc-chat-launcher.is-pulse {
  animation: msc-chat-pulse 1.4s ease-out 1;
}

@keyframes msc-chat-pulse {
  0% {
    box-shadow:
      0 10px 36px rgba(18, 18, 18, 0.32),
      0 0 0 4px rgba(196, 163, 90, 0.28);
  }
  40% {
    box-shadow:
      0 12px 40px rgba(18, 18, 18, 0.36),
      0 0 0 12px rgba(196, 163, 90, 0.18);
  }
  100% {
    box-shadow:
      0 10px 36px rgba(18, 18, 18, 0.32),
      0 0 0 4px rgba(196, 163, 90, 0.28);
  }
}

@media (max-width: 480px) {
  .msc-chat-launcher {
    min-width: 64px;
    min-height: 56px;
    padding: 12px 16px;
    gap: 8px;
    font-size: 0.875rem;
  }

  .msc-chat-launcher-label--full {
    display: none;
  }

  .msc-chat-launcher-label--short {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  .msc-chat-launcher.is-pulse {
    animation: none;
  }
}

/* Panel ------------------------------------------------------------------- */

.msc-chat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 24px));
  height: min(560px, calc(100vh - 100px));
  max-height: calc(100dvh - 100px);
  background: var(--msc-chat-bg);
  border: 1px solid var(--msc-chat-line);
  border-radius: var(--msc-chat-radius);
  box-shadow: 0 16px 48px rgba(18, 18, 18, 0.2);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity var(--msc-chat-dur) var(--msc-chat-ease),
    transform var(--msc-chat-dur) var(--msc-chat-ease),
    visibility var(--msc-chat-dur) var(--msc-chat-ease);
}

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

.msc-chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 14px;
  background: #1a3c34;
  color: #fff;
}

.msc-chat-header-text {
  min-width: 0;
  color: #fff;
}

.msc-chat-title {
  margin: 0;
  font-family: var(--msc-chat-display);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: #fff !important;
}

.msc-chat-subtitle {
  margin: 4px 0 0;
  font-size: 0.8125rem;
  line-height: 1.4;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.92) !important;
  opacity: 1;
}

.msc-chat-header .msc-chat-close {
  color: #fff;
}

.msc-chat-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin: -6px -6px 0 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background var(--msc-chat-dur) var(--msc-chat-ease);
}

.msc-chat-close:hover {
  background: rgba(255, 255, 255, 0.12);
}

.msc-chat-close:focus-visible {
  outline: 2px solid var(--msc-chat-gold);
  outline-offset: 2px;
}

.msc-chat-close svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* Messages ---------------------------------------------------------------- */

.msc-chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msc-chat-disclaimer {
  align-self: stretch;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(196, 163, 90, 0.16);
  border: 1px solid rgba(196, 163, 90, 0.35);
  color: var(--msc-chat-ink);
  font-size: 0.75rem;
  line-height: 1.45;
}

.msc-chat-bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.msc-chat-bubble p {
  margin: 0 0 0.55em;
}

.msc-chat-bubble p:last-child {
  margin-bottom: 0;
}

.msc-chat-bubble-bot {
  align-self: flex-start;
  background: var(--msc-chat-white);
  border: 1px solid var(--msc-chat-line);
  border-bottom-left-radius: 4px;
  color: var(--msc-chat-ink);
}

.msc-chat-bubble-user {
  align-self: flex-end;
  background: var(--msc-chat-accent);
  color: var(--msc-chat-white);
  border-bottom-right-radius: 4px;
}

.msc-chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.msc-chat-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--msc-chat-dur) var(--msc-chat-ease),
    color var(--msc-chat-dur) var(--msc-chat-ease),
    border-color var(--msc-chat-dur) var(--msc-chat-ease);
}

.msc-chat-action:focus-visible {
  outline: 2px solid var(--msc-chat-gold);
  outline-offset: 2px;
}

.msc-chat-action-primary {
  background: var(--msc-chat-accent);
  color: var(--msc-chat-white);
  border: 1px solid var(--msc-chat-accent);
}

.msc-chat-action-primary:hover {
  background: #14302a;
  color: var(--msc-chat-white);
}

.msc-chat-action-secondary {
  background: transparent;
  color: var(--msc-chat-accent);
  border: 1px solid var(--msc-chat-line);
}

.msc-chat-action-secondary:hover {
  border-color: var(--msc-chat-accent);
  color: var(--msc-chat-ink);
}

/* Suggested chips --------------------------------------------------------- */

.msc-chat-suggestions {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 14px 12px;
}

.msc-chat-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--msc-chat-line);
  border-radius: 999px;
  background: var(--msc-chat-white);
  color: var(--msc-chat-ink);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--msc-chat-dur) var(--msc-chat-ease),
    border-color var(--msc-chat-dur) var(--msc-chat-ease);
}

.msc-chat-chip:hover {
  border-color: var(--msc-chat-accent);
  background: #fff;
}

.msc-chat-chip:focus-visible {
  outline: 2px solid var(--msc-chat-accent);
  outline-offset: 2px;
}

/* Composer ---------------------------------------------------------------- */

.msc-chat-composer {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--msc-chat-line);
  background: var(--msc-chat-white);
}

.msc-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--msc-chat-line);
  border-radius: 10px;
  background: var(--msc-chat-bg);
  color: var(--msc-chat-ink);
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.4;
}

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

.msc-chat-input:focus {
  outline: 2px solid var(--msc-chat-accent);
  outline-offset: 0;
  border-color: var(--msc-chat-accent);
}

.msc-chat-send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--msc-chat-accent);
  color: var(--msc-chat-white);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--msc-chat-dur) var(--msc-chat-ease);
}

.msc-chat-send:hover {
  background: #14302a;
}

.msc-chat-send:focus-visible {
  outline: 2px solid var(--msc-chat-gold);
  outline-offset: 2px;
}

.msc-chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  .msc-chat-panel,
  .msc-chat-launcher,
  .msc-chat-chip,
  .msc-chat-action,
  .msc-chat-send,
  .msc-chat-close {
    transition: none;
  }

  .msc-chat-messages {
    scroll-behavior: auto;
  }
}
