/**
 * TBP Toast Notifications Styles
 *
 * Uses CSS custom properties for easy theming.
 * Falls back to sensible defaults if theme variables aren't defined.
 */

/* ==========================================================================
   CSS Variables (with fallbacks)
   ========================================================================== */

:root {
    --tbp-toast-font: var(--font-body, system-ui, -apple-system, sans-serif);
    --tbp-toast-bg: var(--color-bg, #ffffff);
    --tbp-toast-text: var(--color-text, #1f2937);
    --tbp-toast-text-muted: var(--color-text-muted, #6b7280);
    --tbp-toast-border: var(--color-border, #e5e7eb);
    --tbp-toast-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --tbp-toast-radius: 0.75rem;
    --tbp-toast-spacing: 1rem;

    /* Type colors */
    --tbp-toast-success: var(--color-success, #10b981);
    --tbp-toast-success-bg: var(--color-success-bg, rgba(16, 185, 129, 0.1));
    --tbp-toast-error: var(--color-danger, #ef4444);
    --tbp-toast-error-bg: var(--color-danger-bg, rgba(239, 68, 68, 0.1));
    --tbp-toast-warning: var(--color-warning, #f59e0b);
    --tbp-toast-warning-bg: var(--color-warning-bg, rgba(245, 158, 11, 0.1));
    --tbp-toast-info: var(--color-accent, #3b82f6);
    --tbp-toast-info-bg: rgba(59, 130, 246, 0.1);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root:not(.light) {
        --tbp-toast-bg: var(--color-bg, #1f2937);
        --tbp-toast-text: var(--color-text, #f9fafb);
        --tbp-toast-text-muted: var(--color-text-muted, #9ca3af);
        --tbp-toast-border: var(--color-border, #374151);
        --tbp-toast-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
    }
}

.dark {
    --tbp-toast-bg: var(--color-bg, #1f2937);
    --tbp-toast-text: var(--color-text, #f9fafb);
    --tbp-toast-text-muted: var(--color-text-muted, #9ca3af);
    --tbp-toast-border: var(--color-border, #374151);
    --tbp-toast-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* ==========================================================================
   Container
   ========================================================================== */

.tbp-toast-container {
    position: fixed;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: var(--tbp-toast-spacing);
    pointer-events: none;
    max-width: 100%;
    max-height: 100vh;
    overflow: hidden;
}

/* Positions */
.tbp-toast-container--top-right {
    top: 0;
    right: 0;
    align-items: flex-end;
}

.tbp-toast-container--top-left {
    top: 0;
    left: 0;
    align-items: flex-start;
}

.tbp-toast-container--top-center {
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
}

.tbp-toast-container--bottom-right {
    bottom: 0;
    right: 0;
    align-items: flex-end;
    flex-direction: column-reverse;
}

.tbp-toast-container--bottom-left {
    bottom: 0;
    left: 0;
    align-items: flex-start;
    flex-direction: column-reverse;
}

.tbp-toast-container--bottom-center {
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
    flex-direction: column-reverse;
}

/* ==========================================================================
   Toast
   ========================================================================== */

.tbp-toast {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    width: 100%;
    max-width: 380px;
    padding: 1rem;
    background-color: var(--tbp-toast-bg);
    border: 1px solid var(--tbp-toast-border);
    border-radius: var(--tbp-toast-radius);
    box-shadow: var(--tbp-toast-shadow);
    font-family: var(--tbp-toast-font);
    pointer-events: auto;
    position: relative;
    overflow: hidden;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Visible state */
.tbp-toast--visible {
    opacity: 1;
    transform: translateX(0);
}

/* Hiding state */
.tbp-toast--hiding {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
}

/* Animation variants based on position */
.tbp-toast-container--top-left .tbp-toast,
.tbp-toast-container--bottom-left .tbp-toast {
    transform: translateX(-100%);
}

.tbp-toast-container--top-left .tbp-toast--visible,
.tbp-toast-container--bottom-left .tbp-toast--visible {
    transform: translateX(0);
}

.tbp-toast-container--top-left .tbp-toast--hiding,
.tbp-toast-container--bottom-left .tbp-toast--hiding {
    transform: translateX(-100%) scale(0.95);
}

.tbp-toast-container--top-center .tbp-toast,
.tbp-toast-container--bottom-center .tbp-toast {
    transform: translateY(-20px) scale(0.95);
}

.tbp-toast-container--top-center .tbp-toast--visible,
.tbp-toast-container--bottom-center .tbp-toast--visible {
    transform: translateY(0) scale(1);
}

.tbp-toast-container--top-center .tbp-toast--hiding,
.tbp-toast-container--bottom-center .tbp-toast--hiding {
    transform: translateY(-20px) scale(0.95);
    opacity: 0;
}

.tbp-toast-container--bottom-right .tbp-toast,
.tbp-toast-container--bottom-left .tbp-toast,
.tbp-toast-container--bottom-center .tbp-toast {
    /* Bottom positions animate upward when hiding */
}

.tbp-toast-container--bottom-center .tbp-toast {
    transform: translateY(20px) scale(0.95);
}

.tbp-toast-container--bottom-center .tbp-toast--hiding {
    transform: translateY(20px) scale(0.95);
}

/* ==========================================================================
   Toast Icon
   ========================================================================== */

.tbp-toast__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    background-color: var(--tbp-toast-info-bg);
    color: var(--tbp-toast-info);
}

.tbp-toast__icon svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* Type-specific icon colors */
.tbp-toast--success .tbp-toast__icon {
    background-color: var(--tbp-toast-success-bg);
    color: var(--tbp-toast-success);
}

.tbp-toast--error .tbp-toast__icon {
    background-color: var(--tbp-toast-error-bg);
    color: var(--tbp-toast-error);
}

.tbp-toast--warning .tbp-toast__icon {
    background-color: var(--tbp-toast-warning-bg);
    color: var(--tbp-toast-warning);
}

.tbp-toast--info .tbp-toast__icon {
    background-color: var(--tbp-toast-info-bg);
    color: var(--tbp-toast-info);
}

/* ==========================================================================
   Toast Content
   ========================================================================== */

.tbp-toast__content {
    flex: 1;
    min-width: 0;
    padding-top: 0.125rem;
}

.tbp-toast__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--tbp-toast-text);
    margin-bottom: 0.25rem;
    line-height: 1.4;
}

.tbp-toast__message {
    font-size: 0.875rem;
    color: var(--tbp-toast-text-muted);
    line-height: 1.5;
    word-wrap: break-word;
}

/* If no title, make message slightly larger */
.tbp-toast__content:not(:has(.tbp-toast__title)) .tbp-toast__message {
    font-size: 0.9375rem;
    color: var(--tbp-toast-text);
}

/* ==========================================================================
   Close Button
   ========================================================================== */

.tbp-toast__close {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    margin: -0.25rem -0.25rem 0 0;
    background: none;
    border: none;
    border-radius: 0.375rem;
    color: var(--tbp-toast-text-muted);
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.tbp-toast__close:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.05);
}

.dark .tbp-toast__close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.tbp-toast__close svg {
    width: 1rem;
    height: 1rem;
}

/* ==========================================================================
   Progress Bar
   ========================================================================== */

.tbp-toast__progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background-color: rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.dark .tbp-toast__progress {
    background-color: rgba(255, 255, 255, 0.1);
}

.tbp-toast__progress-bar {
    height: 100%;
    width: 100%;
    background-color: var(--tbp-toast-info);
    transition: width linear;
}

.tbp-toast--success .tbp-toast__progress-bar {
    background-color: var(--tbp-toast-success);
}

.tbp-toast--error .tbp-toast__progress-bar {
    background-color: var(--tbp-toast-error);
}

.tbp-toast--warning .tbp-toast__progress-bar {
    background-color: var(--tbp-toast-warning);
}

.tbp-toast--info .tbp-toast__progress-bar {
    background-color: var(--tbp-toast-info);
}

/* ==========================================================================
   Type-specific border accent
   ========================================================================== */

.tbp-toast::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background-color: var(--tbp-toast-info);
    border-radius: var(--tbp-toast-radius) 0 0 var(--tbp-toast-radius);
}

.tbp-toast--success::before {
    background-color: var(--tbp-toast-success);
}

.tbp-toast--error::before {
    background-color: var(--tbp-toast-error);
}

.tbp-toast--warning::before {
    background-color: var(--tbp-toast-warning);
}

.tbp-toast--info::before {
    background-color: var(--tbp-toast-info);
}

/* ==========================================================================
   Hover effects
   ========================================================================== */

.tbp-toast:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .tbp-toast-container {
        padding: 0.75rem;
    }

    .tbp-toast-container--top-center,
    .tbp-toast-container--bottom-center {
        left: 0;
        right: 0;
        transform: none;
    }

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

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
    .tbp-toast {
        transition: opacity 0.15s ease;
        transform: none !important;
    }

    .tbp-toast--visible {
        transform: none !important;
    }

    .tbp-toast--hiding {
        transform: none !important;
    }

    .tbp-toast__progress-bar {
        transition: none !important;
    }
}

/* ==========================================================================
   Print
   ========================================================================== */

@media print {
    .tbp-toast-container {
        display: none !important;
    }
}
