/**
 *  Vansari AI - widget.css
 * Styling widget chat + video launcher.
 * Semua class pakai prefix "aic-" supaya tidak bentrok dengan tema WordPress.
 *
 * v1.1: ukuran frame video desktop 120x180 (rasio 2:3, bisa dioverride lewat
 *       CSS custom properties dari widget.js jika diubah di admin),
 *       mobile 100x160 via media query.
 * v1.6.3: warna utama mengikuti setting admin; posisi widget dinamis.
 *         (left -> right), handle resize pindah POJOK KIRI-ATAS
 *         (cursor nwse, grip segitiga menghadap badan chat di kanan-bawah).
 *         Arah matematika resize TIDAK perlu ubah JS — JS auto-detect
 *         posisi handle terhadap kotak saat pointerdown.
 * v1.0.8: grip handle di-set PER SUDUT (dulu selalu 135deg sehingga untuk
 *         widget kiri-bawah grip-nya jatuh di sudut dalam dan terlihat
 *         berlawanan dengan cursor nesw). Tombol tutup dinaikkan di atas handle.
 */

/* ===== Container ===== */
#aic-ai-widget {
  position: fixed;
  bottom: var(--aic-offset-y, 20px);
  right: var(--aic-offset-x, 10px);
  left: auto;
  top: auto;
  z-index: 99999;
  /* v1.0.13: ikuti font default tema situs, bukan font pilihan plugin. */
  font-family: inherit;
}

/* Elemen form tidak mewarisi font secara default; paksa ikut font situs. */
#aic-ai-widget button,
#aic-ai-widget input,
#aic-ai-widget textarea,
#aic-ai-widget select {
  font-family: inherit;
}

/* Posisi dinamis: chat, launcher, dan handle resize mengikuti sudut yang sama. */
#aic-ai-widget[data-position="bottom-left"] { left: var(--aic-offset-x, 10px); right: auto; bottom: var(--aic-offset-y, 20px); top: auto; }
#aic-ai-widget[data-position="top-right"] { right: var(--aic-offset-x, 10px); left: auto; top: var(--aic-offset-y, 20px); bottom: auto; }
#aic-ai-widget[data-position="top-left"] { left: var(--aic-offset-x, 10px); right: auto; top: var(--aic-offset-y, 20px); bottom: auto; }

/* ===== Launcher: video frame ===== */
#aic-video-launcher {
  cursor: pointer;
  text-align: center;
  user-select: none;
  transition: transform 0.2s ease;
}
#aic-video-launcher:hover { transform: scale(1.05); }

#aic-video-frame {
  position: relative;
  width: var(--aic-frame-w, 120px);   /* desktop 120px */
  height: var(--aic-frame-h, 180px);  /* desktop 180px — rasio 2:3 */
  overflow: hidden;
  border-radius: 14px;
  background: transparent; /* video transparan (webm) tampil bersih; fallback mp4 juga tetap ok */
  box-shadow: none;
}

#aic-video-frame video {
  width: 100%;
  height: 100%;
  object-fit: contain;  /* video sudah di-crop 2:3 via ffmpeg; tidak perlu zoom */
  transform: scale(1.0);
  display: block;
  pointer-events: none;
}

#aic-launcher-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(var(--aic-primary-rgb, 108, 13, 15), 0.92);
  color: #fff;
  font-weight: bold;
  font-size: 14px;
  padding: 6px 0;
  text-align: center;
  border-radius: 0 0 14px 14px;
}

/* ===== Launcher: tombol biasa (jika tidak pakai video) ===== */
#aic-launcher-btn {
  background: linear-gradient(135deg, var(--aic-primary, #6c0d0f), var(--aic-primary-dark, #4e080a)); /* biru tema var(--aic-primary, #6c0d0f) + kedalaman */
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* ===== Launcher: ukuran mobile ===== */
@media (max-width: 768px) {
  #aic-video-frame {
    width: calc(var(--aic-frame-w, 120px) * var(--aic-mobile-scale, 0.85));
    height: calc(var(--aic-frame-h, 180px) * var(--aic-mobile-scale, 0.85));
  }
  #aic-launcher-label {
    font-size: 12px;
    padding: 4px 0;
  }
}

/* ===== Chat box ===== */
#aic-chat-box {
  display: none; /* WAJIB — tersembunyi sampai launcher diklik */
  width: var(--aic-chat-w, 360px);
  max-width: calc(100vw - 20px);
  height: var(--aic-chat-h, 450px);
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: var(--aic-radius, 12px);
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.25);
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 10px;
}

#aic-ai-widget[data-position="top-right"] #aic-chat-box,
#aic-ai-widget[data-position="top-left"] #aic-chat-box {
  margin-bottom: 0;
  margin-top: 10px;
}

.aic-chat-header {
  background: linear-gradient(135deg, var(--aic-primary, #6c0d0f), var(--aic-primary-dark, #4e080a));
  color: var(--aic-header-text, #fff);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.aic-chat-title {
  font-weight: bold;
  font-size: 15px;
}

.aic-chat-subtitle {
  font-size: 11px;
  opacity: 0.85;
}

#aic-chat-close {
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
  position: relative;
  z-index: 10; /* v1.0.8: jangan tertutup handle resize */
}
#aic-chat-close:hover { opacity: 1; }

/* ===== Chat logs ===== */
#aic-chat-logs {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  background: #f6f5f1;
  font-size: 14px;
  line-height: 1.5;
}

.aic-msg-user,
.aic-msg-bot {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  max-width: 85%;
  word-wrap: break-word;
}

.aic-msg-user {
  background: var(--aic-primary, #6c0d0f);
  color: #fff;
  margin-left: auto;
  text-align: left;
}

.aic-msg-bot {
  background: #ffffff;
  border: 1px solid #e2e0d8;
  margin-right: auto;
}

.aic-msg-bot a {
  color: #8a1418; /* biru tua supaya kontras teks di putih tetap terbaca */
  font-weight: 600;
  text-decoration: underline;
}

.aic-msg-img img {
  max-width: 100%;
  border-radius: 8px;
  margin-top: 6px;
  cursor: pointer;
}

.aic-loading {
  font-style: italic;
  opacity: 0.7;
}

.aic-error {
  background: #fdecea;
  border-color: #f5c6cb;
  color: #a94442;
}

/* ===== Input area ===== */
.aic-chat-input-area {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #e8e6de;
}

#aic-user-input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid #d8d6cc;
  border-radius: 20px;
  font-size: 14px;
  outline: none;
}
#aic-user-input:focus { border-color: var(--aic-primary, #6c0d0f); }

#aic-send-btn {
  background: var(--aic-primary, #6c0d0f);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
}
#aic-send-btn:disabled { opacity: 0.6; cursor: wait; }

/* ===== v1.4 VOICE: mic & speaker buttons ===== */
#aic-mic-btn {
  background: #f6f5f1;
  border: 1px solid #d8d6cc;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background 0.15s ease;
}
#aic-mic-btn:hover { background: #e8e6de; }
#aic-mic-btn.aic-mic-active {
  background: #c0392b;
  border-color: #c0392b;
  animation: aic-pulse 1.2s infinite;
}
@keyframes aic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(192, 57, 43, 0); }
}
#aic-speak-toggle {
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.85;
  margin-right: 10px;
}
#aic-speak-toggle:hover { opacity: 1; }
.aic-speak-btn {
  display: inline-block;
  font-size: 13px;
  cursor: pointer;
  opacity: 0.55;
  margin-left: 8px;
  vertical-align: middle;
  transition: opacity 0.15s ease;
}
.aic-speak-btn:hover { opacity: 1; }

/* ===== v1.5: input area 2 baris + lang selector ===== */
.aic-chat-input-area {
  flex-direction: column;
  gap: 8px;
}

.aic-input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.aic-input-actions #aic-send-btn {
  margin-left: auto;
  min-width: 84px;
  flex: 0 0 auto;
}

.aic-lang-wrap { position: relative; flex: 0 0 auto; }
.aic-lang-btn {
  background: #f6f5f1;
  border: 1px solid #d8d6cc;
  border-radius: 18px;
  font-size: 12px;
  color: #8a1418;
  padding: 6px 10px;
  max-width: 130px;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.aic-lang-btn:hover { border-color: var(--aic-primary, #6c0d0f); }
/* Menu buka ke ATAS di dalam chat box -> tidak terpotong overflow/bottom edge */
.aic-lang-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 150px;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: #ffffff;
  border: 1px solid #d8d6cc;
  border-radius: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  z-index: 10;
}
.aic-lang-menu li {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  color: #8a1418;
  cursor: pointer;
  white-space: nowrap;
}
.aic-lang-menu li:hover { background: #eeeee6; }

@media (max-width: 768px) {
  .aic-lang-btn {
    font-size: 11px;
    max-width: 110px;
    padding: 5px 8px;
  }
  .aic-input-actions #aic-send-btn {
    min-width: 72px;
    padding: 9px 12px;
  }
}

/* ===== v1.6.1 RESIZE HANDLE (port Nadi v9.9/v9.10) ===== */
#aic-chat-box {
  position: relative;   /* anchor handle absolut (di-set juga dari JS) */
}
#aic-resize-handle {
  position: absolute;
  left: 0;             /* default: widget kanan-bawah -> handle kiri-atas */
  right: auto;
  top: 0;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  /* v1.0.8: di bawah tombol tutup (dulu 99999 -> tombol X tidak bisa diklik). */
  z-index: 5;
  touch-action: none;
  user-select: none;
  /* v1.0.8: grip HARUS mengisi sudut tempat handle berada.
     315deg = segitiga di sudut kiri-atas (handle default). */
  background: linear-gradient(315deg,
    transparent 50%,
    rgba(225, 225, 225, 0.95) 50%);
  border-radius: 0 0 8px 0;
}

/* Handle selalu di sudut berlawanan dengan posisi widget.
   Cursor = sumbu diagonal antara handle dan sudut kotak yang berlawanan:
   sudut kanan-atas / kiri-bawah -> nesw-resize, kiri-atas / kanan-bawah -> nwse-resize.
   Gradient grip mengikuti sudut yang SAMA supaya arah panah dan arah drag cocok. */
#aic-ai-widget[data-position="bottom-left"] #aic-resize-handle {
  left: auto; right: 0; top: 0; bottom: auto;
  cursor: nesw-resize; border-radius: 0 0 0 8px;
  background: linear-gradient(45deg, transparent 50%, rgba(225, 225, 225, 0.95) 50%);
}
#aic-ai-widget[data-position="top-right"] #aic-resize-handle {
  left: 0; right: auto; top: auto; bottom: 0;
  cursor: nesw-resize; border-radius: 8px 0 0 0;
  background: linear-gradient(225deg, transparent 50%, rgba(225, 225, 225, 0.95) 50%);
}
#aic-ai-widget[data-position="top-left"] #aic-resize-handle {
  left: auto; right: 0; top: auto; bottom: 0;
  cursor: nwse-resize; border-radius: 0 8px 0 0;
  background: linear-gradient(135deg, transparent 50%, rgba(225, 225, 225, 0.95) 50%);
}

/* ===== v1.6.2: ukuran mobile chat-box TANPA !important =====
   Rule diletakkan DI AKHIR file (setelah base #aic-chat-box) supaya
   menang atas base rule berdasarkan urutan, TANPA !important — sehingga
   inline style hasil drag resize (JS) tetap MENANG di mobile.
   Sebelumnya `!important` di sini mematikan resize di mobile. ===== */
@media screen and (max-width: 768px) {
  #aic-chat-box {
    width: min(calc(var(--aic-chat-w, 360px) * var(--aic-mobile-scale, 0.85)), calc(100vw - 20px));
    height: min(calc(var(--aic-chat-h, 450px) * var(--aic-mobile-scale, 0.85)), calc(100vh - 120px));
  }
}
