:root {
  --public-chat-bg: rgba(255, 255, 255, 0.94);
  --public-chat-panel: rgba(15, 23, 42, 0.95);
  --public-chat-surface: rgba(255, 255, 255, 0.92);
  --public-chat-text: #0f172a;
  --public-chat-muted: #64748b;
  --public-chat-primary: #dc2626;
  --public-chat-primary-dark: #991b1b;
  --public-chat-shadow: 0 28px 60px rgba(15, 23, 42, 0.22);
  --chat-vv-height: 100dvh;
  --chat-vv-top: 0px;
  --chat-safe-bottom: env(safe-area-inset-bottom, 0px);
}

.public-chat-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  left: auto;
  top: auto;
  z-index: 99999;
  width: min(400px, calc(100vw - 1.5rem));
  max-width: 400px;
  height: 650px;
  display: grid;
  place-items: end;
  pointer-events: none;
}

.chat-toggle-btn {
  pointer-events: auto;
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #ff7746, #d97706);
  color: white;
  box-shadow: var(--public-chat-shadow);
  cursor: pointer;
  transition: box-shadow 0.25s ease;
  position: relative;
  transform: none;
}

.chat-toggle-btn:hover {
  box-shadow: 0 36px 72px rgba(255, 98, 19, 0.3);
}

.chat-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.chat-badge,
.chat-dot {
  position: absolute;
  right: -4px;
  top: -4px;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #22c55e;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.16);
}

.chat-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: #ff7746;
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  left: auto;
  top: auto;
  width: 400px;
  max-width: calc(100vw - 1.5rem);
  height: 650px;
  border-radius: 30px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: var(--public-chat-panel);
  box-shadow: var(--public-chat-shadow);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(18px);
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease,
    transform 0.25s ease;
  pointer-events: auto;
  z-index: 99998;
}

.chat-panel.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-panel-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
  min-height: 0;
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(15, 23, 42, 0.98);
  border-bottom: 1px solid rgba(148, 163, 184, 0.16);
  position: sticky;
  top: 0;
  z-index: 1;
  flex: 0 0 auto;
}

.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
  color: #f8fafc;
}

.chat-header-subtitle {
  font-size: 0.85rem;
  color: #cbd5e1;
}

.chat-close-btn {
  border: none;
  background: transparent;
  color: #e2e8f0;
  font-size: 1.1rem;
  cursor: pointer;
}

.chat-content {
  min-height: 0;
  height: 100%;
  padding: 1rem 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: white;
  scroll-behavior: smooth;
}

.chat-bubble {
  max-width: min(78%, 310px);
  align-self: flex-start;
  border-radius: 24px;
  padding: 0.95rem 1rem;
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.12);
  line-height: 1.5;
  animation: chatMessageIn 0.22s ease both;
}

.chat-bubble + .chat-bubble.bot,
.chat-bubble + .chat-bubble.user {
  margin-top: -0.25rem;
}

.chat-bubble.bot {
  background: #ffffff;
  color: #1f242d;
  align-self: flex-start;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.chat-bubble.user {
  background: #1f242d;
  color: #ffffff;
  align-self: flex-end;
}

.chat-bubble-author {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: rgba(187, 113, 34, 0.6);
}

.chat-bubble-text {
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-bubble-text a {
  color: #b45309;
  font-weight: 800;
  text-decoration: none;
}

.chat-bubble-text a:hover {
  text-decoration: underline;
}

.chat-bubble-meta {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: rgba(189, 194, 205, 0.6);
}

.chat-product-card {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.85rem;
  padding: 0.8rem;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(255, 119, 70, 0.12), rgba(217, 119, 6, 0.08));
  border: 1px solid rgba(217, 119, 6, 0.18);
  color: #111827;
  text-decoration: none;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.chat-product-card:hover {
  color: #111827;
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.12);
}

.chat-product-icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: #d97706;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  flex: 0 0 auto;
}

.chat-product-card strong,
.chat-product-card small {
  display: block;
}

.chat-product-card small {
  color: #64748b;
  margin-top: 0.15rem;
}

.chat-suggestions {
  width: 100%;
  max-width: 100%;
  padding: 0.9rem;
  border-radius: 22px;
  background: rgba(248, 250, 252, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.2);
  animation: chatMessageIn 0.24s ease both;
}

.chat-followup {
  align-self: flex-start;
  max-width: min(78%, 310px);
  padding: 0.75rem 0.95rem;
  border-radius: 22px;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.18);
  color: #1f2937;
  font-weight: 700;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  animation: chatMessageIn 0.22s ease both;
}

.chat-suggestions-title {
  font-size: 0.78rem;
  font-weight: 800;
  color: #64748b;
  margin-bottom: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chat-suggestion-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  max-width: 100%;
}

.chat-suggestion-chip {
  border: 1px solid rgba(217, 119, 6, 0.2);
  background: #fff;
  color: #1f2937;
  border-radius: 999px;
  padding: 0.65rem 0.85rem;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  max-width: 100%;
  white-space: normal;
  text-align: left;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease,
    box-shadow 0.18s ease;
}

.chat-suggestion-chip:hover {
  background: #fff7ed;
  border-color: rgba(217, 119, 6, 0.42);
  transform: translateY(-1px);
  box-shadow: 0 10px 22px rgba(15, 23, 42, 0.08);
}

.chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.34rem;
  width: fit-content;
  padding: 0.9rem 1rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid rgba(148, 163, 184, 0.18);
  box-shadow: 0 16px 42px rgba(15, 23, 42, 0.1);
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #d97706;
  animation: chatTypingDot 0.9s ease-in-out infinite;
}

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

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

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

@keyframes chatTypingDot {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

.chat-empty,
.chat-step {
  margin: auto;
  max-width: 100%;
  text-align: center;
  color: #64748b;
}

.chat-empty-title,
.chat-step .chat-bubble.bot {
  font-size: 1.05rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 6px;
}

.chat-empty-copy,
.chat-step p {
  font-size: 0.92rem;
  line-height: 1.5;
}

.chat-actions {
  display: grid;
  gap: 0.75rem;
}

.chat-actions input {
  width: 100%;
  min-height: 46px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: rgba(255, 255, 255, 0.95);
  color: #111827;
  padding: 0.9rem 1rem;
  font-size: 0.95rem;
}

.chat-actions input:focus {
  outline: none;
  border-color: rgba(220, 38, 38, 0.8);
  box-shadow: 0 0 0 0.14rem rgba(220, 38, 38, 0.16);
}

.chat-action-btn {
  width: 100%;
  min-height: 46px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(135deg, #ff7746, #d97706);
  color: white;
  font-weight: 700;
  cursor: pointer;
  transition:
    transform 0.2s ease,
    filter 0.2s ease;
}

.chat-action-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.chat-footer {
  padding: 0.45rem 0.75rem calc(0.55rem + var(--chat-safe-bottom));
  font-size: 0.82rem;
  color: #cbd5e1;
  background: rgba(15, 23, 42, 0.95);
  border-top: 1px solid rgba(148, 163, 184, 0.16);
  flex: 0 0 auto;
}

.chat-composer {
  display: none;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 0.45rem;
  margin-top: 0.38rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(148, 163, 184, 0.22);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.14);
  padding: 0.28rem 0.34rem 0.28rem 0.5rem;
}

.chat-composer-icon {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #64748b;
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 1.05rem;
  flex: 0 0 auto;
}

#visitorChatInput {
  width: 100%;
  min-height: 22px;
  max-height: 132px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #111827;
  padding: 0.28rem 0.15rem;
  font-size: 0.95rem;
  line-height: 1.35;
  resize: none;
  overflow-y: hidden;
}

#visitorChatInput:focus {
  outline: none;
  box-shadow: none;
}

#visitorChatSend {
  width: 42px;
  height: 42px;
  min-height: 42px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0;
  flex: 0 0 auto;
}

.chat-status {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

.chat-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
}

.chat-status.info::before {
  background: #38bdf8;
}

.chat-status.success::before {
  background: #22c55e;
}

.chat-status.error::before {
  background: #ef4444;
}

@media (max-width: 599px) {
  html.chat-widget-open,
  body.chat-widget-open {
    overflow: hidden;
    height: var(--chat-vv-height);
  }

  .public-chat-widget {
    inset: var(--chat-vv-top) 0 auto 0;
    width: 100vw;
    height: var(--chat-vv-height);
    max-width: 100vw;
  }

  .chat-toggle-btn {
    width: 60px;
    height: 60px;
    position: fixed;
    right: 16px;
    bottom: 16px;
  }

  .chat-panel {
    inset: var(--chat-vv-top) 0 auto 0;
    width: 100vw;
    height: var(--chat-vv-height);
    max-width: 100vw;
    border-radius: 0;
    transition:
      opacity 0.18s ease,
      visibility 0.18s ease,
      transform 0.18s ease,
      height 0.18s ease;
  }

  .chat-content {
    padding: 0.8rem 0.75rem 0.65rem;
  }

  .chat-bubble,
  .chat-followup {
    max-width: 84%;
  }

  .chat-suggestion-chip {
    font-size: 0.84rem;
    padding: 0.62rem 0.78rem;
  }

  .chat-panel-header {
    padding: calc(0.68rem + env(safe-area-inset-top, 0px)) 0.9rem 0.68rem;
  }

  .chat-footer {
    padding: 0.38rem 0.55rem calc(0.42rem + var(--chat-safe-bottom));
  }

  .chat-status {
    display: none;
  }

  .chat-composer {
    margin-top: 0;
    min-height: 46px;
  }

  #visitorChatInput {
    font-size: 1rem;
    max-height: 118px;
  }
}

@media (min-width: 600px) {
  .public-chat-widget,
  .chat-panel {
    max-height: min(750px, calc(100vh - 150px));
    height: 750px;
  }
}

@media (min-width: 1024px) {
  .public-chat-widget,
  .chat-panel {
    max-height: min(750px, calc(100vh - 150px));
    height: 750px;
  }
}
