/* ============================================================
   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. The avatar PNG is transparent, so this
     no longer has to camouflage a gray image box. */
  background:
    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;
}

/* 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;
  display: flex;
  align-items: flex-end;
  height: auto;
  transform-origin: bottom center;
  animation: jp-breathe 7.5s ease-in-out infinite;
  will-change: transform;
}

.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 —
   no synthetic double-mouth, no fake look when idle. */
.avatar-rig-mouth { opacity: 0; transition: opacity .22s ease; }
.avatar-home[data-state="speaking"] .avatar-rig-mouth { opacity: 1; }
@media (prefers-reduced-motion: reduce) {
  .avatar-rig-mouth { opacity: 0 !important; }
}

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

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

.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;
}

/* Header — dark bar with title + online status + controls */
.jp-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--jp-ink);
  color: #fff;
}
.jp-chat-ident { display: flex; flex-direction: column; gap: 2px; line-height: 1.15; }
.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;
}
.avatar-home-messages { display: flex; flex-direction: column; gap: 14px; }

.jp-msg { display: flex; flex-direction: column; gap: 4px; max-width: 84%; }
.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;
}
.jp-msg--bot .jp-bubble {
  background: var(--jp-bot); color: var(--jp-text);
  border-bottom-left-radius: 5px;
}
.jp-msg--user .jp-bubble {
  background: var(--jp-ink); color: #fff;
  border-bottom-right-radius: 5px;
}

/* 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: 12px; }
  .jp-avatar-lockup { width: min(92vw, 480px); height: auto; }
  .jp-avatar-image { width: 100%; height: auto; max-height: 52svh; }
  .jp-chat-stage { min-height: auto; padding: 12px 14px 84px; }
  .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 { animation: none; }
  * { transition: none !important; }
}
