/* ============================================================================
   public/assets/css/ai-agent.css — STYLING AI AGENT & VOICE CALLING MUSLIMHUB
   ============================================================================ */

/* ---------- Floating Button (§32) — lingkaran kecil berlabel "AI" ----------
   Ukuran 48px: pas dengan target sentuh Material, tetap kecil di layar.
   Gradien + glow emas dipertahankan agar konsisten dengan identitas AI. */
.ai-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1050;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #087F5B 0%, #055C41 100%);
  color: #FFFFFF;
  border: 1.5px solid rgba(212, 175, 55, 0.45);
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 10px 25px -5px rgba(8, 127, 91, 0.4),
              0 0 0 1px rgba(255, 255, 255, 0.1) inset,
              0 0 18px rgba(212, 175, 55, 0.35);
  transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
  user-select: none;
  font-family: inherit;
  touch-action: none; /* wajib: pointermove jalan di sentuhan (tanpa scroll) */
}

/* Saat digeser: transisi dimatikan agar mengikuti jari secara instan, dan
   feedback visual "sedang dipegang" (membesar sedikit + glow lebih kuat). */
.ai-fab.dragging {
  transition: none;
  transform: scale(1.12);
  cursor: grabbing;
  box-shadow: 0 18px 40px -8px rgba(8, 127, 91, 0.6),
              0 0 30px rgba(212, 175, 55, 0.55);
  z-index: 1100;
}

.ai-fab:hover {
  transform: translateY(-3px) scale(1.04);
  box-shadow: 0 14px 30px -5px rgba(8, 127, 91, 0.55),
              0 0 24px rgba(212, 175, 55, 0.5);
}

.ai-fab:active {
  transform: translateY(0) scale(0.98);
}

/* Label teks "AI" — memenuhi lingkaran, tanpa ikon/pill tambahan */
.ai-fab-badge {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  background: none;
  border: none;
  color: #FFDF70;
  padding: 0;
  line-height: 1;
}

/* Mobile viewport bottom spacing for bottom nav */
@media (max-width: 768px) {
  .ai-fab {
    right: 16px;
    bottom: 82px; /* Di atas bottom-nav MuslimHub */
  }
}

@keyframes ai-sparkle-pulse {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.12) rotate(8deg); }
}

/* ---------- AI Chat Panel (§33) ---------- */
.ai-panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 18, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1060;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.ai-panel-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.ai-panel {
  position: fixed;
  z-index: 1070;
  display: flex;
  flex-direction: column;
  background: var(--c-surface, #FFFFFF);
  box-shadow: 0 20px 45px -10px rgba(0, 0, 0, 0.35),
              0 0 0 1px rgba(0, 0, 0, 0.08);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  overflow: hidden;
}

/* Desktop layout: floating drawer at bottom-right */
@media (min-width: 769px) {
  .ai-panel {
    right: 24px;
    bottom: 24px;
    width: 440px;
    height: 640px;
    max-height: calc(100vh - 48px);
    border-radius: 24px;
    border: 1px solid rgba(8, 127, 91, 0.2);
    transform: translateY(20px) scale(0.96);
    opacity: 0;
    pointer-events: none;
  }
  .ai-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
  }
}

/* Mobile layout: bottom sheet */
@media (max-width: 768px) {
  .ai-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 88vh;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
    pointer-events: none;
  }
  .ai-panel.open {
    transform: translateY(0);
    pointer-events: auto;
  }
}

/* Dark mode overrides for panel */
[data-theme="dark"] .ai-panel {
  background: #14241E;
  border-color: rgba(255, 255, 255, 0.1);
  color: #E2E8F0;
}

/* ---------- Mode Layar Penuh (tombol ⛶ di header AI) ----------
   Panel mengisi seluruh viewport tanpa sudut bulat; backdrop ikut
   ditutup rapat agar tidak ada celah terlihat di tepi. Toggle memakai
   class (bukan Fullscreen API) supaya bekerja di WebView APK. */
.ai-panel.fullscreen {
  inset: 0;
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  border-radius: 0;
  border: none;
}
.ai-panel.fullscreen.open {
  transform: none;
  opacity: 1;
}
/* Saat fullscreen, backdrop tidak perlu terlihat (panel sudah menutupi) */
.ai-panel-backdrop.open:has(+ .ai-panel.fullscreen) {
  opacity: 0;
  pointer-events: none;
}

/* ---------- Panel Header ---------- */
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, #087F5B 0%, #066246 100%);
  color: #FFFFFF;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.ai-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-header-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 223, 112, 0.4);
}

.ai-header-avatar svg {
  width: 20px;
  height: 20px;
  stroke: #FFDF70;
}

.ai-header-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
}

.ai-header-sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 5px;
}

.ai-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22C55E;
  box-shadow: 0 0 8px #22C55E;
}

.ai-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ai-btn-icon {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.85);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.ai-btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
}

.ai-btn-call {
  background: rgba(255, 223, 112, 0.2);
  border: 1px solid rgba(255, 223, 112, 0.5);
  color: #FFF2A8;
}

.ai-btn-call:hover {
  background: rgba(255, 223, 112, 0.35);
  color: #FFFFFF;
}

/* ---------- Disclaimer (kecil, kalem, di bawah input bar) ----------
   Satu baris 10.5px, warna redup — cukup terbaca tanpa membuat panel
   penuh/percanggihan dengan nuansa ramah AI. */
.ai-disclaimer {
  padding: 4px 14px 8px;
  font-size: 10.5px;
  line-height: 1.4;
  text-align: center;
  color: var(--c-text-muted, #64748B);
  background: var(--c-surface, #FFFFFF);
  flex-shrink: 0;
  user-select: none;
}

[data-theme="dark"] .ai-disclaimer {
  background: #14241E;
  color: #94A3B8;
}

/* ---------- Quick Action Chips (§34) ---------- */
.ai-quick-actions {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--c-surface-soft, rgba(8, 127, 91, 0.04));
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  flex-shrink: 0;
}

[data-theme="dark"] .ai-quick-actions {
  background: rgba(255, 255, 255, 0.03);
  border-bottom-color: rgba(255, 255, 255, 0.05);
}

.ai-quick-actions::-webkit-scrollbar {
  display: none;
}

.ai-chip {
  background: var(--c-surface, #FFFFFF);
  border: 1px solid rgba(8, 127, 91, 0.2);
  color: var(--c-primary, #087F5B);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
}

[data-theme="dark"] .ai-chip {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.15);
  color: #6EE7B7;
}

.ai-chip:hover {
  background: var(--c-primary, #087F5B);
  color: #FFFFFF;
  border-color: var(--c-primary, #087F5B);
}

/* ---------- Messages Container ---------- */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: ai-fade-in 0.22s ease-out;
}

@keyframes ai-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg.user {
  align-self: flex-end;
}

.ai-msg.user .ai-msg-bubble {
  background: linear-gradient(135deg, #087F5B 0%, #066246 100%);
  color: #FFFFFF;
  border-radius: 16px 16px 4px 16px;
  box-shadow: 0 4px 12px rgba(8, 127, 91, 0.2);
}

.ai-msg.assistant {
  align-self: flex-start;
}

.ai-msg.assistant .ai-msg-bubble {
  background: var(--c-surface-card, #F4FBF7);
  color: var(--c-text, #1E293B);
  border: 1px solid rgba(8, 127, 91, 0.12);
  border-radius: 16px 16px 16px 4px;
}

[data-theme="dark"] .ai-msg.assistant .ai-msg-bubble {
  background: #1A2E27;
  color: #F1F5F9;
  border-color: rgba(255, 255, 255, 0.08);
}

.ai-msg-bubble {
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.ai-msg-bubble p {
  margin: 0 0 8px 0;
}
.ai-msg-bubble p:last-child {
  margin-bottom: 0;
}

/* Tool Status indicator (§39) */
.ai-tool-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: #087F5B;
  background: rgba(8, 127, 91, 0.08);
  border: 1px dashed rgba(8, 127, 91, 0.25);
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 6px;
  align-self: flex-start;
}

[data-theme="dark"] .ai-tool-status {
  color: #6EE7B7;
  background: rgba(110, 231, 183, 0.1);
  border-color: rgba(110, 231, 183, 0.25);
}

.ai-spinner {
  width: 12px;
  height: 12px;
  border: 2px solid rgba(8, 127, 91, 0.2);
  border-top-color: #087F5B;
  border-radius: 50%;
  animation: ai-spin 0.8s linear infinite;
}

@keyframes ai-spin {
  to { transform: rotate(360deg); }
}

/* ---------- Source Chips (§11, §35) ---------- */
.ai-sources-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.ai-source-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(212, 175, 55, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.35);
  color: #B48A14;
  padding: 3px 8px;
  border-radius: 6px;
}

[data-theme="dark"] .ai-source-chip {
  background: rgba(212, 175, 55, 0.15);
  color: #FFDF70;
  border-color: rgba(255, 223, 112, 0.3);
}

/* ---------- Rich Content Cards (§35) ---------- */
.ai-card {
  margin-top: 8px;
  background: var(--c-surface, #FFFFFF);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] .ai-card {
  background: #11201A;
  border-color: rgba(255, 255, 255, 0.08);
}

.ai-card-arabic {
  font-family: 'Amiri', serif;
  font-size: 18px;
  line-height: 1.9;
  text-align: right;
  direction: rtl;
  color: var(--c-text, #1E293B);
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .ai-card-arabic {
  color: #F8FAFC;
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.ai-card-title {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--c-primary, #087F5B);
  margin-bottom: 4px;
}

.ai-card-translation {
  font-size: 12px;
  color: var(--c-text-muted, #64748B);
  line-height: 1.45;
}

[data-theme="dark"] .ai-card-translation {
  color: #94A3B8;
}

/* Prayer times grid */
.ai-prayer-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.ai-prayer-tile {
  background: rgba(8, 127, 91, 0.06);
  padding: 6px;
  border-radius: 8px;
  text-align: center;
}

[data-theme="dark"] .ai-prayer-tile {
  background: rgba(255, 255, 255, 0.05);
}

.ai-prayer-name {
  font-size: 10.5px;
  color: #64748B;
  text-transform: capitalize;
}

.ai-prayer-time {
  font-size: 12.5px;
  font-weight: 700;
  color: #087F5B;
}

[data-theme="dark"] .ai-prayer-time {
  color: #6EE7B7;
}

/* ---------- Confirmation Box (§35, §36) ---------- */
.ai-confirm-box {
  margin-top: 10px;
  background: rgba(212, 175, 55, 0.1);
  border: 1px solid rgba(212, 175, 55, 0.35);
  border-radius: 12px;
  padding: 10px 12px;
}

.ai-confirm-prompt {
  font-size: 12px;
  font-weight: 600;
  color: #936F0A;
  margin-bottom: 8px;
}

[data-theme="dark"] .ai-confirm-prompt {
  color: #FFDF70;
}

.ai-confirm-actions {
  display: flex;
  gap: 8px;
}

.ai-btn-confirm {
  flex: 1;
  background: #087F5B;
  color: #FFFFFF;
  border: none;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.ai-btn-confirm:hover {
  background: #055C41;
}

.ai-btn-cancel {
  background: transparent;
  color: #64748B;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

[data-theme="dark"] .ai-btn-cancel {
  border-color: rgba(255, 255, 255, 0.15);
  color: #94A3B8;
}

/* ---------- Input Area ---------- */
.ai-input-wrap {
  padding: 12px 14px;
  background: var(--c-surface, #FFFFFF);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

[data-theme="dark"] .ai-input-wrap {
  background: #14241E;
  border-top-color: rgba(255, 255, 255, 0.08);
}

.ai-input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-family: inherit;
  background: var(--c-surface-soft, #F8FAFC);
  color: var(--c-text, #1E293B);
  outline: none;
  transition: all 0.2s;
}

[data-theme="dark"] .ai-input {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: #F1F5F9;
}

.ai-input:focus {
  border-color: #087F5B;
  box-shadow: 0 0 0 3px rgba(8, 127, 91, 0.15);
}

.ai-input-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #087F5B;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.ai-input-btn:hover {
  background: #055C41;
  transform: scale(1.05);
}

.ai-input-btn.recording {
  background: #EF4444;
  animation: ai-record-pulse 1.2s infinite;
}

@keyframes ai-record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.ai-btn-mic {
  background: transparent;
  color: #087F5B;
  border: 1px solid rgba(8, 127, 91, 0.25);
}

[data-theme="dark"] .ai-btn-mic {
  color: #6EE7B7;
  border-color: rgba(110, 231, 183, 0.25);
}

.ai-btn-mic:hover {
  background: rgba(8, 127, 91, 0.08);
}

/* ---------- Voice Calling / Hands-Free Overlay (fitur-ai-agent-cloudflare.md) ---------- */
.ai-call-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, #06392C 0%, #031D16 100%);
  color: #FFFFFF;
  z-index: 1080;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 36px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.ai-call-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.ai-call-header {
  text-align: center;
}

.ai-call-title {
  font-size: 18px;
  font-weight: 700;
  color: #FFDF70;
  margin-bottom: 4px;
}

.ai-call-status {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
}

/* Glowing orb & Waveform Visualizer */
.ai-call-visualizer {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 30px 0;
}

.ai-orb-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid rgba(110, 231, 183, 0.3);
  animation: ai-pulse-ring 2.5s infinite cubic-bezier(0.215, 0.61, 0.355, 1);
}

.ai-orb-ring:nth-child(2) {
  animation-delay: 0.8s;
}

@keyframes ai-pulse-ring {
  0% { transform: scale(0.7); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

.ai-orb-core {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: radial-gradient(circle, #2DD4BF 0%, #087F5B 70%, #064E3B 100%);
  box-shadow: 0 0 35px rgba(45, 212, 191, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

.ai-call-overlay.speaking .ai-orb-core {
  transform: scale(1.15);
  box-shadow: 0 0 50px rgba(255, 223, 112, 0.8);
  background: radial-gradient(circle, #FDE047 0%, #D97706 70%, #78350F 100%);
}

.ai-call-overlay.listening .ai-orb-core {
  transform: scale(1.05);
  box-shadow: 0 0 40px rgba(34, 197, 94, 0.8);
}

.ai-call-transcript {
  max-width: 90%;
  max-height: 120px;
  overflow-y: auto;
  text-align: center;
  font-size: 13.5px;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.9);
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-call-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}

.ai-call-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.ai-call-btn:hover {
  transform: scale(1.08);
}

.ai-call-btn.hangup {
  background: #EF4444;
  color: #FFFFFF;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.4);
}

.ai-call-btn.mute {
  background: rgba(255, 255, 255, 0.18);
  color: #FFFFFF;
}

.ai-call-btn.mute.muted {
  background: #F59E0B;
}

/* ============================================================================
   SEMBUNYIKAN FAB AI DI MUSHAF IMERSIF (quran-read.js)
   Body mendapat class `quran-reader-mode` saat halaman /quran/read aktif —
   ditambahkan saat masuk dan dilepas router (runPageCleanup) saat back/exit,
   sehingga FAB otomatis muncul kembali di halaman lain. FAB menutupi teks
   Al-Qur'an di layar sempit, jadi di mode baca imersif disembunyikan seluruh
   (display:none, bukan sekadar opacity — tidak menghalangi sentuhan).
   Panel AI yang sedang terbuka juga ikut disembunyikan.
   ============================================================================ */
body.quran-reader-mode #ai-fab-container {
  display: none !important;
}

/* ============================================================================
   PREFERENSI PENGATURAN — "Tombol AI Mengambang" OFF (settings.js)
   ============================================================================
   Saat user menonaktifkan tombol AI di Pengaturan, kontainer diberi class
   `ai-fab-pref-hidden` (dari ai-agent.js → applyFabPref). display:none
   !important di kontainer menyembunyikan FAB SEKALIGUS panel — dan KARENA
   ini style-based (bukan remove DOM), toggle ON di Pengaturan langsung
   menampilkan kembali tanpa re-init. Class ini menang atas semua aturan
   otomatis (termasuk quran-reader-mode yang melepas class saat back):
   kalau di-setting hilang, ya tetap hilang di halaman mana pun.
   ============================================================================ */
#ai-fab-container.ai-fab-pref-hidden {
  display: none !important;
}

/* ============================================================================
   STREAMING JAWABAN — efek mengetik realtime
   ----------------------------------------------------------------------------
   .ai-stream-text : wadah teks jawaban yang terisi progresif via SSE delta.
   .typing         : kursor berkedip di ujung teks selagi jawaban mengalir;
                     dihapus saat event done (jawaban tuntas).
   Hargai prefers-reduced-motion: kursor statis tanpa animasi.
   ============================================================================ */
.ai-stream-text.typing::after {
  content: '▍';
  display: inline-block;
  margin-left: 2px;
  color: #0B7A4B;
  animation: ai-caret 0.9s steps(1) infinite;
}

@keyframes ai-caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .ai-stream-text.typing::after { animation: none; }
}
