/**
 * ============================================================================
 * TOAST NOTIFICATION SYSTEM - STYLES
 * ============================================================================
 *
 * Dark glassmorphic toast notifications with animated icons.
 * Designed to match MitsuHub's aesthetic.
 *
 * ============================================================================
 */

/* ============================================================================
   CONTAINER POSITIONING
   ============================================================================ */

.toast-container {
    position: fixed;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
    z-index: var(--z-toast);
    max-width: 450px;
}

/* Position variants */
.toast-container.toast-top-left {
    top: 24px;
    left: 24px;
    align-items: flex-start;
}

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

.toast-container.toast-top-right {
    top: 80px;
    right: 24px;
    align-items: flex-end;
}

.toast-container.toast-bottom-left {
    bottom: 24px;
    left: 24px;
    align-items: flex-start;
}

.toast-container.toast-bottom-center {
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    align-items: center;
}

.toast-container.toast-bottom-right {
    bottom: 24px;
    right: 24px;
    align-items: flex-end;
}

/* ============================================================================
   TOAST BASE STYLES
   ============================================================================ */

#toast-container > .toast {
    /* Layout */
    position: relative;
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 300px;
    max-width: 420px;
    padding: 14px 20px;
    pointer-events: auto;

    /* Glassmorphic styling */
    background: rgba(20, 20, 30, 0.9);
    backdrop-filter: blur(var(--glass-blur-md));
    -webkit-backdrop-filter: blur(var(--glass-blur-md));

    /* Pill shape */
    border-radius: var(--radius-pill);

    /* Border with glow */
    border: 1px solid var(--border);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.3),
        0 0 20px var(--toast-glow, rgba(var(--fg-rgb, 255, 255, 255), 0.1)),
        inset 0 1px 0 rgba(var(--fg-rgb, 255, 255, 255), 0.05);

    /* Ensure visibility */
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1);
    transition: background var(--transition-smooth), border-color var(--transition-smooth), box-shadow var(--transition-smooth), opacity var(--transition-smooth), transform var(--transition-smooth);
}

/* ============================================================================
   TOAST STATES & ANIMATIONS
   ============================================================================ */

/* Enter animation - optional enhancement */
#toast-container > .toast.toast-enter {
    opacity: 1 !important;
    transform: translateY(0) scale(1);
}

/* Exit animation */
#toast-container > .toast.toast-exit {
    opacity: 0 !important;
    transform: translateY(-20px) scale(0.95);
    pointer-events: none;
}

/* Update pulse animation */
#toast-container > .toast.toast-updated {
    animation: toast-pulse 0.3s ease;
}

@keyframes toast-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Hover effect */
#toast-container > .toast:hover {
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 0 30px var(--toast-glow, rgba(var(--fg-rgb, 255, 255, 255), 0.15)),
        inset 0 1px 0 rgba(var(--fg-rgb, 255, 255, 255), 0.08);
}

/* ============================================================================
   TOAST CONTENT
   ============================================================================ */

/* Scoped to the shared container, like `#toast-container > .toast` above.
   Left bare, these two collided (#31) with the hand-rolled toast systems in
   watchlist/select-anime.ftlh and select-manga.ftlh, which redeclare only
   `flex`/`font-size`/`color`: the shared `display:flex; align-items:center;
   gap:14px` laid their intentionally-stacked title+message out side by side,
   and `-webkit-line-clamp: 2` truncated a message never designed to clamp. */
#toast-container .toast-content {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0; /* Allow text truncation */
}

#toast-container .toast-message {
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.95);
    font-size: 0.875rem;
    font-weight: var(--weight-medium);
    line-height: var(--leading-base);
    letter-spacing: 0.2px;

    /* Text overflow handling */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ============================================================================
   TOAST ICON
   ============================================================================ */

.toast-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-circle);
    background: var(--toast-gradient, linear-gradient(135deg, #6366f1, #4f46e5));
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.toast-icon {
    color: white;
    font-size: 0.875rem;
}

/* ============================================================================
   ICON ANIMATIONS
   ============================================================================ */

/* Success - Pop/Scale animation */
.toast-icon.toast-icon-pop {
    animation: toast-icon-pop 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes toast-icon-pop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.3);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Error - Shake animation */
.toast-icon.toast-icon-shake {
    animation: toast-icon-shake 0.5s ease;
}

@keyframes toast-icon-shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-3px) rotate(-5deg); }
    40% { transform: translateX(3px) rotate(5deg); }
    60% { transform: translateX(-3px) rotate(-5deg); }
    80% { transform: translateX(3px) rotate(5deg); }
}

/* Warning - Pulse animation */
.toast-icon.toast-icon-pulse {
    animation: toast-icon-pulse 0.6s ease;
}

@keyframes toast-icon-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    25% {
        transform: scale(1.2);
        opacity: 0.8;
    }
    50% {
        transform: scale(1);
        opacity: 1;
    }
    75% {
        transform: scale(1.15);
        opacity: 0.9;
    }
}

/* Info - Fade in animation */
.toast-icon.toast-icon-fade {
    animation: toast-icon-fade 0.4s ease;
}

@keyframes toast-icon-fade {
    0% {
        opacity: 0;
        transform: scale(0.8);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Loading - Continuous spin */
.toast-icon.toast-icon-spin {
    animation: toast-icon-spin 1s linear infinite;
}

@keyframes toast-icon-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Achievement - Bounce with glow */
.toast-icon.toast-icon-bounce {
    animation: toast-icon-bounce 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes toast-icon-bounce {
    0% {
        transform: scale(0) rotate(-15deg);
        opacity: 0;
    }
    50% {
        transform: scale(1.3) rotate(10deg);
    }
    70% {
        transform: scale(0.9) rotate(-5deg);
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

/* Achievement icon glow effect */
.toast-achievement .toast-icon-wrapper {
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.2),
        0 0 20px rgba(251, 191, 36, 0.4);
}

/* ============================================================================
   TOAST ACTIONS (BUTTONS)
   ============================================================================ */

.toast-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toast-dismiss-btn,
.toast-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-pill);
    font-size: 0.6875rem;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: white;
    cursor: pointer;
    transition: filter var(--transition-base), transform var(--transition-base);
    white-space: nowrap;
}

.toast-dismiss-btn:hover,
.toast-action-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

.toast-dismiss-btn:active,
.toast-action-btn:active {
    transform: scale(0.98);
}

/* Action button - slightly different style */
.toast-action-btn {
    background: transparent !important;
    border: 1px solid rgba(var(--fg-rgb, 255, 255, 255), 0.3);
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.9);
}

.toast-action-btn:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.1) !important;
    border-color: rgba(var(--fg-rgb, 255, 255, 255), 0.5);
}

/* ============================================================================
   TYPE-SPECIFIC STYLING
   ============================================================================ */

/* Success */
#toast-container > .toast.toast-success {
    border-color: rgba(16, 185, 129, 0.3);
}

/* Error */
#toast-container > .toast.toast-error {
    border-color: rgba(239, 68, 68, 0.3);
}

/* Warning */
#toast-container > .toast.toast-warning {
    border-color: rgba(var(--amber-500-rgb), 0.3);
}

/* Info */
#toast-container > .toast.toast-info {
    border-color: rgba(59, 130, 246, 0.3);
}

/* Loading */
#toast-container > .toast.toast-loading {
    border-color: rgba(var(--indigo-500-rgb), 0.3);
}

/* Achievement - Extra special styling */
#toast-container > .toast.toast-achievement {
    border-color: rgba(251, 191, 36, 0.4);
    background: linear-gradient(
        135deg,
        rgba(30, 25, 20, 0.95) 0%,
        rgba(40, 30, 20, 0.9) 100%
    );
}

#toast-container > .toast.toast-achievement::before {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border-radius: var(--radius-pill);
    background: linear-gradient(
        135deg,
        rgba(251, 191, 36, 0.3),
        rgba(var(--amber-500-rgb), 0.1),
        rgba(251, 191, 36, 0.3)
    );
    z-index: -1;
    animation: achievement-shimmer 2s ease infinite;
}

@keyframes achievement-shimmer {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

/* ============================================================================
   MOBILE RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    .toast-container {
        padding: 12px;
    }

    #toast-container > .toast {
        min-width: unset;
        max-width: calc(100vw - 24px);
        width: 100%;
        padding: 12px 16px;
        gap: 12px;
        border-radius: 40px;
    }

    #toast-container .toast-content {
        gap: 12px;
    }

    .toast-icon-wrapper {
        width: 32px;
        height: 32px;
    }

    .toast-icon {
        font-size: 12px;
    }

    #toast-container .toast-message {
        font-size: 13px;
    }

    .toast-dismiss-btn,
    .toast-action-btn {
        padding: 6px 14px;
        font-size: 0.625rem;
    }
}

/* Small phones */
@media (max-width: 400px) {
    #toast-container > .toast {
        border-radius: var(--radius-2xl);
        padding: 10px 14px;
    }

    .toast-actions {
        gap: 6px;
    }

    .toast-dismiss-btn,
    .toast-action-btn {
        padding: 6px 12px;
        font-size: 0.5625rem;
    }
}

/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    #toast-container > .toast {
        transition: opacity var(--transition-base);
        transform: none !important;
    }

    #toast-container > .toast.toast-enter {
        transform: none !important;
    }

    #toast-container > .toast.toast-exit {
        transform: none !important;
    }

    .toast-icon {
        animation: none !important;
    }

    #toast-container > .toast.toast-achievement::before {
        animation: none !important;
    }
}

/* ============================================================================
   HIGH CONTRAST MODE
   ============================================================================ */

@media (prefers-contrast: high) {
    #toast-container > .toast {
        background: rgba(0, 0, 0, 0.95);
        border-width: 2px;
    }

    #toast-container .toast-message {
        color: white;
    }
}

/* ============================================================================
   PROGRESS BAR
   ============================================================================ */

.toast-progress-track {
    position: absolute;
    bottom: 0;
    left: 20px;
    right: 20px;
    height: 3px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.1);
    border-radius: 0 0 50px 50px;
    overflow: hidden;
}

.toast-progress-bar {
    height: 100%;
    width: 100%;
    border-radius: var(--radius-xs);
    will-change: width;
}

/* Hide progress bar on loading toasts (they're persistent) */
.toast-loading .toast-progress-track {
    display: none;
}

/* ============================================================================
   DEDUPLICATION COUNT BADGE
   ============================================================================ */

.toast-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.15);
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.9);
    font-size: 11px;
    font-weight: var(--weight-bold);
    flex-shrink: 0;
    animation: toast-icon-pop 0.3s ease;
}

/* ============================================================================
   EXPANDED TOAST DETAIL CARD
   ============================================================================ */

.toast-detail-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-scrim);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
    z-index: calc(var(--z-toast) + 2);
    opacity: 0;
    transition: opacity var(--transition-normal);
    padding: 24px;
}

.toast-detail-overlay.toast-detail-enter {
    opacity: 1;
}

.toast-detail-overlay.toast-detail-exit {
    opacity: 0;
    pointer-events: none;
}

.toast-detail-card {
    position: relative;
    background: rgba(20, 20, 30, 0.95);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 28px;
    max-width: 420px;
    width: 100%;
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.5),
        0 0 40px var(--toast-detail-glow, rgba(var(--fg-rgb, 255, 255, 255), 0.05)),
        inset 0 1px 0 rgba(var(--fg-rgb, 255, 255, 255), 0.05);
    transform: scale(0.4) translateY(-20px);
    transform-origin: top right;
    transition: transform 0.35s var(--ease-spring);
    margin-top: 56px;
}

.toast-detail-enter .toast-detail-card {
    transform: scale(1) translateY(0);
}

.toast-detail-exit .toast-detail-card {
    transform: scale(0.4) translateY(-20px);
    transition: transform var(--dur-base) var(--ease-standard);
}

/* Close button */
.toast-detail-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    border: none;
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.06);
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background var(--dur-base), color var(--dur-base);
}

.toast-detail-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.toast-detail-close:focus-visible {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    outline: 2px solid rgba(239, 68, 68, 0.6);
    outline-offset: 2px;
}

/* Header: icon + type badge */
.toast-detail-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 16px;
}

.toast-detail-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-circle);
    flex-shrink: 0;
    box-shadow: var(--shadow-md);
}

.toast-detail-icon i {
    color: white;
    font-size: 1.125rem;
}

.toast-detail-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toast-detail-type {
    display: inline-flex;
    align-items: center;
    font-size: 0.6875rem;
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.5);
}

.toast-detail-time {
    font-size: 0.75rem;
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.3);
}

/* Message body */
.toast-detail-message {
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.9);
    font-size: 0.9375rem;
    font-weight: var(--weight-normal);
    line-height: 1.65;
    margin-bottom: 20px;
    word-break: break-word;
}

/* Actions */
.toast-detail-actions {
    display: flex;
    gap: 10px;
}

.toast-detail-dismiss-btn {
    flex: 1;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    border: none;
    font-size: 0.8125rem;
    font-weight: var(--weight-semibold);
    cursor: pointer;
    transition: filter var(--dur-base), transform var(--dur-base);
    font-family: 'Poppins', sans-serif;
    color: white;
    box-shadow: var(--shadow-md);
}

.toast-detail-dismiss-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.1);
}

.toast-detail-dismiss-btn:active {
    transform: scale(0.98);
}

.toast-detail-action-btn {
    flex: 1;
    padding: 10px 20px;
    border-radius: var(--radius-md);
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.06);
    border: 1px solid var(--border);
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.7);
    font-size: 0.8125rem;
    font-weight: var(--weight-semibold);
    cursor: pointer;
    transition: background var(--dur-base), color var(--dur-base);
    font-family: 'Poppins', sans-serif;
}

.toast-detail-action-btn:hover {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.1);
    color: #fff;
}

/* Accent bar at top */
.toast-detail-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 3px;
    border-radius: 0 0 3px 3px;
}

/* Click hint on toasts that are expandable */
#toast-container > .toast.toast-expandable {
    cursor: pointer;
}

#toast-container > .toast.toast-expandable:active {
    transform: scale(0.98);
}

/* Truncation indicator — inside .toast-message, not a flex sibling */
.toast-expand-hint {
    display: none;
    color: rgba(var(--fg-rgb, 255, 255, 255), 0.4);
    font-size: 0.625rem;
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

#toast-container > .toast.toast-truncated .toast-expand-hint {
    display: block;
}

/* ============================================================================
   EXPANDED TOAST - MOBILE
   ============================================================================ */

@media (max-width: 768px) {
    .toast-detail-overlay {
        padding: 12px;
        align-items: center;
        justify-content: center;
    }

    .toast-detail-card {
        margin-top: 0;
        transform-origin: center center;
        transform: scale(0.85) translateY(30px);
        padding: 24px;
        border-radius: var(--radius-lg);
        max-width: calc(100vw - 24px);
    }

    .toast-detail-enter .toast-detail-card {
        transform: scale(1) translateY(0);
    }

    .toast-detail-exit .toast-detail-card {
        transform: scale(0.85) translateY(30px);
    }

    .toast-detail-icon {
        width: 38px;
        height: 38px;
    }

    .toast-detail-icon i {
        font-size: 16px;
    }

    .toast-detail-message {
        font-size: 14px;
    }
}

/* ============================================================================
   EXPANDED TOAST - REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
    .toast-detail-overlay {
        transition: opacity var(--transition-fast);
    }

    .toast-detail-card {
        transition: none;
        transform: none !important;
    }
}

/* ============================================================================
   DARK/LIGHT MODE VARIANTS (Optional - for future use)
   ============================================================================ */

/* Light mode variant (uncomment if needed)
#toast-container.toast-light > .toast {
    background: rgba(var(--fg-rgb, 255, 255, 255), 0.95);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.1),
        0 0 20px var(--toast-glow, rgba(0, 0, 0, 0.05));
}

#toast-container.toast-light .toast-message {
    color: rgba(0, 0, 0, 0.9);
}
*/