/* =========================================
   CHAT WIDGET — Wahyu Alfaris Portfolio
========================================= */

/* === FAB BUTTON === */
.chat-fab {
  position: fixed;
  bottom: 2.8rem;
  right: 2.8rem;
  width: 5.6rem;
  height: 5.6rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2000;
  box-shadow: 0 6px 28px rgba(var(--accent-rgb), 0.38);
  border: none;
  transition: transform 0.3s var(--ease), box-shadow 0.3s;
  outline: none;
}
.chat-fab:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: 0 10px 36px rgba(var(--accent-rgb), 0.5);
}
.chat-fab .chat-fab-icon,
.chat-fab .chat-fab-close {
  position: absolute;
  transition: opacity 0.25s, transform 0.3s var(--ease);
}
.chat-fab .chat-fab-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.7);
}
.chat-fab.open .chat-fab-icon {
  opacity: 0;
  transform: rotate(90deg) scale(0.7);
}
.chat-fab.open .chat-fab-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* =========================================
   FINAL FIX — FAB tidak menutupi tombol kirim
========================================= */

/* Saat chat terbuka, FAB disembunyikan */
.chat-fab.open {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.7);
}

/* Scroll mobile lebih stabil */
.chat-panel {
  overscroll-behavior: contain;
}

/* Badge */
.chat-fab-badge {
  position: absolute;
  top: -0.2rem;
  right: -0.2rem;
  width: 1.6rem;
  height: 1.6rem;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid var(--bg);
  display: none;
}
.chat-fab-badge.show { display: block; }

/* === CHAT PANEL === */
.chat-panel {
  position: fixed;
  bottom: 9.5rem;
  right: 2.8rem;
  width: 36rem;
  max-width: calc(100vw - 3.2rem);
  height: 52rem;
  max-height: calc(100vh - 12rem);
  background: var(--bg-card);
  border: 1px solid var(--border-h);
  border-radius: 2rem;
  display: flex;
  flex-direction: column;
  z-index: 1999;
  box-shadow: 0 24px 64px rgba(0,0,0,0.35), 0 0 0 1px var(--border);
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  transform-origin: bottom right;
}
.chat-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* === HEADER === */
.chat-panel-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.4rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  flex-shrink: 0;
}
.chat-panel-avatar {
  width: 3.4rem;
  height: 3.4rem;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.chat-panel-info { flex: 1; min-width: 0; }
.chat-panel-info h4 {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-panel-info span {
  font-size: 1.1rem;
  opacity: 0.85;
}
.chat-panel-info .chat-status-dot {
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: #4ade80;
  margin-right: 0.35rem;
  vertical-align: middle;
}

/* Header action buttons (help, reset, close) */
.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}
/* =========================================
   MODERN HEADER BUTTONS
========================================= */

.chat-header-btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.12);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);

  border-radius: 1rem;
  color: #fff;

  width: 3.4rem;
  height: 3.4rem;

  display: flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  flex-shrink: 0;

  transition:
    transform 0.2s ease,
    background 0.2s ease,
    border-color 0.2s ease,
    box-shadow 0.2s ease;
}

/* Hover modern */
.chat-header-btn:hover {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.2);
  transform: translateY(-1px) scale(1.05);
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

/* Active click */
.chat-header-btn:active {
  transform: scale(0.96);
}

/* Focus accessibility */
.chat-header-btn:focus-visible {
  outline: 2px solid rgba(255,255,255,0.5);
  outline-offset: 2px;
}

/* CLOSE BUTTON khusus */
.chat-close-btn {
  width: 3.8rem;
  height: 3.8rem;

  border-radius: 1.2rem;

  background: rgba(255,255,255,0.2);

  font-size: 1.8rem;
  font-weight: 700;
}

/* Hover close button */
.chat-close-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: rotate(90deg) scale(1.08);
}
/* === MESSAGES === */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.6rem 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-h); border-radius: 3px; }

/* Bubbles */
.chat-bubble {
  max-width: 84%;
  padding: 1rem 1.4rem;
  border-radius: 1.4rem;
  font-size: 1.3rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
  animation: bubbleIn 0.25s var(--ease) both;
}
@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-bubble.bot {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 0.3rem;
  align-self: flex-start;
}
.chat-bubble.user {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-bottom-right-radius: 0.3rem;
  align-self: flex-end;
}
.chat-bubble.error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  color: #ef4444;
}
[data-theme="dark"] .chat-bubble.error { color: #f87171; }

/* Typing */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 1rem 1.3rem;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  border-bottom-left-radius: 0.3rem;
  align-self: flex-start;
  width: fit-content;
}
.chat-typing span {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  background: var(--muted);
  animation: typingDot 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%,60%,100% { opacity: 0.35; transform: scale(0.85); }
  30%          { opacity: 1;    transform: scale(1.2); }
}

/* === SUGGESTIONS === */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0 1.4rem 0.8rem;
  flex-shrink: 0;
}
.chat-suggestion-btn {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10rem;
  color: var(--muted);
  font-size: 1.15rem;
  padding: 0.5rem 1.1rem;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  font-family: var(--font);
}
.chat-suggestion-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

/* === INPUT ROW === */
.chat-input-row {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem 1.2rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-card);
  box-sizing: border-box;
  width: 100%;
  overflow: hidden;
}

.chat-input {
  flex: 1 1 0%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10rem;
  color: var(--text);
  font-family: var(--font);
  font-size: 1.3rem;
  padding: 0.85rem 1.4rem;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.4;
  max-height: 10rem;
  overflow-y: auto;
  display: block;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--subtle); }

/* Send button — ukuran terkunci, tidak boleh geser */
.chat-send-btn {
  flex: 0 0 3.6rem;
  width: 3.6rem;
  height: 3.6rem;
  min-width: 3.6rem;
  max-width: 3.6rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: #fff;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s var(--ease), opacity 0.2s;
  position: static;
  top: auto;
  right: auto;
}
.chat-send-btn:hover { transform: scale(1.08); }
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* === RESPONSIVE MOBILE === */
@media (max-width: 480px) {
  .chat-fab {
    bottom: 2rem;
    right: 2rem;
  }

  /* Panel penuh dari bawah */
  .chat-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 78vh;
    max-height: 78vh;
    border-radius: 1.6rem 1.6rem 0 0;
    transform-origin: bottom center;
  }

  /* Header lebih compact di mobile */
  .chat-panel-header {
    padding: 1rem 1.1rem;
    gap: 0.8rem;
  }
  .chat-panel-avatar {
    width: 3rem;
    height: 3rem;
    font-size: 1.3rem;
  }
  .chat-header-btn {
  width: 3rem;
  height: 3rem;
  font-size: 1.15rem;
  border-radius: 0.9rem;
}

.chat-close-btn {
  width: 3.3rem;
  height: 3.3rem;
  font-size: 1.5rem;
}
  /* Messages */
  .chat-messages {
    padding: 1.2rem 1rem;
    gap: 0.8rem;
  }
  .chat-bubble {
    font-size: 1.25rem;
    padding: 0.85rem 1.2rem;
  }

  /* Suggestions lebih rapat */
  .chat-suggestions {
    padding: 0 0.8rem 0.6rem;
    gap: 0.45rem;
  }
  .chat-suggestion-btn {
    font-size: 1.05rem;
    padding: 0.4rem 0.85rem;
  }

  /* Input row — kunci utama agar send tidak keluar */
  .chat-input-row {
    padding: 0.7rem 0.9rem;
    padding-bottom: calc(0.7rem + env(safe-area-inset-bottom, 0px));
    gap: 0.5rem;
  }
  .chat-input {
    font-size: 1.2rem;
    padding: 0.75rem 1.1rem;
  }
  .chat-send-btn {
    flex: 0 0 3.2rem;
    width: 3.2rem;
    height: 3.2rem;
    min-width: 3.2rem;
    max-width: 3.2rem;
    font-size: 1.25rem;
  }
}

/* Mobile sangat kecil (< 360px) */
@media (max-width: 360px) {
  .chat-panel {
    height: 82vh;
    max-height: 82vh;
  }
  .chat-header-btn {
  width: 3rem;
  height: 3rem;
  font-size: 1.15rem;
  border-radius: 0.9rem;
}

.chat-close-btn {
  width: 3.3rem;
  height: 3.3rem;
  font-size: 1.5rem;
}
  .chat-panel-info h4 { font-size: 1.2rem; }
  .chat-panel-info span { font-size: 1rem; }
  .chat-input-row {
    padding: 0.6rem 0.7rem;
    gap: 0.4rem;
  }
  .chat-send-btn {
    flex: 0 0 3rem;
    width: 3rem;
    height: 3rem;
    min-width: 3rem;
    max-width: 3rem;
  }
  .chat-suggestions {
    padding: 0 0.6rem 0.5rem;
    gap: 0.4rem;
  }
  .chat-suggestion-btn {
    font-size: 1rem;
    padding: 0.35rem 0.75rem;
  }
}