/**
 * Cards de feedback — substituem alert(), console.log e texto solto de status.
 *
 * Tokens: se o projeto ja tem um design system (ex.: OFFICE/Orquestra), troque
 * os valores do :root pelos tokens de la. As variaveis existem justamente para
 * essa substituicao ser de uma linha cada.
 */

:root {
  --fb-radius: 14px;
  --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: cubic-bezier(0.22, 1, 0.36, 1);

  --fb-surface: #ffffff;
  --fb-text: #0f172a;
  --fb-muted: #64748b;
  --fb-border: #e6eaf2;

  --fb-success: #10b981;
  --fb-error: #ef4444;
  --fb-warning: #f59e0b;
  --fb-info: #3b82f6;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fb-surface: #1a2233;
    --fb-text: #e8edf7;
    --fb-muted: #94a3b8;
    --fb-border: #2b3448;
    --fb-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

/* --- 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;
  z-index: 9999;
  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; }
}
