/* Butang terapung + drawer AI Assistant — semua halaman (perlukan token :root dari base.css) */

.ai-bubble {
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.ai-bubble--user {
  align-self: flex-end;
}

.ai-bubble--ai {
  align-self: flex-start;
}

.ai-bubble__inner {
  padding: 0.65rem 0.85rem;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.ai-bubble--user .ai-bubble__inner {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-bottom-right-radius: 4px;
}

.ai-bubble--ai .ai-bubble__inner {
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.ai-bubble__time {
  font-size: 0.68rem;
  color: var(--text-muted);
  padding: 0 0.25rem;
}

.ai-staff-drawer__typing {
  display: none;
  gap: 4px;
  padding: 0 1rem 0.5rem;
}

.ai-staff-drawer__typing.is-active {
  display: flex;
}

.ai-staff-drawer__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  animation: ai-typing 1s infinite ease-in-out;
}

.ai-staff-drawer__typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-staff-drawer__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-typing {
  0%,
  80%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* Widget — sentiasa fixed, atas semua kandungan (kecuali loader app) */
.ai-staff-widget {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 200000;
  pointer-events: none;
}

.ai-staff-widget__backdrop {
  position: fixed;
  inset: 0;
  border: none;
  padding: 0;
  margin: 0;
  background: rgba(0, 0, 0, 0.4);
  cursor: pointer;
  pointer-events: auto;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ai-staff-widget.is-open .ai-staff-widget__backdrop {
  opacity: 1;
  visibility: visible;
}

.ai-staff-widget__fab {
  position: relative;
  z-index: 2;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  cursor: pointer;
  pointer-events: auto;
  background: linear-gradient(145deg, #ffc04d 0%, var(--sidebar-accent, #f5a623) 45%, #d4921a 100%);
  color: #fff;
  font-size: 1.35rem;
  box-shadow:
    0 4px 18px rgba(245, 166, 35, 0.5),
    0 0 0 1px rgba(0, 0, 0, 0.06) inset;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-staff-widget__fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 24px rgba(245, 166, 35, 0.55);
}

.ai-staff-widget__fab:focus-visible {
  outline: 3px solid var(--accent-ring, rgba(245, 166, 35, 0.35));
  outline-offset: 2px;
}

.ai-staff-widget.is-open .ai-staff-widget__fab {
  transform: scale(0.96);
}

.ai-staff-widget__fab-icon {
  width: 1.75rem;
  height: 1.75rem;
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.12));
}

.ai-staff-drawer {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: calc(max(1rem, env(safe-area-inset-bottom, 0px)) + 4.25rem);
  z-index: 1;
  width: min(calc(100vw - 2rem), 400px);
  max-height: min(78vh, 560px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius, 10px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: none;
  transform: translateY(8px) scale(0.98);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.22s ease, opacity 0.22s ease, visibility 0.22s ease;
}

.ai-staff-widget.is-open .ai-staff-drawer {
  transform: translateY(0) scale(1);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.ai-staff-drawer__head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  flex-shrink: 0;
}

.ai-staff-drawer__title {
  margin: 0;
  font-size: 1rem;
}

.ai-staff-drawer__sub {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  opacity: 0.85;
  line-height: 1.4;
}

.ai-staff-drawer__close {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md, 6px);
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ai-staff-drawer__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-bottom: 1px solid var(--border);
  max-height: 96px;
  overflow-y: auto;
  flex-shrink: 0;
}

.ai-suggestion-chip {
  font-size: 0.72rem;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  cursor: pointer;
  color: var(--text);
}

.ai-suggestion-chip:hover {
  border-color: var(--sidebar-accent);
  background: var(--accent-soft, rgba(245, 166, 35, 0.18));
}

.ai-staff-drawer__messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 140px;
  -webkit-overflow-scrolling: touch;
}

.ai-staff-drawer__empty {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.ai-staff-drawer__composer {
  flex-shrink: 0;
  padding: 0.6rem 0.75rem 0.7rem;
  border-top: 1px solid var(--border);
  background: var(--surface-muted, #fafafa);
}

.ai-staff-drawer__composer-inner {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.35rem 0.4rem 0.35rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.35rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ai-staff-drawer__composer-inner:focus-within {
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 3px var(--accent-ring, rgba(245, 166, 35, 0.28));
}

.ai-staff-drawer__input {
  flex: 1;
  min-width: 0;
  min-height: 1.45rem;
  max-height: 120px;
  margin: 0;
  padding: 0.5rem 0;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--text);
  background: transparent;
  border: none;
  resize: none;
  overflow-y: hidden;
  field-sizing: content;
}

.ai-staff-drawer__input::placeholder {
  color: var(--text-muted);
  opacity: 0.85;
}

.ai-staff-drawer__input:focus {
  outline: none;
}

.ai-staff-drawer__send {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  margin-bottom: 1px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #1a1a1a;
  background: linear-gradient(135deg, var(--sidebar-accent), var(--accent-active, #d4921a));
  box-shadow: 0 2px 8px rgba(245, 166, 35, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.ai-staff-drawer__send:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 3px 12px rgba(245, 166, 35, 0.45);
}

.ai-staff-drawer__send:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: 2px;
}

.ai-staff-drawer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.ai-staff-drawer__send-icon {
  width: 1.05rem;
  height: 1.05rem;
  margin-left: 1px;
}

@media (max-width: 600px) {
  .ai-staff-drawer {
    left: max(0.75rem, env(safe-area-inset-left, 0px));
    right: max(0.75rem, env(safe-area-inset-right, 0px));
    width: auto;
    max-height: min(70vh, 520px);
  }

  .ai-staff-widget__fab {
    width: 52px;
    height: 52px;
  }

  .ai-staff-drawer__composer {
    padding: 0.5rem 0.6rem 0.6rem;
  }

  .ai-staff-drawer__composer-inner {
    padding: 0.3rem 0.35rem 0.3rem 0.7rem;
  }

  .ai-staff-drawer__send {
    width: 2.1rem;
    height: 2.1rem;
  }
}
