/* ============================================================
   HEPIDEI — AI CHAT WIDGET
   Bubble chat AI mengambang. Warna mengikuti design tokens.
   ============================================================ */

.hchat-fab {
  position: fixed;
  right: 22px;
  bottom: calc(22px + var(--hchat-kb, 0px));
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  background: var(--btn);
  color: #fff;
  box-shadow: 0 8px 24px rgba(42, 30, 44, 0.28);
  transition:
    transform 0.2s ease,
    background-color 0.2s ease;
}

.hchat-fab:hover {
  transform: scale(1.06);
  background: var(--btnh);
}

.hchat-fab svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.hchat-panel {
  position: fixed;
  right: 22px;
  bottom: calc(92px + var(--hchat-kb, 0px));
  z-index: 1001;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 130px));
  height: min(560px, calc(100dvh - 130px - var(--hchat-kb, 0px)));
  min-height: 120px;
  border-radius: var(--radius-md);
  background: var(--bg);
  box-shadow: 0 16px 48px rgba(42, 30, 44, 0.25);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0.22s;
}

.hchat-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.hchat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 8px;
  padding: 14px 16px;
  background: var(--cta);
  color: var(--on-dark);
}

.hchat-title {
  font: 600 15px/1.3 var(--font-display);
}

.hchat-sub {
  margin-top: 2px;
  color: var(--on-dark-muted);
  font-size: 12px;
}

.hchat-close {
  padding: 2px 6px;
  border: 0;
  background: transparent;
  color: var(--on-dark);
  font-size: 22px;
  line-height: 1;
  opacity: 0.8;
}

.hchat-close:hover {
  opacity: 1;
}

.hchat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  padding: 14px;
  background: var(--card);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.hchat-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.hchat-bubble--bot {
  align-self: flex-start;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  background: var(--bg);
  color: var(--ink);
}

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

.hchat-bubble--thinking {
  border: 1px dashed var(--line);
  background: var(--bg);
  color: var(--mute);
  font-style: italic;
}

.hchat-wa {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--wa);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.hchat-wa:hover {
  background: var(--wa-dark);
}

.hchat-inputrow {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.hchat-input {
  flex: 1;
  min-width: 0;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  outline: none;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
}

.hchat-input:focus {
  border-color: var(--btn);
}

.hchat-send {
  padding: 9px 16px;
  border: 0;
  border-radius: 20px;
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
}

.hchat-send:hover {
  opacity: 0.9;
}

.hchat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .hchat-fab {
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px) + var(--hchat-kb, 0px));
  }

  .hchat-panel {
    right: 8px;
    left: 8px;
    bottom: calc(86px + env(safe-area-inset-bottom, 0px) + var(--hchat-kb, 0px));
    width: auto;
    height: min(520px, calc(100vh - 110px));
    height: min(
      520px,
      calc(100dvh - 110px - env(safe-area-inset-bottom, 0px) - var(--hchat-kb, 0px))
    );
  }
}

@media (prefers-reduced-motion: reduce) {
  .hchat-panel,
  .hchat-fab {
    transition: none;
  }
}
