:root {
  --notif-z-index: var(--app-z-toast, 1100);
  --notif-dropdown-z-index: var(--app-z-dropdown, 200);
}

#toast-container {
  position: fixed;
  top: var(--app-toast-top-offset, calc(env(safe-area-inset-top, 0px) + 80px));
  left: 50%;
  width: min(520px, calc(100vw - 24px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: var(--notif-z-index);
  pointer-events: none;
}

.toast {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  max-width: 520px;
  margin-inline: auto;
  /* Keep the surface opaque even when a theme token is missing or overridden. */
  background-color: #ffffff;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 48px color-mix(in srgb, var(--color-slate-900) 24%, transparent), 0 4px 12px color-mix(in srgb, var(--color-slate-900) 12%, transparent);
  color: var(--color-slate-900);
  padding: 12px;
  transform: translateY(-12px) scale(0.98);
  opacity: 0;
  transition: transform 220ms ease, opacity 220ms ease;
  pointer-events: auto;
}

.toast--visible {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.toast--exiting,
.toast--swiped {
  transform: translateX(120%);
  opacity: 0;
}

.toast__icon {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.toast__content {
  min-width: 0;
  flex: 1 1 auto;
}

.toast__title {
  margin: 0;
  font-size: var(--font-size-sm);
  line-height: 1.35;
  font-weight: 700;
}

.toast__message {
  margin: 4px 0 0;
  font-size: var(--font-size-compact);
  line-height: 1.35;
  color: var(--color-slate-700);
}

.toast__time {
  margin: 4px 0 0;
  font-size: var(--font-size-xs);
  color: var(--color-slate-500);
}

.toast__actions {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.toast__cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--color-slate-300);
  border-radius: var(--radius-md);
  background: var(--color-slate-50);
  color: var(--color-slate-900);
  text-decoration: none;
  font-size: var(--font-size-xs);
  line-height: 1;
  padding: 7px 10px;
}

.toast__close {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  color: var(--color-slate-500);
  border-radius: var(--radius-md);
}

.toast__close:hover {
  background: var(--color-slate-100);
}

.toast__progress {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  height: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--color-info-600) 15%, transparent);
  overflow: hidden;
}

.toast__progress::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--color-info-600);
  transform-origin: left center;
  animation-name: toast-progress;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  animation-duration: inherit;
}

.toast--success .toast__icon {
  background: var(--color-success-50);
  color: var(--color-success-700);
}

.toast--success {
  border-left: 4px solid var(--color-success-600);
  border-color: #86efac;
  background: #f0fdf4;
  color: #14532d;
}

.toast--error .toast__icon {
  background: var(--color-danger-100);
  color: var(--color-danger-700);
}

.toast--error {
  border-left: 4px solid var(--color-danger-600);
  border-color: #fca5a5;
  background: #fef2f2;
  color: #7f1d1d;
}

.toast--warning .toast__icon {
  background: var(--color-warning-50);
  color: var(--color-warning-700);
}

.toast--warning {
  border-left: 4px solid var(--color-warning-600);
  border-color: #fcd34d;
  background: #fffbeb;
  color: #78350f;
}

.toast--info {
  border-left: 4px solid var(--color-info-600);
  border-color: #7dd3fc;
  background: #f0f9ff;
  color: #0c4a6e;
}

.toast--undo {
  border-color: #cbd5e1;
  background-color: #ffffff;
  color: #0f172a;
}

.toast--undo .toast__icon {
  background-color: #e2e8f0;
  color: #334155;
}

.toast--critical {
  border-color: #ef4444;
  background: #fee2e2;
  color: #7f1d1d;
}

.toast--success .toast__message,
.toast--success .toast__time,
.toast--error .toast__message,
.toast--error .toast__time,
.toast--warning .toast__message,
.toast--warning .toast__time,
.toast--info .toast__message,
.toast--info .toast__time,
.toast--critical .toast__message,
.toast--critical .toast__time {
  color: inherit;
  opacity: 0.82;
}

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

.notif-badge {
  position: relative;
}

.notif-badge__count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--color-danger-500);
  color: var(--color-white);
  font-size: var(--font-size-caption, 12px);
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}

.notif-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 10px);
  width: min(92vw, 360px);
  background: var(--color-white);
  border: 1px solid var(--color-slate-200);
  border-radius: 14px;
  box-shadow: 0 18px 34px color-mix(in srgb, var(--color-slate-900) 16%, transparent);
  overflow: hidden;
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: var(--notif-dropdown-z-index);
}

.notif-dropdown.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.notif-dropdown__header,
.notif-dropdown__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-slate-100);
}

.notif-dropdown__footer {
  border-top: 1px solid var(--color-slate-100);
  border-bottom: 0;
}

.notif-dropdown__title {
  font-size: var(--font-size-sm);
  font-weight: 700;
  color: var(--color-slate-900);
}

.notif-dropdown__mark-read,
.notif-dropdown__footer a {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-info-600);
  text-decoration: none;
}

.notif-dropdown__mark-read {
  border: 0;
  background: transparent;
  padding: 0;
}

.notif-dropdown__list {
  max-height: 360px;
  overflow-y: auto;
}

.notif-loading {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 72px;
}

.notif-item {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  align-items: start;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--color-slate-100);
  color: var(--color-slate-900);
}

.notif-item--unread {
  background: var(--color-slate-50);
}

.notif-item__icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-lg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}

.notif-item__title {
  margin: 0;
  font-size: var(--font-size-compact);
  line-height: 1.3;
  font-weight: 700;
}

.notif-item__message {
  margin: 3px 0 0;
  font-size: var(--font-size-xs);
  color: var(--color-slate-700);
}

.notif-item__meta {
  margin-top: 6px;
  font-size: var(--font-size-caption, 12px);
  color: var(--color-slate-500);
}

.notif-item__actions {
  display: flex;
  gap: 6px;
}

.notif-item__action {
  width: 24px;
  height: 24px;
  border: 1px solid var(--color-slate-200);
  border-radius: var(--radius-md);
  background: var(--color-white);
  color: var(--color-slate-600);
}

@media (max-width: 768px) {
  #toast-container {
    top: calc(env(safe-area-inset-top, 0px) + 12px);
    width: calc(100vw - 16px);
  }

  .toast {
    max-width: 100%;
  }
}

#django-messages-container {
  top: var(--app-toast-top-offset, calc(env(safe-area-inset-top, 0px) + 80px)) !important;
  right: auto !important;
  left: 50% !important;
  width: min(520px, calc(100vw - 24px)) !important;
  max-width: 520px !important;
  transform: translateX(-50%);
}

[data-message-toast][data-message-level="success"] {
  border-color: #86efac;
  background: #f0fdf4;
  color: #14532d;
}

[data-message-toast][data-message-level="error"] {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #7f1d1d;
}

[data-message-toast][data-message-level="warning"] {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #78350f;
}

[data-message-toast][data-message-level="info"] {
  border-color: #7dd3fc;
  background: #f0f9ff;
  color: #0c4a6e;
}

#app-toast {
  top: var(--app-toast-top-offset, calc(env(safe-area-inset-top, 0px) + 80px)) !important;
  width: min(520px, calc(100vw - 24px));
  text-align: center;
  box-shadow: 0 18px 48px color-mix(in srgb, var(--color-slate-900) 28%, transparent);
}

@media (max-width: 768px) {
  #django-messages-container,
  #app-toast {
    top: calc(env(safe-area-inset-top, 0px) + 12px) !important;
    width: calc(100vw - 16px) !important;
  }
}

html.dark .toast,
html.dark .notif-dropdown {
  background-color: #0f172a;
  border-color: var(--color-slate-800);
  box-shadow: 0 18px 40px color-mix(in srgb, var(--color-black) 38%, transparent);
  color: var(--color-slate-100);
}

html.dark .toast--undo {
  border-color: #475569;
  background-color: #1e293b;
  color: #f8fafc;
}

html.dark .toast--undo .toast__icon {
  background-color: #334155;
  color: #e2e8f0;
}

html.dark .toast--success,
html.dark [data-message-toast][data-message-level="success"] {
  border-color: #22c55e;
  background: #052e16;
  color: #bbf7d0;
}

html.dark .toast--error,
html.dark .toast--critical,
html.dark [data-message-toast][data-message-level="error"] {
  border-color: #ef4444;
  background: #450a0a;
  color: #fecaca;
}

html.dark .toast--warning,
html.dark [data-message-toast][data-message-level="warning"] {
  border-color: #f59e0b;
  background: #451a03;
  color: #fde68a;
}

html.dark .toast--info,
html.dark [data-message-toast][data-message-level="info"] {
  border-color: #0ea5e9;
  background: #082f49;
  color: #bae6fd;
}

html.dark .toast__message,
html.dark .notif-item__message {
  color: var(--color-slate-300);
}

html.dark .toast__time,
html.dark .toast__close,
html.dark .notif-item__meta {
  color: var(--color-slate-400);
}

html.dark .toast__icon,
html.dark .notif-item__icon {
  background: color-mix(in srgb, var(--brand-500) 14%, transparent);
  color: var(--brand-300);
}

html.dark .toast__cta,
html.dark .notif-item__action {
  background: var(--color-slate-900);
  border-color: var(--color-slate-800);
  color: var(--color-slate-200);
}

html.dark .toast__close:hover,
html.dark .notif-item__action:hover {
  background: var(--color-slate-800);
}

html.dark .toast__progress {
  background: color-mix(in srgb, var(--brand-500) 14%, transparent);
}

html.dark .toast__progress::after {
  background: var(--brand-400);
}

[data-message-toast][data-message-level] :is(p, button),
html.dark [data-message-toast][data-message-level] :is(p, button),
html.dark :is(.toast--success, .toast--error, .toast--warning, .toast--info, .toast--critical) :is(.toast__message, .toast__time, .toast__close) {
  color: inherit;
}

html.dark .notif-dropdown__header,
html.dark .notif-dropdown__footer,
html.dark .notif-item {
  border-color: var(--color-slate-800);
}

html.dark .notif-dropdown__title,
html.dark .notif-item {
  color: var(--color-slate-100);
}

html.dark .notif-dropdown__mark-read,
html.dark .notif-dropdown__footer a {
  color: var(--brand-300);
}

html.dark .notif-item--unread {
  background: color-mix(in srgb, var(--brand-500) 8%, transparent);
}
