/* Trade Alchemy — Assistente chat widget (dark + gold) */
.ta-assist {
  --ta-gold: #ffd700;
  --ta-gold-dim: #c9a227;
  --ta-bg: #0e0e0e;
  --ta-panel: #141414;
  --ta-surface: #1c1c1c;
  --ta-border: rgba(255, 215, 0, 0.22);
  --ta-text: #f2f2f2;
  --ta-muted: #a8a8a8;
  --ta-user: #2a2410;
  --ta-bot: #1a1a1a;
  position: fixed;
  z-index: 2147483000;
  right: max(1.1rem, env(safe-area-inset-right, 0px));
  bottom: max(1.1rem, env(safe-area-inset-bottom, 0px));
  font-family: inherit;
  color: var(--ta-text);
  /* iOS/Android: evita che il FAB resti fuori dal visual viewport fino allo scroll */
  -webkit-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  isolation: isolate;
  pointer-events: none;
}

.ta-assist > * {
  pointer-events: auto;
}

.ta-assist[hidden] {
  display: none !important;
}

.ta-assist__launcher {
  position: relative;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  background: radial-gradient(circle at 30% 25%, #2a2a2a 0%, #0b0b0b 70%);
  box-shadow:
    0 0 0 1px rgba(255, 215, 0, 0.35),
    0 8px 28px rgba(0, 0, 0, 0.55),
    0 0 24px rgba(255, 215, 0, 0.18);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease;
}

.ta-assist__launcher:hover,
.ta-assist__launcher:focus-visible {
  transform: translateY(-3px) scale(1.04);
  box-shadow:
    0 0 0 1px rgba(255, 215, 0, 0.55),
    0 12px 36px rgba(0, 0, 0, 0.6),
    0 0 32px rgba(255, 215, 0, 0.28);
  outline: none;
}

.ta-assist__launcher-ring {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid rgba(255, 215, 0, 0.35);
  animation: ta-assist-pulse 2.4s ease-out infinite;
  pointer-events: none;
}

@keyframes ta-assist-pulse {
  0% { transform: scale(0.92); opacity: 0.85; }
  70% { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

.ta-assist__launcher-logo {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center center;
  display: block;
  margin: 0;
}

.ta-assist__brand img,
.ta-assist__brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center center;
  display: block;
  flex-shrink: 0;
}

.ta-assist__title-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.ta-assist__info {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 215, 0, 0.55);
  background: rgba(255, 215, 0, 0.12);
  color: var(--ta-gold);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ta-assist__info:hover,
.ta-assist__info:focus-visible {
  background: rgba(255, 215, 0, 0.22);
  outline: none;
}

.ta-assist.is-open .ta-assist__launcher {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.6);
}

.ta-assist__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: min(400px, calc(100vw - 1.5rem));
  height: min(620px, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(165deg, rgba(255, 215, 0, 0.06) 0%, transparent 38%),
    linear-gradient(180deg, #161616 0%, var(--ta-bg) 100%);
  border: 1px solid var(--ta-border);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  overflow: hidden;
  transform-origin: bottom right;
  animation: ta-assist-open 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ta-assist__panel[hidden] {
  display: none !important;
}

@keyframes ta-assist-open {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.ta-assist__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: linear-gradient(90deg, rgba(255, 215, 0, 0.12), transparent 70%);
  border-bottom: 1px solid var(--ta-border);
}

.ta-assist__brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  flex: 1;
}

.ta-assist__brand img {
  border-radius: 50%;
  border: 1px solid rgba(255, 215, 0, 0.4);
  background: #000;
  flex-shrink: 0;
}

.ta-assist__brand-text {
  flex: 1;
  min-width: 0;
}

.ta-assist__title {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 0.95rem;
  color: var(--ta-gold);
  line-height: 1.2;
}

.ta-assist__meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.1rem;
}

.ta-assist__subtitle,
.ta-assist__idle-timer {
  font-size: 0.72rem;
  color: var(--ta-muted);
  line-height: 1.2;
}

.ta-assist__idle-timer {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  margin-right: 0.35rem;
}

.ta-assist__idle-timer[hidden] {
  display: none !important;
}

.ta-assist__close {
  border: none;
  background: transparent;
  color: var(--ta-muted);
  font-size: 1.35rem;
  line-height: 1;
  width: 2rem;
  height: 2rem;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ta-assist__close:hover {
  color: var(--ta-gold);
  background: rgba(255, 215, 0, 0.08);
}

.ta-assist__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
  color-scheme: dark;
  scrollbar-width: thin;
  scrollbar-color: #c9a227 #1c1c1c;
}

.ta-assist__messages::-webkit-scrollbar {
  width: 10px;
  height: 10px;
  background: #1c1c1c;
}

.ta-assist__messages::-webkit-scrollbar-track {
  background: #141414;
  border-radius: 10px;
}

.ta-assist__messages::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #ffd700, #c9a227);
  border-radius: 10px;
  border: 2px solid #141414;
  min-height: 40px;
}

.ta-assist__messages::-webkit-scrollbar-thumb:hover {
  background: #ffd700;
}

.ta-assist__messages::-webkit-scrollbar-corner {
  background: #141414;
}

.ta-assist__bubble {
  position: relative;
  max-width: 92%;
  padding: 0.7rem 0.85rem;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-break: break-word;
  animation: ta-assist-msg 0.28s ease both;
}

@keyframes ta-assist-msg {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.ta-assist__bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.ta-assist__bubble--bot {
  align-self: flex-start;
  background: var(--ta-bot);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-bottom-left-radius: 4px;
  padding-bottom: 1.55rem;
}

.ta-assist__bubble--user {
  align-self: flex-end;
  background: linear-gradient(145deg, #3a3214, var(--ta-user));
  border: 1px solid rgba(255, 215, 0, 0.28);
  border-bottom-right-radius: 4px;
  color: #fff8d6;
  padding-left: 1.85rem;
}

.ta-assist__bubble--user .ta-assist__copy {
  left: 0.3rem;
  right: auto;
  bottom: 0.25rem;
  color: rgba(255, 248, 214, 0.5);
}

.ta-assist__bubble--user.is-single-line .ta-assist__copy {
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
}

.ta-assist__bubble--user .ta-assist__copy:hover {
  color: rgba(255, 215, 0, 0.95);
  background: rgba(255, 215, 0, 0.12);
}

.ta-assist__copy {
  position: absolute;
  right: 0.35rem;
  bottom: 0.25rem;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(242, 242, 242, 0.45);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.ta-assist__copy:hover {
  color: rgba(255, 215, 0, 0.9);
  background: rgba(255, 215, 0, 0.1);
}

.ta-assist__copy .ta-assist__copy-ico--check {
  display: none;
}

.ta-assist__copy.is-copied {
  color: #7dffa3;
}

.ta-assist__copy.is-copied .ta-assist__copy-ico--copy {
  display: none;
}

.ta-assist__copy.is-copied .ta-assist__copy-ico--check {
  display: block;
}

.ta-assist__mode-item--copy {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.15rem;
  border-top: 1px solid rgba(255, 215, 0, 0.12);
  border-radius: 0 0 8px 8px;
  color: rgba(255, 215, 0, 0.85);
  font-weight: 600;
}

.ta-assist__mode-item--copy:hover {
  background: rgba(255, 215, 0, 0.14);
  color: #ffe566;
}

.ta-assist__toast {
  position: absolute;
  left: 50%;
  bottom: 4.6rem;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: min(280px, calc(100% - 1.5rem));
  max-width: calc(100% - 1.5rem);
  padding: 0.7rem 0.75rem 0.7rem 0.85rem;
  border-radius: 12px;
  background: rgba(28, 28, 32, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  color: #f2f2f2;
  font-size: 0.82rem;
  font-weight: 500;
  pointer-events: auto;
}

.ta-assist__toast[hidden] {
  display: none !important;
}

.ta-assist__toast-info {
  flex-shrink: 0;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 215, 0, 0.7);
  color: rgba(255, 215, 0, 0.95);
  font-size: 0.7rem;
  font-weight: 700;
  font-style: italic;
  display: grid;
  place-items: center;
  line-height: 1;
}

.ta-assist__toast-text {
  flex: 1;
  min-width: 0;
}

.ta-assist__toast-close {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: rgba(242, 242, 242, 0.55);
  font-size: 1.1rem;
  line-height: 1;
  width: 1.5rem;
  height: 1.5rem;
  cursor: pointer;
  border-radius: 6px;
}

.ta-assist__toast-close:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.ta-assist__typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  background: var(--ta-bot);
  border: 1px solid rgba(255, 215, 0, 0.15);
  border-radius: 14px;
  font-size: 0.8rem;
  color: var(--ta-muted);
}

.ta-assist__dots {
  display: inline-flex;
  gap: 4px;
}

.ta-assist__dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ta-gold);
  animation: ta-assist-dot 1.2s ease-in-out infinite;
}

.ta-assist__dots span:nth-child(2) { animation-delay: 0.15s; }
.ta-assist__dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ta-assist-dot {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.ta-assist__composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--ta-border);
  background: rgba(0, 0, 0, 0.35);
}

.ta-assist__input-wrap {
  flex: 1;
  position: relative;
  display: flex;
  align-items: flex-end;
  min-width: 0;
}

.ta-assist__input {
  flex: 1;
  width: 100%;
  resize: none;
  min-height: 42px;
  max-height: 120px;
  border-radius: 12px;
  border: 1px solid rgba(255, 215, 0, 0.2);
  background: var(--ta-surface);
  color: var(--ta-text);
  padding: 0.65rem 4.85rem 0.65rem 0.8rem;
  font-size: 0.9rem;
  line-height: 1.35;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.ta-assist__input::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.ta-assist__input:focus {
  outline: none;
  border-color: rgba(255, 215, 0, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 215, 0, 0.12);
}

.ta-assist__mode {
  position: absolute;
  right: 0.65rem;
  bottom: 0.4rem;
  z-index: 3;
}

.ta-assist__mode-btn {
  min-width: 32px;
  height: 28px;
  padding: 0 0.55rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 215, 0, 0.35);
  background: rgba(0, 0, 0, 0.45);
  color: rgba(255, 215, 0, 0.9);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.ta-assist__mode-btn:hover {
  border-color: rgba(255, 215, 0, 0.65);
  color: #ffe566;
}

.ta-assist__mode-btn.is-on {
  background: linear-gradient(145deg, rgba(255, 229, 102, 0.95), rgba(201, 162, 39, 0.95));
  border-color: transparent;
  color: #111;
  box-shadow: 0 0 10px rgba(255, 215, 0, 0.22);
}

.ta-assist__mode-btn.is-on .ta-assist__mode-icon {
  display: none;
}

.ta-assist__mode-icon {
  display: grid;
  place-items: center;
}

.ta-assist__mode-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  min-width: 132px;
  padding: 0.35rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 215, 0, 0.28);
  background: rgba(12, 12, 14, 0.96);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  display: grid;
  gap: 0.25rem;
}

.ta-assist__mode-menu[hidden] {
  display: none !important;
}

.ta-assist__mode-item {
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #f2f2f2;
  text-align: left;
  padding: 0.55rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.ta-assist__mode-item:hover,
.ta-assist__mode-item.is-active {
  background: rgba(255, 215, 0, 0.14);
  color: #ffe566;
}

.ta-assist__mode-item--off {
  color: rgba(242, 242, 242, 0.55);
  font-weight: 500;
}

.ta-assist__send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(145deg, #ffe566, var(--ta-gold-dim));
  color: #111;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s ease, filter 0.15s ease, background 0.15s ease;
}

.ta-assist__send .ta-assist__icon-stop {
  display: none;
}

.ta-assist__send.is-stop {
  background: linear-gradient(145deg, #f0f0f0, #c8c8c8);
}

.ta-assist__send.is-stop .ta-assist__icon-send {
  display: none;
}

.ta-assist__send.is-stop .ta-assist__icon-stop {
  display: block;
}

.ta-assist__send:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.ta-assist__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .ta-assist {
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    bottom: max(0.85rem, env(safe-area-inset-bottom, 0px));
  }
  .ta-assist__panel {
    width: calc(100vw - 1.5rem);
    max-width: 400px;
    height: min(78vh, 640px);
    max-height: calc(100dvh - 1.5rem);
  }
  .ta-assist__launcher {
    width: 60px;
    height: 60px;
  }
  /* impulso anche su mobile, scala un filo più contenuta (niente overflow pagina) */
  .ta-assist__launcher-ring {
    inset: -3px;
    animation: ta-assist-pulse-mobile 2.4s ease-out infinite;
  }
}

@keyframes ta-assist-pulse-mobile {
  0% { transform: scale(0.94); opacity: 0.85; }
  70% { transform: scale(1.12); opacity: 0; }
  100% { transform: scale(1.12); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ta-assist__launcher-ring,
  .ta-assist__panel,
  .ta-assist__bubble,
  .ta-assist__dots span {
    animation: none !important;
  }
}
