/* =========================================================================
   Profi — mini-asistent flotant (colț dreapta-jos)
   Folosește tokenurile design-system-ului proto (--pro-*), deci se
   adaptează automat la tema luminoasă / întunecată.
   ========================================================================= */

.profi {
  --profi-accent: var(--pro-primary, #2563eb);
  --profi-panel-w: 380px;
  position: fixed;
  right: clamp(1rem, 2.5vw, 1.5rem);
  bottom: clamp(1rem, 2.5vw, 1.5rem);
  z-index: 1100;
  font-family: var(--pro-font, system-ui, sans-serif);
}

/* Butonul „back to top" stă în același colț → îl ridicăm deasupra lui Profi
   ca să nu se suprapună. Selectorul cu `body` întrece `!important`-ul lui. */
body .back-top { bottom: 100px !important; }
@media (max-width: 767.98px) {
  body .back-top { bottom: 78px !important; right: 12px !important; }
}

/* ---- launcher (butonul cu mascota) ---------------------------------- */
.profi-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  color: #fff;
  background: var(--pro-grad-btn, linear-gradient(135deg, #2563eb, #38bdf8));
  box-shadow: 0 .6rem 1.4rem color-mix(in srgb, var(--profi-accent) 34%, transparent),
              0 .2rem .5rem rgba(2, 8, 23, .3);
  transition: transform .18s ease, box-shadow .18s ease;
}
.profi-launcher:hover { transform: translateY(-2px) scale(1.03); }
.profi-launcher:active { transform: translateY(0) scale(.97); }
.profi-launcher:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--profi-accent) 55%, #fff);
  outline-offset: 3px;
}
.profi-launcher svg { width: 34px; height: 34px; display: block; }

/* pulse ring on first sight */
.profi-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--profi-accent) 50%, transparent);
  animation: profi-pulse 2.4s ease-out infinite;
}
.profi.is-open .profi-launcher::after { animation: none; }
@keyframes profi-pulse {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--profi-accent) 45%, transparent); }
  70%  { box-shadow: 0 0 0 16px color-mix(in srgb, var(--profi-accent) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--profi-accent) 0%, transparent); }
}
@media (prefers-reduced-motion: reduce) {
  .profi-launcher::after { animation: none; }
}

/* icon crossfade: bubble ↔ close */
.profi-launcher .profi-ic-close { display: none; }
.profi.is-open .profi-launcher .profi-ic-open { display: none; }
.profi.is-open .profi-launcher .profi-ic-close { display: block; }

/* first-visit nudge bubble */
.profi-nudge {
  position: absolute;
  right: calc(100% + .7rem);
  bottom: 8px;
  white-space: nowrap;
  background: var(--pro-surface, #0f172a);
  color: var(--pro-heading, #e2e8f0);
  border: 1px solid var(--pro-border, rgba(148,163,184,.2));
  border-radius: 12px;
  padding: .5rem .8rem;
  font-size: .82rem;
  font-weight: 600;
  box-shadow: var(--pro-shadow, 0 .5rem 1.5rem rgba(2,8,23,.35));
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.profi-nudge::after {
  content: "";
  position: absolute;
  right: -5px; bottom: 14px;
  width: 10px; height: 10px;
  background: inherit;
  border-right: inherit; border-top: inherit;
  transform: rotate(45deg);
}
.profi.show-nudge .profi-nudge { opacity: 1; transform: translateX(0); pointer-events: auto; }
.profi.is-open .profi-nudge { display: none; }

/* ---- panel ---------------------------------------------------------- */
.profi-panel {
  position: absolute;
  right: 0;
  bottom: calc(60px + .75rem);
  width: min(var(--profi-panel-w), calc(100vw - 2rem));
  max-height: min(72vh, 620px);
  display: flex;
  flex-direction: column;
  background: var(--pro-surface, #0f172a);
  border: 1px solid var(--pro-border, rgba(148,163,184,.2));
  border-radius: 20px;
  box-shadow: 0 1.5rem 3rem rgba(2, 8, 23, .45);
  overflow: hidden;
  transform-origin: bottom right;
  opacity: 0;
  transform: translateY(12px) scale(.96);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.profi.is-open .profi-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* header */
.profi-head {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .9rem 1rem;
  color: #fff;
  background: var(--pro-grad-btn, linear-gradient(135deg, #2563eb, #38bdf8));
}
.profi-head-avatar {
  width: 40px; height: 40px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .18);
  display: grid; place-items: center;
  flex: none;
}
.profi-head-avatar svg { width: 26px; height: 26px; }
.profi-head-meta { line-height: 1.2; min-width: 0; }
.profi-head-name { font-weight: 800; font-size: .98rem; display: flex; align-items: center; gap: .4rem; }
.profi-head-sub { font-size: .72rem; opacity: .9; display: flex; align-items: center; gap: .35rem; }
.profi-head-sub::before {
  content: ""; width: 7px; height: 7px; border-radius: 999px;
  background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .3);
}
.profi-close {
  margin-left: auto;
  border: 0; background: rgba(255,255,255,.15); color: #fff;
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; cursor: pointer; font-size: 1rem;
  transition: background .15s ease;
}
.profi-close:hover { background: rgba(255,255,255,.28); }

/* messages area */
.profi-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  background: var(--pro-bg, #0b1220);
}
.profi-msg { display: flex; gap: .55rem; max-width: 92%; }
.profi-msg-av {
  width: 28px; height: 28px; border-radius: 999px; flex: none;
  display: grid; place-items: center; color: #fff;
  background: var(--pro-grad-btn, linear-gradient(135deg, #2563eb, #38bdf8));
}
.profi-msg-av svg { width: 18px; height: 18px; }
.profi-bubble {
  background: var(--pro-surface, #0f172a);
  border: 1px solid var(--pro-border, rgba(148,163,184,.2));
  color: var(--pro-text, #cbd5e1);
  padding: .65rem .8rem;
  border-radius: 4px 14px 14px 14px;
  font-size: .9rem;
  line-height: 1.5;
}
.profi-bubble strong { color: var(--pro-heading, #e2e8f0); }
.profi-msg.is-user { align-self: flex-end; flex-direction: row-reverse; }
.profi-msg.is-user .profi-bubble {
  background: var(--profi-accent);
  border-color: transparent;
  color: #fff;
  border-radius: 14px 4px 14px 14px;
}
.profi-msg.is-user .profi-msg-av {
  background: var(--pro-elevated, #1e293b);
  color: var(--pro-muted, #94a3b8);
}

/* action links inside an answer */
.profi-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.profi-action {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .38rem .7rem;
  border-radius: 999px;
  font-size: .8rem; font-weight: 700; text-decoration: none;
  color: var(--profi-accent);
  background: var(--pro-primary-soft, rgba(37,99,235,.14));
  border: 1px solid color-mix(in srgb, var(--profi-accent) 30%, transparent);
  transition: background .15s ease, transform .12s ease;
}
.profi-action:hover { transform: translateY(-1px); background: color-mix(in srgb, var(--profi-accent) 22%, transparent); }
.profi-action i { font-size: .9em; }

/* suggestion chips */
.profi-suggests { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .2rem; }
.profi-chip {
  border: 1px solid var(--pro-border, rgba(148,163,184,.2));
  background: var(--pro-surface, #0f172a);
  color: var(--pro-text, #cbd5e1);
  border-radius: 999px;
  padding: .4rem .8rem;
  font-size: .8rem; font-weight: 600; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.profi-chip:hover {
  border-color: var(--profi-accent);
  color: var(--pro-heading, #e2e8f0);
  background: var(--pro-primary-soft, rgba(37,99,235,.12));
}

/* typing indicator */
.profi-typing { display: inline-flex; gap: 4px; align-items: center; padding: .2rem 0; }
.profi-typing span {
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--pro-muted, #94a3b8);
  animation: profi-bounce 1.1s infinite ease-in-out both;
}
.profi-typing span:nth-child(2) { animation-delay: .15s; }
.profi-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes profi-bounce {
  0%, 80%, 100% { transform: scale(.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* footer input */
.profi-foot {
  flex: none;
  border-top: 1px solid var(--pro-border, rgba(148,163,184,.2));
  padding: .6rem;
  background: var(--pro-surface, #0f172a);
}
.profi-form { display: flex; gap: .5rem; align-items: center; }
.profi-input {
  flex: 1 1 auto; min-width: 0;
  border: 1px solid var(--pro-border, rgba(148,163,184,.2));
  background: var(--pro-bg, #0b1220);
  color: var(--pro-text, #e2e8f0);
  border-radius: 12px;
  padding: .6rem .8rem;
  font-size: .9rem;
  outline: none;
  transition: border-color .15s ease;
}
.profi-input:focus { border-color: var(--profi-accent); }
.profi-input::placeholder { color: var(--pro-faint, #64748b); }
.profi-send {
  flex: none;
  width: 42px; height: 42px;
  border: 0; border-radius: 12px; cursor: pointer;
  color: #fff;
  background: var(--pro-grad-btn, linear-gradient(135deg, #2563eb, #38bdf8));
  display: grid; place-items: center; font-size: 1.05rem;
  transition: transform .12s ease, opacity .15s ease;
}
.profi-send:hover { transform: translateY(-1px); }
.profi-send:disabled { opacity: .5; cursor: default; transform: none; }
.profi-foot-links {
  display: flex; gap: 1rem; justify-content: center;
  margin-top: .5rem;
}
.profi-foot-links a {
  font-size: .74rem; font-weight: 600; text-decoration: none;
  color: var(--pro-muted, #94a3b8);
  display: inline-flex; align-items: center; gap: .3rem;
}
.profi-foot-links a:hover { color: var(--profi-accent); }

/* mobile: full-width sheet */
@media (max-width: 480px) {
  .profi { right: .75rem; bottom: .75rem; }
  .profi-panel {
    position: fixed;
    right: .5rem; left: .5rem; bottom: 5rem;
    width: auto;
    max-height: 76vh;
  }
}
