/**
 * Cards de feedback — substituem alert(), console.log e texto solto de status.
 *
 * Tokens herdados de styles.css (--accent, --radius, --ease-apple...), com
 * fallback literal caso este arquivo seja carregado sozinho.
 */

:root {
  --fb-radius: var(--radius, 12px);
  --fb-gap: 12px;
  --fb-width: 380px;
  --fb-shadow: 0 10px 30px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.06);
  --fb-ease: var(--ease-apple, cubic-bezier(0.4, 0, 0.2, 1));

  --fb-surface: var(--panel, #ffffff);
  --fb-text: var(--ink, #181c22);
  --fb-muted: var(--muted, #64748b);
  --fb-border: var(--border, #e2e8f0);

  --fb-success: var(--success, #16a34a);
  --fb-error: var(--error, #ba1a1a);
  --fb-warning: #f59e0b;
  --fb-info: var(--accent, #005ab4);
}

/* --- Pilha ---------------------------------------------------------------
   Fixa no canto, acima de modais. `pointer-events: none` na pilha e `auto`
   no card: o espaco vazio entre cards nao bloqueia cliques na pagina. */

.fb-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  /* Acima de .modal-overlay (11000): um erro ao salvar precisa aparecer
     mesmo com o modal de usuario aberto. */
  z-index: 12000;
  display: flex;
  flex-direction: column;
  gap: var(--fb-gap);
  width: min(var(--fb-width), calc(100vw - 40px));
  pointer-events: none;
}

.fb-stack[data-position="bottom-right"] { top: auto; bottom: 20px; }
.fb-stack[data-position="top-center"] { right: 50%; transform: translateX(50%); }

/* --- Card ---------------------------------------------------------------- */

.fb-card {
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 14px 14px 14px 16px;
  background: var(--fb-surface);
  color: var(--fb-text);
  border: 1px solid var(--fb-border);
  border-radius: var(--fb-radius);
  box-shadow: var(--fb-shadow);
  overflow: hidden;
  animation: fb-in 260ms var(--fb-ease) both;
}

/* Faixa lateral colorida: a cor identifica o tipo antes da leitura do texto. */
.fb-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--fb-accent, var(--fb-info));
}

.fb-card[data-variant="success"] { --fb-accent: var(--fb-success); }
.fb-card[data-variant="error"] { --fb-accent: var(--fb-error); }
.fb-card[data-variant="warning"] { --fb-accent: var(--fb-warning); }
.fb-card[data-variant="info"] { --fb-accent: var(--fb-info); }

.fb-card.is-leaving {
  animation: fb-out 200ms var(--fb-ease) both;
}

/* --- Conteudo ------------------------------------------------------------ */

.fb-icon {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--fb-accent) 14%, transparent);
  color: var(--fb-accent);
  flex-shrink: 0;
}

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

.fb-body { min-width: 0; }

.fb-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.fb-message {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--fb-muted);
  /* Mensagens de erro de servidor podem vir longas — quebra em vez de estourar. */
  overflow-wrap: anywhere;
}

.fb-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.fb-action {
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--fb-border);
  background: transparent;
  color: var(--fb-accent);
  cursor: pointer;
  transition: background 140ms var(--fb-ease);
}

.fb-action:hover { background: color-mix(in srgb, var(--fb-accent) 10%, transparent); }

.fb-close {
  background: none;
  border: 0;
  padding: 2px;
  cursor: pointer;
  color: var(--fb-muted);
  line-height: 0;
  border-radius: 6px;
  transition: color 140ms var(--fb-ease);
}

.fb-close:hover { color: var(--fb-text); }
.fb-close svg { width: 14px; height: 14px; }

/* --- Barra de tempo restante --------------------------------------------- */

.fb-progress {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: var(--fb-accent);
  transform-origin: left;
  opacity: 0.45;
  animation: fb-progress linear both;
}

/* --- Animacoes ----------------------------------------------------------- */

@keyframes fb-in {
  from { opacity: 0; transform: translateX(16px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

@keyframes fb-out {
  from { opacity: 1; transform: none; max-height: 220px; }
  to { opacity: 0; transform: translateX(16px); max-height: 0; margin-top: calc(var(--fb-gap) * -1); }
}

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

/* Icone do card de loading. */
.fb-spin { animation: fb-spin 900ms linear infinite; }

@keyframes fb-spin {
  to { transform: rotate(360deg); }
}

/* Respeita quem desativou animacao no sistema. */
@media (prefers-reduced-motion: reduce) {
  .fb-card, .fb-card.is-leaving, .fb-progress, .fb-spin { animation: none; }
}
