/* ============================================================
   MAX — Left Coast Exteriors Mascot Widget
   Home page only. Self-contained, no dependencies.
   Z-index ceiling: 800 (below mobile-nav at 998/999)
   ============================================================ */

/* ── Root positioning ──────────────────────────────────────── */
.max-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 800;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  /* Prevent widget from being a focus trap before it appears */
  pointer-events: none;
}
.max-widget.is-ready { pointer-events: auto; }

/* ── Keyframes ─────────────────────────────────────────────── */
@keyframes max-entrance {
  from {
    opacity: 0;
    transform: translateY(72px) scale(0.8);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes max-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

@keyframes max-badge-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(245, 196, 25, 0.5); }
  60%       { transform: scale(1.12); box-shadow: 0 0 0 6px rgba(245, 196, 25, 0); }
}

/* ── Trigger (minimized bubble) ────────────────────────────── */
.max-trigger {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 3px solid var(--gold);
  background: var(--navy-dark);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22), 0 2px 8px rgba(0, 0, 0, 0.14);
  transition: box-shadow 0.25s ease, border-color 0.25s ease;
  /* Hidden until JS fires entrance */
  opacity: 0;
  pointer-events: none;
}

.max-trigger.is-visible {
  pointer-events: auto;
  animation:
    max-entrance 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
    max-float 3.2s ease-in-out 0.6s infinite;
}

.max-trigger:hover,
.max-trigger:focus-visible {
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.28), 0 0 0 4px rgba(245, 196, 25, 0.25);
  border-color: var(--gold);
  outline: none;
}

/* Pause float when panel is open */
.max-widget.is-open .max-trigger {
  animation-play-state: paused, paused;
}

.max-trigger-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Crop to head + hard hat — top ~18% of portrait image */
  object-position: center 10%;
  pointer-events: none;
}

/* Unread badge */
.max-unread {
  position: absolute;
  top: 0;
  right: 0;
  width: 20px;
  height: 20px;
  background: var(--gold);
  color: var(--navy-dark);
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 800;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
  animation: max-badge-pulse 2.4s ease-in-out 1.2s infinite;
  pointer-events: none;
}
.max-unread.is-hidden { display: none; }

/* ── Panel (expanded state) ────────────────────────────────── */
.max-panel {
  width: 308px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.16), 0 4px 16px rgba(0, 0, 0, 0.10);
  border: 1px solid rgba(0, 0, 0, 0.08);
  overflow: hidden;

  /* Entry state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  pointer-events: none;
  transition:
    opacity 0.28s cubic-bezier(0.22, 1, 0.36, 1),
    transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: opacity, transform;
}

.max-widget.is-open .max-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Speech bubble tail → triangle pointing down-right at trigger */
.max-panel::after {
  content: '';
  position: absolute;
  bottom: -9px;
  right: 28px;
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 9px solid var(--white);
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.06));
  pointer-events: none;
}

/* ── Panel — header bar ────────────────────────────────────── */
.max-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 12px 14px;
  background: var(--navy-dark);
  /* Gold top accent line */
  border-top: 3px solid var(--gold);
}

.max-identity {
  display: flex;
  align-items: center;
  gap: 10px;
}

.max-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 10%;
  border: 2px solid var(--gold);
  flex-shrink: 0;
}

.max-identity-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.max-name {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--white);
  line-height: 1;
}

.max-tagline {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
  font-weight: 500;
  line-height: 1;
}

.max-dismiss {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.2s ease, color 0.2s ease;
}
.max-dismiss:hover { background: rgba(255, 255, 255, 0.2); color: var(--white); }
.max-dismiss:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.max-dismiss svg { width: 14px; height: 14px; }

/* ── Panel — messages ──────────────────────────────────────── */
.max-panel-body {
  padding: 16px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--gray-50, #f8f9fa);
}

.max-msg {
  max-width: 88%;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Stagger messages in after panel opens */
.max-widget.is-open .max-msg--1 {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.18s;
}
.max-widget.is-open .max-msg--2 {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 0.36s;
}

.max-msg p {
  background: var(--navy-dark);
  color: rgba(255, 255, 255, 0.92);
  font-size: 0.8125rem;
  line-height: 1.6;
  padding: 10px 13px;
  border-radius: 12px 12px 12px 4px;
  margin: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.10);
}

/* ── Panel — CTA footer ────────────────────────────────────── */
.max-panel-cta {
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--white);
  border-top: 1px solid rgba(0, 0, 0, 0.07);
}

.max-cta-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--gold);
  color: var(--navy-dark);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  text-decoration: none;
  padding: 11px 16px;
  border-radius: 8px;
  letter-spacing: 0.02em;
  transition: background 0.2s ease, transform 0.15s ease;
}
.max-cta-primary:hover {
  background: #e8b800;
  transform: translateY(-1px);
}
.max-cta-primary svg { width: 14px; height: 14px; flex-shrink: 0; }

.max-cta-phone {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: var(--navy-dark);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  padding: 8px;
  border-radius: 6px;
  transition: background 0.2s ease;
}
.max-cta-phone:hover { background: var(--gray-50, #f8f9fa); }
.max-cta-phone svg { width: 13px; height: 13px; flex-shrink: 0; color: var(--navy); }

/* ── Mobile adjustments ────────────────────────────────────── */
@media (max-width: 480px) {
  .max-widget {
    bottom: 16px;
    right: 16px;
  }
  .max-trigger {
    width: 60px;
    height: 60px;
  }
  .max-panel {
    width: calc(100vw - 32px);
    max-width: 308px;
  }
}

/* ── Reduced motion — disable all animation ─────────────────── */
@media (prefers-reduced-motion: reduce) {
  .max-trigger.is-visible {
    animation: none;
    opacity: 1;
    transform: none;
  }
  .max-panel {
    transition: opacity 0.15s ease;
    transform: none;
  }
  .max-widget.is-open .max-panel {
    transform: none;
  }
  .max-msg {
    transition: opacity 0.15s ease;
    transform: none;
  }
  .max-widget.is-open .max-msg--1,
  .max-widget.is-open .max-msg--2 {
    transform: none;
  }
  .max-unread { animation: none; }
}
