/* ==========================================================================
   BOOKLINK SHARED TOAST SYSTEM
   - Toast dung chung cho toan du an.
   - Mau trạng thái giữ co dinh: success/warning/error/info.
   - Mau role chi dung cho vien/glow/trang tri nhé qua --booklink-toast-role-color.
   ========================================================================== */

:root {
  --booklink-toast-success: #22c55e;
  --booklink-toast-warning: #facc15;
  --booklink-toast-error: #ef4444;
  --booklink-toast-info: #3b82f6;
  --booklink-toast-role-color: var(--role-primary, var(--color-primary, #8f00ff));
  --booklink-toast-bg: rgba(255, 255, 255, 0.96);
  --booklink-toast-text: #111827;
  --booklink-toast-muted: #6b7280;
  --booklink-toast-border: rgba(17, 24, 39, 0.08);
  --booklink-toast-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
  --booklink-toast-radius: 18px;
}

.booklink-toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  z-index: 2147483000;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}

.booklink-toast-stack[data-booklink-toast-position="top"] {
  top: calc(14px + env(safe-area-inset-top, 0px));
  bottom: auto;
}

.booklink-toast-stack[data-booklink-toast-position="bottom"] {
  top: auto;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.portal-app.is-nav-hidden ~ .booklink-toast-stack:not([data-booklink-toast-position="top"]) {
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
}

.booklink-toast {
  --booklink-toast-status-color: var(--booklink-toast-info);

  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 11px;
  align-items: start;
  min-height: 62px;
  padding: 13px 12px 13px 14px;
  border: 1px solid var(--booklink-toast-border);
  border-radius: var(--booklink-toast-radius);
  overflow: hidden;
  background: var(--booklink-toast-bg);
  color: var(--booklink-toast-text);
  box-shadow: var(--booklink-toast-shadow);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  pointer-events: auto;
  animation: booklinkToastIn 240ms cubic-bezier(.22, 1, .36, 1) both;
}

@supports (color: color-mix(in srgb, red 50%, white)) {
  .booklink-toast {
    border-color: color-mix(in srgb, var(--booklink-toast-role-color) 22%, transparent);
    box-shadow:
      0 18px 42px rgba(15, 23, 42, 0.16),
      0 0 0 1px color-mix(in srgb, var(--booklink-toast-role-color) 8%, transparent);
  }
}

.booklink-toast--success {
  --booklink-toast-status-color: var(--booklink-toast-success);
}

.booklink-toast--warning {
  --booklink-toast-status-color: var(--booklink-toast-warning);
}

.booklink-toast--error {
  --booklink-toast-status-color: var(--booklink-toast-error);
}

.booklink-toast--info {
  --booklink-toast-status-color: var(--booklink-toast-info);
}

.booklink-toast.is-leaving {
  animation: booklinkToastOut 180ms ease forwards;
}

.booklink-toast__decor {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: linear-gradient(
    180deg,
    var(--booklink-toast-status-color),
    var(--booklink-toast-role-color)
  );
  pointer-events: none;
}

.booklink-toast__icon {
  width: 36px;
  height: 36px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(59, 130, 246, 0.1);
  color: var(--booklink-toast-status-color);
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.12);
}

.booklink-toast--success .booklink-toast__icon {
  background: rgba(34, 197, 94, 0.12);
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.16);
}

.booklink-toast--warning .booklink-toast__icon {
  background: rgba(250, 204, 21, 0.18);
  box-shadow: inset 0 0 0 1px rgba(250, 204, 21, 0.2);
}

.booklink-toast--error .booklink-toast__icon {
  background: rgba(239, 68, 68, 0.12);
  box-shadow: inset 0 0 0 1px rgba(239, 68, 68, 0.16);
}

.booklink-toast__icon svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.35;
}

.booklink-toast__body {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.booklink-toast__title,
.booklink-toast__message {
  display: block;
  overflow-wrap: anywhere;
}

.booklink-toast__title {
  color: var(--booklink-toast-text);
  font-size: 14px;
  font-weight: 800;
  line-height: 1.3;
}

.booklink-toast__message {
  color: var(--booklink-toast-muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.booklink-toast__controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.booklink-toast__action,
.booklink-toast__close {
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.booklink-toast__action {
  min-height: 30px;
  padding: 0 10px;
  color: var(--booklink-toast-status-color);
  font-size: 12px;
  font-weight: 800;
}

.booklink-toast__close {
  width: 30px;
  height: 30px;
  color: #6b7280;
}

.booklink-toast__close svg {
  width: 17px;
  height: 17px;
  stroke-width: 2.4;
}

.booklink-toast__action:focus-visible,
.booklink-toast__close:focus-visible {
  outline: 2px solid var(--booklink-toast-status-color);
  outline-offset: 2px;
}

.booklink-toast__progress {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 7px;
  height: 3px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(17, 24, 39, 0.08);
}

.booklink-toast__progress::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--booklink-toast-status-color);
  transform-origin: left center;
  animation: booklinkToastProgress var(--booklink-toast-duration, 3200ms) linear forwards;
}

@keyframes booklinkToastIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes booklinkToastOut {
  to {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

@keyframes booklinkToastProgress {
  from {
    transform: scaleX(1);
  }

  to {
    transform: scaleX(0);
  }
}

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .booklink-toast {
    background: #fff;
  }
}

@media (prefers-reduced-motion: reduce) {
  .booklink-toast,
  .booklink-toast.is-leaving,
  .booklink-toast__progress::before {
    animation: none !important;
    transition: none !important;
  }
}
