@import url("phone-input.css");

.floating-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 85;
}

.chat-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 0 18px 0 14px;
  border: 1px solid rgba(183, 140, 255, 0.32);
  border-radius: 999px;
  color: #f8fafc;
  background: linear-gradient(135deg, var(--blue), var(--blue-bright));
  box-shadow: 0 18px 54px rgba(139, 75, 220, 0.34), var(--glow);
  font-weight: 800;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.chat-toggle:hover,
.chat-toggle:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 22px 60px rgba(139, 75, 220, 0.42), var(--glow);
}

.chat-toggle-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.12);
  font-family: "Sora", sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
}

.chat-toggle-label {
  font-size: 0.92rem;
  letter-spacing: 0.01em;
}

.floating-chat.is-open .chat-toggle {
  display: none;
}

.chat-window {
  position: absolute;
  right: 0;
  bottom: 0;
  display: none;
  flex-direction: column;
  width: min(460px, calc(100vw - 32px));
  max-height: min(680px, calc(100vh - 32px));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 26px;
  background:
    linear-gradient(165deg, rgba(19, 34, 56, 0.98), rgba(5, 8, 22, 0.98)),
    var(--surface);
  box-shadow: var(--shadow), var(--glow);
  font-family: inherit;
}

.chat-window input,
.chat-window textarea,
.chat-window select,
.chat-window button {
  font-family: inherit;
}

.floating-chat.is-open .chat-window {
  display: flex;
}

.chat-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(183, 140, 255, 0.14);
  background: rgba(3, 7, 18, 0.52);
}

.chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: rgba(3, 7, 18, 0.18);
}

.chat-body {
  flex: 1;
  min-height: 300px;
  max-height: 440px;
  padding: 20px 18px;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(183, 140, 255, 0.35) transparent;
}

.chat-top-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-avatar {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid rgba(183, 140, 255, 0.28);
  border-radius: 12px;
  color: var(--cyan);
  background: linear-gradient(145deg, rgba(139, 75, 220, 0.42), rgba(15, 23, 42, 0.78));
  box-shadow: 0 0 18px rgba(139, 75, 220, 0.22);
  font-family: "Sora", sans-serif;
  font-size: 0.72rem;
  font-weight: 800;
  overflow: hidden;
}

.chat-avatar.has-brand-icon {
  padding: 6px;
}

.chat-avatar-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.chat-top strong {
  display: block;
  font-family: "Sora", sans-serif;
  font-size: 0.92rem;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-size: 12px;
  line-height: 1;
  color: rgba(255, 255, 255, 0.78);
  font-weight: 400;
}

.chat-status-dot {
  width: 7px;
  height: 7px;
  min-width: 7px;
  min-height: 7px;
  flex-shrink: 0;
  border-radius: 999px;
  display: inline-block;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.75);
}

.chat-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.chat-reset,
.chat-close {
  display: grid;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-soft);
  background: rgba(3, 7, 18, 0.48);
  font-size: 1.1rem;
  line-height: 1;
  transition: color 180ms ease, border-color 180ms ease;
}

.chat-reset:hover,
.chat-reset:focus-visible,
.chat-close:hover,
.chat-close:focus-visible {
  color: var(--text);
  border-color: rgba(183, 140, 255, 0.34);
}

.chat-close {
  font-size: 1.25rem;
}

.chat-footer {
  flex: 0 0 auto;
  border-top: 1px solid rgba(183, 140, 255, 0.12);
  background: rgba(3, 7, 18, 0.44);
}

.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: transparent;
}

.chat-body::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(183, 140, 255, 0.28);
}

.chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(183, 140, 255, 0.42);
}

.chat-body .message-row {
  display: flex;
  width: 100%;
  margin-bottom: 12px;
}

.chat-body .message-row.bot {
  justify-content: flex-start;
}

.chat-body .message-row.user {
  justify-content: flex-end;
}

.chat-body .message {
  max-width: 80%;
  margin: 0;
  padding: 13px 16px;
  border-radius: 20px;
  font-size: 0.91rem;
  line-height: 1.52;
}

.chat-body .message.bot {
  color: var(--text-soft);
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.08);
  border-bottom-left-radius: 6px;
}

.chat-body .message.user {
  color: #f8fafc;
  background: linear-gradient(135deg, var(--blue), var(--blue-bright));
  box-shadow: 0 8px 24px rgba(139, 75, 220, 0.22);
  border-bottom-right-radius: 6px;
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  color: var(--muted);
  font-size: 0.84rem;
  font-style: normal;
  background: rgba(148, 163, 184, 0.08);
}

.chat-typing-label {
  font-weight: 600;
}

.chat-typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.chat-typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--blue-soft);
  animation: chat-dot-pulse 1.2s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.message.error {
  max-width: 100%;
  color: #fca5a5;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.22);
}

.message.success {
  max-width: 100%;
  color: var(--success-soft);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.22);
}

.chat-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px 18px 18px;
  border-top: 0;
  background: transparent;
}

.chat-input input {
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  color: var(--text);
  background: rgba(3, 7, 18, 0.56);
  font-size: 16px;
}

.chat-input input::placeholder {
  color: var(--muted);
}

.chat-input input:focus {
  border-color: rgba(183, 140, 255, 0.48);
  outline: 3px solid rgba(139, 75, 220, 0.16);
}

.chat-input button {
  display: grid;
  min-width: 44px;
  min-height: 44px;
  place-items: center;
  padding: 0 14px;
  border: 0;
  border-radius: 14px;
  color: #f8fafc;
  background: linear-gradient(135deg, var(--blue), var(--blue-bright));
  font-size: 1.1rem;
  font-weight: 900;
  transition: transform 180ms ease, opacity 180ms ease;
}

.chat-input button:hover:not(:disabled),
.chat-input button:focus-visible:not(:disabled) {
  transform: translateY(-1px);
}

.chat-input input:disabled,
.chat-input button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.chat-input[hidden] {
  display: none;
}

.chat-quick-actions {
  display: grid;
  gap: 10px;
  padding: 14px 18px 0;
}

.chat-quick-actions[hidden] {
  display: none;
}

.chat-quick-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chat-quick-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 34px;
  opacity: 1;
  transition: opacity 200ms ease;
}

.chat-quick-chips.is-fading {
  opacity: 0;
}

.chat-quick-label[hidden] {
  display: none;
}

.chat-chip {
  padding: 8px 13px;
  border: 1px solid rgba(183, 140, 255, 0.24);
  border-radius: 999px;
  color: var(--blue-soft);
  background: rgba(139, 75, 220, 0.12);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.2;
  transition: background 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.chat-chip:hover,
.chat-chip:focus-visible {
  border-color: rgba(183, 140, 255, 0.42);
  background: rgba(139, 75, 220, 0.2);
  transform: translateY(-1px);
}

.chat-lead-form {
  display: grid;
  gap: 14px;
  width: 100%;
  margin-top: 8px;
  padding: 18px;
  border: 1px solid rgba(183, 140, 255, 0.26);
  border-radius: 18px;
  background: rgba(3, 7, 18, 0.58);
  box-shadow: inset 0 1px 0 rgba(183, 140, 255, 0.06);
  font-family: inherit;
}

.chat-lead-form-title {
  margin: 0 0 4px;
  color: var(--text-soft);
  font-size: 0.84rem;
  font-weight: 700;
}

.chat-lead-privacy {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
}

.chat-lead-privacy a {
  color: #e9d5ff;
  font-weight: 700;
  text-underline-offset: 2px;
}

.chat-lead-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
}

.chat-lead-form input,
.chat-lead-form textarea {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid rgba(183, 140, 255, 0.18);
  border-radius: 14px;
  color: var(--text);
  background: rgba(3, 7, 18, 0.66);
  caret-color: #c084fc;
  font: inherit;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: normal;
  transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.chat-lead-form textarea {
  min-height: 104px;
  resize: vertical;
}

.chat-lead-form input:focus,
.chat-lead-form textarea:focus {
  border-color: rgba(192, 132, 252, 0.72);
  outline: 0;
  background: rgba(5, 8, 22, 0.82);
  box-shadow:
    0 0 0 3px rgba(139, 92, 246, 0.18),
    0 14px 34px rgba(3, 7, 18, 0.24);
}

.chat-lead-form button[type="submit"] {
  min-height: 44px;
  margin-top: 4px;
  border: 0;
  border-radius: 12px;
  color: #f8fafc;
  background: linear-gradient(135deg, var(--blue), var(--blue-bright));
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.chat-lead-form button[type="submit"]:hover:not(:disabled),
.chat-lead-form button[type="submit"]:focus-visible:not(:disabled) {
  transform: translateY(-1px);
}

.chat-lead-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-lead-form-status {
  min-height: 1.2em;
  margin: 0;
  font-size: 0.8rem;
}

.chat-lead-form-status.error {
  color: #fca5a5;
}

@media (max-width: 640px) {
  .floating-chat {
    right: 12px;
    bottom: 12px;
  }

  .chat-toggle {
    min-height: 52px;
    padding: 0 16px 0 12px;
  }

  .chat-toggle-label {
    display: none;
  }

  .chat-window {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    max-height: min(82vh, 620px);
  }

  .chat-body {
    min-height: 220px;
    max-height: calc(82vh - 220px);
  }

  .chat-quick-actions {
    padding: 12px 14px 0;
  }

  .chat-input {
    padding: 12px 14px 16px;
  }
}

.chat-toggle,
.chat-input button,
.chat-reset,
.chat-close {
  position: relative;
  overflow: hidden;
  transition:
    transform 260ms cubic-bezier(0.22, 1, 0.36, 1),
    border-color 260ms ease,
    box-shadow 260ms ease,
    background-position 260ms ease,
    opacity 260ms ease;
}

.chat-toggle,
.chat-input button {
  background-size: 160% 160%;
}

.chat-toggle::after {
  position: absolute;
  inset: -45% auto -45% -70%;
  width: 48%;
  content: "";
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
  transform: skewX(-18deg);
  transition: left 560ms ease;
}

.chat-toggle:hover::after {
  left: 125%;
}

.chat-toggle:hover,
.chat-input button:hover {
  transform: translateY(-3px);
  background-position: 100% 0;
  box-shadow: 0 18px 48px rgba(139, 75, 220, 0.3);
}

.chat-toggle:active,
.chat-input button:active {
  transform: translateY(0) scale(0.98);
}

.chat-toggle:focus-visible,
.chat-input button:focus-visible,
.chat-reset:focus-visible,
.chat-close:focus-visible {
  outline: 3px solid rgba(183, 140, 255, 0.48);
  outline-offset: 3px;
}

.chat-toggle:hover {
  box-shadow: 0 20px 58px rgba(139, 75, 220, 0.38), 0 0 0 1px rgba(183, 140, 255, 0.28);
}

.chat-toggle {
  animation: chat-button-breathe 3.2s ease-in-out infinite;
}

.floating-chat.is-open .chat-toggle {
  animation: none;
}

@media (max-width: 640px) {
  .chat-toggle {
    animation: none;
  }
}

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

.floating-chat,
.chat-window,
.chat-toggle {
  pointer-events: auto;
}

.floating-chat {
  position: fixed;
  right: clamp(16px, 2vw, 28px);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 1000;
  pointer-events: auto;
  transition:
    bottom 240ms ease,
    transform 220ms ease;
}

.floating-chat.chat-near-footer {
  bottom: calc(88px + env(safe-area-inset-bottom));
}

.chat-toggle {
  color: #f8fafc;
  background:
    radial-gradient(circle at 24% 20%, rgba(216, 180, 254, 0.24), transparent 34%),
    linear-gradient(135deg, rgba(139, 75, 220, 0.96), rgba(88, 28, 135, 0.94));
  box-shadow: 0 18px 54px rgba(139, 75, 220, 0.34), 0 0 38px rgba(168, 85, 247, 0.16);
}

.chat-window {
  right: 0;
  bottom: 0;
  width: min(540px, calc(100vw - 56px));
  height: min(680px, calc(100dvh - 96px - env(safe-area-inset-bottom)));
  max-height: calc(100dvh - 96px - env(safe-area-inset-bottom));
}

.chat-body {
  min-height: 0;
  max-height: none;
}

.floating-chat::before {
  position: absolute;
  inset: -12px;
  z-index: -1;
  content: "";
  pointer-events: none;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(139, 75, 220, 0.16), transparent 64%);
  opacity: 0.9;
}

@media (max-width: 640px) {
  .floating-chat {
    right: 12px;
    bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .floating-chat.chat-near-footer {
    bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .chat-window {
    left: auto;
    right: 0;
    bottom: 0;
    width: calc(100vw - 24px);
    height: min(640px, calc(100dvh - 90px - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 90px - env(safe-area-inset-bottom));
  }
}

@media (max-width: 768px) {
  .chat-window {
    max-width: 100%;
  }

  .floating-chat {
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .chat-window {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 90px);
    border-radius: 22px;
  }

  .chat-top {
    padding: 14px;
  }

  .chat-body {
    min-height: 190px;
    max-height: calc(100dvh - 310px);
  }

  .chat-lead-form {
    padding: 14px;
  }

  .chat-lead-form textarea {
    min-height: 92px;
  }
}

@media (max-width: 480px) {
  .chat-toggle {
    min-height: 50px;
    padding: 0 12px;
  }

  .chat-toggle-icon {
    width: 30px;
    height: 30px;
  }

  .chat-window {
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 76px);
    border-radius: 20px;
  }

  .chat-body {
    min-height: 170px;
    max-height: calc(100dvh - 292px);
  }

  .chat-input {
    gap: 8px;
    padding: 10px 12px 14px;
  }
}

@media (max-width: 390px) {
  .chat-window {
    left: 8px;
    right: 8px;
    width: calc(100vw - 16px);
  }
}

.chat-window {
  border-color: rgba(216, 180, 254, 0.26);
  background:
    radial-gradient(circle at 18% 0%, rgba(168, 85, 247, 0.13), transparent 42%),
    linear-gradient(155deg, rgba(15, 10, 26, 0.72), rgba(3, 3, 10, 0.68));
  box-shadow:
    0 30px 90px rgba(0, 0, 0, 0.52),
    0 0 54px rgba(139, 75, 220, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(22px) saturate(1.16);
  -webkit-backdrop-filter: blur(22px) saturate(1.16);
}

.chat-top {
  border-bottom-color: rgba(216, 180, 254, 0.14);
  background:
    linear-gradient(180deg, rgba(22, 13, 36, 0.48), rgba(8, 6, 17, 0.32));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-panel {
  background:
    linear-gradient(180deg, rgba(8, 5, 16, 0.2), rgba(3, 3, 10, 0.12));
}

.chat-footer {
  border-top-color: rgba(216, 180, 254, 0.13);
  background: rgba(7, 4, 14, 0.34);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-input input,
.chat-lead-form input,
.chat-lead-form textarea {
  border-color: rgba(216, 180, 254, 0.2);
  background: rgba(5, 3, 12, 0.48);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.chat-input input:focus,
.chat-lead-form input:focus,
.chat-lead-form textarea:focus {
  border-color: rgba(216, 180, 254, 0.54);
  background: rgba(8, 4, 17, 0.64);
  box-shadow:
    0 0 0 3px rgba(139, 75, 220, 0.16),
    0 0 28px rgba(139, 75, 220, 0.1);
}

.chat-quick-actions,
.chat-lead-form {
  background: rgba(8, 4, 17, 0.28);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-chip {
  border-color: rgba(216, 180, 254, 0.23);
  color: #d8b4fe;
  background: rgba(139, 75, 220, 0.12);
}

.chat-body .message.bot,
.chat-typing {
  border-color: rgba(216, 180, 254, 0.1);
  color: rgba(226, 232, 240, 0.9);
  background: rgba(20, 15, 31, 0.52);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.035);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chat-body .message.user {
  border: 1px solid rgba(216, 180, 254, 0.22);
  background:
    linear-gradient(135deg, rgba(139, 75, 220, 0.82), rgba(88, 28, 135, 0.76));
  box-shadow:
    0 10px 30px rgba(88, 28, 135, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.09);
}

.chat-reset,
.chat-close {
  border-color: rgba(216, 180, 254, 0.2);
  background: rgba(7, 4, 14, 0.36);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

@media (max-width: 768px) {
  .chat-window {
    backdrop-filter: blur(16px) saturate(1.1);
    -webkit-backdrop-filter: blur(16px) saturate(1.1);
  }

  .chat-body .message.bot,
  .chat-typing,
  .chat-quick-actions,
  .chat-lead-form {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-window,
  .chat-top,
  .chat-footer,
  .chat-quick-actions,
  .chat-lead-form,
  .chat-body .message.bot,
  .chat-typing {
    transition: none !important;
  }
}

.floating-chat {
  position: fixed;
  z-index: 1000;
}

@keyframes chat-dot-pulse {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@keyframes chat-button-breathe {
  0%,
  100% {
    box-shadow: 0 16px 42px rgba(139, 75, 220, 0.22);
  }
  50% {
    box-shadow: 0 18px 56px rgba(139, 75, 220, 0.38);
  }
}
