/*
 * Xoompa — Help Widget Stylesheet
 * All custom properties prefixed --hw-* to avoid collisions with Bootstrap --bs-*
 * Supports: dark theme, prefers-reduced-motion, WCAG 2.1 AA contrast
 */

:root {
  --hw-accent:        #e63946;
  --hw-accent-hover:  #c1121f;
  --hw-bg:            #111214;
  --hw-bg-panel:      #18191c;
  --hw-bg-message:    #222327;
  --hw-bg-user:       #e63946;
  --hw-text:          #f0f0f0;
  --hw-text-muted:    #9a9a9a;
  --hw-border:        #2e2f33;
  --hw-radius:        14px;
  --hw-radius-sm:     8px;
  --hw-shadow:        0 8px 32px rgba(0,0,0,0.55);
  --hw-font:          system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hw-z:             9999;
  --hw-launcher-size: 56px;
  --hw-panel-width:   380px;
  --hw-panel-height:  520px;
  --hw-avatar-width:  260px;
  --hw-avatar-height: 520px;
}

#hw-root, #hw-root * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

#hw-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: var(--hw-z);
  font-family: var(--hw-font);
  font-size: 14px;
  line-height: 1.5;
}

.hw-launcher {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--hw-launcher-size);
  padding: 0 18px;
  background: var(--hw-accent);
  color: #fff;
  border: none;
  border-radius: calc(var(--hw-launcher-size) / 2);
  cursor: pointer;
  font-family: var(--hw-font);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(230, 57, 70, 0.45);
  transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
  user-select: none;
}

.hw-launcher:hover {
  background: var(--hw-accent-hover);
  box-shadow: 0 6px 20px rgba(230, 57, 70, 0.55);
}

.hw-launcher:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.hw-launcher:active {
  transform: scale(0.96);
}

.hw-launcher__icon {
  font-size: 18px;
  line-height: 1;
}

@keyframes hw-bounce {
  0%, 100% { transform: translateY(0); }
  20%       { transform: translateY(-8px); }
  40%       { transform: translateY(0); }
  55%       { transform: translateY(-4px); }
  70%       { transform: translateY(0); }
}

.hw-launcher.hw-bounce {
  animation: hw-bounce 3.5s ease-in-out infinite;
  animation-delay: 2s;
}

@media (prefers-reduced-motion: reduce) {
  .hw-launcher.hw-bounce {
    animation: none;
  }
  .hw-panel {
    transition: none !important;
  }
  .hw-typing span {
    animation: none !important;
    opacity: 0.5;
  }
}

.hw-panel {
  position: absolute;
  bottom: calc(var(--hw-launcher-size) + 12px);
  right: 0;
  width: var(--hw-panel-width);
  max-height: var(--hw-panel-height);
  background: var(--hw-bg-panel);
  border: 1px solid var(--hw-border);
  border-radius: var(--hw-radius);
  box-shadow: var(--hw-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.18s ease;
}

.hw-panel.hw-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: all;
}

.hw-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--hw-border);
  background: var(--hw-bg);
  flex-shrink: 0;
}

.hw-panel__title {
  font-size: 14px;
  font-weight: 700;
  color: var(--hw-text);
  letter-spacing: 0.3px;
}

.hw-panel__title::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  margin-top: -1px;
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.hw-close-btn {
  background: none;
  border: none;
  color: var(--hw-text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
}

.hw-close-btn:hover {
  color: var(--hw-text);
  background: var(--hw-bg-message);
}

.hw-close-btn:focus-visible {
  outline: 2px solid var(--hw-accent);
  outline-offset: 2px;
}

#hw-avatar-float {
  position: fixed;
  bottom: calc(24px + var(--hw-launcher-size) - 30px);
  right: calc(24px + var(--hw-panel-width) - 60px);
  width: var(--hw-avatar-width);
  height: var(--hw-avatar-height);
  pointer-events: none;
  opacity: 0;
  transform: scale(0.85);
  transform-origin: bottom right;
  transition:
    opacity 0.32s ease,
    transform 0.38s cubic-bezier(0.34, 1.56, 0.64, 1),
    right    0.38s cubic-bezier(0.34, 1.56, 0.64, 1),
    bottom   0.38s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: var(--hw-z);
}

#hw-avatar-float.hw-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: all;
}

#hw-avatar-canvas {
  display: block;
  width: var(--hw-avatar-width);
  height: var(--hw-avatar-height);
}

.hw-avatar-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--hw-text-muted);
  font-size: 12px;
  gap: 6px;
}

.hw-avatar-loading-dot {
  width: 6px;
  height: 6px;
  background: var(--hw-accent);
  border-radius: 50%;
  animation: hw-pulse-dot 1.2s ease-in-out infinite;
}
.hw-avatar-loading-dot:nth-child(2) { animation-delay: 0.2s; }
.hw-avatar-loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes hw-pulse-dot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40%            { transform: scale(1); opacity: 1; }
}

.hw-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  scroll-behavior: smooth;
}

.hw-messages::-webkit-scrollbar {
  width: 4px;
}
.hw-messages::-webkit-scrollbar-track {
  background: transparent;
}
.hw-messages::-webkit-scrollbar-thumb {
  background: var(--hw-border);
  border-radius: 2px;
}

.hw-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: var(--hw-radius-sm);
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.hw-bubble--assistant {
  background: var(--hw-bg-message);
  color: var(--hw-text);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.hw-bubble--user {
  background: var(--hw-bg-user);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.hw-bubble--assistant p {
  margin: 0 0 6px;
}
.hw-bubble--assistant p:last-child {
  margin-bottom: 0;
}
.hw-bubble--assistant ul {
  margin: 4px 0 6px;
  padding-left: 18px;
}
.hw-bubble--assistant ul:last-child {
  margin-bottom: 0;
}
.hw-bubble--assistant li {
  margin-bottom: 4px;
  line-height: 1.5;
}
.hw-bubble--assistant strong {
  color: var(--hw-text);
  font-weight: 600;
}
.hw-bubble--assistant a {
  color: #4fa3ff;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
}
.hw-bubble--assistant a:hover {
  opacity: 0.85;
}

.hw-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 13px;
  background: var(--hw-bg-message);
  border-radius: var(--hw-radius-sm);
  border-bottom-left-radius: 3px;
  align-self: flex-start;
}

.hw-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--hw-text-muted);
  border-radius: 50%;
  animation: hw-typing-bounce 1.2s ease-in-out infinite;
}
.hw-typing span:nth-child(2) { animation-delay: 0.2s; }
.hw-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes hw-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}

.hw-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px 4px;
  flex-shrink: 0;
}

.hw-chip {
  display: inline-block;
  padding: 5px 11px;
  background: transparent;
  border: 1px solid var(--hw-accent);
  border-radius: 20px;
  color: var(--hw-accent);
  font-size: 12px;
  font-family: var(--hw-font);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hw-chip:hover {
  background: var(--hw-accent);
  color: #fff;
}

.hw-chip:focus-visible {
  outline: 2px solid var(--hw-accent);
  outline-offset: 2px;
}

.hw-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--hw-border);
  flex-shrink: 0;
  background: var(--hw-bg);
}

.hw-input {
  flex: 1;
  background: var(--hw-bg-message);
  border: 1px solid var(--hw-border);
  border-radius: 20px;
  padding: 8px 14px;
  color: var(--hw-text);
  font-family: var(--hw-font);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
}

.hw-input:focus {
  border-color: var(--hw-accent);
}

.hw-input::placeholder {
  color: var(--hw-text-muted);
}

.hw-send-btn,
.hw-mic-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.hw-send-btn {
  background: var(--hw-accent);
  color: #fff;
}

.hw-send-btn:hover {
  background: var(--hw-accent-hover);
}

.hw-send-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.hw-send-btn:active {
  transform: scale(0.92);
}

.hw-send-btn:disabled {
  background: var(--hw-border);
  cursor: not-allowed;
}

.hw-mic-btn {
  background: var(--hw-bg-message);
  color: var(--hw-text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.hw-mic-btn:focus-visible {
  outline: 2px solid var(--hw-accent);
  outline-offset: 2px;
}

.hw-escalation {
  padding: 10px 14px;
  background: #2d1b1e;
  border-top: 1px solid #5c1a22;
  color: #f8a4ab;
  font-size: 12.5px;
  text-align: center;
  flex-shrink: 0;
}

.hw-escalation a {
  color: var(--hw-accent);
  font-weight: 600;
  text-decoration: underline;
}

.hw-escalation a:hover {
  color: #ff6b73;
}

@media (max-width: 768px) {
  #hw-root {
    bottom: 16px;
    right: 12px;
    left: auto;
  }

  .hw-panel {
    width: calc(100vw - 24px);
    right: 0;
    left: auto;
    max-height: 80vh;
    border-radius: var(--hw-radius);
    bottom: calc(var(--hw-launcher-size) + 8px);
  }

  .hw-input {
    font-size: 16px;
  }

  #hw-avatar-float {
    top: calc(env(safe-area-inset-top, 0px) + 185px);
    right: calc(env(safe-area-inset-right, 0px) + 24px);
    left: auto;
    bottom: auto;
    width: 200px;
    height: 420px;
    z-index: 99999;
  }

  #hw-avatar-float.hw-open {
    transform: scale(1);
  }

  #hw-avatar-canvas {
    width: 200px;
    height: 420px;
  }
}

#hw-avatar-float.hw-peek {
  bottom: calc(24px + var(--hw-launcher-size));
  right: 36px;
  transform: scale(0.31);
  transform-origin: bottom right;
  opacity: 1;
  pointer-events: none;
  filter: drop-shadow(0 6px 18px rgba(0,0,0,0.65));
  animation:
    hw-peek-rise 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) 0s 1 normal none,
    hw-peek-idle 3s ease-in-out 0.5s infinite;
}

#hw-avatar-float.hw-peek.hw-from-open {
  animation: hw-peek-idle 3s 0.45s ease-in-out infinite;
}

#hw-peek-hit {
  position: fixed;
  width: 92px;
  height: 174px;
  cursor: pointer;
  z-index: calc(var(--hw-z) + 1);
  display: none;
  border-radius: 6px 6px 0 0;
}

#hw-avatar-float.hw-open #hw-avatar-canvas {
  transform: none;
}

#hw-avatar-float.hw-open {
  filter: none;
}

@keyframes hw-peek-rise {
  from { opacity: 0; transform: scale(0.31) translateY(28px); }
  to   { opacity: 1; transform: scale(0.31) translateY(0); }
}

@keyframes hw-peek-idle {
  0%, 100% { transform: scale(0.31) translateY(0); }
  50%       { transform: scale(0.31) translateY(-18px); }
}

@media (prefers-reduced-motion: reduce) {
  #hw-avatar-float.hw-peek {
    animation: none;
    opacity: 1;
  }
  #hw-avatar-float,
  #hw-avatar-float #hw-avatar-canvas {
    transition: opacity 0.15s ease;
  }
}
