/* ==========================================================================
   ShopReply AI — chat-widget.css
   AI chat widget with light/dark themes and visible keyboard focus.
   Narrow screens and enlarged text need rendered regression checks;
   respects prefers-reduced-motion. No cookies, no external assets.
   ========================================================================== */

/* ---------- Launcher button ---------- */
.chat-launcher {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 90;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: var(--color-primary, #0e5a6d);
  color: var(--color-on-primary, #ffffff);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(18, 36, 46, 0.35);
  overflow: hidden;
  transition: transform 200ms ease-out, box-shadow 200ms ease-out;
}

.chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(18, 36, 46, 0.45);
}

.chat-launcher:focus-visible {
  outline: 3px solid var(--color-focus, #0e5a6d);
  outline-offset: 3px;
}

/* Subtle wave pulse on the launcher (skipped with reduced motion) */
.chat-launcher .launcher-wave {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}

.chat-launcher .launcher-wave::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  animation: launcher-pulse 2.6s ease-out infinite;
}

@keyframes launcher-pulse {
  0% {
    transform: scale(1);
    opacity: 0.6;
  }
  70% {
    transform: scale(1.55);
    opacity: 0;
  }
  100% {
    transform: scale(1.55);
    opacity: 0;
  }
}

/* ---------- Dialog ---------- */
.chat-dialog {
  position: fixed;
  right: 1rem;
  bottom: calc(1rem + 56px + 0.75rem);
  z-index: 91;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - 6rem));
  display: flex;
  flex-direction: column;
  background: var(--color-bg, #ffffff);
  color: var(--color-text, #17242e);
  border: 1px solid var(--color-border, #d5e0e4);
  border-radius: 0.875rem;
  box-shadow: 0 16px 48px rgba(18, 36, 46, 0.28);
  overflow-x: hidden;
  overflow-y: auto;
}

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

/* Lead form open: the message log gives up its space so the form fits */
.chat-dialog--lead .chat-log {
  display: none;
}

/* ---------- Header ---------- */
.chat-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--color-dark, #12242e);
  color: var(--color-on-dark, #e8f1f4);
}

.chat-header .chat-header-text {
  flex: 1;
  min-width: 0;
}

.chat-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-on-dark, #e8f1f4);
  margin: 0;
}

.chat-header .chat-header-sub {
  font-size: 0.75rem;
  color: var(--color-on-dark-muted, #b3c8d1);
  margin: 0;
}

.chat-header .chat-header-sub a {
  color: var(--color-on-dark-primary, #7fc5d5);
}

.chat-close {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 0.5rem;
  color: var(--color-on-dark, #e8f1f4);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.chat-close:hover {
  background: rgba(143, 211, 227, 0.15);
  color: #ffffff;
}

.chat-close:focus-visible {
  outline: 3px solid var(--color-focus-dark, #8fd3e3);
  outline-offset: 2px;
}

/* ---------- Messages ---------- */
.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: var(--color-surface, #f6f9fa);
  min-height: 0;
}

.chat-msg {
  max-width: 85%;
  padding: 0.625rem 0.875rem;
  border-radius: 0.75rem;
  font-size: 0.9375rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.chat-msg .chat-msg-author {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.125rem;
}

.chat-msg--user {
  align-self: flex-end;
  background: var(--color-primary, #0e5a6d);
  color: var(--color-on-primary, #ffffff);
  border-bottom-right-radius: 0.25rem;
}

.chat-msg--user .chat-msg-author {
  color: rgba(255, 255, 255, 0.85);
}

[data-theme="dark"] .chat-msg--user .chat-msg-author {
  color: rgba(12, 26, 34, 0.85);
}

.chat-msg--bot {
  align-self: flex-start;
  background: var(--color-bg, #ffffff);
  color: var(--color-text, #17242e);
  border: 1px solid var(--color-border, #d5e0e4);
  border-bottom-left-radius: 0.25rem;
}

.chat-msg--bot .chat-msg-author {
  color: var(--color-primary, #0e5a6d);
}

.chat-msg a {
  color: var(--color-primary, #0e5a6d);
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  color: var(--color-text-muted, #4d5f6b);
}

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

.chat-typing .dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary, #0e5a6d);
  animation: typing-dot 1.2s ease-in-out infinite;
}

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

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

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

/* System notice (errors, limits) */
.chat-notice {
  align-self: stretch;
  padding: 0.625rem 0.875rem;
  border-radius: 0.5rem;
  background: var(--color-error-bg, #fdeceb);
  border: 1px solid var(--color-error, #b3261e);
  color: var(--color-error, #b3261e);
  font-size: 0.875rem;
}

.chat-notice a {
  color: var(--color-error, #b3261e);
  font-weight: 600;
}

/* ---------- Quick actions ---------- */
.chat-quick {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0.25rem;
  background: var(--color-surface, #f6f9fa);
}

.chat-quick button {
  min-height: 44px;
  padding: 0.375rem 0.875rem;
  border-radius: 9999px;
  border: 1px solid var(--color-primary, #0e5a6d);
  color: var(--color-primary, #0e5a6d);
  background: var(--color-bg, #ffffff);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.chat-quick button:hover {
  background: var(--color-surface-2, #edf3f5);
}

.chat-quick button:focus-visible {
  outline: 3px solid var(--color-focus, #0e5a6d);
  outline-offset: 2px;
}

/* ---------- Input area ---------- */
.chat-form {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--color-divider, #e3ebee);
  background: var(--color-bg, #ffffff);
}

.chat-form .chat-note {
  font-size: 0.75rem;
  color: var(--color-text-muted, #4d5f6b);
  margin: 0;
}

.chat-form .chat-note a {
  color: var(--color-primary, #0e5a6d);
}

.chat-input-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.chat-input-flex {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.chat-input-row label {
  font-size: 0.75rem;
  font-weight: 600;
  margin: 0;
  white-space: normal;
}

.chat-input-row textarea {
  flex: 1;
  flex-basis: 8rem;
  min-width: 0;
  min-height: 48px;
  max-height: 6rem;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-border, #d5e0e4);
  border-radius: 0.5rem;
  background: var(--color-bg, #ffffff);
  color: var(--color-text, #17242e);
  font: inherit;
  font-size: 0.9375rem;
  resize: none;
}

/* Dark theme: stronger input borders for WCAG 1.4.11 (3:1 non-text contrast) */
[data-theme="dark"] .chat-input-row textarea,
[data-theme="dark"] .chat-lead input {
  border-color: #5d8294;
}

.chat-input-row textarea:focus-visible {
  outline: 3px solid var(--color-focus, #0e5a6d);
  outline-offset: 2px;
}

.chat-send {
  flex: none;
  max-width: 100%;
  min-height: 48px;
  min-width: 48px;
  padding: 0.625rem 1rem;
  border-radius: 0.5rem;
  background: var(--color-primary, #0e5a6d);
  color: var(--color-on-primary, #ffffff);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
}

.chat-send:hover {
  background: var(--color-primary-hover, #0a4655);
}

.chat-send:focus-visible {
  outline: 3px solid var(--color-focus, #0e5a6d);
  outline-offset: 2px;
}

/* ---------- Lead form ---------- */
.chat-lead {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--color-divider, #e3ebee);
  background: var(--color-bg, #ffffff);
}

.chat-lead .chat-lead-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0;
}

.chat-lead > * {
  flex-shrink: 0;
}

.chat-lead .chat-lead-contact {
  margin: 0;
  font-size: 0.875rem;
}

.chat-lead input {
  min-height: 48px;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--color-border, #d5e0e4);
  border-radius: 0.5rem;
  background: var(--color-bg, #ffffff);
  color: var(--color-text, #17242e);
  font: inherit;
  font-size: 0.9375rem;
  width: 100%;
}

.chat-lead input:focus-visible {
  outline: 3px solid var(--color-focus, #0e5a6d);
  outline-offset: 2px;
}

.chat-lead .chat-lead-status {
  font-size: 0.875rem;
  margin: 0;
}

.chat-lead .chat-lead-status--ok {
  color: var(--color-success, #1e6b34);
}

.chat-lead .chat-lead-status--error {
  color: var(--color-error, #b3261e);
}

/* ---------- Small screens ---------- */
@media (max-width: 30rem) {
  .chat-dialog {
    right: 0.75rem;
    bottom: calc(0.75rem + 56px + 0.5rem);
    width: calc(100vw - 1.5rem);
    max-height: calc(100vh - 6.5rem);
  }

  .chat-msg {
    max-width: 92%;
  }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .chat-launcher .launcher-wave::before {
    animation: none;
    display: none;
  }

  .chat-typing .dots span {
    animation: none;
    opacity: 0.7;
  }

  .chat-launcher,
  .chat-launcher:hover {
    transform: none;
  }
}

/* Lead form secondary button (no inline styles — CSP) */
.chat-lead .chat-lead-cancel {
  background: transparent;
  color: var(--color-text, #17242e);
  border-color: currentColor;
}

/* The hidden attribute must always win over author display rules */
[hidden] { display: none !important; }
