/* HiDocument — floating site chatbox */

.hd-chat-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  background: var(--accent-gradient, linear-gradient(135deg, #3b82f6, #8b5cf6));
  color: #fff;
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  z-index: 1000;
}
.hd-chat-launcher:hover { filter: brightness(1.05); }
.hd-chat-launcher:focus-visible { outline: 3px solid var(--accent, #3b82f6); outline-offset: 2px; }
.hd-chat-launcher .hd-chat-launcher-close { display: none; }
.hd-chat-launcher.is-open .hd-chat-launcher-open { display: none; }
.hd-chat-launcher.is-open .hd-chat-launcher-close { display: inline-block; }

.hd-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 20px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: var(--radius-lg, 16px);
  box-shadow: 0 16px 48px rgba(15, 23, 42, 0.28);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  overflow: hidden;
  z-index: 1000;
}
.hd-chat-panel[hidden] { display: none; }

.hd-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--primary-dark, #0a1628);
  color: #fff;
}
.hd-chat-header .hd-chat-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.95rem;
}
.hd-chat-header .hd-chat-title i { color: #93c5fd; }
.hd-chat-header .hd-chat-sub { font-size: 0.75rem; color: #cbd5e1; font-weight: 400; }
.hd-chat-close {
  background: transparent;
  border: none;
  color: #cbd5e1;
  font-size: 1.1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}
.hd-chat-close:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }

.hd-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  background: var(--bg, #f8fafc);
}

.hd-chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.hd-chat-msg.user {
  align-self: flex-end;
  background: var(--accent, #3b82f6);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.hd-chat-msg.assistant {
  align-self: flex-start;
  background: #fff;
  color: var(--text, #0f172a);
  border: 1px solid var(--border, #e2e8f0);
  border-bottom-left-radius: 4px;
}
.hd-chat-msg.error {
  align-self: flex-start;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.hd-chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.hd-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--text-light, #94a3b8);
  display: inline-block;
}

.hd-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border, #e2e8f0);
  background: #fff;
}
.hd-chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border-strong, #cbd5e1);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom */
  line-height: 1.4;
  max-height: 120px;
  color: var(--text, #0f172a);
}
.hd-chat-input:focus { outline: none; border-color: var(--accent, #3b82f6); }
.hd-chat-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--accent, #3b82f6);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hd-chat-send:hover { background: var(--accent-hover, #2563eb); }
.hd-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

.hd-chat-disclaimer {
  font-size: 0.7rem;
  color: var(--text-light, #94a3b8);
  text-align: center;
  padding: 0 12px 10px;
  background: #fff;
}

@media (max-width: 480px) {
  .hd-chat-panel {
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    bottom: 84px;
    height: calc(100vh - 104px);
  }
  .hd-chat-launcher { bottom: 14px; right: 14px; }
}

@media (prefers-reduced-motion: no-preference) {
  .hd-chat-launcher { transition: filter 150ms ease, transform 150ms ease; }
  .hd-chat-launcher:active { transform: scale(0.94); }
  .hd-chat-send { transition: background 150ms ease; }
  .hd-chat-typing span { animation: hd-chat-bounce 1.2s infinite ease-in-out; }
  .hd-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
  .hd-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
  @keyframes hd-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
  }
}
