/* Rosyvely Chat — premium bilingual chat widget */

:root {
  --rv-chat-bg: #ffffff;
  --rv-chat-surface: #ffffff;
  --rv-chat-ink: #1f2937;
  --rv-chat-muted: #6b7280;
  --rv-chat-line: rgba(15, 23, 42, 0.08);
  --rv-chat-brand: #b91c1c;
  --rv-chat-brand-dark: #8c1414;
  --rv-chat-brand-soft: #fef2f2;
  --rv-chat-radius: 18px;
  --rv-chat-shadow: 0 18px 60px rgba(15, 23, 42, 0.22);
}

.rv-chat {
  position: fixed;
  right: clamp(0.85rem, 2.4vw, 1.5rem);
  bottom: clamp(0.85rem, 2.4vw, 1.5rem);
  z-index: 2147483646;
  font-family:
    "Inter", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

.rv-chat__fab {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--rv-chat-brand), var(--rv-chat-brand-dark));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(185, 28, 28, 0.45);
  -webkit-tap-highlight-color: transparent;
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease;
}

.rv-chat__fab:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 14px 38px rgba(185, 28, 28, 0.6);
}

.rv-chat__fab:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
}

.rv-chat__fab-icon {
  width: 26px;
  height: 26px;
  transition: opacity 0.2s ease;
}

.rv-chat__fab-icon--close { display: none; }

.rv-chat[data-open="1"] .rv-chat__fab-icon--chat { display: none; }
.rv-chat[data-open="1"] .rv-chat__fab-icon--close { display: block; }

.rv-chat__fab-pulse {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(185, 28, 28, 0.45);
  animation: rvPulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes rvPulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  100% { transform: scale(1.4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .rv-chat__fab-pulse { animation: none; }
}

.rv-chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 14px);
  width: min(380px, calc(100vw - 1.5rem));
  height: min(560px, calc(100vh - 6rem));
  background: var(--rv-chat-surface);
  border-radius: var(--rv-chat-radius);
  box-shadow: var(--rv-chat-shadow);
  display: flex;
  flex-direction: column;
  transform: translateY(12px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
  transition:
    transform 0.26s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 0.22s ease;
  border: 1px solid var(--rv-chat-line);
}

.rv-chat[data-open="1"] .rv-chat__panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

.rv-chat__head {
  padding: 0.85rem 1rem;
  display: flex;
  gap: 0.7rem;
  align-items: center;
  background: linear-gradient(135deg, var(--rv-chat-brand-dark), var(--rv-chat-brand));
  color: #fff;
}

.rv-chat__avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}

.rv-chat__avatar svg {
  width: 22px;
  height: 22px;
}

.rv-chat__head-info {
  flex: 1;
  min-width: 0;
}

.page-products .rv-chat__head-name,
.page-product-detail .rv-chat__head-name {
  display: none;
}

.page-products .rv-chat__head-info,
.page-product-detail .rv-chat__head-info {
  align-items: center;
}

.rv-chat__head-name {
  font-weight: 700;
  font-size: 0.95rem;
  line-height: 1.2;
}

.rv-chat__head-status {
  font-size: 0.74rem;
  opacity: 0.95;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.rv-chat__head-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

.rv-chat__head-status--closed::before {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}

.rv-chat__head-actions {
  display: flex;
  gap: 0.4rem;
}

.rv-chat__head-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition:
    background 0.18s ease,
    transform 0.18s ease;
}

.rv-chat__head-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: translateY(-1px);
}

.rv-chat__head-btn svg {
  width: 16px;
  height: 16px;
}

.rv-chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  background: linear-gradient(180deg, #fdfdfd, #f7f7f8);
  scroll-behavior: smooth;
}

.rv-chat__messages::-webkit-scrollbar { width: 4px; }
.rv-chat__messages::-webkit-scrollbar-thumb { background: rgba(15, 23, 42, 0.18); border-radius: 4px; }

.rv-chat__msg {
  max-width: 86%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  font-size: 0.86rem;
  line-height: 1.5;
  word-wrap: break-word;
  animation: rvMsgIn 0.18s ease;
}

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

.rv-chat__msg--bot {
  background: #fff;
  color: var(--rv-chat-ink);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  border: 1px solid var(--rv-chat-line);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}

.rv-chat__msg--bot a {
  color: var(--rv-chat-brand);
  text-decoration: underline;
  font-weight: 600;
}

.rv-chat__msg--user {
  background: linear-gradient(135deg, var(--rv-chat-brand), var(--rv-chat-brand-dark));
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.rv-chat__typing {
  display: inline-flex;
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--rv-chat-line);
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  gap: 4px;
  align-items: center;
}

.rv-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rv-chat-muted);
  animation: rvDot 1.1s ease-in-out infinite;
}
.rv-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.rv-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes rvDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.rv-chat__chips {
  padding: 0.55rem 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  border-top: 1px solid var(--rv-chat-line);
  background: #fff;
}

.rv-chat__chip {
  background: var(--rv-chat-brand-soft);
  border: 1px solid rgba(185, 28, 28, 0.18);
  color: var(--rv-chat-brand-dark);
  font: inherit;
  font-size: 0.77rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    transform 0.18s ease;
}

.rv-chat__chip:hover {
  background: var(--rv-chat-brand);
  color: #fff;
  transform: translateY(-1px);
}

.rv-chat__input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 0.85rem;
  border-top: 1px solid var(--rv-chat-line);
  background: #fff;
}

.rv-chat__input {
  flex: 1;
  background: #f7f7f8;
  color: var(--rv-chat-ink);
  font: inherit;
  font-size: 0.88rem;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--rv-chat-line);
  outline: none;
  transition: border-color 0.18s ease, background 0.18s ease;
}

.rv-chat__input:focus {
  background: #fff;
  border-color: var(--rv-chat-brand);
  box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.12);
}

.rv-chat__send {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, var(--rv-chat-brand), var(--rv-chat-brand-dark));
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.rv-chat__send:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(185, 28, 28, 0.4);
}

.rv-chat__send svg { width: 16px; height: 16px; }

/* Mobile tweaks */
@media (max-width: 480px) {
  .rv-chat {
    right: 0.8rem;
    bottom: 0.8rem;
  }
  .rv-chat__panel {
    width: calc(100vw - 1.6rem);
    height: min(80vh, 580px);
    bottom: calc(100% + 12px);
  }
  .rv-chat__fab {
    width: 56px;
    height: 56px;
  }
  .rv-chat__fab-icon {
    width: 24px;
    height: 24px;
  }
}

/* Ensure main content doesn't sit underneath the mobile bar on small screens */
body:not(.na-page--admin) main {
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
}

@media (max-width: 480px) {
  body:not(.na-page--admin) main {
    padding-bottom: max(5.5rem, calc(env(safe-area-inset-bottom, 0px) + 4.5rem));
  }
  body:not(.na-page--admin) .home-cta-band {
    padding-bottom: 1rem;
  }
}

/* Hide legacy floating widget if it slips in */
.site-float { display: none !important; }
