/* ============================================
   Ria — Personal AI Buddy for EventSphereX
   Dark theme, lime accent, topographic wave bg.
   Replaced by 3D VRM scene in Phase C.
   ============================================ */

#ria-root {
  --ria-bg: #0a1210;
  --ria-bg-2: #121a18;
  --ria-panel: #141e1b;
  --ria-surface: #1b2623;
  --ria-surface-2: #22302c;
  --ria-border: rgba(255, 255, 255, 0.08);
  --ria-border-2: rgba(179, 210, 55, 0.22);
  --ria-text: #f2f7f4;
  --ria-text-dim: #a4b3af;
  --ria-muted: #6b7b77;
  --ria-lime: #b3d237;
  --ria-lime-2: #c4e24a;
  --ria-cyan: #5ee7ff;
  --ria-pink: #e8a9c2;
  --ria-violet: #c9b3f0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ria-text);
}

/* === LAUNCHER (single floating pill, not a circle + separate label) ===
   Single element = no off-screen clipping. Mascot face + "Ask Ria" text + status dot,
   all inside one rounded pill. Lifted 84px above the page bottom so it clears the
   site's existing .back-to-top button (which lives at bottom:24px right:24px). */

.ria-launcher {
  position: fixed;
  bottom: 84px;
  right: 16px;
  z-index: 9999;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 8px;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--ria-lime), var(--ria-lime-2));
  color: var(--ria-bg);
  font-family: inherit;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow:
    0 12px 30px rgba(179, 210, 55, 0.45),
    0 4px 12px rgba(0, 0, 0, 0.3),
    0 0 0 0 rgba(179, 210, 55, 0.55);
  transition: transform .2s ease;
  animation: ria-launch-pulse 2.4s ease-in-out infinite;
}
@keyframes ria-launch-pulse {
  0%, 100% { box-shadow: 0 12px 30px rgba(179,210,55,0.45), 0 4px 12px rgba(0,0,0,0.3), 0 0 0 0 rgba(179,210,55,0.55); }
  50%       { box-shadow: 0 12px 30px rgba(179,210,55,0.45), 0 4px 12px rgba(0,0,0,0.3), 0 0 0 12px rgba(179,210,55,0); }
}
.ria-launcher:hover { transform: scale(1.04); animation-play-state: paused; }
.ria-launcher:active { transform: scale(0.96); }

.ria-launcher-face {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--ria-bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.15);
}
.ria-launcher-face svg { width: 100%; height: 100%; display: block; }

.ria-launcher-text {
  line-height: 1;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.ria-launcher-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ria-cyan);
  box-shadow: 0 0 0 3px var(--ria-bg);
  animation: ria-dot-pulse 1.8s ease-in-out infinite;
}
@keyframes ria-dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(1.3); }
}

/* Hero mode: no launcher, panel shown inline */
#ria-root.hero .ria-launcher { display: none; }
#ria-root.hero .ria-panel { position: relative; inset: auto; width: 100%; max-width: 400px; margin: 0 auto; height: 620px; max-height: 80vh; }

/* Hide launcher when panel is open in corner mode */
#ria-root.open .ria-launcher { display: none; }

/* === PANEL === */

.ria-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: 400px;
  max-width: calc(100vw - 24px);
  height: 620px;
  max-height: calc(100vh - 48px);
  background: var(--ria-bg);
  border-radius: 28px;
  border: 1px solid var(--ria-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow:
    0 24px 70px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(179, 210, 55, 0.08);
  /* Subtle diagonal glow — modern, no topo noise */
  background-image:
    radial-gradient(ellipse 520px 320px at 75% 12%, rgba(179, 210, 55, 0.14) 0%, transparent 60%),
    radial-gradient(ellipse 420px 280px at 15% 95%, rgba(94, 231, 255, 0.08) 0%, transparent 60%);
}
#ria-root.open .ria-panel { display: flex; animation: ria-panel-in .28s ease-out; }
#ria-root.hero .ria-panel { display: flex; }

@keyframes ria-panel-in {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* === HEADER === */

.ria-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--ria-border);
  position: relative;
}
.ria-header-id { display: flex; align-items: center; gap: 12px; }

.ria-avatar-chip {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--ria-lime), var(--ria-lime-2));
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  box-shadow: 0 4px 12px rgba(179, 210, 55, 0.3);
}
.ria-avatar-chip svg { width: 100%; height: 100%; }
.ria-avatar-chip svg g:first-child path { fill: var(--ria-bg); }
.ria-avatar-chip svg g:last-child path { fill: var(--ria-bg); }

.ria-header-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.ria-header-text strong {
  font-size: 15px;
  font-weight: 700;
  color: var(--ria-text);
}
.ria-header-text span {
  font-size: 11px;
  color: var(--ria-lime);
  font-weight: 500;
  margin-top: 2px;
}

.ria-close {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: var(--ria-surface);
  border: 1px solid var(--ria-border);
  color: var(--ria-text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.ria-close:hover { background: var(--ria-surface-2); color: var(--ria-text); }

/* === MASCOT HERO (starter screen, collapses when chat starts) === */

.ria-hero {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 22px 18px 6px;
  transition: max-height .4s cubic-bezier(.4,0,.2,1), opacity .3s ease, padding .4s ease;
  max-height: 280px;
  overflow: visible;
}
.ria-hero.collapsed {
  max-height: 0;
  opacity: 0;
  padding: 0;
  pointer-events: none;
}

.ria-mascot {
  width: 170px;
  height: 170px;
  display: block;
  filter: drop-shadow(0 14px 34px rgba(179, 210, 55, 0.28));
}

/* Speech bubble floating next to mascot — matches reference */
.ria-hero-bubble {
  position: absolute;
  top: 24px;
  right: 14px;
  max-width: 180px;
  padding: 12px 16px;
  background: #ffffff;
  color: #0d3d39;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  border-radius: 20px 20px 20px 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: ria-bubble-in .45s ease-out .3s both;
}
.ria-hero-bubble::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 14px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  transform: rotate(45deg);
  box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.08);
}
@keyframes ria-bubble-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.92); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Gentle idle bob */
.ria-mascot .ria-head,
.ria-mascot .ria-visor,
.ria-mascot .ria-eye,
.ria-mascot .ria-mouth,
.ria-mascot .ria-forehead-x {
  transform-box: fill-box;
  transform-origin: center;
}
.ria-hero[data-state=idle] .ria-mascot { animation: ria-bob 3.2s ease-in-out infinite; }
@keyframes ria-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

/* Rings pulse out */
.ria-rings circle {
  transform-origin: 100px 102px;
  animation: ria-ring-wave 2.6s ease-out infinite;
}
.ria-rings circle:nth-child(1) { animation-delay: 0s; }
.ria-rings circle:nth-child(2) { animation-delay: 0.25s; }
.ria-rings circle:nth-child(3) { animation-delay: 0.5s; }
.ria-rings circle:nth-child(4) { animation-delay: 0.75s; }
@keyframes ria-ring-wave {
  0%   { opacity: 0.45; transform: scale(0.85); }
  60%  { opacity: 0.18; }
  100% { opacity: 0; transform: scale(1.15); }
}

/* Listening — rings go faster + cyan tint */
.ria-hero[data-state=listening] .ria-rings circle { stroke: #5ee7ff; animation-duration: 1.4s; }
.ria-hero[data-state=listening] .ria-eye { fill: #5ee7ff; }

/* Thinking — eyes drift up-left */
.ria-hero[data-state=thinking] .ria-eye-left  { transform: translate(-2px, -3px); }
.ria-hero[data-state=thinking] .ria-eye-right { transform: translate(-2px, -3px); }

/* Speaking — mouth switches from smile line to animated open ellipse; X pulses */
.ria-mouth-speak { opacity: 0; }
.ria-hero[data-state=speaking] .ria-mouth-idle  { opacity: 0; }
.ria-hero[data-state=speaking] .ria-mouth-speak { opacity: 1; animation: ria-mouth-talk 0.28s ease-in-out infinite; }
@keyframes ria-mouth-talk {
  0%, 100% { transform: scaleY(0.4); }
  50% { transform: scaleY(1); }
}
.ria-hero[data-state=speaking] .ria-forehead-x { animation: ria-x-glow 0.55s ease-in-out infinite; }
@keyframes ria-x-glow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(179,210,55,0)); }
  50% { filter: drop-shadow(0 0 4px rgba(179,210,55,0.9)); }
}

/* Blink every ~4s (idle + speaking) */
.ria-hero[data-state=idle] .ria-eye,
.ria-hero[data-state=speaking] .ria-eye { animation: ria-blink 4.2s infinite; }
.ria-hero[data-state=speaking] .ria-eye-right { animation-delay: 0.04s; }
@keyframes ria-blink {
  0%, 90%, 100% { transform: scaleY(1); }
  94%, 97% { transform: scaleY(0.08); }
}

/* === MESSAGES === */

.ria-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}
.ria-messages::-webkit-scrollbar { width: 5px; }
.ria-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.ria-msg {
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  animation: ria-msg-in .22s ease-out;
}
@keyframes ria-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.ria-msg-user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--ria-lime), var(--ria-lime-2));
  color: var(--ria-bg);
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  font-weight: 500;
  box-shadow: 0 2px 10px rgba(179, 210, 55, 0.2);
}

.ria-msg-ria {
  align-self: flex-start;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.ria-msg-ria .ria-msg-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 10px;
  background: var(--ria-surface);
  border: 1px solid var(--ria-border-2);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}
.ria-msg-ria .ria-msg-avatar svg { width: 100%; height: 100%; }
.ria-msg-ria .ria-msg-avatar svg g:first-child path { fill: var(--ria-text-dim); }
.ria-msg-ria .ria-msg-avatar svg g:last-child path { fill: var(--ria-lime); }

.ria-msg-ria .ria-msg-body {
  background: var(--ria-surface);
  border: 1px solid var(--ria-border);
  color: var(--ria-text);
  padding: 10px 14px;
  border-radius: 4px 16px 16px 16px;
  min-width: 0;
}

.ria-msg-ria.ria-speaking .ria-msg-avatar {
  border-color: var(--ria-lime);
  box-shadow: 0 0 0 3px rgba(179, 210, 55, 0.2);
  animation: ria-ring-pulse 0.8s ease-in-out infinite;
}
@keyframes ria-ring-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(179, 210, 55, 0.2); }
  50% { box-shadow: 0 0 0 6px rgba(179, 210, 55, 0.4); }
}

/* Typing dots */
.ria-pending .ria-msg-body { display: flex; gap: 4px; padding: 14px; }
.ria-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ria-text-dim);
  animation: ria-dot-bounce 1.1s ease-in-out infinite;
}
.ria-dot:nth-child(2) { animation-delay: 0.15s; }
.ria-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes ria-dot-bounce {
  0%, 70%, 100% { opacity: 0.4; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-4px); background: var(--ria-lime); }
}

/* Inline action link button inside a Ria reply */
.ria-action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 12px;
  background: var(--ria-lime);
  color: var(--ria-bg);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  transition: transform .15s, filter .15s;
}
.ria-action:hover { transform: translateY(-1px); filter: brightness(1.05); }

/* === COMPOSER (pill-style input bar) === */

.ria-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--ria-bg-2);
  border-top: 1px solid var(--ria-border);
}

.ria-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: 999px;
  border: 1px solid var(--ria-border);
  background: var(--ria-surface);
  color: var(--ria-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.ria-input:focus {
  border-color: var(--ria-lime);
  box-shadow: 0 0 0 3px rgba(179, 210, 55, 0.15);
}
.ria-input::placeholder { color: var(--ria-muted); }

.ria-icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .12s, filter .15s;
  flex-shrink: 0;
}
.ria-icon-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.ria-icon-btn:active { transform: scale(0.95); }
.ria-icon-btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; filter: grayscale(0.4); }

.ria-icon-btn.mic {
  background: var(--ria-surface);
  color: var(--ria-text);
  border: 1px solid var(--ria-border);
}
.ria-icon-btn.mic[data-active="1"] {
  background: var(--ria-cyan);
  color: var(--ria-bg);
  animation: ria-mic-pulse 1.1s ease-in-out infinite;
}
@keyframes ria-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(94, 231, 255, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(94, 231, 255, 0); }
}

.ria-icon-btn.send {
  background: linear-gradient(135deg, var(--ria-lime), var(--ria-lime-2));
  color: var(--ria-bg);
  box-shadow: 0 3px 10px rgba(179, 210, 55, 0.3);
}

/* === TILES (starter screen, 2x2 colored card grid) === */

.ria-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 8px 14px 18px;
  flex-shrink: 0;
}
.ria-tiles.hidden { display: none; }

.ria-tile {
  position: relative;
  padding: 12px 14px 14px;
  border-radius: 16px;
  border: none;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  display: flex;
  flex-direction: column;
  gap: 2px;
  aspect-ratio: 1.8 / 1;
  overflow: hidden;
  transition: transform .15s ease, box-shadow .15s ease;
  color: var(--ria-bg);
}
.ria-tile:hover { transform: translateY(-2px); }
.ria-tile:active { transform: translateY(0); }

.ria-tile-arrow {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0.75;
}
.ria-tile-icon {
  font-size: 22px;
  margin-bottom: 6px;
}
.ria-tile-title {
  font-size: 14px;
  font-weight: 800;
  line-height: 1.15;
}
.ria-tile-sub {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.7;
  margin-top: 2px;
}

/* Tile color variants — matches reference palette on a dark panel */
.ria-tile-lime   { background: linear-gradient(140deg, #c4e24a 0%, #b3d237 100%); box-shadow: 0 6px 16px rgba(179,210,55,0.28); }
.ria-tile-violet { background: linear-gradient(140deg, #d6c1ff 0%, #c9b3f0 100%); box-shadow: 0 6px 16px rgba(201,179,240,0.22); }
.ria-tile-pink   { background: linear-gradient(140deg, #f7c9de 0%, #e8a9c2 100%); box-shadow: 0 6px 16px rgba(232,169,194,0.22); }
.ria-tile-cyan   { background: linear-gradient(140deg, #8ef0ff 0%, #5ee7ff 100%); box-shadow: 0 6px 16px rgba(94,231,255,0.28); }

/* === LEAD FORM (inline in message list) === */

.ria-lead-form .ria-msg-body { display: flex; flex-direction: column; gap: 8px; }
.ria-lead-msg {
  font-weight: 700;
  color: var(--ria-lime);
  font-size: 13px;
  margin-bottom: 2px;
}
.ria-lead-form .ria-input {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
}
.ria-lead-actions { display: flex; gap: 8px; margin-top: 4px; }
.ria-pill {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--ria-border);
  background: transparent;
  color: var(--ria-text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.ria-pill:hover { background: var(--ria-surface-2); color: var(--ria-text); }
.ria-pill.primary {
  background: var(--ria-lime);
  color: var(--ria-bg);
  border-color: var(--ria-lime);
}
.ria-pill.primary:hover { filter: brightness(1.06); }
.ria-lead-status { font-size: 11px; color: var(--ria-text-dim); min-height: 14px; }

/* === MOBILE === */

@media (max-width: 640px) {
  .ria-launcher {
    bottom: calc(84px + env(safe-area-inset-bottom, 0px));
    right: 14px;
    left: auto;
    padding: 5px 12px 5px 5px;
    gap: 7px;
    font-size: 12px;
    max-width: calc(100vw - 28px);
    box-sizing: border-box;
  }
  .ria-launcher-face { width: 32px; height: 32px; }

  /* Corner mode: compact bottom-sheet (NOT full screen) */
  #ria-root.open .ria-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 78dvh;
    max-height: 78dvh;
    border-radius: 22px 22px 0 0;
    border: none;
    border-top: 1px solid var(--ria-border);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  }
  #ria-root.open .ria-panel::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 44px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
  }

  /* Hero mode on mobile: full-width chat that doesn't steal the page */
  #ria-root.hero .ria-panel {
    width: 100%;
    max-width: 100%;
    height: 75dvh;
    min-height: 540px;
    border-radius: 20px;
  }

  /* Header safe-area top */
  .ria-header {
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }

  /* Bigger touch targets */
  .ria-icon-btn { width: 48px; height: 48px; }
  .ria-close { width: 38px; height: 38px; }
  .ria-input {
    font-size: 16px;         /* prevents iOS auto-zoom */
    padding: 13px 16px;
  }

  .ria-msg { max-width: 88%; font-size: 14px; }
  .ria-msg-ria .ria-msg-avatar { width: 28px; height: 28px; }

  /* Composer hugs bottom with safe-area */
  .ria-composer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    gap: 6px;
  }

  .ria-tiles {
    padding: 4px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .ria-messages {
    padding: 14px 14px 6px;
    gap: 8px;
  }

  /* Slightly smaller hero on phones */
  .ria-hero { padding: 10px 14px 2px; max-height: 170px; flex-shrink: 0; }
  .ria-mascot { width: 130px; height: 130px; }
  .ria-hero-bubble { top: 8px; right: 8px; max-width: 150px; font-size: 12px; padding: 8px 12px; }
  .ria-tile { aspect-ratio: 2 / 1; padding: 10px 12px; }
  .ria-tile-icon { font-size: 18px; margin-bottom: 2px; }
  .ria-tile-title { font-size: 13px; }
  .ria-tile-sub { font-size: 10px; }
}

/* Tiny phones */
@media (max-width: 380px) {
  .ria-header-text span { display: none; }
  .ria-avatar-chip { width: 34px; height: 34px; }
  .ria-icon-btn { width: 44px; height: 44px; }
}
