/* Virtual Assistant Widget */
.assistant-root {
  position: fixed;
  right: 0.85rem;
  bottom: 5.2rem;
  z-index: 130;
  font-family: var(--font);
  pointer-events: none;
}

.assistant-root > * {
  pointer-events: auto;
}

.assistant-float {
  display: grid;
  place-items: center;
  animation: assistantFloat 4s ease-in-out infinite;
  will-change: transform;
}

.assistant-toggle {
  position: relative;
  width: 110px;
  height: 165px;
  border: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  transition: transform 0.25s var(--ease), filter 0.25s var(--ease);
  box-shadow: none;
  overflow: visible;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.35));
}

.assistant-toggle:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 16px 28px rgba(0, 0, 0, 0.4));
}

.assistant-toggle:active {
  transform: scale(0.97);
}

.assistant-toggle[aria-expanded="true"] {
  animation: none;
}

.assistant-toggle__ring,
.assistant-toggle__frame {
  display: contents;
}

.assistant-toggle__avatar {
  display: block;
  width: 110px;
  height: 165px;
  object-fit: contain;
  object-position: center bottom;
  background: transparent;
  border: 0;
  border-radius: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.assistant-toggle__badge {
  position: absolute;
  top: 8px;
  right: 4px;
  z-index: 2;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--red), var(--red-bright));
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 900;
  display: grid;
  place-items: center;
  border: 2px solid var(--white);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.assistant-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 1rem);
  width: min(390px, calc(100vw - 2.4rem));
  height: min(560px, calc(100svh - 8rem));
  display: flex;
  flex-direction: column;
  border-radius: 28px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 28px 80px rgba(0, 26, 150, 0.22);
  animation: assistantSlideUp 0.45s var(--ease);
  min-width: 0;
}

.assistant-panel[hidden] { display: none; }

.assistant-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1rem 0.9rem;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: var(--white);
}

.assistant-avatar {
  --avatar-size: 36px;
  width: var(--avatar-size);
  height: var(--avatar-size);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  overflow: visible;
  background: transparent;
}

.assistant-avatar img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  background: transparent;
  border: 0;
  border-radius: 0;
  display: block;
}

.assistant-avatar--header {
  --avatar-size: 56px;
}

.assistant-header .assistant-avatar {
  border: 0;
  background: transparent;
}

.assistant-header__text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 800;
}

.assistant-header__text span {
  font-size: 0.75rem;
  opacity: 0.85;
}

.assistant-header__status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.assistant-header__status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.2);
  animation: assistantPulse 2s ease-out infinite;
}

.assistant-close {
  margin-left: auto;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
  font-size: 1.2rem;
  cursor: pointer;
}

.assistant-messages {
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  background: linear-gradient(180deg, #f7f9ff, #ffffff);
  min-height: 0;
}

.assistant-msg {
  display: flex;
  gap: 0.55rem;
  align-items: flex-end;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  animation: assistantMsgIn 0.35s var(--ease);
}

.assistant-msg--user {
  justify-content: flex-end;
}

.assistant-msg .assistant-avatar {
  --avatar-size: 36px;
  align-self: flex-end;
  flex: 0 0 auto;
}

.assistant-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 1em;
}

.assistant-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  opacity: 0.45;
  animation: assistantDot 1.2s ease-in-out infinite;
}

.assistant-typing i:nth-child(2) { animation-delay: 0.15s; }
.assistant-typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes assistantDot {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-3px); opacity: 1; }
}

.assistant-msg__bubble {
  max-width: min(78%, 280px);
  min-width: 0;
  padding: 0.8rem 0.95rem;
  border-radius: 18px;
  font-size: 0.9rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.assistant-msg--assistant .assistant-msg__bubble {
  background: var(--white);
  border: 1px solid var(--line);
  color: var(--ink);
  border-bottom-left-radius: 6px;
}

.assistant-msg--user .assistant-msg__bubble {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: var(--white);
  border-bottom-right-radius: 6px;
}

.assistant-msg__bubble p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.assistant-msg__bubble a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: underline;
  word-break: break-word;
}

.assistant-msg--user .assistant-msg__bubble a {
  color: #fff;
}

.assistant-msg__bubble time {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.65rem;
  opacity: 0.55;
}

@keyframes assistantMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.assistant-quick {
  display: flex;
  gap: 0.45rem;
  padding: 0 1rem 0.65rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.assistant-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(0, 26, 150, 0.12);
  background: var(--white);
  color: var(--blue);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.25s, transform 0.25s;
}

.assistant-chip:hover {
  background: rgba(0, 174, 239, 0.12);
  transform: translateY(-1px);
}

.assistant-form {
  display: flex;
  gap: 0.55rem;
  padding: 0.85rem 1rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.assistant-input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  resize: none;
  min-height: 48px;
  max-height: 96px;
}

.assistant-input:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 4px rgba(0, 174, 239, 0.12);
}

.assistant-send {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: var(--white);
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.25s;
}

.assistant-send:hover { transform: scale(1.05); }

@keyframes assistantFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes assistantSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes assistantPulse {
  0% { box-shadow: 0 0 0 0 rgba(0, 174, 239, 0.45); }
  70% { box-shadow: 0 0 0 12px rgba(0, 174, 239, 0); }
  100% { box-shadow: 0 0 0 0 rgba(0, 174, 239, 0); }
}

@media (max-width: 720px) {
  .assistant-root {
    right: max(0.55rem, env(safe-area-inset-right));
    bottom: calc(4.6rem + env(safe-area-inset-bottom, 0px));
  }

  .assistant-panel {
    position: fixed;
    left: 0.65rem;
    right: 0.65rem;
    bottom: calc(5.8rem + env(safe-area-inset-bottom, 0px));
    width: auto;
    height: min(62svh, 480px);
    border-radius: 22px;
  }

  .assistant-header {
    padding: 0.85rem;
    gap: 0.65rem;
  }

  .assistant-avatar--header {
    --avatar-size: 46px;
  }

  .assistant-header__text strong {
    font-size: 0.88rem;
  }

  .assistant-messages {
    padding: 0.85rem;
    gap: 0.7rem;
  }

  .assistant-msg__bubble {
    max-width: min(82%, 240px);
    font-size: 0.86rem;
    padding: 0.7rem 0.85rem;
  }

  .assistant-quick {
    padding: 0 0.75rem 0.55rem;
    gap: 0.4rem;
  }

  .assistant-chip {
    font-size: 0.68rem;
    padding: 0.4rem 0.7rem;
  }

  .assistant-form {
    padding: 0.7rem 0.75rem 0.85rem;
    gap: 0.45rem;
  }

  .assistant-input {
    min-height: 44px;
    font-size: 0.88rem;
    padding: 0.7rem 0.85rem;
  }

  .assistant-send {
    width: 44px;
    height: 44px;
  }

  .assistant-toggle {
    width: 78px;
    height: 118px;
  }

  .assistant-toggle__avatar {
    width: 78px;
    height: 118px;
  }

  .assistant-toggle__badge {
    top: 4px;
    right: 0;
    min-width: 20px;
    height: 20px;
    font-size: 0.58rem;
  }
}

@media (max-width: 420px) {
  .assistant-toggle {
    width: 70px;
    height: 105px;
  }

  .assistant-toggle__avatar {
    width: 70px;
    height: 105px;
  }

  .assistant-panel {
    height: min(58svh, 440px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .assistant-float {
    animation: none !important;
  }
}
