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

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

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

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

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

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

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

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

.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: toast-slide-in 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  max-width: 100%;
  word-break: keep-all;
  overflow-wrap: break-word;
}

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

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

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

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

@keyframes 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); }
}

.toast__icon {
  flex-shrink: 0;
  font-size: 18px;
  line-height: 1.3;
}
.toast__body {
  flex: 1;
  min-width: 0;
}
.toast__title {
  font-weight: 600;
  margin-bottom: 2px;
}
.toast__msg {
  font-size: 12.5px;
  opacity: 0.95;
  line-height: 1.55;
}
.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;
}
.toast__close:hover {
  opacity: 1;
}

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

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