/* ==========================================================================
   GracIA · widget flotante · Iglesia LaVid Buenos Aires
   Degradé de marca verde -> azul -> violeta · Montserrat · mobile-first.
   Todo namespaced bajo .gia- para no chocar con el resto del sitio.
   ========================================================================== */
:root {
  --gia-green: #4BBA7C;
  --gia-blue:  #4BA6DD;
  --gia-violet:#5E2E86;
  --gia-grad: linear-gradient(120deg, #4BBA7C, #4BA6DD, #5E2E86);
  --gia-ink:  #1D2440;
  --gia-soft: #6B7590;
  --gia-line: #E7EAF2;
  --gia-bg:   #FFFFFF;
  --gia-user: #EAF3FB;
  --gia-bot:  #F4F6FB;
}

.gia-root, .gia-root * { box-sizing: border-box; }
.gia-root {
  font-family: 'Montserrat', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  position: fixed; right: 20px; bottom: 20px; z-index: 2147483000;
}

/* -------- Launcher (burbuja flotante) -------- */
.gia-launcher {
  display: inline-flex; align-items: center; gap: .5em;
  border: none; cursor: pointer; color: #fff;
  font-family: inherit; font-weight: 700; font-size: .95rem;
  padding: .7em 1.15em; border-radius: 999px;
  background: var(--gia-grad); background-size: 180% 180%;
  box-shadow: 0 14px 34px -10px rgba(94, 46, 134, .55);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
  animation: gia-pop .45s cubic-bezier(.2,.9,.3,1.2) both, gia-flow 8s ease infinite;
}
.gia-launcher:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 18px 40px -10px rgba(94,46,134,.6); }
.gia-launcher:active { transform: scale(.97); }
.gia-launcher .gia-ava {
  width: 26px; height: 26px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: grid; place-items: center; font-size: 1rem; line-height: 1; overflow: hidden;
}
/* Foto real de GracIA dentro del avatar (launcher, header e inline). */
.gia-ava-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.gia-launcher.gia-hidden { display: none; }

/* burbuja de bienvenida proactiva */
.gia-nudge {
  position: absolute; right: 0; bottom: calc(100% + 12px);
  max-width: 260px; background: #fff; color: var(--gia-ink);
  border: 1px solid var(--gia-line); border-radius: 16px 16px 4px 16px;
  padding: 12px 34px 12px 14px; font-size: .9rem; line-height: 1.45;
  box-shadow: 0 18px 40px -16px rgba(29,36,64,.35);
  animation: gia-pop .4s cubic-bezier(.2,.9,.3,1.2) both;
}
.gia-nudge b { color: var(--gia-violet); }
.gia-nudge .gia-nudge-x {
  position: absolute; top: 6px; right: 8px; border: none; background: none;
  cursor: pointer; color: var(--gia-soft); font-size: 1.05rem; line-height: 1; padding: 2px;
}
.gia-nudge.gia-hidden { display: none; }

/* -------- Panel de chat -------- */
.gia-panel {
  position: absolute; right: 0; bottom: 0;
  width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 40px);
  background: var(--gia-bg); border-radius: 22px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 30px 70px -20px rgba(29,36,64,.5), 0 4px 14px rgba(29,36,64,.12);
  transform-origin: bottom right;
  animation: gia-panel-in .34s cubic-bezier(.2,.8,.2,1) both;
}
.gia-panel.gia-hidden { display: none; }

.gia-head {
  background: var(--gia-grad); background-size: 200% 200%; animation: gia-flow 10s ease infinite;
  color: #fff; padding: 16px 16px 15px; display: flex; align-items: center; gap: 12px;
}
.gia-head .gia-ava {
  width: 42px; height: 42px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: grid; place-items: center; font-size: 1.3rem; flex: none; overflow: hidden;
}
.gia-head .gia-meta { flex: 1; min-width: 0; }
.gia-head .gia-name { font-weight: 800; font-size: 1.02rem; }
.gia-head .gia-status { font-size: .76rem; opacity: .9; display: flex; align-items: center; gap: 6px; }
.gia-head .gia-dot { width: 7px; height: 7px; border-radius: 50%; background: #b8f2ce; box-shadow: 0 0 0 0 rgba(184,242,206,.7); animation: gia-live 2s infinite; }
.gia-head .gia-close {
  border: none; background: rgba(255,255,255,.16); color: #fff; cursor: pointer;
  width: 32px; height: 32px; border-radius: 50%; font-size: 1.1rem; line-height: 1;
  display: grid; place-items: center; transition: background .2s;
}
.gia-head .gia-close:hover { background: rgba(255,255,255,.3); }

.gia-body {
  flex: 1; overflow-y: auto; padding: 16px; background: #FBFCFE;
  display: flex; flex-direction: column; gap: 10px;
  scroll-behavior: smooth; overscroll-behavior: contain;
}

.gia-msg { max-width: 84%; padding: 10px 13px; border-radius: 16px; font-size: .92rem; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; animation: gia-msg-in .28s ease both; }
.gia-msg.gia-bot  { align-self: flex-start; background: var(--gia-bot); color: var(--gia-ink); border-bottom-left-radius: 5px; }
.gia-msg.gia-user { align-self: flex-end;  background: var(--gia-user); color: var(--gia-ink); border-bottom-right-radius: 5px; }
.gia-msg a { color: var(--gia-blue); font-weight: 600; }

.gia-links { display: flex; flex-wrap: wrap; gap: 7px; align-self: flex-start; max-width: 90%; }
.gia-links a {
  display: inline-flex; align-items: center; gap: 5px; text-decoration: none;
  font-size: .82rem; font-weight: 600; color: var(--gia-violet);
  background: #fff; border: 1.5px solid var(--gia-line); border-radius: 999px; padding: .42em .8em;
  transition: border-color .2s, transform .2s, color .2s;
}
.gia-links a:hover { border-color: var(--gia-blue); color: var(--gia-blue); transform: translateY(-1px); }

.gia-chips { display: flex; flex-wrap: wrap; gap: 7px; padding: 4px 2px 2px; }
.gia-chip {
  cursor: pointer; border: 1.5px solid var(--gia-line); background: #fff; color: var(--gia-ink);
  font-family: inherit; font-size: .82rem; font-weight: 600; border-radius: 999px; padding: .5em .85em;
  transition: border-color .2s, background .2s, transform .2s;
}
.gia-chip:hover { border-color: var(--gia-green); background: #F3FBF6; transform: translateY(-1px); }

/* indicador "escribiendo" */
.gia-typing { align-self: flex-start; background: var(--gia-bot); border-radius: 16px; border-bottom-left-radius: 5px; padding: 12px 14px; display: inline-flex; gap: 4px; }
.gia-typing i { width: 7px; height: 7px; border-radius: 50%; background: #B7C0D6; display: inline-block; animation: gia-blink 1.3s infinite both; }
.gia-typing i:nth-child(2) { animation-delay: .2s; }
.gia-typing i:nth-child(3) { animation-delay: .4s; }

.gia-foot { border-top: 1px solid var(--gia-line); padding: 10px; background: #fff; }
.gia-inrow { display: flex; align-items: flex-end; gap: 8px; }
.gia-input {
  flex: 1; resize: none; border: 1.5px solid var(--gia-line); border-radius: 14px;
  padding: 10px 12px; font-family: inherit; font-size: .92rem; color: var(--gia-ink);
  max-height: 96px; line-height: 1.4; outline: none; transition: border-color .2s;
}
.gia-input:focus { border-color: var(--gia-blue); }
.gia-send {
  flex: none; width: 42px; height: 42px; border: none; border-radius: 50%; cursor: pointer;
  background: var(--gia-grad); color: #fff; font-size: 1.1rem; display: grid; place-items: center;
  transition: transform .2s, opacity .2s; box-shadow: 0 8px 20px -8px rgba(94,46,134,.6);
}
.gia-send:hover { transform: scale(1.06); }
.gia-send:disabled { opacity: .5; cursor: default; transform: none; }
.gia-legal { text-align: center; font-size: .68rem; color: var(--gia-soft); margin-top: 7px; }
.gia-legal a { color: var(--gia-soft); }

/* -------- Página /gracia (embebido grande) -------- */
.gia-embed { max-width: 720px; margin: 0 auto; }
.gia-embed .gia-panel {
  position: static; width: 100%; max-width: 100%; height: min(72vh, 640px);
  animation: none; box-shadow: 0 24px 60px -24px rgba(29,36,64,.4);
}

/* -------- Animaciones -------- */
@keyframes gia-pop { from { opacity: 0; transform: translateY(10px) scale(.9); } to { opacity: 1; transform: none; } }
@keyframes gia-panel-in { from { opacity: 0; transform: translateY(16px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes gia-msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes gia-flow { 0%,100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }
@keyframes gia-blink { 0%,60%,100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes gia-live { 0% { box-shadow: 0 0 0 0 rgba(184,242,206,.7); } 70% { box-shadow: 0 0 0 7px rgba(184,242,206,0); } 100% { box-shadow: 0 0 0 0 rgba(184,242,206,0); } }

/* -------- Mobile -------- */
@media (max-width: 560px) {
  .gia-root { right: 14px; bottom: 14px; }
  .gia-panel {
    position: fixed; right: 0; bottom: 0; left: 0; top: 0;
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0;
  }
  .gia-launcher .gia-label { display: none; }
  .gia-launcher { padding: .8em; }
  .gia-launcher .gia-ava { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .gia-launcher, .gia-panel, .gia-nudge, .gia-msg, .gia-head { animation: none !important; }
}

/* ===== Historial de chats (usuarios logueados) ===== */
.gia-head .gia-hist {
  margin-left: auto; border: 0; background: rgba(255,255,255,.18); color: #fff;
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
  font-size: .95rem; line-height: 1; display: flex; align-items: center; justify-content: center;
  transition: background .15s ease;
}
.gia-head .gia-hist:hover { background: rgba(255,255,255,.34); }
.gia-head .gia-hist + .gia-close { margin-left: 6px; }
.gia-hist-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.gia-hist-back, .gia-hist-new {
  border: 1px solid var(--gia-line); background: #fff; color: var(--gia-ink);
  border-radius: 999px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer;
}
.gia-hist-new { color: var(--gia-violet); border-color: var(--gia-violet); }
.gia-hist-back:hover, .gia-hist-new:hover { filter: brightness(.97); }
.gia-hist-title { font-size: .78rem; font-weight: 700; color: var(--gia-soft); text-transform: uppercase; letter-spacing: .04em; margin: 4px 0 10px; }
.gia-hist-empty { color: var(--gia-soft); font-size: .9rem; padding: 14px 4px; text-align: center; }
.gia-hist-list { display: flex; flex-direction: column; gap: 8px; }
.gia-hist-item {
  text-align: left; border: 1px solid var(--gia-line); background: #fff; color: var(--gia-ink);
  border-radius: 14px; padding: 10px 12px; cursor: pointer; transition: border-color .15s ease, box-shadow .15s ease;
}
.gia-hist-item:hover { border-color: var(--gia-blue); box-shadow: 0 4px 14px rgba(75,166,221,.14); }
.gia-hist-t { font-weight: 700; font-size: .92rem; margin-bottom: 2px; }
.gia-hist-p { font-size: .82rem; color: var(--gia-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gia-hist-d { font-size: .74rem; color: var(--gia-violet); font-weight: 600; margin-top: 4px; }
