:root {
  --toast-z-index: 1200;
  --toast-gap: 0.85rem;
  --toast-shadow: 0 18px 40px rgba(33, 37, 41, 0.18);
  --toast-shadow-soft: 0 10px 24px rgba(33, 37, 41, 0.12);
  --toast-surface: rgba(255, 255, 255, 0.96);
  --toast-surface-alt: #f7f3ea;
  --toast-text: #24324a;
  --toast-muted: #6c757d;
  --toast-border: rgba(184, 168, 124, 0.2);
  --toast-success: #2d8a5f;
  --toast-error: #c45252;
  --toast-warning: #d19833;
  --toast-info: #4f6f9f;
  --toast-history-bg: rgba(66, 82, 110, 0.94);
  --toast-history-text: #ffffff;
}

.app-toast-container {
  position: fixed;
  top: 5.5rem;
  right: 1rem;
  z-index: var(--toast-z-index);
  display: flex;
  flex-direction: column;
  gap: var(--toast-gap);
  pointer-events: none;
  width: min(26rem, calc(100vw - 2rem));
}

.app-toast {
  pointer-events: auto;
  width: 100%;
  color: var(--toast-text);
  background: var(--toast-surface);
  backdrop-filter: blur(10px);
  border-radius: 1rem;
  border: 1px solid var(--toast-border);
  border-left-width: 5px;
  box-shadow: var(--toast-shadow);
  opacity: 0;
  transform: translate3d(110%, 0, 0);
  transition:
    transform 0.32s ease,
    opacity 0.32s ease;
  overflow: hidden;
}

.app-toast.show {
  opacity: 1;
  transform: translate3d(0, 0, 0);
}

.app-toast.hiding {
  opacity: 0;
  transform: translate3d(110%, 0, 0);
}

.app-toast-content {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.85rem;
  align-items: start;
  padding: 1rem 1.05rem;
}

.app-toast-icon {
  font-size: 1.15rem;
  line-height: 1;
  padding-top: 0.15rem;
}

.app-toast-message {
  font-size: 0.96rem;
  line-height: 1.45;
  font-weight: 500;
}

.app-toast-close {
  border: 0;
  background: transparent;
  color: var(--toast-muted);
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

.app-toast-close:hover {
  background: rgba(36, 50, 74, 0.08);
  color: var(--toast-text);
}

.app-toast-success {
  border-left-color: var(--toast-success);
}

.app-toast-success .app-toast-icon {
  color: var(--toast-success);
}

.app-toast-error {
  border-left-color: var(--toast-error);
}

.app-toast-error .app-toast-icon {
  color: var(--toast-error);
}

.app-toast-warning {
  border-left-color: var(--toast-warning);
}

.app-toast-warning .app-toast-icon {
  color: var(--toast-warning);
}

.app-toast-info {
  border-left-color: var(--toast-info);
}

.app-toast-info .app-toast-icon {
  color: var(--toast-info);
}

.toast-history-toggle {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: calc(var(--toast-z-index) - 10);
  width: 3rem;
  height: 3rem;
  border: 0;
  border-radius: 999px;
  background: var(--toast-history-bg);
  color: var(--toast-history-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--toast-shadow-soft);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.toast-history-toggle:hover {
  transform: translateY(-2px);
  box-shadow: var(--toast-shadow);
}

.toast-history-badge {
  position: absolute;
  top: -0.2rem;
  right: -0.2rem;
  min-width: 1.2rem;
  height: 1.2rem;
  border-radius: 999px;
  background: var(--toast-error);
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 0.25rem;
  font-size: 0.68rem;
  font-weight: 700;
}

.toast-history-panel {
  position: fixed;
  right: 1rem;
  bottom: 4.75rem;
  z-index: calc(var(--toast-z-index) - 20);
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(28rem, calc(100vh - 8rem));
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--toast-border);
  border-radius: 1rem;
  box-shadow: var(--toast-shadow);
  overflow: hidden;
  display: none;
}

.toast-history-panel.open {
  display: flex;
  flex-direction: column;
}

.toast-history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 0.9rem;
  background: var(--toast-surface-alt);
  border-bottom: 1px solid var(--toast-border);
}

.toast-history-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 700;
  color: var(--toast-text);
  font-size: 0.98rem;
  line-height: 1.35;
}

.toast-history-actions {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.35rem;
}

.toast-history-actions .btn {
  font-size: 0.78rem;
  min-height: 2.15rem;
  padding: 0.34rem 0.72rem;
  border-radius: 999px;
  line-height: 1.1;
  white-space: nowrap;
}

.toast-history-clear {
  flex: 0 0 auto;
}

.toast-history-close {
  flex: 0 0 2.15rem;
  width: 2.15rem;
  min-width: 2.15rem;
  padding: 0;
}

.toast-history-list {
  overflow-y: auto;
  padding: 0.9rem;
}

.toast-history-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.8rem;
  padding: 0.8rem;
  border-radius: 0.9rem;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(36, 50, 74, 0.06);
}

.toast-history-item + .toast-history-item {
  margin-top: 0.7rem;
}

.toast-history-item .toast-history-icon {
  margin-top: 0.1rem;
}

.toast-history-item .toast-history-message {
  color: var(--toast-text);
  font-size: 0.9rem;
  line-height: 1.4;
}

.toast-history-item .toast-history-time {
  color: var(--toast-muted);
  font-size: 0.74rem;
  margin-top: 0.3rem;
}

.toast-history-item.success .toast-history-icon {
  color: var(--toast-success);
}

.toast-history-item.error .toast-history-icon {
  color: var(--toast-error);
}

.toast-history-item.warning .toast-history-icon {
  color: var(--toast-warning);
}

.toast-history-item.info .toast-history-icon {
  color: var(--toast-info);
}

body.dark-mode .app-toast,
body.dark-mode .toast-history-panel {
  background: rgba(25, 31, 43, 0.96);
  border-color: rgba(255, 255, 255, 0.08);
}

body.dark-mode .app-toast-message,
body.dark-mode .toast-history-title,
body.dark-mode .toast-history-item .toast-history-message {
  color: #f3f4f6;
}

body.dark-mode .app-toast-close,
body.dark-mode .toast-history-item .toast-history-time {
  color: rgba(243, 244, 246, 0.7);
}

body.dark-mode .toast-history-header,
body.dark-mode .toast-history-item {
  background: rgba(36, 44, 60, 0.95);
}

@media (max-width: 767.98px) {
  .app-toast-container {
    top: 4.75rem;
    left: 0.75rem;
    right: 0.75rem;
    width: auto;
  }

  .app-toast {
    transform: translate3d(0, -1rem, 0);
  }

  .app-toast.show {
    transform: translate3d(0, 0, 0);
  }

  .app-toast.hiding {
    transform: translate3d(0, -1rem, 0);
  }

  .toast-history-toggle {
    right: 0.75rem;
    bottom: 0.75rem;
  }

  .toast-history-panel {
    right: 0.75rem;
    left: 0.75rem;
    bottom: 4.5rem;
    width: auto;
  }

  .toast-history-header {
    gap: 0.65rem;
    padding: 0.8rem;
  }

  .toast-history-title {
    font-size: 0.92rem;
  }

  .toast-history-actions .btn {
    min-height: 2rem;
    padding: 0.3rem 0.65rem;
    font-size: 0.74rem;
  }

  .toast-history-close {
    flex-basis: 2rem;
    width: 2rem;
    min-width: 2rem;
  }
}
