/* ==========================================================
   Chat widget  —  templates/partials/chat_widget.html
   Our launcher + welcome panel. The real chat window is
   Tawk.to's (its colors are set in the Tawk.to dashboard).
   ========================================================== */

.chat-widget {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 900;
}

/* ---------- Launcher ---------- */

.chat-launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  /* Ruby red, to match the theme */
  background:#ff1744;
  color: var(--text);
  box-shadow:
    0 0 0 2px var(--pure-black),
    0 0 0 3px var(--line-accent),
    0 12px 28px rgba(0, 0, 0, 0.6),
    var(--glow-accent);
  cursor: pointer;
  transition: filter 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease, visibility 0.2s;
}

.chat-launcher:hover {
  filter: brightness(1.12);
  transform: translateY(-2px) scale(1.04);
  box-shadow:
    0 0 0 2px var(--pure-black),
    0 0 0 3px var(--accent),
    0 14px 32px rgba(0, 0, 0, 0.6),
    0 0 30px rgba(255, 23, 68, 0.7);
}

.chat-launcher:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 6px;
}

/* Soft pulse ring while closed */
.chat-launcher-ring {
  position: absolute;
  inset: 0;
  border: 2px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  animation: chat-pulse 2.4s ease-out infinite;
}

@keyframes chat-pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.65); opacity: 0; }
}

.chat-launcher-icon {
  position: absolute;
  width: 26px;
  height: 26px;
  stroke-width: 2.2;
  transition: transform 0.25s ease, opacity 0.2s ease;
}

.chat-launcher-icon--close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.6);
}

.chat-widget.is-open .chat-launcher-icon--open {
  opacity: 0;
  transform: rotate(90deg) scale(0.6);
}

.chat-widget.is-open .chat-launcher-icon--close {
  opacity: 1;
  transform: none;
}

.chat-widget.is-open .chat-launcher-ring {
  display: none;
}

/* Unread messages from support while the chat is minimized */
.chat-unread {
  position: absolute;
  top: -4px;
  right: -4px;
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border: 2px solid var(--pure-black);
  border-radius: 999px;
  background: var(--gold);
  color: var(--pure-black);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

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

/* Tawk.to window is open: hide our launcher so it doesn't overlap */
.chat-widget.is-chatting .chat-launcher {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
}

/* ---------- Panel ---------- */

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 78px;
  width: 360px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  border: 1px solid var(--line-accent);
  border-radius: 20px;
  background:
    radial-gradient(90% 55% at 100% 0%, rgba(255, 23, 68, 0.16), transparent 60%),
    radial-gradient(70% 45% at 0% 100%, rgba(255, 176, 0, 0.08), transparent 70%),
    var(--surface);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75), 0 0 40px rgba(255, 23, 68, 0.12);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s linear 0.22s;
}

.chat-widget.is-open .chat-panel {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0s;
}

.chat-panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.chat-avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line-gold);
  border-radius: 50%;
  background: var(--gold-soft);
  color: var(--gold);
  box-shadow: 0 0 16px rgba(255, 176, 0, 0.18);
}

.chat-avatar .ico {
  width: 22px;
  height: 22px;
}

.chat-panel-id {
  flex: 1;
  min-width: 0;
}

.chat-panel-title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 16px;
  font-weight: 600;
  line-height: 22px;
  color: var(--text);
}

.chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 0;
  font-size: 12px;
  line-height: 16px;
  color: var(--muted);
}

.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.chat-status[data-status="online"] {
  color: var(--gold-light);
}

.chat-status[data-status="online"] .chat-status-dot {
  background: var(--gold);
  box-shadow: 0 0 8px #ff1744;
}

.chat-status[data-status="away"] .chat-status-dot {
  background: var(--gold-light);
  opacity: 0.6;
}

.chat-close {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-soft);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.chat-close .ico {
  width: 16px;
  height: 16px;
}

.chat-close:hover {
  border-color: var(--accent);
  color: var(--text);
}

.chat-panel-body {
  padding: 18px;
}

/* Greeting styled as a support message */
.chat-bubble {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 4px 14px 14px 14px;
  background: rgba(255, 255, 255, 0.04);
  font-size: 14px;
  line-height: 21px;
  color: var(--text-soft);
}

.chat-bubble p {
  margin: 0;
}

.chat-bubble p + p {
  margin-top: 4px;
}

.chat-bubble strong {
  color: var(--text);
}

.chat-topics-label {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  line-height: 16px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.chat-topics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.chat-topic {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-topic .ico {
  width: 16px;
  height: 16px;
  color: var(--gold);
}

.chat-topic:hover {
  border-color: var(--line-accent);
  background: rgba(255, 23, 68, 0.06);
}

.chat-topic[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent), 0 0 14px rgba(255, 23, 68, 0.2);
}

.chat-topic[aria-pressed="true"] .ico {
  color: var(--accent);
}

.chat-start {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 46px;
  margin-top: 18px;
  border: 0;
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--on-btn);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: var(--glow-btn);
  transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.chat-start .ico {
  width: 18px;
  height: 18px;
}

.chat-start:hover {
  background: var(--btn-bg-hover);
  transform: translateY(-1px);
  box-shadow: 0 0 26px rgba(255, 176, 0, 0.6);
}

.chat-note {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  color: var(--gold-light);
}

.chat-note:empty {
  display: none;
}

.chat-panel-foot {
  margin: 0;
  padding: 12px 18px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 11px;
  line-height: 16px;
  text-align: center;
  color: var(--muted);
}

.chat-close:focus-visible,
.chat-topic:focus-visible,
.chat-start:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .chat-widget {
    right: 16px;
    bottom: 16px;
  }

  .chat-launcher {
    width: 56px;
    height: 56px;
  }

  /* Panel spans the screen width above the launcher */
  .chat-panel {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 86px;
    width: auto;
    max-height: calc(100dvh - 110px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-launcher-ring {
    display: none;
  }
}
