/* Help assistant — floating dock (Abre o Olho design tokens) */
:root {
  --ha-accent: #ff4500;
  --ha-accent-hover: #e03c00;
  --ha-gold: #ffd700;
  --ha-bg: rgba(12, 12, 14, 0.97);
  --ha-surface: #18181b;
  --ha-border: #27272a;
  --ha-text: #fafafa;
  --ha-muted: #a1a1aa;
  --ha-radius: 1.25rem;
  --ha-shadow: 0 24px 48px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.04);
  --ha-fab-size: 3.5rem;
  --ha-z: 50;
}

#floating-dock {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: var(--ha-z);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  pointer-events: none;
}

#floating-dock > * {
  pointer-events: auto;
}

.ha-fab-row {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 0.75rem;
}

.ha-fab {
  width: var(--ha-fab-size);
  height: var(--ha-fab-size);
  border-radius: 9999px;
  border: 1px solid var(--ha-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.ha-fab:focus-visible {
  outline: 2px solid var(--ha-accent);
  outline-offset: 3px;
}

.ha-fab:hover {
  transform: translateY(-2px);
}

.ha-fab--help {
  background: linear-gradient(135deg, var(--ha-accent) 0%, #c73500 100%);
  border-color: rgba(255, 69, 0, 0.5);
  color: #fff;
}

.ha-fab--help:hover {
  box-shadow: 0 12px 28px rgba(255, 69, 0, 0.35);
}

.ha-fab--help.is-open {
  background: var(--ha-surface);
  border-color: var(--ha-border);
  color: var(--ha-muted);
}

.ha-fab--rating {
  background: rgba(255, 255, 255, 0.1);
  color: #fbbf24;
  backdrop-filter: blur(8px);
}

.ha-fab--rating:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(251, 191, 36, 0.4);
}

.ha-fab-label {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Panel shared */
.ha-panel {
  width: min(380px, calc(100vw - 2rem));
  max-height: min(72vh, 560px);
  display: flex;
  flex-direction: column;
  border-radius: var(--ha-radius);
  border: 1px solid var(--ha-border);
  background: var(--ha-bg);
  color: var(--ha-text);
  box-shadow: var(--ha-shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
  opacity: 0;
  transform: translateY(12px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.ha-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ha-panel[hidden] {
  display: none !important;
}

.ha-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--ha-border);
  background: linear-gradient(180deg, rgba(255, 69, 0, 0.08) 0%, transparent 100%);
}

.ha-panel__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.ha-panel__subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.75rem;
  color: var(--ha-muted);
  line-height: 1.4;
}

.ha-panel__close {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 9999px;
  background: transparent;
  color: var(--ha-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.ha-panel__close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--ha-text);
}

/* Help chat */
.ha-chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.875rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-behavior: smooth;
}

.ha-msg {
  max-width: 92%;
  font-size: 0.8125rem;
  line-height: 1.5;
  border-radius: 1rem;
  padding: 0.625rem 0.875rem;
  word-wrap: break-word;
}

.ha-msg--bot {
  align-self: flex-start;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border);
  border-bottom-left-radius: 0.25rem;
}

.ha-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--ha-accent) 0%, #c73500 100%);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.ha-msg__source {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--ha-gold);
  text-decoration: none;
  font-weight: 600;
}

.ha-msg__source:hover {
  text-decoration: underline;
}

.ha-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 0.3rem;
  padding: 0.625rem 0.875rem;
  background: var(--ha-surface);
  border: 1px solid var(--ha-border);
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
}

.ha-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ha-muted);
  animation: ha-bounce 1.2s infinite ease-in-out;
}

.ha-typing span:nth-child(2) { animation-delay: 0.15s; }
.ha-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ha-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.ha-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 1rem 0.5rem;
}

.ha-chip {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.35rem 0.65rem;
  border-radius: 9999px;
  border: 1px solid var(--ha-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ha-text);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.ha-chip:hover {
  border-color: rgba(255, 69, 0, 0.5);
  background: rgba(255, 69, 0, 0.1);
}

.ha-chip--inline {
  display: inline;
  margin: 0 0.15rem;
  vertical-align: baseline;
  font-size: 0.68rem;
  padding: 0.2rem 0.45rem;
}

.ha-fallback {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--ha-border);
}

.ha-fallback p {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  color: var(--ha-muted);
}

.ha-btn-wa {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  border-radius: 0.75rem;
  border: none;
  background: #25d366;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: filter 0.15s;
}

.ha-btn-wa:hover {
  filter: brightness(1.08);
}

.ha-btn-wa--primary {
  width: 100%;
  justify-content: center;
  padding: 0.65rem 1rem;
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

.ha-answer-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ha-answer-title {
  margin: 0 0 0.25rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ha-gold);
  line-height: 1.35;
}

.ha-answer-p {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.55;
  color: var(--ha-text);
}

.ha-ref-link {
  margin: 0.35rem 0 0;
  font-size: 0.68rem;
}

.ha-ref-link a {
  color: var(--ha-muted);
  text-decoration: underline;
}

.ha-ref-link a:hover {
  color: var(--ha-accent);
}

.ha-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.ha-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.4rem 0.65rem;
  border-radius: 0.6rem;
  border: 1px solid var(--ha-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ha-text);
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.ha-btn-secondary:hover {
  border-color: rgba(255, 69, 0, 0.45);
  background: rgba(255, 69, 0, 0.08);
}

.ha-muted-note {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ha-muted);
  font-style: italic;
}

.ha-wa-missing {
  margin: 0;
  font-size: 0.75rem;
  color: var(--ha-muted);
  line-height: 1.45;
}

.ha-wa-missing a {
  color: var(--ha-accent);
}

.ha-wa-missing code {
  font-size: 0.68rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
}

.ha-related-label {
  margin: 0.65rem 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ha-muted);
}

.ha-related-item {
  margin: 0 0 0.5rem;
  padding: 0.5rem 0 0.5rem 0.65rem;
  border-left: 2px solid rgba(255, 69, 0, 0.45);
}

.ha-related-item strong {
  display: block;
  font-size: 0.75rem;
  color: var(--ha-gold);
  margin-bottom: 0.2rem;
}

.ha-answer-step {
  padding-left: 0.5rem;
  border-left: 2px solid rgba(255, 69, 0, 0.35);
}

.ha-btn-primary {
  border-color: rgba(255, 69, 0, 0.55) !important;
  background: rgba(255, 69, 0, 0.12) !important;
  color: var(--ha-text) !important;
  font-weight: 700;
}

.ha-btn-link {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.7rem;
  color: var(--ha-muted);
  text-decoration: underline;
}

.ha-composer {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--ha-border);
  background: rgba(0, 0, 0, 0.2);
}

.ha-composer input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--ha-border);
  border-radius: 9999px;
  background: var(--ha-surface);
  color: var(--ha-text);
  font-size: 0.8125rem;
  padding: 0.55rem 0.9rem;
  outline: none;
}

.ha-composer input::placeholder {
  color: #71717a;
}

.ha-composer input:focus {
  border-color: rgba(255, 69, 0, 0.55);
  box-shadow: 0 0 0 2px rgba(255, 69, 0, 0.15);
}

.ha-composer button {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  border-radius: 9999px;
  background: var(--ha-accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.ha-composer button:hover:not(:disabled) {
  background: var(--ha-accent-hover);
}

.ha-composer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Rating panel (existing widget restyled inside dock) */
#support-panel.ha-panel {
  padding: 1.25rem;
}

#support-panel .support-star {
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

@media (max-width: 480px) {
  #floating-dock {
    bottom: max(1rem, env(safe-area-inset-bottom));
    right: max(1rem, env(safe-area-inset-right));
  }

  .ha-panel {
    width: calc(100vw - 2rem);
    max-height: min(78vh, 620px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ha-panel,
  .ha-fab,
  .ha-typing span {
    transition: none;
    animation: none;
  }
}

/* Terms layout: hide rating FAB, keep help */
body.terms-layout #floating-dock .ha-fab--rating,
body.terms-layout #support-panel {
  display: none !important;
}

body.terms-layout #floating-dock {
  display: flex !important;
}

/* Light terms pages — help panel readable */
body.terms-layout .ha-panel {
  --ha-bg: rgba(255, 255, 255, 0.98);
  --ha-surface: #f4f4f5;
  --ha-border: #e4e4e7;
  --ha-text: #18181b;
  --ha-muted: #71717a;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.12);
}

body.terms-layout .ha-fab--help {
  box-shadow: 0 8px 24px rgba(255, 69, 0, 0.25);
}
