/* ============================================================
   Aive 공통 토스트 + 레이아웃 충돌 방지
   V5.3 신규 · 2026-04-26 · UX 보강 작업

   설계 원칙:
   - z-index 표준화 (4 계층): 컨텐츠 < 모달 < 배너 < 토스트
   - 모달은 항상 토스트보다 위 (사용자 결정 우선)
   - 배너는 항상 콘텐츠 위 (영구 경고 우선)
   - body padding 자동 보정 (배너 / floating 충돌 방지)
   ============================================================ */

/* ------------------------------------------------------------
   z-index 표준 (CSS 변수 - 토큰화)
   ------------------------------------------------------------ */
:root {
  --aive-z-content: 1;
  --aive-z-dropdown: 100;
  --aive-z-tooltip: 500;
  --aive-z-banner: 9000;        /* Impersonate / BreakGlass 영구 배너 */
  --aive-z-modal-backdrop: 9500;
  --aive-z-modal: 9600;          /* 모달은 배너보다 위 */
  --aive-z-toast: 9700;          /* 토스트는 모달보다 약간 아래 (모달 버튼 가리지 않게) */
  --aive-z-floating: 9100;       /* Floating 도움말 (배너 위 · 토스트 아래) */
  --aive-z-critical-overlay: 9800; /* 긴급 오버레이 (Kill-switch 발동 등) */

  /* body padding 자동 보정 변수 */
  --aive-banner-height: 0px;
  --aive-floating-bottom-offset: 20px;
}

/* body 자동 padding 적용 (배너 활성 시 컨텐츠가 가려지지 않도록) */
body.aive-has-banner {
  padding-top: var(--aive-banner-height) !important;
  transition: padding-top 0.2s ease;
}

/* ------------------------------------------------------------
   공통 Toast Host (우상단 고정)
   ------------------------------------------------------------ */
.aive-toast-host {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: var(--aive-z-toast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  max-width: 420px;
}

/* 모달이 떠있을 때는 토스트 호스트를 모달보다 약간 아래로 이동 (충돌 방지) */
body.aive-modal-open .aive-toast-host {
  top: 80px;
}

/* 배너가 활성일 때 토스트 호스트도 그만큼 아래로 (헤더 가려짐 방지) */
body.aive-has-banner .aive-toast-host {
  top: calc(24px + var(--aive-banner-height));
}

.aive-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 13.5px;
  line-height: 1.5;
  font-family: inherit;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18), 0 2px 6px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.06);
  animation: aive-toast-slide-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 100%;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.aive-toast.is-leaving {
  animation: aive-toast-slide-out 0.2s ease forwards;
}

@keyframes aive-toast-slide-in {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes aive-toast-slide-out {
  to { transform: translateX(120%); opacity: 0; }
}

/* 토스트 유형별 색상 (severity) */
.aive-toast--info {
  background: #2563eb;
  color: white;
}
.aive-toast--success {
  background: #10b981;
  color: white;
}
.aive-toast--warn {
  background: #f59e0b;
  color: white;
}
.aive-toast--error {
  background: #ef4444;
  color: white;
}
.aive-toast--critical {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  color: white;
  border-color: rgba(255, 255, 255, 0.2);
  animation: aive-toast-slide-in 0.25s cubic-bezier(0.4, 0, 0.2, 1),
             aive-toast-pulse 1.6s ease-in-out infinite 0.5s;
}

@keyframes aive-toast-pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(220, 38, 38, 0.35), 0 0 0 0 rgba(220, 38, 38, 0.4); }
  50% { box-shadow: 0 8px 24px rgba(220, 38, 38, 0.5), 0 0 0 8px rgba(220, 38, 38, 0); }
}

.aive-toast__icon {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1.3;
}
.aive-toast__body {
  flex: 1;
  min-width: 0;
}
.aive-toast__title {
  font-weight: 600;
  margin-bottom: 2px;
}
.aive-toast__msg {
  font-size: 12.5px;
  opacity: 0.95;
  line-height: 1.55;
}
.aive-toast__close {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: inherit;
  opacity: 0.65;
  cursor: pointer;
  font-size: 16px;
  padding: 0 0 0 8px;
  line-height: 1;
  transition: opacity 0.15s;
}
.aive-toast__close:hover {
  opacity: 1;
}

/* ------------------------------------------------------------
   Floating 도움말 버튼 위치 보정 (다른 우하단 fixed 요소와 겹침 방지)
   contact-custom.html 의 채팅 버튼이 있으면 footer-nav.js 가
   .aive-has-chat-widget 클래스를 body에 부여하여 위로 올림
   ------------------------------------------------------------ */
#aive-faq-floating {
  z-index: var(--aive-z-floating) !important;
}
body.aive-has-chat-widget #aive-faq-floating {
  bottom: calc(var(--aive-floating-bottom-offset) + 70px) !important;
}

/* ------------------------------------------------------------
   Impersonate 배너 - body padding 자동 보정
   ------------------------------------------------------------ */
#aive-impersonate-banner {
  z-index: var(--aive-z-banner) !important;
}

/* 모달 활성 시 floating 도움말 hidden (방해 방지) */
body.aive-modal-open #aive-faq-floating {
  display: none !important;
}

/* ------------------------------------------------------------
   RBAC 비활성 버튼 시각화 (display:none 대신 disabled+tooltip 우선)
   ------------------------------------------------------------ */
[data-rbac-required] {
  position: relative;
}
[data-rbac-required][data-rbac-blocked="1"] {
  opacity: 0.4;
  cursor: not-allowed !important;
  pointer-events: none;
}
[data-rbac-required][data-rbac-blocked="1"]::after {
  content: attr(data-rbac-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 10px;
  background: rgba(17, 24, 39, 0.95);
  color: white;
  font-size: 11px;
  font-weight: 400;
  white-space: nowrap;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: var(--aive-z-tooltip);
}
[data-rbac-required][data-rbac-blocked="1"]:hover::after {
  opacity: 1;
}

/* RBAC 차단 시 완전 숨김 모드 (data-rbac-mode="hide" 적용된 요소) */
[data-rbac-required][data-rbac-blocked="1"][data-rbac-mode="hide"] {
  display: none !important;
}

/* ------------------------------------------------------------
   모바일 (< 768px) 보정 - 토스트 / 배너 자동 축소
   ------------------------------------------------------------ */
@media (max-width: 768px) {
  .aive-toast-host {
    top: 16px;
    right: 12px;
    left: 12px;
    max-width: none;
  }
  body.aive-has-banner .aive-toast-host {
    top: calc(16px + var(--aive-banner-height));
  }
  #aive-faq-floating {
    bottom: 12px !important;
    right: 12px !important;
    padding: 8px 12px !important;
    font-size: 12px !important;
  }
}
