/* ==========================================================================
   SAGA AI (Swift Automated Guide Agent) - Modern Floating Widget Stylesheet
   Living Rainbow Border • Periodic Greeting Bubble • Luxury Glassmorphism Chat
   ========================================================================== */

:root {
  --saga-primary: #dc2626;
  --saga-primary-hover: #b91c1c;
  --saga-bg-card: #ffffff;
  --saga-text-main: #1f2937;
  --saga-text-muted: #6b7280;
  --saga-border: #e5e7eb;
  --saga-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.18), 0 8px 18px -4px rgba(0, 0, 0, 0.1);
}

/* --------------------------------------------------------------------------
   1. FLOATING LAUNCHER CONTAINER (LEFT SCREEN ANCHOR)
   -------------------------------------------------------------------------- */
#saga-ai-widget {
  position: fixed;
  bottom: 26px;
  left: 24px;
  z-index: 999999;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Avatar Button Wrapper */
.saga-launcher-btn {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22), 0 0 20px rgba(239, 68, 68, 0.35);
  border: none;
  outline: none;
  padding: 0;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

.saga-launcher-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28), 0 0 28px rgba(239, 68, 68, 0.5);
}

.saga-launcher-btn:active {
  transform: scale(0.96);
}

/* --------------------------------------------------------------------------
   LIVING RAINBOW ANIMATED RING (MERAH, PUTIH, UNGU, BIRU)
   Searah jarum jam 360deg, lalu berbalik melawan jarum jam 360deg
   -------------------------------------------------------------------------- */
.saga-rainbow-ring {
  position: absolute;
  inset: -4.5px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    #dc2626 0%,
    #ffffff 25%,
    #9333ea 50%,
    #2563eb 75%,
    #dc2626 100%
  );
  animation: sagaRingClockwiseCounter 3.5s ease-in-out infinite;
  z-index: 1;
  filter: drop-shadow(0 0 6px rgba(147, 51, 234, 0.45));
}

/* Inner white mask separating the rainbow border and the ladybug avatar */
.saga-avatar-inner {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  background-color: #ffffff;
  background-image: url('../assets/images/saga-avatar.png');
  background-size: cover;
  background-position: center 48%;
  background-repeat: no-repeat;
  z-index: 2;
  border: 2px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Ladybug Image Avatar */
.saga-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 48%;
  transform: scale(1.18);
  transition: transform 0.3s ease;
  border-radius: 50%;
  pointer-events: none;
}

.saga-launcher-btn:hover .saga-avatar-img {
  transform: scale(1.24);
}

/* Online Live Pulse Badge */
.saga-online-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  background: #10b981;
  border-radius: 50%;
  border: 2.5px solid #ffffff;
  z-index: 3;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.saga-online-badge::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.6);
  animation: sagaPulseRing 2s cubic-bezier(0.24, 0, 0.38, 1) infinite;
  z-index: -1;
}

@keyframes sagaRingClockwiseCounter {
  0% {
    transform: rotate(0deg);
  }
  50% {
    transform: rotate(360deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

@keyframes sagaPulseRing {
  0% {
    transform: scale(0.8);
    opacity: 0.9;
  }
  70% {
    transform: scale(2.2);
    opacity: 0;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* --------------------------------------------------------------------------
   2. PERIODIC GREETING SPEECH BUBBLE (MUNCUL TIAP 10 DETIK, HILANG 5 DETIK)
   -------------------------------------------------------------------------- */
.saga-speech-bubble {
  position: absolute;
  left: 76px;
  bottom: 12px;
  background: #ffffff;
  color: #1f2937;
  padding: 11px 16px;
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16), 0 2px 8px rgba(0, 0, 0, 0.08);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  border: 1px solid rgba(220, 38, 38, 0.15);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateX(-12px) scale(0.92);
  transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 10;
}

.saga-speech-bubble::before {
  content: '';
  position: absolute;
  left: -8px;
  bottom: 10px;
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-right: 8px solid #ffffff;
}

.saga-speech-bubble.saga-bubble-visible {
  opacity: 1;
  transform: translateX(0) scale(1);
}

.saga-speech-bubble:hover {
  background: #fef2f2;
  border-color: rgba(220, 38, 38, 0.3);
  transform: translateX(2px) scale(1.02);
}

.saga-bubble-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #dc2626;
  flex-shrink: 0;
}

.saga-bubble-icon svg {
  width: 15px;
  height: 15px;
}

.saga-bubble-text {
  color: #111827;
  letter-spacing: -0.01em;
}

.saga-bubble-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #9ca3af;
  font-size: 12px;
  line-height: 1;
  margin-left: 4px;
  transition: background 0.2s, color 0.2s;
}

.saga-bubble-close:hover {
  background: #e5e7eb;
  color: #ef4444;
}

/* --------------------------------------------------------------------------
   3. CHAT WINDOW DIALOG
   -------------------------------------------------------------------------- */
.saga-chat-window {
  position: fixed;
  bottom: 104px;
  left: 24px;
  width: 390px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 128px);
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.22), 0 4px 16px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(229, 231, 235, 0.9);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(20px) scale(0.94);
  pointer-events: none;
  transition: opacity 0.32s cubic-bezier(0.16, 1, 0.3, 1), transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 999999;
}

.saga-chat-window.saga-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* Header */
.saga-chat-header {
  background: linear-gradient(135deg, #991b1b 0%, #b91c1c 50%, #7f1d1d 100%);
  color: #ffffff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.saga-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.saga-header-avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background-color: #ffffff;
  background-image: url('../assets/images/saga-avatar.png');
  background-size: cover;
  background-position: center 48%;
  background-repeat: no-repeat;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.saga-header-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 48%;
  transform: scale(1.15);
}

.saga-header-info h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.saga-header-sub {
  margin: 1px 0 0 0;
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.85);
  display: flex;
  align-items: center;
  gap: 6px;
}

.saga-header-pulse {
  width: 7px;
  height: 7px;
  background: #34d399;
  border-radius: 50%;
  box-shadow: 0 0 6px #34d399;
  display: inline-block;
}

.saga-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.saga-header-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #ffffff;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  padding: 0;
}

.saga-header-btn:hover {
  background: rgba(255, 255, 255, 0.28);
  transform: scale(1.05);
}

/* Memory Status Banner */
.saga-memory-banner {
  background: #fef2f2;
  border-bottom: 1px solid #fee2e2;
  padding: 6px 14px;
  font-size: 0.74rem;
  color: #991b1b;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.saga-memory-banner span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.saga-memory-btn-reset {
  background: transparent;
  border: none;
  color: #b91c1c;
  font-size: 0.7rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

/* Body / Messages Area */
.saga-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafaf9;
  scroll-behavior: smooth;
}

.saga-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.saga-chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

/* Message Bubble */
.saga-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: sagaMsgFadeIn 0.3s ease-out;
}

.saga-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.saga-msg-model {
  align-self: flex-start;
}

.saga-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background-color: #ffffff;
  background-image: url('../assets/images/saga-avatar.png');
  background-size: cover;
  background-position: center 48%;
  background-repeat: no-repeat;
  border: 1px solid rgba(0, 0, 0, 0.08);
  flex-shrink: 0;
}

.saga-msg-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 48%;
  transform: scale(1.15);
}

.saga-msg-content {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.88rem;
  line-height: 1.48;
  word-break: break-word;
}

.saga-msg-model .saga-msg-content {
  background: #ffffff;
  color: #1f2937;
  border: 1px solid #e5e7eb;
  border-top-left-radius: 4px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.saga-msg-user .saga-msg-content {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #ffffff;
  border-top-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.saga-msg-content p {
  margin: 0 0 6px 0;
}

.saga-msg-content p:last-child {
  margin-bottom: 0;
}

.saga-msg-content a {
  color: #b91c1c;
  text-decoration: underline;
  font-weight: 700;
}

.saga-msg-user .saga-msg-content a {
  color: #fef08a;
}

.saga-msg-time {
  font-size: 0.68rem;
  color: #9ca3af;
  margin-top: 4px;
  display: block;
  text-align: right;
}

.saga-msg-user .saga-msg-time {
  color: rgba(255, 255, 255, 0.8);
}

@keyframes sagaMsgFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Quick Suggestion Chips */
.saga-quick-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

.saga-quick-chips.saga-chips-visible {
  opacity: 1;
  transform: translateY(0);
}

.saga-chip {
  background: #ffffff;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 6px 12px;
  border-radius: var(--radius-full, 9999px);
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.saga-chip svg {
  width: 13px;
  height: 13px;
  stroke: currentColor;
  flex-shrink: 0;
}

.saga-chip:hover {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
  transform: translateY(-1px);
}

/* Typewriter Effect Cursor (Efek Kata-Kata Berjalan) */
.saga-typewriter-cursor {
  display: inline-block;
  color: #dc2626;
  font-weight: 700;
  margin-left: 2px;
  animation: sagaCursorBlink 0.7s infinite;
}

@keyframes sagaCursorBlink {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0;
  }
}

.saga-welcome-p {
  font-size: 0.92rem;
  font-weight: 600;
  color: #1f2937;
  line-height: 1.5;
  margin: 0;
  min-height: 1.5em;
}

/* Typing Indicator with Dynamic Status Cycling */
.saga-typing {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: #f8fafc;
  border-radius: 16px;
  border-top-left-radius: 4px;
  border: 1px solid #e2e8f0;
  width: fit-content;
  max-width: 100%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.saga-typing-status-text {
  font-size: 0.82rem;
  color: #4b5563;
  font-weight: 500;
  letter-spacing: -0.01em;
  transition: opacity 0.2s ease;
}

.saga-typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 3.5px;
}

.saga-typing-dot {
  width: 5.5px;
  height: 5.5px;
  border-radius: 50%;
  animation: sagaDotBounce 1.4s infinite ease-in-out both;
}

.saga-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
  background: #dc2626; /* Merah */
}

.saga-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
  background: #9333ea; /* Ungu */
}

.saga-typing-dot:nth-child(3) {
  animation-delay: 0;
  background: #2563eb; /* Biru */
}

@keyframes sagaDotBounce {
  0%, 80%, 100% {
    transform: scale(0);
  }
  40% {
    transform: scale(1);
  }
}

/* Footer / Input Area */
.saga-chat-footer {
  padding: 12px 14px;
  background: #ffffff;
  border-top: 1px solid #e5e7eb;
}

.saga-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  padding: 4px 6px 4px 14px;
  border-radius: 24px;
  border: 1.5px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}

.saga-chat-form:focus-within {
  background: #ffffff;
  border-color: #dc2626;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.saga-chat-input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 0.88rem;
  color: #1f2937;
  font-family: inherit;
  padding: 8px 0;
}

.saga-chat-input::placeholder {
  color: #9ca3af;
}

.saga-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s;
  padding: 0;
  flex-shrink: 0;
}

.saga-send-btn:hover {
  transform: scale(1.08);
  background: #991b1b;
}

.saga-send-btn:disabled {
  background: #d1d5db;
  cursor: not-allowed;
  transform: none;
}

.saga-send-btn svg {
  transform: translateX(1px);
}

.saga-creator-credit {
  text-align: center;
  font-size: 0.68rem;
  color: #9ca3af;
  margin-top: 6px;
}

.saga-creator-credit strong {
  color: #6b7280;
}

/* --------------------------------------------------------------------------
   4. RESPONSIVE DESIGN (HP & TABLET)
   -------------------------------------------------------------------------- */
@media (max-width: 960px) {
  #saga-ai-widget {
    bottom: 82px; /* Diberi ruang di atas .mobile-dock */
    left: 16px;
  }
}

@media (max-width: 640px) {
  #saga-ai-widget {
    bottom: 84px;
    left: 14px;
  }

  .saga-launcher-btn {
    width: 58px;
    height: 58px;
  }

  .saga-speech-bubble {
    left: 0;
    bottom: 74px; /* Posisi anggun tepat di atas tombol avatar */
    top: auto;
    font-size: 0.82rem;
    padding: 10px 14px;
    width: max-content;
    max-width: calc(100vw - 36px);
    white-space: normal;
    line-height: 1.4;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .saga-speech-bubble::before {
    /* Ekor segitiga mengarah ke bawah tepat menuju lingkaran avatar */
    left: 20px;
    bottom: -8px;
    top: auto;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-top: 8px solid #ffffff;
    border-bottom: none;
  }

  .saga-chat-window {
    left: 12px;
    right: 12px;
    bottom: 88px;
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
    height: calc(100vh - 125px);
    border-radius: 18px;
  }
}
