:root {
  --fab-enter-duration: 600ms;
  --fab-enter-easing: cubic-bezier(0.34, 1.56, 0.64, 1); /* spring/overshoot */
  --fab-exit-duration: 350ms;
  --fab-exit-easing: cubic-bezier(0.4, 0, 1, 1); /* ease-in */
  --fab-stagger-delay: 100ms;
  --fab-enter-translate: 20px;
  --fab-exit-translate: 20px;

  /* Ukuran */
  --fab-create-size: 60px;
  --fab-create-radius: 16px;
  --fab-create-icon: 26px;

  --fab-action-size: 56px;
  --fab-action-icon: 24px;

  --fab-stack-gap: 10px;

  --fab-bottomnav-base: 90px;
  /* baseline universal utk fabAdd (semua screen) */
  --fab-nonav-base: 156px; /* disimpan utk kompatibilitas, tak dipakai fabAdd */

  --fab-right: max(18px, calc((100vw - 480px) / 2 + 18px));
}

html.fab-boot-pending .fab {
  opacity: 0 !important;
  transform: translateY(var(--fab-enter-translate, 20px)) scale(0) !important;
  pointer-events: none !important;
}

@media (prefers-reduced-motion: reduce) {
  /* Tetap disembunyikan sesaat (hindari flash), tapi tanpa transform
     berlebihan karena animasi enter versi reduced-motion nyaris instan. */
  html.fab-boot-pending .fab {
    transform: none !important;
  }
}

/* ============================================================
   FAB BASE
   ============================================================ */

.fab {
  position: fixed;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.fab:active {
  transform: scale(0.92);
}
.fab.hidden {
  display: none !important;
}

.fab svg {
  display: block;
  flex-shrink: 0;
  transition: transform 0.3s ease;
}
.fab:hover svg {
  transform: scale(1.05);
}
.fab:active svg {
  transform: scale(0.85);
}

/* ------------------------------------------------------------
   TAP RIPPLE — feedback taktil universal untuk semua FAB.
   CSS murni (tanpa JS): lingkaran memudar dari tengah saat
   ditekan, memberi kesan "material" modern.
   ------------------------------------------------------------ */
.fab {
  position: fixed; /* (sudah ada di atas, dipertahankan) */
  overflow: hidden;
}

.fab::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 255, 255, 0) 70%
  );
  opacity: 0;
  transform: scale(0.4);
  transition:
    transform 0.35s ease,
    opacity 0.5s ease;
  pointer-events: none;
}

.fab:active::after {
  opacity: 1;
  transform: scale(1.15);
  transition:
    transform 0.05s ease,
    opacity 0.05s ease;
}

/* Grup CREATE (persegi radius): fabAdd, fabZakat — ukuran identik */
#fabAdd,
#fabZakat {
  width: var(--fab-create-size) !important;
  height: var(--fab-create-size) !important;
  right: var(--fab-right) !important;
  border-radius: var(--fab-create-radius) !important;
}

#fabAdd svg,
#fabZakat svg {
  width: var(--fab-create-icon) !important;
  height: var(--fab-create-icon) !important;
}

/* Grup ACTION (lingkaran): fabPostToKas, fabAiChat — ukuran identik */
#fabPostToKas,
#fabAiChat {
  width: var(--fab-action-size) !important;
  height: var(--fab-action-size) !important;
  right: var(--fab-right) !important;
  border-radius: 50% !important;
}

#fabPostToKas svg,
#fabAiChat svg {
  width: var(--fab-action-icon) !important;
  height: var(--fab-action-icon) !important;
}

/* Label helper classes (dipakai fabAiChat via class="fab fab-action") */
.fab-create .fab-label,
.fab-action .fab-label {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  padding: 6px 14px;
  border-radius: 8px;
  font-family: "Plus Jakarta Sans", sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
}

.fab-create:hover .fab-label,
.fab-create:focus .fab-label,
.fab-action:hover .fab-label,
.fab-action:focus .fab-label {
  opacity: 1;
  transform: translateY(-50%) translateX(-4px);
}

/* ============================================================
   FAB ADD — "create"
   ------------------------------------------------------------
   Dipakai di SEMUA screen (transaksi kas / home / history,
   shodaqoh, dan zakat). Tata letak disamakan: baseline
   --fab-bottomnav-base + safe-area. Tidak ada lagi override
   posisi khusus per-screen.
   ============================================================ */

#fabAdd {
  position: fixed !important;
  bottom: calc(
    var(--fab-bottomnav-base) + env(safe-area-inset-bottom)
  ) !important;
  background: var(--brand) !important;
  color: #fff !important;
  box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4) !important;
  z-index: 50 !important;
}

#fabAdd:not(:hover) {
  animation: fabPulse 3s ease-in-out infinite;
}
#fabAdd:hover {
  animation: none;
}

/* Ikon "+" berotasi terbuka saat hover — kesan "siap membuat baru" */
#fabAdd svg {
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#fabAdd:hover svg {
  transform: rotate(90deg) scale(1.05);
}
#fabAdd:active svg {
  transform: rotate(90deg) scale(0.85);
}

@keyframes fabPulse {
  0% {
    box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4);
  }
  50% {
    box-shadow:
      0 8px 48px rgba(22, 163, 74, 0.55),
      0 0 0 8px rgba(22, 163, 74, 0.08);
  }
  100% {
    box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4);
  }
}

/* ============================================================
   FAB ZAKAT — "create" (hanya tampil di Zakat list)
   ------------------------------------------------------------
   Ukuran & bentuk identik dengan #fabAdd. Baseline posisinya
   kini mengikuti fabAdd (--fab-bottomnav-base), BUKAN lagi
   --fab-nonav-base, agar tata letak konsisten.
   ============================================================ */

#fabZakat {
  position: fixed !important;
  bottom: calc(
    var(--fab-bottomnav-base) + env(safe-area-inset-bottom)
  ) !important;
  background: var(--brand) !important;
  color: #fff !important;
  box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4) !important;
  z-index: 50 !important;
}

/* Zakat = "memberi" — mengambang lembut naik-turun, bukan sekadar
   pulse statis, untuk kesan yang lebih hidup & mengundang. */
#fabZakat:not(:hover) {
  animation:
    fabZakatFloat 2.6s ease-in-out infinite,
    fabZakatPulse 2.6s ease-in-out infinite;
}
#fabZakat:hover {
  animation: none;
}

#fabZakat svg {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#fabZakat:hover svg {
  transform: rotate(-8deg) scale(1.08);
}

@keyframes fabZakatFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes fabZakatPulse {
  0% {
    box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4);
  }
  50% {
    box-shadow:
      0 8px 48px rgba(22, 163, 74, 0.55),
      0 0 0 8px rgba(22, 163, 74, 0.08);
  }
  100% {
    box-shadow: 0 8px 32px rgba(22, 163, 74, 0.4);
  }
}

/* ============================================================
   FAB POST TO KAS — "action" (hanya tampil di screen Shodaqoh)
   ------------------------------------------------------------
   Tata letak DISAMAKAN dengan #fabAiChat:
   bottom = --fab-bottomnav-base + --fab-create-size + --fab-stack-gap
   sehingga selalu berada 10px di atas FAB "create" tingkat pertama.
   Di screen Zakat & Shodaqoh ikut bergeser mengikuti pola
   body.screen-*-active #fabAiChat.
   ============================================================ */

#fabPostToKas {
  position: fixed !important;
  bottom: calc(
    var(--fab-bottomnav-base) + var(--fab-create-size) + var(--fab-stack-gap) +
      env(safe-area-inset-bottom)
  ) !important;
  background: var(--gold) !important;
  color: #fff !important;
  box-shadow: 0 8px 28px rgba(199, 154, 68, 0.35) !important;
  z-index: 50 !important;
}

/* Post ke Kas = "mengirim" — ikon bergeser maju lalu kembali,
   seolah mendorong data ke ledger. Aksi penting → tetap disertai
   pulsing ring emas agar terasa "menunggu ditekan". */
#fabPostToKas:not(:hover) {
  animation: fabGoldPulse 2.4s ease-in-out infinite;
}
#fabPostToKas:hover {
  animation: none;
}

#fabPostToKas svg {
  animation: fabPostNudge 2.4s ease-in-out infinite;
  transition: transform 0.25s ease;
}
#fabPostToKas:hover svg {
  animation: none;
  transform: translate(3px, -3px) scale(1.08);
}

@keyframes fabPostNudge {
  0%,
  60%,
  100% {
    transform: translate(0, 0);
  }
  75% {
    transform: translate(2px, -2px);
  }
  85% {
    transform: translate(0, 0);
  }
}

@keyframes fabGoldPulse {
  0% {
    box-shadow: 0 8px 28px rgba(199, 154, 68, 0.35);
  }
  50% {
    box-shadow:
      0 8px 48px rgba(199, 154, 68, 0.55),
      0 0 0 8px rgba(199, 154, 68, 0.08);
  }
  100% {
    box-shadow: 0 8px 28px rgba(199, 154, 68, 0.35);
  }
}

/* ============================================================
   FAB AI CHAT — "action"
   ------------------------------------------------------------
   Posisi mengikuti layar aktif:

   - Home/History (bottom nav ada): di atas #fabAdd
     (--fab-bottomnav-base + create-size + stack-gap)
   - Zakat (tanpa bottom nav):      ikut bergeser mengikuti
     pola yang sama dengan #fabPostToKas.
   - Shodaqoh: #fabPostToKas kini menempati tingkat ke-2
     (sama seperti fabAiChat di home), jadi fabAiChat naik ke
     tingkat ke-3 di atas #fabPostToKas.
   ============================================================ */

#fabAiChat {
  position: fixed !important;
  bottom: calc(
    var(--fab-bottomnav-base) + var(--fab-create-size) + var(--fab-stack-gap) +
      env(safe-area-inset-bottom)
  ) !important;
  background: linear-gradient(
    135deg,
    #8b5cf6,
    #6d28d9,
    #a78bfa,
    #6d28d9
  ) !important;
  background-size: 300% 300% !important;
  animation: fabAiGradientBreathe 6s ease-in-out infinite !important;
  color: #fff !important;
  box-shadow: 0 6px 24px rgba(139, 92, 246, 0.35) !important;
  z-index: 55 !important;
  border: none !important;
  cursor: pointer !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

body.screen-zakat-active #fabAiChat {
  bottom: calc(
    var(--fab-bottomnav-base) + var(--fab-create-size) + var(--fab-stack-gap) +
      env(safe-area-inset-bottom)
  ) !important;
}

body.screen-shodaqoh-active #fabAiChat {
  bottom: calc(
    var(--fab-bottomnav-base) + var(--fab-create-size) + var(--fab-stack-gap) +
      var(--fab-action-size) + var(--fab-stack-gap) +
      env(safe-area-inset-bottom)
  ) !important;
}

#fabAiChat svg,
#fabAiChat i {
  stroke: #fff !important;
  color: #fff !important;
}

#fabAiChat:hover {
  transform: translateY(-3px) scale(1.05) !important;
  box-shadow: 0 10px 32px rgba(139, 92, 246, 0.5) !important;
}
#fabAiChat:active {
  transform: scale(0.9) !important;
}
#fabAiChat:hover svg,
#fabAiChat:hover i {
  transform: rotate(180deg) scale(1.1) !important;
}

#fabAiChat svg path {
  animation: sparkleTwinkle 2s ease-in-out infinite;
}
#fabAiChat svg path:nth-child(2) {
  animation-delay: 0.6s;
}
#fabAiChat svg path:nth-child(3) {
  animation-delay: 1.2s;
}

@keyframes sparkleTwinkle {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(0.8);
  }
}

/* Gradient "bernapas" — kesan AI yang hidup/berpikir, halus & lambat
   supaya tidak mengganggu (6 detik per siklus). */
@keyframes fabAiGradientBreathe {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

#fabAiChat::before {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  opacity: 0.3;
  z-index: -1;
  animation: pulseRing 2s ease-in-out infinite;
}

@keyframes pulseRing {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.3;
  }
  50% {
    transform: scale(1.15);
    opacity: 0.1;
  }
}

#fabAiChat:hover .fab-label,
#fabAiChat:focus .fab-label {
  opacity: 1;
  transform: translateY(-50%) translateX(-4px) scale(1);
}

/* ============================================================
   FAB PRINT — ACTION (mandiri, tidak termasuk grup di atas)
   ============================================================ */

#fabPrint {
  position: fixed !important;
  width: 48px !important;
  height: 48px !important;
  right: max(24px, calc((100vw - 480px) / 2 + 24px)) !important;
  bottom: calc(222px + env(safe-area-inset-bottom)) !important;
  background: var(--ink-soft) !important;
  color: #fff !important;
  box-shadow: 0 6px 24px rgba(23, 25, 28, 0.3) !important;
  z-index: 40 !important;
  border-radius: 50% !important;
}

#fabPrint svg {
  width: 19px !important;
  height: 19px !important;
}

/* Print: idle diam (aksi jarang & tidak butuh perhatian terus
   menerus). Saat hover, ikon "meluncur keluar" seperti kertas
   yang tercetak dari printer. */
#fabPrint svg {
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#fabPrint:hover svg {
  transform: translateY(3px) scale(1.05);
}
#fabPrint:active svg {
  transform: translateY(1px) scale(0.9);
}

/* ============================================================
   VISIBILITY / Z-INDEX RULES — BEHAVIOR TIDAK DIUBAH
   (disalin persis dari fab-styles.css, shodaqoh-screen.css,
   dan zakat-screen.css yang lama)
   ============================================================ */

#fabAdd,
#fabZakat,
#fabPostToKas,
#fabAiChat {
  z-index: 40 !important;
}

body:has(#txOverlay:not(.hidden)) #fabAdd,
body:has(#txOverlay:not(.hidden)) #fabZakat,
body:has(#txOverlay:not(.hidden)) #fabPostToKas,
body:has(#txOverlay:not(.hidden)) #fabAiChat {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: scale(0.92) !important;
}

body.screen-shodaqoh-active #fabAiChat,
body.screen-zakat-active #fabAiChat {
  display: flex !important;
}

body.screen-ai-chat-active #fabAiChat {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
  transform: scale(0.92) !important;
}

/* ============================================================
   DARK THEME
   ============================================================ */

html[data-theme="dark"] .fab {
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] #fabAdd {
  box-shadow: 0 8px 32px rgba(40, 199, 111, 0.35) !important;
}
html[data-theme="dark"] #fabAdd:hover {
  box-shadow: 0 12px 40px rgba(40, 199, 111, 0.45) !important;
}

html[data-theme="dark"] #fabZakat {
  box-shadow: 0 8px 32px rgba(40, 199, 111, 0.35) !important;
}
html[data-theme="dark"] #fabZakat:hover {
  box-shadow: 0 12px 40px rgba(40, 199, 111, 0.45) !important;
}

html[data-theme="dark"] #fabPostToKas {
  box-shadow: 0 8px 28px rgba(233, 173, 56, 0.25) !important;
}
html[data-theme="dark"] #fabPostToKas:hover {
  box-shadow: 0 12px 36px rgba(233, 173, 56, 0.35) !important;
}

html[data-theme="dark"] #fabAiChat {
  background: linear-gradient(135deg, #a78bfa, #7c3aed) !important;
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.4) !important;
}
html[data-theme="dark"] #fabAiChat:hover {
  box-shadow: 0 10px 32px rgba(124, 58, 237, 0.55) !important;
}
html[data-theme="dark"] #fabAiChat::before {
  background: linear-gradient(135deg, #a78bfa, #7c3aed);
}

html[data-theme="dark"] #fabPrint {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45) !important;
}

/* ============================================================
   RESPONSIVE ≤480px
   ============================================================ */

@media (max-width: 480px) {
  :root {
    --fab-bottomnav-base: 80px;
    --fab-nonav-base: 140px;
  }

  #fabAdd,
  #fabZakat {
    width: 54px !important;
    height: 54px !important;
    right: 16px !important;
    border-radius: 14px !important;
  }
  #fabAdd svg,
  #fabZakat svg {
    width: 24px !important;
    height: 24px !important;
  }

  #fabPostToKas,
  #fabAiChat {
    width: 50px !important;
    height: 50px !important;
    right: 16px !important;
  }
  #fabPostToKas svg,
  #fabAiChat svg {
    width: 22px !important;
    height: 22px !important;
  }

  #fabAdd .fab-label,
  #fabZakat .fab-label,
  #fabPostToKas .fab-label,
  #fabAiChat .fab-label,
  #fabPrint .fab-label {
    display: none !important;
  }

  #fabPrint {
    width: 44px !important;
    height: 44px !important;
    right: 20px !important;
    bottom: calc(200px + env(safe-area-inset-bottom)) !important;
  }
  #fabPrint svg {
    width: 17px !important;
    height: 17px !important;
  }
}

/* ============================================================
   RESPONSIVE ≤380px
   ============================================================ */

@media (max-width: 380px) {
  :root {
    --fab-bottomnav-base: 76px;
    --fab-nonav-base: 132px;
  }

  #fabAdd,
  #fabZakat {
    width: 48px !important;
    height: 48px !important;
    right: 14px !important;
    border-radius: 12px !important;
  }
  #fabAdd svg,
  #fabZakat svg {
    width: 22px !important;
    height: 22px !important;
  }

  #fabPostToKas,
  #fabAiChat {
    width: 46px !important;
    height: 46px !important;
    right: 14px !important;
  }
  #fabPostToKas svg,
  #fabAiChat svg {
    width: 20px !important;
    height: 20px !important;
  }

  #fabPrint {
    width: 40px !important;
    height: 40px !important;
    right: 18px !important;
    bottom: calc(188px + env(safe-area-inset-bottom)) !important;
  }
  #fabPrint svg {
    width: 15px !important;
    height: 15px !important;
  }
}

/* ============================================================
   ≥481px — pusatkan ke max-width 480px container
   ============================================================ */

@media (min-width: 481px) {
  #fabAdd {
    right: max(24px, calc((100vw - 480px) / 2 + 24px)) !important;
  }
  #fabZakat {
    right: max(24px, calc((100vw - 480px) / 2 + 24px)) !important;
  }
  #fabPostToKas {
    right: max(24px, calc((100vw - 480px) / 2 + 24px)) !important;
  }
  #fabAiChat {
    right: max(26px, calc((100vw - 480px) / 2 + 26px)) !important;
  }
  #fabPrint {
    right: max(24px, calc((100vw - 480px) / 2 + 24px)) !important;
  }
}

/* ============================================================
   AKSESIBILITAS — matikan semua animasi idle/loop untuk
   pengguna yang memilih "reduce motion" di OS/browser-nya.
   Hover/tap tetap responsif (transition tidak dimatikan).
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  #fabAdd,
  #fabZakat,
  #fabPostToKas,
  #fabAiChat,
  #fabZakat svg,
  #fabPostToKas svg {
    animation: none !important;
  }
}
