/* ============================================
   ASSISTENTE AI — widget flottante (bottom-right)
   Palette OMNIGATE: --og-orange #C74209, --og-navy #273348
   ============================================ */

.oai {
  --oai-orange: var(--og-orange, #C74209);
  --oai-navy: var(--og-navy, #273348);
  --oai-line: var(--og-line, #E6E9EF);
  --oai-muted: var(--og-muted, #6A7280);
  --oai-ink: var(--og-ink, #273348);
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 1400;
  font-family: var(--font-body, 'Plus Jakarta Sans', system-ui, sans-serif);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
}

/* Nascosto durante lo scroll verso il basso (solo mobile, vedi media query).
   Non si applica quando il pannello è aperto (.is-open). */
.oai.is-tucked:not(.is-open) {
  transform: translateY(150%);
  opacity: 0;
  pointer-events: none;
}

/* ── Teaser proattivo ───────────────────────────────────────────── */
.oai-teaser {
  position: absolute;
  right: 0;
  bottom: 84px;
  width: 268px;
  background: var(--oai-navy);
  color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 16px 18px 16px;
  box-shadow: 0 18px 40px rgba(10, 20, 40, 0.28);
  transform-origin: bottom right;
  animation: oai-pop 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}
.oai-teaser__eyebrow {
  display: block;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  margin-bottom: 6px;
}
.oai-teaser__text { font-size: 0.92rem; line-height: 1.45; font-weight: 500; }
.oai-teaser__close {
  position: absolute;
  top: 8px; right: 10px;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.7);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}
.oai-teaser__close:hover { color: #fff; }

/* ── Launcher (orb) ─────────────────────────────────────────────── */
.oai-launcher {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 32% 28%, #34435c, var(--oai-navy) 70%);
  box-shadow: 0 12px 30px rgba(10, 20, 40, 0.34);
  display: grid;
  place-items: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  margin-left: auto;
}
.oai-launcher:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 16px 36px rgba(10, 20, 40, 0.4); }
.oai-launcher:active { transform: scale(0.97); }
.oai-orb { width: 52px; height: 52px; display: block; }
.oai-orb--sm { width: 40px; height: 40px; }

.oai.is-open .oai-launcher { display: none; }
.oai.is-open .oai-teaser { display: none !important; }

/* L'attributo [hidden] deve battere i display di .oai-panel/.oai-teaser */
.oai-panel[hidden], .oai-teaser[hidden] { display: none !important; }

/* ── Pannello chat ──────────────────────────────────────────────── */
.oai-panel {
  width: min(380px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--oai-line);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 28px 64px rgba(10, 20, 40, 0.3);
  transform-origin: bottom right;
  animation: oai-pop 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.oai-panel__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 16px;
  background: linear-gradient(135deg, #2f3e58, var(--oai-navy));
  color: #fff;
}
.oai-panel__head .oai-orb--sm { flex-shrink: 0; }
.oai-panel__head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.oai-panel__eyebrow {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}
.oai-panel__status { font-size: 0.92rem; font-weight: 600; }
.oai-iconbtn {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}
.oai-iconbtn:hover { background: rgba(255, 255, 255, 0.22); }
.oai-iconbtn svg { width: 18px; height: 18px; }
.oai-iconbtn.is-muted { color: rgba(255, 255, 255, 0.45); }

/* ── Messaggi ───────────────────────────────────────────────────── */
.oai-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 6px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafbfc;
}
.oai-msg {
  max-width: 86%;
  padding: 11px 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  border-radius: 16px;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: oai-fade 0.22s ease;
}
.oai-msg--ai {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--oai-line);
  color: var(--oai-ink);
  border-bottom-left-radius: 5px;
}
.oai-msg--user {
  align-self: flex-end;
  background: var(--oai-orange);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.oai-msg--error { background: #fdecec; border-color: #f6c6c6; color: #a02020; }

/* Typing indicator */
.oai-typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.oai-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--oai-muted);
  opacity: 0.5;
  animation: oai-bounce 1.2s infinite ease-in-out;
}
.oai-typing span:nth-child(2) { animation-delay: 0.18s; }
.oai-typing span:nth-child(3) { animation-delay: 0.36s; }

/* ── Suggerimenti rapidi ────────────────────────────────────────── */
.oai-panel__suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 16px 4px;
  background: #fafbfc;
}
.oai-chip {
  border: 1.5px solid var(--oai-line);
  background: #fff;
  color: var(--oai-navy);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.13s, border-color 0.13s, color 0.13s;
}
.oai-chip:hover { background: var(--oai-navy); border-color: var(--oai-navy); color: #fff; }

/* ── Nota trasparenza AI ─────────────────────────────────────────── */
.oai-panel__note {
  margin: 0;
  padding: 6px 14px 8px;
  font-size: 0.68rem;
  line-height: 1.4;
  color: var(--oai-muted);
}
.oai-panel__note a { color: inherit; text-decoration: underline; }

/* ── Input ──────────────────────────────────────────────────────── */
.oai-panel__input {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--oai-line);
  background: #fff;
}
.oai-input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--oai-line);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--oai-ink);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.oai-input:focus { border-color: var(--oai-navy); box-shadow: 0 0 0 3px rgba(39, 51, 72, 0.08); }
.oai-input::placeholder { color: var(--oai-muted); }
.oai-mic, .oai-send {
  width: 42px; height: 42px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, transform 0.15s;
}
.oai-mic { background: #f0f2f6; color: var(--oai-navy); }
.oai-mic:hover { background: #e4e8ef; }
.oai-mic svg, .oai-send svg { width: 19px; height: 19px; }
.oai-mic.is-listening { background: var(--oai-orange); color: #fff; animation: oai-mic-pulse 1.4s ease-in-out infinite; }
.oai-send { background: var(--oai-navy); color: #fff; }
.oai-send:hover { background: #1c2738; }
.oai-send:disabled { opacity: 0.45; cursor: default; }

/* ── Animazioni ─────────────────────────────────────────────────── */
@keyframes oai-pop { from { opacity: 0; transform: translateY(14px) scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes oai-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes oai-bounce { 0%, 80%, 100% { transform: translateY(0); opacity: 0.4; } 40% { transform: translateY(-5px); opacity: 0.9; } }
@keyframes oai-mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(232, 78, 15, 0.45); } 50% { box-shadow: 0 0 0 10px rgba(232, 78, 15, 0); } }

/* ── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .oai { right: 14px; bottom: 14px; }
  .oai-launcher { width: 54px; height: 54px; }
  .oai-orb { width: 42px; height: 42px; }
  .oai-teaser { bottom: 70px; }
  .oai-panel {
    width: calc(100vw - 24px);
    height: calc(100vh - 92px);
  }
  .oai-teaser { width: calc(100vw - 28px); }
}

@media (prefers-reduced-motion: reduce) {
  .oai-teaser, .oai-panel, .oai-msg { animation: none; }
  .oai-mic.is-listening { animation: none; }
}
