/* ==========================================================================
   Brisa — chat widget. Uses the tokens defined in styles.css.
   ========================================================================== */

/* Hidden until /api/chat reports Brisa is available (chat.js adds .brisa-ready). */
.brisa-launcher, [data-open-chat] { display: none !important; }
html.brisa-ready .brisa-launcher, html.brisa-ready [data-open-chat] { display: inline-flex !important; }

.brisa-launcher {
  position: fixed; z-index: 70;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  align-items: center; gap: 10px;
  padding: 7px 14px 7px 7px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--night); color: var(--on-night);
  font: 700 .98rem/1 var(--f-body);
  box-shadow: 0 0 0 1.5px rgba(52, 224, 201, .55), 0 16px 34px -12px rgba(12, 4, 40, .75);
  transition: transform .2s ease, box-shadow .2s ease;
}
.brisa-launcher:hover { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--calypso), 0 18px 36px -12px rgba(12, 4, 40, .8); }
.brisa-launcher__av {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(150deg, #2A1170, var(--night-3));
  box-shadow: inset 0 0 0 1.5px rgba(255, 255, 255, .14);
}
.brisa-launcher__av svg { width: 26px; height: 26px; }
.brisa-launcher__ai {
  font-family: var(--f-mono); font-size: .56rem; font-weight: 500; letter-spacing: .08em;
  padding: .45em .55em; border-radius: 6px;
  background: var(--calypso); color: var(--night);
}
html.brisa-open .brisa-launcher { opacity: 0; pointer-events: none; transform: translateY(8px); }

/* ---------- Panel ---------- */
.brisa {
  position: fixed; z-index: 80;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  width: min(400px, calc(100vw - 32px));
  height: min(660px, calc(100dvh - 32px));
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-radius: var(--r-lg);
  background: var(--sand);
  color: var(--ink);
  box-shadow: 0 0 0 1px rgba(28, 10, 69, .08), 0 40px 90px -30px rgba(12, 4, 40, .6);
  animation: brisa-in .28s cubic-bezier(.2, .7, .2, 1) both;
}
.brisa[hidden] { display: none !important; }

.brisa__head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 12px 14px 16px;
  background:
    radial-gradient(80% 140% at 100% 0%, rgba(122, 60, 255, .45), transparent 70%),
    var(--night);
  color: var(--on-night);
}
.brisa__av {
  display: grid; place-items: center; flex: none;
  width: 42px; height: 42px; border-radius: 50%;
  background: rgba(255, 255, 255, .06);
  box-shadow: inset 0 0 0 1.5px rgba(52, 224, 201, .5);
}
.brisa__av svg { width: 28px; height: 28px; }
.brisa__who { display: grid; gap: 2px; min-width: 0; margin-inline-end: auto; }
.brisa__title { font-family: var(--f-display); font-weight: 800; font-stretch: 82%; font-size: 1.3rem; line-height: 1; }
.brisa__subtitle { font-size: .78rem; color: var(--on-night-2); }
.brisa__iconbtn {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; cursor: pointer; color: var(--on-night);
  background: rgba(255, 255, 255, .08);
  transition: background-color .15s ease;
}
.brisa__iconbtn:hover { background: rgba(255, 255, 255, .16); }
.brisa__iconbtn svg { width: 20px; height: 20px; }
.brisa__iconbtn--wa { background: var(--green); color: var(--night); }
.brisa__iconbtn--wa:hover { background: var(--green-hover); }
.brisa__x { position: relative; width: 14px; height: 14px; }
.brisa__x::before, .brisa__x::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 16px; height: 2px; border-radius: 2px; background: currentColor;
}
.brisa__x::before { transform: translate(-50%, -50%) rotate(45deg); }
.brisa__x::after { transform: translate(-50%, -50%) rotate(-45deg); }

.brisa :focus-visible { outline: 3px solid var(--violet); outline-offset: 2px; }
.brisa__head :focus-visible { outline-color: var(--calypso); }

/* ---------- Log ---------- */
.brisa__log {
  display: flex; flex-direction: column; gap: 10px;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 14px 14px;
  scroll-behavior: smooth;
}
.brisa-msg {
  max-width: 88%;
  padding: 10px 14px;
  font-size: .96rem; line-height: 1.5;
  overflow-wrap: anywhere;
}
.brisa-msg p + p, .brisa-msg p + ul, .brisa-msg ul + p { margin-top: .55em; }
.brisa-msg ul { margin: 0; padding-left: 1.15em; display: grid; gap: .25em; }
.brisa-msg strong { font-weight: 700; }
.brisa-msg--assistant {
  align-self: flex-start;
  background: var(--paper);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 1px 0 var(--line), 0 6px 16px -12px rgba(28, 10, 69, .3);
}
.brisa-msg--user {
  align-self: flex-end;
  background: var(--violet); color: #FFFFFF;
  border-radius: 16px 16px 5px 16px;
  white-space: pre-wrap;
}

.brisa-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.brisa-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3);
  animation: brisa-dot 1.1s ease-in-out infinite;
}
.brisa-dots i:nth-child(2) { animation-delay: .15s; }
.brisa-dots i:nth-child(3) { animation-delay: .3s; }

.brisa-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.brisa-chip {
  padding: .55em .9em; border-radius: 999px; cursor: pointer;
  border: 0; background: var(--paper); color: var(--violet-ink);
  box-shadow: inset 0 0 0 1.5px #D9CBF2;
  font: 600 .88rem/1.25 var(--f-body); text-align: left;
  transition: background-color .15s ease, box-shadow .15s ease;
}
.brisa-chip:hover { background: #F3ECFF; box-shadow: inset 0 0 0 1.5px var(--violet); }

.brisa-handoff {
  display: grid; gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--seaglass);
  box-shadow: inset 0 0 0 1px rgba(10, 111, 98, .18);
}
.brisa-handoff__title { font-family: var(--f-display); font-weight: 750; font-stretch: 88%; font-size: 1.05rem; }
.brisa-handoff__msg {
  padding: 10px 12px; border-radius: 12px 12px 4px 12px;
  background: #005C4B; color: #E9EDEF;
  font-size: .9rem; line-height: 1.45;
}
.brisa-handoff__hint { font-size: .78rem; color: var(--ink-2); text-align: center; }

.brisa-notice {
  display: grid; gap: 10px; justify-items: start;
  padding: 12px 14px; border-radius: 14px;
  background: #F1EAFB; color: var(--ink);
  font-size: .92rem; line-height: 1.45;
}

/* ---------- Composer ---------- */
.brisa__compose {
  display: grid; gap: 8px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  border-top: 1px solid var(--line);
}
.brisa__form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 6px 6px 14px;
  border-radius: 22px;
  background: var(--sand);
  box-shadow: inset 0 0 0 1.5px var(--line);
  transition: box-shadow .15s ease;
}
.brisa__form:focus-within { box-shadow: inset 0 0 0 1.5px var(--violet); }
.brisa__input {
  flex: 1; min-width: 0; resize: none;
  max-height: 140px; padding: 8px 0;
  border: 0; outline: none; background: transparent; color: var(--ink);
  font: 400 1rem/1.4 var(--f-body);
}
.brisa__input::placeholder { color: var(--ink-3); }
.brisa__send {
  display: grid; place-items: center; flex: none;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--calypso); color: var(--night);
  transition: transform .15s ease, opacity .15s ease;
}
.brisa__send:hover { transform: scale(1.05); }
.brisa__sendicon {
  width: 0; height: 0; margin-left: 3px;
  border-top: 7px solid transparent; border-bottom: 7px solid transparent;
  border-left: 11px solid currentColor;
}
.brisa__form.is-busy .brisa__send { opacity: .45; pointer-events: none; }

.brisa__foot { font-size: .72rem; line-height: 1.4; color: var(--ink-3); padding-inline: 4px; }
.brisa__reset {
  padding: 0; border: 0; background: none; cursor: pointer;
  font: inherit; color: var(--violet-ink); text-decoration: underline; text-underline-offset: 2px;
}

.brisa__sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- Page hooks ---------- */
.ask-brisa {
  align-items: center; gap: 10px;
  margin-top: 28px; padding: 12px 18px 12px 12px;
  border: 0; border-radius: 999px; cursor: pointer;
  background: var(--night); color: var(--on-night);
  font: 600 .98rem/1.3 var(--f-body); text-align: left;
  transition: transform .15s ease;
}
.ask-brisa:hover { transform: translateY(-1px); }
.ask-brisa svg { width: 28px; height: 28px; flex: none; }

/* ---------- Phones: full-screen sheet ---------- */
@media (max-width: 640px) {
  .brisa {
    inset: 0; right: 0; bottom: 0;
    width: 100%; height: 100%;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--sand);
  }
  .brisa-launcher__label { font-size: .92rem; }
  html.brisa-lock, html.brisa-lock body { overflow: hidden; }
}

@keyframes brisa-in { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes brisa-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .brisa, .brisa-launcher, .brisa-dots i { animation: none !important; transition: none !important; }
  .brisa__log { scroll-behavior: auto; }
}
