/* ═══════════════════════════════════════════════════════════════════════════
   TOAST SYSTEM — CDOA Sistema
   Sem dependências externas. JavaScript puro + CSS puro.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Container ─────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  width: 22rem;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}

/* ── Card base ──────────────────────────────────────────────────────────────── */
.toast-card {
  pointer-events: all;
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem 0.875rem 1rem;
  border-radius: 0.875rem;
  background: #ffffff;
  border: 1px solid transparent;
  box-shadow:
    0 4px 6px -1px rgba(0,0,0,.07),
    0 10px 24px -4px rgba(0,0,0,.10),
    0 0 0 1px rgba(0,0,0,.04);
  overflow: hidden;
  cursor: default;

  /* Animação de entrada — slide from right */
  animation: toast-slide-in 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.toast-card.toast-leaving {
  animation: toast-slide-out 0.28s cubic-bezier(0.55, 0, 1, 0.45) forwards;
}

/* ── Variantes de cor ───────────────────────────────────────────────────────── */
.toast-success {
  border-color: #bbf7d0;
  background: linear-gradient(135deg, #f0fdf4 0%, #ffffff 60%);
}
.toast-success .toast-icon-wrap  { background: #dcfce7; color: #16a34a; }
.toast-success .toast-progress   { background: #22c55e; }
.toast-success .toast-title      { color: #15803d; }

.toast-error {
  border-color: #fecaca;
  background: linear-gradient(135deg, #fff1f2 0%, #ffffff 60%);
}
.toast-error .toast-icon-wrap  { background: #fee2e2; color: #dc2626; }
.toast-error .toast-progress   { background: #ef4444; }
.toast-error .toast-title      { color: #b91c1c; }

.toast-warning {
  border-color: #fed7aa;
  background: linear-gradient(135deg, #fff7ed 0%, #ffffff 60%);
}
.toast-warning .toast-icon-wrap  { background: #ffedd5; color: #ea580c; }
.toast-warning .toast-progress   { background: #f97316; }
.toast-warning .toast-title      { color: #c2410c; }

.toast-info {
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #eff6ff 0%, #ffffff 60%);
}
.toast-info .toast-icon-wrap  { background: #dbeafe; color: #2563eb; }
.toast-info .toast-progress   { background: #3b82f6; }
.toast-info .toast-title      { color: #1d4ed8; }

/* ── Ícone ──────────────────────────────────────────────────────────────────── */
.toast-icon-wrap {
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  line-height: 1;
  margin-top: 0.05rem;
}

.toast-icon-wrap .fas {
  font-size: 1.25rem;
}

/* ── Corpo do texto ─────────────────────────────────────────────────────────── */
.toast-body {
  flex: 1;
  min-width: 0;
}

.toast-title {
  font-family: "Public Sans", sans-serif;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 0 0 0.2rem 0;
  letter-spacing: -0.01em;
}

.toast-message {
  font-family: "Public Sans", sans-serif;
  font-size: 0.8125rem;
  font-weight: 400;
  color: #4b5563;
  line-height: 1.45;
  margin: 0;
  word-break: break-word;
}

/* ── Botão fechar ───────────────────────────────────────────────────────────── */
.toast-close {
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 0.375rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  padding: 0;
  margin-top: 0.05rem;
  transition: background 0.15s, color 0.15s;
}

.toast-close:hover {
  background: rgba(0,0,0,.06);
  color: #374151;
}

.toast-close .fas {
  font-size: 1rem;
}

/* ── Barra de progresso ─────────────────────────────────────────────────────── */
.toast-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(0,0,0,.06);
  border-radius: 0 0 0.875rem 0.875rem;
  overflow: hidden;
}

.toast-progress {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transform-origin: left center;
  animation: toast-progress-shrink linear forwards;
}

/* ── Animações ──────────────────────────────────────────────────────────────── */
@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(calc(100% + 1.5rem));
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toast-slide-out {
  from {
    opacity: 1;
    transform: translateX(0);
    max-height: 8rem;
    margin-bottom: 0;
  }
  to {
    opacity: 0;
    transform: translateX(calc(100% + 1.5rem));
    max-height: 0;
    margin-bottom: -0.625rem;
    padding-top: 0;
    padding-bottom: 0;
  }
}

@keyframes toast-progress-shrink {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

/* ── Dark mode ──────────────────────────────────────────────────────────────── */
html.dark .toast-card {
  background: #1e2533;
  box-shadow:
    0 4px 6px -1px rgba(0,0,0,.3),
    0 10px 24px -4px rgba(0,0,0,.4),
    0 0 0 1px rgba(255,255,255,.05);
}

html.dark .toast-success { border-color: #166534; background: linear-gradient(135deg, #052e16 0%, #1e2533 60%); }
html.dark .toast-error   { border-color: #991b1b; background: linear-gradient(135deg, #450a0a 0%, #1e2533 60%); }
html.dark .toast-warning { border-color: #9a3412; background: linear-gradient(135deg, #431407 0%, #1e2533 60%); }
html.dark .toast-info    { border-color: #1e40af; background: linear-gradient(135deg, #172554 0%, #1e2533 60%); }

html.dark .toast-success .toast-icon-wrap { background: #14532d; color: #4ade80; }
html.dark .toast-error   .toast-icon-wrap { background: #7f1d1d; color: #f87171; }
html.dark .toast-warning .toast-icon-wrap { background: #7c2d12; color: #fb923c; }
html.dark .toast-info    .toast-icon-wrap { background: #1e3a8a; color: #60a5fa; }

html.dark .toast-success .toast-title { color: #4ade80; }
html.dark .toast-error   .toast-title { color: #f87171; }
html.dark .toast-warning .toast-title { color: #fb923c; }
html.dark .toast-info    .toast-title { color: #60a5fa; }

html.dark .toast-message { color: #9ca3af; }
html.dark .toast-close   { color: #6b7280; }
html.dark .toast-close:hover { background: rgba(255,255,255,.08); color: #d1d5db; }

/* ── Responsivo mobile ──────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #toast-container {
    top: auto;
    bottom: 1rem;
    right: 0.75rem;
    left: 0.75rem;
    width: auto;
    max-width: 100%;
  }

  .toast-card {
    animation-name: toast-slide-in-mobile;
  }

  .toast-card.toast-leaving {
    animation-name: toast-slide-out-mobile;
  }

  @keyframes toast-slide-in-mobile {
    from { opacity: 0; transform: translateY(1.5rem); }
    to   { opacity: 1; transform: translateY(0); }
  }

  @keyframes toast-slide-out-mobile {
    from { opacity: 1; transform: translateY(0); max-height: 8rem; }
    to   { opacity: 0; transform: translateY(1.5rem); max-height: 0; padding: 0; }
  }
}
