/* -------------------------------------------------------------
   Sophie chat + voice widget — Bailey Hague Joinery
   Matches site palette: forest green + cream, Fraunces + Inter
   ------------------------------------------------------------- */

:root {
  --sophie-forest: #1e3a2f;
  --sophie-forest-dark: #142720;
  --sophie-forest-light: #2a5a45;
  --sophie-cream: #f7f2e8;
  --sophie-cream-warm: #efe6d3;
  --sophie-ink: #1a1a17;
  --sophie-ink-soft: #3d3d38;
  --sophie-ink-mute: #6d6d66;
  --sophie-line: #d9cfba;
  --sophie-gold: #a97a3a;
  --sophie-shadow: 0 12px 40px rgba(20, 39, 32, 0.22);
  --sophie-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Root container ------------------------------------------ */
.sophie-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 9999;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--sophie-ink);
}

/* --- Launcher (closed state) --------------------------------- */
.sophie-launcher {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  outline: none;
}

.sophie-launcher-prompt {
  background: #fff;
  color: var(--sophie-ink);
  padding: 10px 40px 10px 16px;
  border-radius: 18px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  box-shadow: var(--sophie-shadow);
  position: relative;
  max-width: 220px;
  line-height: 1.35;
  transition: opacity 0.3s var(--sophie-ease), transform 0.3s var(--sophie-ease);
  transform-origin: right center;
}

.sophie-launcher-prompt.hidden {
  opacity: 0;
  transform: scale(0.85);
  pointer-events: none;
}

.sophie-launcher-prompt::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 14px;
  width: 0;
  height: 0;
  border-left: 8px solid #fff;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.sophie-launcher-prompt-close {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  padding: 4px;
  color: var(--sophie-ink-mute);
  cursor: pointer;
  display: flex;
  align-items: center;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
}

.sophie-launcher-prompt-close:hover {
  color: var(--sophie-ink);
  background: rgba(0, 0, 0, 0.05);
}

.sophie-launcher-prompt-title {
  display: block;
  font-weight: 600;
  color: var(--sophie-forest);
  font-size: 14px;
  line-height: 1.15;
}

.sophie-launcher-prompt-sub {
  display: block;
  font-weight: 400;
  color: #6b7263;
  font-size: 12px;
  line-height: 1.25;
}

.sophie-launcher-bubble {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--sophie-forest);
  color: #fff;
  border: 3px solid #fff;
  cursor: pointer;
  box-shadow: var(--sophie-shadow);
  padding: 0;
  overflow: visible;
  transition: transform 0.25s var(--sophie-ease), box-shadow 0.25s ease;
}

.sophie-launcher-avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.sophie-launcher-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #22c55e; /* live "available" dot */
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.06);
}

.sophie-launcher-bubble:hover {
  transform: scale(1.06);
  box-shadow: 0 12px 28px rgba(0,0,0,0.22);
}

.sophie-launcher-bubble.pulse::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--sophie-forest);
  opacity: 0.5;
  animation: sophie-pulse 2.5s infinite;
  pointer-events: none;
  z-index: -1;
}

@keyframes sophie-pulse {
  0% { transform: scale(1); opacity: 0.5; }
  100% { transform: scale(1.35); opacity: 0; }
}

/* --- Chat panel ---------------------------------------------- */
.sophie-panel {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 40px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: var(--sophie-cream);
  border-radius: 20px;
  box-shadow: var(--sophie-shadow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  transition: opacity 0.25s var(--sophie-ease), transform 0.25s var(--sophie-ease);
}

.sophie-panel.open {
  display: flex;
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* --- Panel header -------------------------------------------- */
.sophie-header {
  background: var(--sophie-forest);
  color: #fff;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.sophie-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--sophie-cream-warm);
  color: var(--sophie-forest);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}

.sophie-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sophie-header-text {
  flex: 1;
  min-width: 0;
}

.sophie-name {
  font-family: "Fraunces", Georgia, serif;
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sophie-role {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sophie-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #7bd88f;
  box-shadow: 0 0 0 3px rgba(123, 216, 143, 0.25);
}

.sophie-close {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  opacity: 0.75;
  transition: opacity 0.2s ease, background 0.2s ease;
}

.sophie-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.12);
}

/* --- Voice CTA (top of panel) -------------------------------- */
.sophie-voice-bar {
  background: var(--sophie-cream-warm);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--sophie-line);
  font-size: 13px;
}

.sophie-voice-bar.hidden {
  display: none;
}

.sophie-voice-btn {
  background: var(--sophie-forest);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.2s ease;
}

.sophie-voice-btn:hover:not(:disabled) {
  background: var(--sophie-forest-dark);
}

.sophie-voice-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sophie-voice-btn.calling {
  background: #b23c3c;
}

.sophie-voice-btn.calling:hover {
  background: #952f2f;
}

.sophie-voice-note {
  font-size: 12px;
  color: var(--sophie-ink-mute);
}

.sophie-voice-timer {
  font-size: 12px;
  color: var(--sophie-forest);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* --- Message list -------------------------------------------- */
.sophie-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--sophie-line) transparent;
}

.sophie-messages::-webkit-scrollbar {
  width: 6px;
}

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

.sophie-msg {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: sophie-msg-in 0.25s var(--sophie-ease);
}

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

.sophie-msg.assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--sophie-ink);
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(20, 39, 32, 0.05);
}

.sophie-msg.user {
  align-self: flex-end;
  background: var(--sophie-forest);
  color: #fff;
  border-bottom-right-radius: 6px;
}

.sophie-msg.system {
  align-self: center;
  background: transparent;
  color: var(--sophie-ink-mute);
  font-size: 12px;
  font-style: italic;
  padding: 4px 8px;
  text-align: center;
}

/* "Send this to the team" backstop button */
.sophie-msg.sophie-send-cta {
  align-self: stretch;
  padding: 8px 0;
  font-style: normal;
}
.sophie-send-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  background: var(--sophie-accent, #14532d);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.sophie-send-btn:hover:not(:disabled) {
  background: var(--sophie-accent-hover, #0f3d21);
}
.sophie-send-btn:active:not(:disabled) {
  transform: scale(0.98);
}
.sophie-send-btn:disabled {
  opacity: 0.7;
  cursor: default;
}
.sophie-send-cta-done .sophie-send-btn {
  background: #4b6b3a;
  color: #fff;
}

.sophie-typing {
  align-self: flex-start;
  background: #fff;
  padding: 12px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 6px;
  box-shadow: 0 1px 2px rgba(20, 39, 32, 0.05);
  display: none;
}

.sophie-typing.show {
  display: flex;
  gap: 4px;
}

.sophie-typing span {
  width: 6px;
  height: 6px;
  background: var(--sophie-ink-mute);
  border-radius: 50%;
  animation: sophie-bounce 1.2s infinite;
}

.sophie-typing span:nth-child(2) { animation-delay: 0.15s; }
.sophie-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes sophie-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* --- Composer (input) ---------------------------------------- */
.sophie-composer {
  padding: 12px 16px 16px 16px;
  border-top: 1px solid var(--sophie-line);
  background: var(--sophie-cream);
}

.sophie-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: #fff;
  border: 1px solid var(--sophie-line);
  border-radius: 22px;
  padding: 4px 6px 4px 14px;
  transition: border-color 0.2s ease;
}

.sophie-input-row:focus-within {
  border-color: var(--sophie-forest);
}

.sophie-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 0;
  font-family: inherit;
  font-size: 14px;
  color: var(--sophie-ink);
  background: transparent;
  resize: none;
  max-height: 100px;
  min-height: 20px;
  line-height: 1.4;
}

.sophie-input::placeholder {
  color: var(--sophie-ink-mute);
}

.sophie-send {
  background: var(--sophie-forest);
  color: #fff;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, opacity 0.2s ease;
  flex-shrink: 0;
}

.sophie-send:hover:not(:disabled) {
  background: var(--sophie-forest-dark);
}

.sophie-send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.sophie-footer {
  text-align: center;
  font-size: 11px;
  color: var(--sophie-ink-mute);
  margin-top: 8px;
}

/* --- Mobile responsiveness ----------------------------------- */
@media (max-width: 480px) {
  .sophie-widget {
    right: 12px;
    bottom: 12px;
  }
  .sophie-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 100px);
    bottom: 76px;
  }
  .sophie-launcher-prompt {
    display: none;
  }
}

/* --- Reduced motion ------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .sophie-widget *, .sophie-widget *::before, .sophie-widget *::after {
    animation: none !important;
    transition: none !important;
  }
}
