/**
 * Studio 360 Assistant — floating chat widget.
 * Midnight & Gold glass panel, bottom-right launcher.
 *
 * NOTE: `position: fixed` and `z-index` live INLINE on #s360-chat (see
 * template-parts/chat-widget.php) so that neither the base.css direct-child
 * rule (`body.s360-body > * { position: relative; z-index: 1 }`) nor the
 * logged-in-only GoDaddy Launch overlay (#gdl-publish-guide, z-index 99999)
 * can un-pin or cover it. Only the offsets belong here, so the mobile media
 * query below can adjust them.
 */

.s360-chat {
  right: 1.25rem;
  bottom: 1.25rem;
  font-family: var(--s360-font-body);
}

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

.s360-chat__launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--s360-navy);
  background: var(--s360-gradient-gold);
  box-shadow: var(--s360-glow-gold);
  transition: transform var(--s360-duration) var(--s360-ease-spring), box-shadow var(--s360-duration) var(--s360-ease-out);
}

.s360-chat__launcher:hover,
.s360-chat__launcher:focus-visible {
  transform: scale(1.06);
  box-shadow: var(--s360-glow-gold), var(--s360-shadow-elevated);
}

.s360-chat__launcher-close {
  display: none;
}

.s360-chat.is-open .s360-chat__launcher-icon {
  display: none;
}

.s360-chat.is-open .s360-chat__launcher-close {
  display: block;
}

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

.s360-chat__panel {
  position: absolute;
  right: 0;
  bottom: calc(56px + 0.875rem);
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 2rem));
  max-height: min(600px, calc(100vh - 7rem));
  overflow: hidden;
  border: 1px solid var(--s360-glass-border);
  border-radius: var(--s360-radius-lg);
  background: var(--s360-gradient-card);
  box-shadow: var(--s360-shadow-elevated);
}

/* The admin bar (32px desktop / 46px mobile) shrinks the usable viewport for
   logged-in users; keep the panel top clear of it. */
body.admin-bar .s360-chat__panel {
  max-height: min(600px, calc(100vh - 7rem - 32px));
}

.s360-chat__panel[hidden] {
  display: none;
}

/* ---- Header ---- */

.s360-chat__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--s360-glass-border);
  background: var(--s360-glass-strong);
}

.s360-chat__status {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--s360-success);
  box-shadow: 0 0 8px rgba(61, 214, 140, 0.6);
}

.s360-chat__header-text {
  flex: 1;
  min-width: 0;
}

.s360-chat__title {
  margin: 0;
  font-family: var(--s360-font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: var(--s360-white);
}

.s360-chat__subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--s360-white-muted);
}

.s360-chat__close {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: var(--s360-radius-sm);
  cursor: pointer;
  font-size: 1.375rem;
  line-height: 1;
  color: var(--s360-white-muted);
  background: transparent;
  transition: color var(--s360-duration) var(--s360-ease-out), background var(--s360-duration) var(--s360-ease-out);
}

.s360-chat__close:hover,
.s360-chat__close:focus-visible {
  color: var(--s360-white);
  background: var(--s360-glass);
}

/* ---- Messages ---- */

.s360-chat__messages {
  flex: 1;
  min-height: 180px;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  overscroll-behavior: contain;
}

.s360-chat__msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: var(--s360-radius);
  font-size: 0.875rem;
  line-height: 1.55;
  overflow-wrap: break-word;
}

.s360-chat__msg p {
  margin: 0 0 0.5em;
}

.s360-chat__msg p:last-child {
  margin-bottom: 0;
}

.s360-chat__msg a {
  color: var(--s360-gold);
  text-decoration: underline;
}

.s360-chat__msg a:hover {
  color: var(--s360-gold-hover);
}

.s360-chat__msg--bot {
  align-self: flex-start;
  color: var(--s360-white);
  background: var(--s360-glass-strong);
  border: 1px solid var(--s360-glass-border);
  border-bottom-left-radius: 4px;
}

.s360-chat__msg--user {
  align-self: flex-end;
  color: var(--s360-white);
  background: var(--s360-gold-muted);
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-bottom-right-radius: 4px;
}

.s360-chat__msg--error {
  align-self: flex-start;
  color: var(--s360-danger);
  background: rgba(240, 113, 103, 0.1);
  border: 1px solid rgba(240, 113, 103, 0.3);
}

/* Typing indicator */

.s360-chat__typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.75rem 0.875rem;
  border-radius: var(--s360-radius);
  background: var(--s360-glass-strong);
  border: 1px solid var(--s360-glass-border);
}

.s360-chat__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--s360-gold);
  animation: s360-chat-bounce 1.2s infinite ease-in-out;
}

.s360-chat__typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.s360-chat__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

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

/* ---- Suggestions ---- */

.s360-chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0 1rem 0.625rem;
}

.s360-chat__suggestions[hidden] {
  display: none;
}

.s360-chat__suggestion {
  padding: 0.375rem 0.75rem;
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--s360-gold);
  background: transparent;
  transition: background var(--s360-duration) var(--s360-ease-out), color var(--s360-duration) var(--s360-ease-out);
}

.s360-chat__suggestion:hover,
.s360-chat__suggestion:focus-visible {
  color: var(--s360-navy);
  background: var(--s360-gold);
}

/* ---- Input form ---- */

.s360-chat__form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--s360-glass-border);
  background: var(--s360-glass);
}

.s360-chat__input {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--s360-border);
  border-radius: var(--s360-radius-sm);
  resize: none;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--s360-white);
  background: var(--s360-navy);
}

.s360-chat__input:focus {
  outline: none;
  border-color: var(--s360-gold);
  box-shadow: 0 0 0 2px var(--s360-gold-muted);
}

.s360-chat__input::placeholder {
  color: var(--s360-white-muted);
}

.s360-chat__send {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--s360-radius-sm);
  cursor: pointer;
  color: var(--s360-navy);
  background: var(--s360-gradient-gold);
  transition: opacity var(--s360-duration) var(--s360-ease-out), transform var(--s360-duration) var(--s360-ease-spring);
}

.s360-chat__send:hover:not(:disabled),
.s360-chat__send:focus-visible {
  transform: scale(1.05);
}

.s360-chat__send:disabled {
  cursor: default;
  opacity: 0.45;
}

/* ---- Disclaimer ---- */

.s360-chat__disclaimer {
  margin: 0;
  padding: 0.375rem 1rem 0.625rem;
  font-size: 0.6875rem;
  text-align: center;
  color: var(--s360-white-muted);
}

/* ---- Mobile ---- */

@media (max-width: 640px) {
  .s360-chat {
    right: 0.875rem;
    bottom: 0.875rem;
  }

  .s360-chat__panel {
    position: fixed;
    inset: auto 0.5rem 4.75rem 0.5rem;
    width: auto;
    max-height: calc(100vh - 6.5rem);
    max-height: calc(100dvh - 6.5rem);
  }

  body.admin-bar .s360-chat__panel {
    max-height: calc(100vh - 6.5rem - 46px);
    max-height: calc(100dvh - 6.5rem - 46px);
  }
}

/* ---- Reduced motion ---- */

@media (prefers-reduced-motion: reduce) {
  .s360-chat__launcher,
  .s360-chat__send,
  .s360-chat__suggestion,
  .s360-chat__close {
    transition: none;
  }

  .s360-chat__typing span {
    animation: none;
    opacity: 0.7;
  }
}
