/*
 * Greeting avatar widget (chat-bot style character, bottom right).
 * On-brand with the lawyer palette. Sits below the contact modal (z-index).
 */

.lawtheme-avatar-widget {
  position: fixed;
  right: clamp(16px, 2.5vw, 32px);
  bottom: clamp(16px, 2.5vw, 32px);
  z-index: 99000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 14px;
  font-family: inherit;
  pointer-events: none;
}

.lawtheme-avatar-widget > * {
  pointer-events: auto;
}

/* ---------- Floating character button ---------- */
.lawtheme-avatar-toggle {
  position: relative;
  width: clamp(60px, 7vw, 76px);
  height: clamp(60px, 7vw, 76px);
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  background: linear-gradient(160deg, #c8aecb 0%, #9a859e 100%);
  box-shadow:
    0 14px 34px rgba(74, 61, 82, 0.34),
    0 3px 10px rgba(74, 61, 82, 0.22),
    0 0 0 4px rgba(255, 255, 255, 0.85);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease;
  animation: lawthemeAvatarFloat 4.5s ease-in-out infinite;
}

.lawtheme-avatar-toggle:hover,
.lawtheme-avatar-toggle:focus-visible {
  transform: translateY(-4px) scale(1.04);
  box-shadow:
    0 20px 44px rgba(74, 61, 82, 0.4),
    0 5px 14px rgba(74, 61, 82, 0.26),
    0 0 0 4px rgba(255, 255, 255, 0.95);
  outline: none;
}

.lawtheme-avatar-toggle-img {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  overflow: hidden;
  background: #efe7ef;
  display: block;
}

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

/* Soft pulsing ring to draw the eye */
.lawtheme-avatar-toggle-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(154, 133, 158, 0.55);
  animation: lawthemeAvatarPulse 2.6s ease-out infinite;
  pointer-events: none;
}

/* Unread badge */
.lawtheme-avatar-toggle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: #d9534f;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transform: scale(1);
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.lawtheme-avatar-widget.is-open .lawtheme-avatar-toggle-badge {
  transform: scale(0);
  opacity: 0;
}

.lawtheme-avatar-widget.is-open .lawtheme-avatar-toggle-ring {
  animation: none;
}

/* ---------- Speech bubble ---------- */
.lawtheme-avatar-bubble {
  position: relative;
  width: min(320px, calc(100vw - 40px));
  background: linear-gradient(180deg, #ffffff 0%, #fbf7f2 100%);
  border: 1px solid rgba(150, 130, 95, 0.18);
  border-radius: 20px 20px 6px 20px;
  box-shadow: 0 22px 54px rgba(45, 38, 52, 0.18), 0 4px 14px rgba(45, 38, 52, 0.1);
  padding: 18px 18px 20px;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(14px) scale(0.92);
  transition: opacity 0.32s ease, transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.lawtheme-avatar-bubble[hidden] {
  display: none;
}

.lawtheme-avatar-widget.is-open .lawtheme-avatar-bubble {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* little tail toward the avatar */
.lawtheme-avatar-bubble::after {
  content: '';
  position: absolute;
  right: 26px;
  bottom: -9px;
  width: 18px;
  height: 18px;
  background: #fbf7f2;
  border-right: 1px solid rgba(150, 130, 95, 0.18);
  border-bottom: 1px solid rgba(150, 130, 95, 0.18);
  transform: rotate(45deg);
}

.lawtheme-avatar-bubble-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  background: transparent;
  color: #9a8f99;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.2s ease, color 0.2s ease;
}

.lawtheme-avatar-bubble-close:hover {
  background: rgba(154, 133, 158, 0.14);
  color: #5c4a62;
}

.lawtheme-avatar-bubble-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 22px;
  margin-bottom: 12px;
}

.lawtheme-avatar-bubble-avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  overflow: hidden;
  background: linear-gradient(160deg, #c8aecb 0%, #9a859e 100%);
  box-shadow: 0 0 0 3px rgba(200, 174, 203, 0.3);
}

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

.lawtheme-avatar-bubble-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.lawtheme-avatar-bubble-name {
  color: #2e2830;
  font-size: 15px;
  font-weight: 700;
}

.lawtheme-avatar-bubble-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #6a9a6a;
  font-size: 12.5px;
  font-weight: 600;
}

.lawtheme-avatar-bubble-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #57b757;
  box-shadow: 0 0 0 3px rgba(87, 183, 87, 0.18);
}

.lawtheme-avatar-bubble-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lawtheme-avatar-msg {
  margin: 0;
  padding: 11px 14px;
  background: rgba(197, 173, 197, 0.16);
  border: 1px solid rgba(150, 130, 95, 0.12);
  border-radius: 14px 14px 14px 4px;
  color: #4a4048;
  font-size: 14px;
  line-height: 1.55;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.lawtheme-avatar-msg.is-shown {
  opacity: 1;
  transform: translateY(0);
}

.lawtheme-avatar-msg[hidden] {
  display: none;
}

/* typing dots */
.lawtheme-avatar-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  align-self: flex-start;
  padding: 12px 14px;
  background: rgba(197, 173, 197, 0.16);
  border-radius: 14px 14px 14px 4px;
}

.lawtheme-avatar-typing[hidden] {
  display: none;
}

.lawtheme-avatar-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b09bb3;
  animation: lawthemeAvatarTyping 1.2s infinite ease-in-out;
}

.lawtheme-avatar-typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.lawtheme-avatar-typing span:nth-child(3) {
  animation-delay: 0.36s;
}

.lawtheme-avatar-cta {
  display: block;
  margin-top: 14px;
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--lawyer-btn-bg, #9a859e);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(154, 133, 158, 0.4);
  transition: background 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}

.lawtheme-avatar-cta[hidden] {
  display: none;
}

.lawtheme-avatar-cta:hover {
  background: var(--lawyer-btn-hover, #8b7790);
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(139, 119, 144, 0.45);
  color: #fff;
}

/* ---------- 3D standing character mode (Three.js) ---------- */
.lawtheme-avatar-widget.is-3d {
  right: 8px;
  bottom: 20px;
  display: block;
  width: clamp(286px, 34vw, 390px);
  height: clamp(400px, 47vw, 546px);
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-bubble {
  position: absolute;
  right: 8px;
  bottom: 52%;
  z-index: 2;
  margin-bottom: 2px;
  transform-origin: bottom right;
  transform: translateY(10px) scale(0.94);
}

.lawtheme-avatar-widget.is-3d.is-open .lawtheme-avatar-bubble {
  transform: translateY(0) scale(1);
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-bubble::after {
  right: 22px;
  bottom: -8px;
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  animation: none;
  overflow: visible;
  pointer-events: none;
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle:hover,
.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle:focus-visible {
  transform: none;
  box-shadow: none;
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle-img,
.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle-ring,
.lawtheme-avatar-widget.is-3d .lawtheme-avatar-toggle-badge {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-bubble-avatar {
  display: none;
}

.lawtheme-avatar-widget.is-3d .lawtheme-avatar-bubble-head {
  padding-right: 0;
  margin-bottom: 10px;
}

.lawtheme-avatar-3d-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: auto;
}

.lawtheme-avatar-3d-stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  cursor: default;
  pointer-events: auto;
  filter: drop-shadow(0 16px 14px rgba(45, 38, 52, 0.28));
}

/* ---------- Animations ---------- */
@keyframes lawthemeAvatarFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

@keyframes lawthemeAvatarPulse {
  0% { box-shadow: 0 0 0 0 rgba(154, 133, 158, 0.5); }
  70% { box-shadow: 0 0 0 16px rgba(154, 133, 158, 0); }
  100% { box-shadow: 0 0 0 0 rgba(154, 133, 158, 0); }
}

@keyframes lawthemeAvatarTyping {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .lawtheme-avatar-toggle,
  .lawtheme-avatar-toggle-ring,
  .lawtheme-avatar-typing span {
    animation: none !important;
  }
  .lawtheme-avatar-bubble,
  .lawtheme-avatar-msg {
    transition: opacity 0.2s ease !important;
    transform: none !important;
  }
}
