/* ============================================================
   Joe Pimentel — homepage
   Large uncropped JosePimentel.png (transparent PNG) on the LEFT
   (bottom-aligned), floating Intercom-style chat panel on the RIGHT.
   The avatar has an alpha channel, so the page uses its own clean
   light background — it no longer needs to match a baked-in gray box.
   ============================================================ */

:root {
  --jp-text: #1d1d1f;
  --jp-muted: #6e6e73;
  --jp-line: rgba(17, 24, 39, .10);
  --jp-ink: #1f2024;            /* dark header / user bubble / send */
  --jp-ink-soft: #2b2c31;
  --jp-bot: #f1f3f5;            /* bot bubble */
  --jp-online: #34c759;
  --jp-card: #ffffff;
  --jp-shadow: 0 26px 70px rgba(15, 23, 42, .20);

  /* Mouth placement fallbacks — calibrated to JosePimentel.png.
     avatar-home.js overrides these from layers.mouth.placement.
     left/top = mouth CENTER (translate(-50%,-50%)). */
  --avatar-mouth-left: 48.4%;
  --avatar-mouth-top: 38.7%;
  --avatar-mouth-bottom: auto;
  --avatar-mouth-width: 12.0%;
  --avatar-mouth-transform: translate(-50%, -50%);
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.avatar-home-body {
  margin: 0;
  min-height: 100svh;
  overflow-x: hidden;
  /* Clean, soft light background with subtle radial depth. The avatar PNG
     is transparent, so this no longer has to camouflage a gray image box. */
  background:
    radial-gradient(1100px 620px at 16% 100%, rgba(0, 113, 227, .06), transparent 62%),
    radial-gradient(900px 540px at 88% -10%, rgba(31, 32, 36, .05), transparent 58%),
    linear-gradient(180deg, #ffffff 0%, #f4f6f9 60%, #eef1f5 100%);
  color: var(--jp-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---- Two-column shell ------------------------------------------- */
.jp-home-shell {
  min-height: 100svh;
  display: grid;
  grid-template-columns: minmax(420px, 60vw) minmax(340px, 40vw);
  align-items: stretch;
}

/* ---- Avatar (left) ---------------------------------------------- */
.jp-avatar-stage {
  position: relative;
  min-height: 100svh;
  display: flex;
  align-items: flex-end;     /* image bottom on viewport bottom */
  justify-content: center;
  overflow: hidden;
}

/* Soft floor shadow grounding the figure to the page. */
.jp-avatar-stage::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -14px;
  transform: translateX(-50%);
  width: min(58%, 480px);
  height: 42px;
  border-radius: 50%;
  background: radial-gradient(50% 50% at 50% 50%, rgba(15, 23, 42, .16), transparent 72%);
  filter: blur(6px);
  pointer-events: none;
  z-index: 0;
}

/* The lockup shrink-wraps the image, so this positioned box always
   equals the rendered image box → the mouth layer is locked to the
   face and can never drift relative to it. */

/* WebP <picture> wrapper adds NO box — the <img> stays the layout
   element, so the avatar mouth-rig positioning is unchanged. */
.avatar-pic { display: contents; }

.jp-avatar-lockup {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: flex-end;
  height: auto;
  transform-origin: bottom center;
  animation:
    jp-enter-avatar .8s ease-out both,
    jp-breathe 7.5s ease-in-out .9s infinite;
  will-change: transform;
}

/* Tap/click the avatar to stop it mid-sentence (bound in JS). */
.avatar-home[data-state="speaking"] .jp-avatar-lockup { cursor: pointer; }

.jp-avatar-image {
  display: block;
  height: auto;
  width: auto;
  max-height: 100svh;        /* full height, no crop */
  max-width: 100%;
  object-fit: contain;       /* never cover/crop */
  object-position: bottom center;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
}

/* Mouth overlay / procedural rig — absolutely positioned INSIDE the
   same frame as the image, so they always move together. */
.avatar-home-mouth,
.avatar-rig-mouth {
  position: absolute;
  left: var(--avatar-mouth-left);
  top: var(--avatar-mouth-top);
  bottom: var(--avatar-mouth-bottom);
  width: var(--avatar-mouth-width);
  transform: var(--avatar-mouth-transform);
  pointer-events: none;
  z-index: 3;
}
.avatar-rig-mouth { height: auto; aspect-ratio: 240 / 160; overflow: visible; }
.avatar-home[data-rig="true"] .avatar-home-mouth { display: none; }

/* The portrait already has a well-drawn mouth, so the procedural rig stays
   hidden at rest and only fades in while the avatar is actually speaking
   (or celebrating a completed lead) — no synthetic double-mouth, no fake
   look when idle. */
.avatar-rig-mouth { opacity: 0; transition: opacity .3s ease; }
.avatar-home[data-state="speaking"] .avatar-rig-mouth,
.avatar-home[data-state="happy"] .avatar-rig-mouth { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .avatar-rig-mouth { opacity: 0 !important; }
}

/* Gentle head life while speaking, layered additively onto the breathing
   transform. Gated on animation-composition support so browsers without
   it keep plain breathing (no transform snap when speech ends). */
@supports (animation-composition: add) {
  .avatar-home[data-state="speaking"] .jp-avatar-lockup {
    animation:
      jp-enter-avatar .8s ease-out both,
      jp-breathe 7.5s ease-in-out .9s infinite,
      jp-talk 2.2s ease-in-out infinite;
    animation-composition: replace, replace, add;
  }
}

@keyframes jp-breathe {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

@keyframes jp-talk {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  30% { transform: translateY(-1.6px) rotate(.22deg); }
  70% { transform: translateY(.8px) rotate(-.18deg); }
}

@keyframes jp-enter-avatar {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes jp-rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- Chat panel (right) ----------------------------------------- */
.jp-chat-stage {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(18px, 2.6vh, 28px);
  padding: clamp(20px, 4vw, 56px);
}

/* Hero copy above the chat card (also the page's h1). */
.jp-hero-copy {
  width: min(100%, 400px);
  animation: jp-rise .6s ease-out both;
}
.jp-hero-eyebrow {
  margin: 0 0 8px;
  color: #0071e3;
  font-weight: 700;
  font-size: .74rem;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.jp-hero-title {
  margin: 0 0 8px;
  font-size: clamp(1.9rem, 3.4vw, 2.6rem);
  line-height: 1.05;
  letter-spacing: -.02em;
}
.jp-hero-sub {
  margin: 0;
  color: var(--jp-muted);
  font-size: 1.02rem;
  line-height: 1.5;
  max-width: 42ch;
}

.jp-chat-card {
  width: min(100%, 400px);
  max-height: min(80svh, 660px);
  display: flex;
  flex-direction: column;
  background: var(--jp-card);
  border: 1px solid var(--jp-line);
  border-radius: 22px;
  box-shadow: var(--jp-shadow);
  overflow: hidden;
  animation: jp-rise .6s .12s ease-out both;
}

/* Header — dark bar with title + online status + controls */
.jp-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--jp-ink);
  color: #fff;
}
.jp-chat-ident { display: flex; align-items: center; gap: 10px; line-height: 1.15; }
.jp-chat-ident-text { display: flex; flex-direction: column; gap: 2px; }
.jp-chat-avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  background: #fff;
  border: 1px solid rgba(255, 255, 255, .35);
  display: block;
}
.jp-chat-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 12%;   /* the face sits near the top of the portrait */
  transform: scale(1.7);
  transform-origin: 50% 14%;
  display: block;
}
.jp-chat-title { font-weight: 700; font-size: 1rem; }
.jp-chat-online {
  display: flex; align-items: center; gap: 6px;
  font-size: .72rem; color: #c9cdd4;
}
.jp-chat-online i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--jp-online); display: inline-block;
}
.jp-chat-head-actions { display: flex; align-items: center; gap: 4px; }
.jp-head-btn {
  width: 30px; height: 30px; border: 0; border-radius: 8px;
  background: transparent; color: #fff; opacity: .75;
  cursor: pointer; display: grid; place-items: center;
  font-size: 1.1rem; line-height: 1; padding: 0;
}
.jp-head-btn:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.jp-head-btn svg { width: 16px; height: 16px; }

/* Body — scrollable transcript */
.jp-chat-body {
  flex: 1;
  min-height: 220px;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fff;
  scrollbar-width: thin;
  scrollbar-color: #ced4db transparent;
}
.jp-chat-body::-webkit-scrollbar { width: 8px; }
.jp-chat-body::-webkit-scrollbar-thumb { background: #ced4db; border-radius: 8px; }
.jp-chat-body::-webkit-scrollbar-track { background: transparent; }
.avatar-home-messages { display: flex; flex-direction: column; gap: 14px; }

.jp-msg {
  display: flex; flex-direction: column; gap: 4px; max-width: 84%;
  animation: jp-msg-in .26s ease-out both;
}
.jp-msg--bot { align-self: flex-start; align-items: flex-start; }
.jp-msg--user { align-self: flex-end; align-items: flex-end; }
.jp-msg-meta {
  display: flex; align-items: center; gap: 6px;
  font-size: .68rem; color: #9aa0a8;
}
.jp-msg-meta i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--jp-online); display: inline-block;
}
.jp-bubble {
  padding: 10px 14px;
  font-size: .95rem;
  line-height: 1.45;
  border-radius: 16px;
  word-break: break-word;
  white-space: pre-line;     /* multi-line AI / lead-flow replies keep breaks */
}
.jp-msg--bot .jp-bubble {
  background: var(--jp-bot); color: var(--jp-text);
  border-bottom-left-radius: 5px;
}
.jp-msg--bot .jp-bubble a { color: #0b62c4; text-decoration: underline; }
.jp-msg--user .jp-bubble {
  background: var(--jp-ink); color: #fff;
  border-bottom-right-radius: 5px;
}
.jp-msg--error .jp-bubble {
  background: #fdecec; color: #9b1c1c;
}

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

/* "Jose is typing" — three bouncing dots in a bot bubble */
.jp-typing-bubble {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 20px;
}
.jp-typing-bubble i {
  width: 7px; height: 7px; border-radius: 50%;
  background: #aab2bb; display: inline-block;
  animation: jp-typing 1.2s ease-in-out infinite;
}
.jp-typing-bubble i:nth-child(2) { animation-delay: .15s; }
.jp-typing-bubble i:nth-child(3) { animation-delay: .3s; }

@keyframes jp-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Chips: starter suggestions + reply actions (compact, in body) */
.avatar-home-actions,
.avatar-home-suggestions { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-home-actions { margin-top: 2px; }
.avatar-home-suggestions { margin-top: 2px; }
.avatar-home-actions:empty,
.avatar-home-suggestions:empty { display: none; }
.jp-chip {
  border: 1px solid var(--jp-line);
  border-radius: 980px;
  padding: 8px 14px;
  font: inherit; font-size: .84rem; font-weight: 600;
  cursor: pointer; text-decoration: none; display: inline-block;
  background: #fff; color: var(--jp-text);
  transition: background .15s ease, transform .12s ease;
}
.jp-chip--primary { background: var(--jp-ink); color: #fff; border-color: var(--jp-ink); }
.jp-chip--primary:hover { background: var(--jp-ink-soft); }
.jp-chip--ghost:hover { background: #f1f3f5; }
.jp-chip:active { transform: translateY(1px); }

/* Input row */
.avatar-home-form {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 14px;
  border-top: 1px solid var(--jp-line);
  background: #fff;
}
.avatar-home-input {
  flex: 1; min-width: 0;
  border: 0; background: #f1f3f5;
  border-radius: 980px;
  padding: 12px 16px;
  font: inherit; font-size: .95rem; color: var(--jp-text);
}
.avatar-home-input::placeholder { color: #9aa0a8; }
.avatar-home-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(31, 32, 36, .14);
}
.avatar-home-send {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--jp-ink); color: #fff;
  display: grid; place-items: center; cursor: pointer;
}
.avatar-home-send:hover { background: var(--jp-ink-soft); }
.avatar-home-send:disabled { opacity: .55; cursor: progress; }
.avatar-home-send svg { width: 18px; height: 18px; }

/* Optional Web Speech mic button (revealed by JS only when supported) */
.avatar-home-mic {
  flex: none; width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--jp-line); background: #fff; color: var(--jp-text);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.avatar-home-mic[hidden] { display: none; }
.avatar-home-mic:hover { background: #f1f3f5; }
.avatar-home-mic svg { width: 18px; height: 18px; }
.avatar-home-mic--on {
  background: var(--jp-ink); color: #fff; border-color: var(--jp-ink);
  box-shadow: 0 0 0 4px rgba(31, 32, 36, .14);
}

/* "Was this helpful?" feedback under a reply (subtle, Apple-style) */
.jp-feedback {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 0 2px; padding-left: 2px;
}
.jp-feedback-q { font-size: .72rem; color: var(--jp-muted); }
.jp-feedback-btn {
  display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--jp-line); background: #fff;
  color: var(--jp-muted); cursor: pointer;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.jp-feedback-btn:hover { background: #f1f3f5; color: var(--jp-text); border-color: var(--jp-text); }
.jp-feedback-btn svg { width: 14px; height: 14px; }
.jp-feedback-done { font-size: .72rem; color: var(--jp-muted); }

/* Privacy controls (small, muted) */
.avatar-home-privacy {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  padding: 0 16px 12px;
  font-size: .74rem; color: var(--jp-muted);
  background: #fff;
}
.avatar-home-privacy:empty { display: none; }
.avatar-home-privacy a { color: var(--jp-text); }
.jp-link-btn {
  background: none; border: 0; padding: 0;
  color: var(--jp-text); font: inherit; font-size: .74rem;
  cursor: pointer; text-decoration: underline;
}
.jp-dnl { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Collapsed (minimized) — only the header shows */
.jp-chat-card[data-collapsed="true"] .jp-chat-body,
.jp-chat-card[data-collapsed="true"] .avatar-home-form,
.jp-chat-card[data-collapsed="true"] .avatar-home-privacy { display: none; }

/* Corner badges — bottom-right, stacked (Status always when enabled,
   Admin only when show_admin_link). */
.jp-corner-badges {
  position: fixed; right: 18px; bottom: 16px; z-index: 40;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.jp-status-badge,
.jp-admin-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px; border-radius: 12px;
  font-size: .82rem; font-weight: 600; text-decoration: none;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .26);
}
.jp-admin-badge { background: var(--jp-ink); color: #fff; }
.jp-admin-badge:hover { background: var(--jp-ink-soft); }
.jp-status-badge { background: rgba(255, 255, 255, .92); color: var(--jp-ink);
  border: 1px solid rgba(17, 24, 39, .12); backdrop-filter: blur(8px); }
.jp-status-badge:hover { background: #fff; }
.jp-admin-dot,
.jp-status-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.jp-admin-dot { background: var(--jp-online); }
.jp-status-dot { background: #9aa3b2; }
.jp-status-operational .jp-status-dot { background: #1ba672; }
.jp-status-degraded .jp-status-dot { background: #c77700; }
.jp-status-partial_outage .jp-status-dot,
.jp-status-major_outage .jp-status-dot { background: #c0392b; }
.jp-status-maintenance .jp-status-dot { background: #3b6fb5; }
@media (max-width: 560px) {
  .jp-corner-badges { right: 12px; bottom: 12px; gap: 6px; }
  .jp-status-badge, .jp-admin-badge { padding: 7px 12px; font-size: .78rem; }
}

/* Accessibility: visible focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
.jp-chip:focus-visible {
  outline: 3px solid rgba(31, 32, 36, .5);
  outline-offset: 2px;
}

/* ---- Mobile / tablet -------------------------------------------- */
@media (max-width: 900px) {
  .jp-home-shell { display: flex; flex-direction: column; min-height: 100svh; }
  .jp-avatar-stage { min-height: auto; padding-top: 64px; }
  .jp-avatar-stage::after { bottom: -10px; height: 26px; }
  .jp-avatar-lockup { width: min(92vw, 480px); height: auto; }
  .jp-avatar-image { width: 100%; height: auto; max-height: 48svh; }
  .jp-chat-stage { min-height: auto; gap: 14px; padding: 14px 14px 96px; }
  .jp-hero-copy { width: 100%; }
  .jp-hero-title { font-size: clamp(1.6rem, 6.4vw, 2.1rem); }
  .jp-hero-sub { font-size: .95rem; }
  .jp-chat-card { width: 100%; max-height: none; }
  .jp-chat-body { min-height: 180px; max-height: 50svh; }
}

/* ---- Reduced motion --------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .jp-avatar-lockup,
  .jp-hero-copy,
  .jp-chat-card,
  .jp-msg,
  .jp-typing-bubble i { animation: none !important; }
  * { transition: none !important; }
}
