/* Import Google font - Poppins */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
}

:root {
  --text-color: #FFFFFF;
  --icon-color: #ACACBE;
  --icon-hover-bg: #5b5e71;
  --placeholder-color: #dcdcdc;
  --outgoing-chat-bg: #343541;
  --incoming-chat-bg: #444654;
  --outgoing-chat-border: #343541;
  --incoming-chat-border: #444654;
  --gemini-grad-1: #4285f4;
  --gemini-grad-2: #9b72cb;
  --gemini-grad-3: #d96570;
}

.light-mode {
  --text-color: #343541;
  --icon-color: #a9a9bc;
  --icon-hover-bg: #f1f1f3;
  --placeholder-color: #6c6c6c;
  --outgoing-chat-bg: #FFFFFF;
  --incoming-chat-bg: #F7F7F8;
  --outgoing-chat-border: #FFFFFF;
  --incoming-chat-border: #D9D9E3;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--outgoing-chat-bg);
}

/* ============================
   TOAST NOTIFICATION
   ============================ */
#toast {
  visibility: hidden;
  min-width: 200px;
  background-color: #333;
  color: #fff;
  text-align: center;
  border-radius: 8px;
  padding: 12px;
  position: fixed;
  z-index: 9999;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.3s, bottom 0.3s;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

#toast.show {
  visibility: visible;
  opacity: 1;
  bottom: 110px;
}

/* ============================
   ADS CONTAINER
   ============================ */
.ads-container {
  position: absolute;
  z-index: 999;
  top: 15px;
  left: 0;
  right: 0;
  width: 90%;
  max-width: 600px;
  background-color: var(--incoming-chat-bg);
  color: var(--text-color);
  border: 2px solid skyblue;
  border-radius: 10px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 5px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}

.ads-container .close-btn {
  margin-top: 5px;
  color: crimson;
  cursor: pointer;
}

/* ============================
   CHAT CONTAINER
   ============================ */
.chat-container {
  height: 100dvh;
  width: 100%;
  overflow-y: auto;
  padding-top: 100px;
  padding-bottom: 140px;
  scroll-behavior: smooth;
}

.chat-container::-webkit-scrollbar { width: 6px; }
.chat-container::-webkit-scrollbar-track { background: var(--incoming-chat-bg); border-radius: 25px; }
.chat-container::-webkit-scrollbar-thumb { background: var(--icon-color); border-radius: 25px; }

/* Default Welcome Text */
.default-text {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  height: 60%;
  padding: 0 10px;
  text-align: center;
  color: var(--text-color);
  margin-top: 50px;
}
.default-text h1 { font-size: 3.3rem; }
.default-text p { margin-top: 10px; font-size: 1.1rem; }

.inovixa-gradient {
  background: linear-gradient(to right, #4285f4, #d96570);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ============================
   CHAT BUBBLES
   ============================ */
.chat-container .chat {
  padding: 25px 10px;
  display: flex;
  justify-content: center;
  color: var(--text-color);
  -webkit-tap-highlight-color: transparent; /* remove mobile highlight */
  outline: none; /* allow focus styling via :focus */
}
.chat-container .chat.outgoing {
  background: var(--outgoing-chat-bg);
  border: 1px solid var(--outgoing-chat-border);
}
.chat-container .chat.incoming {
  background: var(--incoming-chat-bg);
  border: 1px solid var(--incoming-chat-border);
}
.chat .chat-content {
  display: flex;
  max-width: 1200px;
  width: 100%;
  align-items: flex-start;
  justify-content: space-between;
}

span.material-symbols-rounded { user-select: none; cursor: pointer; }

/* Hide default icons except file icons and our custom action buttons which we control separately */
.chat .chat-content > span:not(.file-icon) {
  cursor: pointer;
  font-size: 1.3rem;
  color: var(--icon-color);
  visibility: hidden;
}

/* hover still shows on desktop */
.chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) > span:not(.file-icon) {
  visibility: visible;
}

/* --- REVISI JARAK AVATAR (Fix Dempet) --- */
.chat .chat-details {
  display: flex;
  align-items: flex-start;
  width: 100%;
  gap: 20px; /* Jarak lega antara avatar dan teks */
}

.chat .chat-details img {
  width: 35px;
  height: 35px;
  align-self: flex-start;
  object-fit: cover;
  border-radius: 2px;
  flex-shrink: 0; /* Mencegah gambar mengecil */
}

.chat .chat-details .msg-content {
  width: 100%;
  min-width: 0; /* Mencegah overflow flex item */
}

.chat .chat-details p {
  white-space: pre-wrap;
  font-size: 1.05rem;
  color: var(--text-color);
  word-break: break-word;
  margin-top: 0;
  line-height: 1.6;
}
.chat .chat-details p.error { color: #e55865; }

/* ============================
   USER ACTIONS (EDIT/COPY)
   ============================ */
/* default: hidden (desktop & mobile) */
.user-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  transform: translateY(-2px);
}

/* show on desktop hover (outgoing) + show when chat is focused/active or when `.show-actions` added */
.chat.outgoing:hover .user-actions,
.chat.outgoing:focus-within .user-actions,
.chat.outgoing:active .user-actions,
.chat.outgoing.show-actions .user-actions {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* action button visuals */
.action-btn-small {
  font-size: 18px !important;
  color: var(--icon-color);
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  border-radius: 4px;
}
.action-btn-small:hover {
  color: var(--text-color);
  background-color: var(--icon-hover-bg);
}

/* ============================
   EDIT MODE STYLES
   ============================ */
.edit-wrapper {
  width: 100%;
  margin-top: 10px;
}

.edit-textarea-input {
  width: 100%;
  background: var(--incoming-chat-bg);
  color: var(--text-color);
  border: 1px solid var(--incoming-chat-border);
  border-radius: 8px;
  padding: 12px;
  font-size: 1rem;
  resize: none; /* Disable manual resize, use auto-expand */
  min-height: 60px;
  outline: none;
  margin-bottom: 8px;
  line-height: 1.5;
  overflow-y: hidden;
}

.edit-controls {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-edit-action {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  border: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px; /* Jarak icon ke teks */
  transition: background 0.2s;
}

.btn-edit-action span {
  font-size: 18px; /* Ukuran icon dalam tombol */
}

.btn-save {
  background-color: #4285f4;
  color: white;
}
.btn-save:hover {
  background-color: #3367d6;
}

.btn-cancel {
  background-color: transparent;
  color: var(--icon-color);
  border: 1px solid var(--icon-color);
}
.btn-cancel:hover {
  background-color: var(--icon-hover-bg);
  color: var(--text-color);
}

/* ============================
   ANIMATIONS
   ============================ */
.bot-thinking { animation: botPulse 1.5s infinite ease-in-out; }

@keyframes botPulse {
  0% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.8; }
  100% { transform: scale(1); opacity: 1; }
}

.chat .typing-animation { padding-left: 0; display: inline-flex; } /* removed padding-left because of gap in parent */
.typing-animation .typing-dot {
  height: 8px; width: 8px; border-radius: 50%; margin: 0 4px; opacity: 1;
  background: linear-gradient(135deg, var(--gemini-grad-1), var(--gemini-grad-2), var(--gemini-grad-3));
  background-size: 200% 200%;
  animation: animateDots 1.5s var(--delay) ease-in-out infinite, gradientMove 2s infinite linear;
}

@keyframes gradientMove {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes animateDots {
  0%, 100% { transform: translateY(0px); opacity: 0.6; }
  50% { transform: translateY(-8px); opacity: 1; box-shadow: 0 0 8px rgba(155, 114, 203, 0.6); }
}

/* ============================
   TYPING AREA (INPUT)
   ============================ */
.typing-container {
  position: fixed; bottom: 0; width: 100%; display: flex; padding: 15px 10px;
  justify-content: center; background: var(--outgoing-chat-bg);
  border-top: 1px solid var(--incoming-chat-border); z-index: 1000;
}
.typing-container .typing-content { display: flex; max-width: 950px; width: 100%; align-items: flex-end; }

.action-wrapper { position: relative; display: flex; align-items: center; justify-content: center; margin-right: 12px; height: 56px; padding-bottom: 4px; }
.action-btn { font-size: 2.2rem !important; cursor: pointer; padding: 5px; color: var(--icon-color); transition: transform 0.3s ease, color 0.3s ease; border-radius: 50%; }
.action-btn:hover { background: var(--icon-hover-bg); }
.action-btn.active { transform: rotate(45deg); color: var(--text-color); background: var(--icon-hover-bg); }

.action-menu {
  position: absolute; bottom: 65px; left: 0; background: var(--incoming-chat-bg);
  border: 1px solid var(--incoming-chat-border); border-radius: 12px; padding: 8px;
  display: flex; flex-direction: column; gap: 5px; min-width: 150px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.2); opacity: 0; pointer-events: none;
  transform: translateY(15px) scale(0.95); transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1); z-index: 2000;
}
.action-menu.show { opacity: 1; pointer-events: auto; transform: translateY(0) scale(1); }

.menu-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; border-radius: 8px; transition: background 0.2s; color: var(--text-color); }
.menu-item:hover { background: var(--icon-hover-bg); }
.menu-item span { font-size: 0.95rem; font-weight: 500; }

.typing-textarea {
  flex: 1; display: flex; flex-direction: column; position: relative;
  background: var(--incoming-chat-bg); border-radius: 16px;
  border: 1px solid var(--incoming-chat-border);
}

#file-preview-container { display: none; padding: 10px 15px; border-bottom: 1px solid var(--incoming-chat-border); background: var(--incoming-chat-bg); margin-bottom: -1px; border-radius: 16px 16px 0 0; }
.preview-box { position: relative; display: inline-block; }
#file-preview { max-height: 80px; border-radius: 8px; border: 1px solid var(--icon-color); display: none; }
#file-icon-preview { display: none; width: 60px; height: 60px; background: var(--outgoing-chat-bg); border-radius: 8px; align-items: center; justify-content: center; border: 1px solid var(--icon-color); }
#file-icon-preview span { font-size: 30px; color: var(--text-color); }
#remove-file-btn { position: absolute; top: -8px; right: -8px; background: #ff4d4d; color: white; border-radius: 50%; font-size: 16px !important; width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 5px rgba(0,0,0,0.2); }
#file-name-label { display: block; font-size: 0.75rem; color: var(--icon-color); margin-top: 6px; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* REVISI TEXTAREA UTAMA (Auto Expand) */
.typing-textarea textarea {
  resize: none;
  width: 100%; border: none;
  padding: 16px 45px 16px 20px;
  color: var(--text-color);
  font-size: 1rem; border-radius: 16px;
  background: transparent; outline: none;

  /* Initial height */
  height: 56px;
  max-height: 200px; /* Batas tinggi sebelum scroll */
  overflow-y: hidden; /* Sembunyikan scrollbar jika belum max-height */
  line-height: 1.5;
}

/* Class tambahan saat konten melebihi max-height (diatur JS) */
.typing-textarea textarea.scrolly { overflow-y: auto; }

.typing-textarea textarea::placeholder { color: var(--placeholder-color); }
.typing-textarea span#mic-btn, .typing-textarea span#send-btn { position: absolute; right: 10px; bottom: 5px; width: 45px; height: 45px; display: flex; align-items: center; justify-content: center; color: var(--icon-color); font-size: 1.4rem; cursor: pointer; }

.typing-controls { display: flex; align-items: center; margin-left: 10px; height: 56px; padding-bottom: 4px; }
.typing-controls span { font-size: 1.4rem; background: var(--incoming-chat-bg); border: 1px solid var(--incoming-chat-border); padding: 10px; border-radius: 50%; cursor: pointer; color: var(--icon-color); margin-left: 8px; }
.typing-controls span:hover { background: var(--icon-hover-bg); }

/* Chat Image & File */
.chat-img { max-width: 350px; width: 100%; height: auto; border-radius: 12px; margin-bottom: 8px; display: block; object-fit: cover; border: 1px solid var(--incoming-chat-border); cursor: zoom-in; transition: transform 0.2s; }
.chat-img:hover { opacity: 0.9; }

.file-attachment { display: flex; align-items: center; gap: 12px; background: var(--incoming-chat-bg); padding: 8px 12px; border-radius: 12px; margin-bottom: 8px; border: 1px solid var(--incoming-chat-border); width: fit-content; max-width: 100%; }
.file-attachment .file-icon { font-size: 2rem !important; color: #4285f4; }
.file-attachment .file-name { font-size: 0.95rem !important; color: var(--text-color); font-weight: 500; word-break: break-all; }
.chat .chat-content .file-attachment span { visibility: visible !important; opacity: 1 !important; pointer-events: auto !important; }

/* Overlay */
.image-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.9); z-index: 99999; display: none; justify-content: center; align-items: center; opacity: 0; transition: opacity 0.3s ease; backdrop-filter: blur(5px); }
.image-overlay.active { display: flex; opacity: 1; }
.image-overlay img { max-width: 95%; max-height: 95%; border-radius: 8px; box-shadow: 0 0 20px rgba(0,0,0,0.5); transform: scale(0.9); transition: transform 0.3s ease; }
.image-overlay.active img { transform: scale(1); }
#close-overlay { position: absolute; top: 20px; right: 20px; color: white; font-size: 2.5rem; cursor: pointer; background: rgba(255,255,255,0.1); border-radius: 50%; padding: 5px; }

/* Mobile Response */
@media screen and (max-width: 600px) {
  .default-text h1 { font-size: 2.3rem; }
  :where(.default-text p, textarea, .chat p) { font-size: 0.95rem!important; }
  .chat-container { padding-bottom: 110px; padding-top: 100px; }
  .chat-container .chat { padding: 20px 10px; }
  .typing-container { padding: 10px 5px; }
  .typing-textarea textarea { padding: 16px 40px 16px 15px; }
  .action-wrapper, .typing-controls { height: 56px; }
  .action-btn { font-size: 1.8rem !important; }
  .typing-controls span { padding: 8px; font-size: 1.2rem; }
  .chat-img { max-width: 100%; }
  .file-attachment { width: 100%; }

  /* IMPORTANT: do NOT force-show actions on mobile by default.
     Use :focus-within/:active or JS toggling (.show-actions) instead for touch behavior. */
}

/* Optional focus visual for keyboard / accessibility */
.chat:focus {
  box-shadow: 0 0 0 3px rgba(66,133,244,0.08);
  border-radius: 8px;
}

/* Small helper to quickly hide actions (if needed) */
.chat.hide-actions .user-actions { opacity: 0 !important; pointer-events: none !important; transform: translateY(-2px) !important; }
