/**
 * Тосты: сверху, «из» Dynamic Island / челки на iPhone.
 * Без backdrop-filter (белый экран в iOS PWA).
 */

.toast-container {
    position: fixed;
    z-index: 10040;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    max-width: min(420px, calc(100vw - 1.5rem));
    width: 100%;
    box-sizing: border-box;
    /* Десктоп: сверху справа */
    top: max(1rem, env(safe-area-inset-top, 0px));
    right: max(1rem, env(safe-area-inset-right, 0px));
    left: auto;
    bottom: auto;
    align-items: stretch;
}

/* PWA / узкий экран / app shell: остров по центру под челкой */
@media (max-width: 900px) {
    .toast-container,
    html.pwa-standalone .toast-container,
    html.atcarnet-app .toast-container {
        top: max(0.55rem, env(safe-area-inset-top, 0px));
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: min(26.5rem, calc(100vw - 1.25rem));
        max-width: calc(100vw - 1.25rem);
        align-items: center;
        padding-left: env(safe-area-inset-left, 0px);
        padding-right: env(safe-area-inset-right, 0px);
    }
}

html.pwa-standalone .toast-container,
html.atcarnet-app .toast-container {
    top: max(0.45rem, env(safe-area-inset-top, 0px));
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: min(26.5rem, calc(100vw - 1.25rem));
    max-width: calc(100vw - 1.25rem);
    align-items: center;
}

.toast {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.72rem 0.85rem 0.72rem 0.75rem;
    border-radius: 1.35rem;
    background: #f2f2f7;
    color: #1c1c1e;
    border: 0;
    box-shadow:
        0 0 0 0.33px rgba(0, 0, 0, 0.14),
        0 10px 28px rgba(0, 0, 0, 0.14),
        inset 0 0.5px 0 rgba(255, 255, 255, 0.75);
    pointer-events: auto;
    overflow: hidden;
    transform-origin: top center;
    animation: toastIslandIn 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
    -webkit-font-smoothing: antialiased;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
}

html[data-theme="dark"] .toast {
    background: #1c1c1e;
    color: #f5f5f7;
    box-shadow:
        0 0 0 0.33px rgba(255, 255, 255, 0.14),
        0 12px 32px rgba(0, 0, 0, 0.45),
        inset 0 0.5px 0 rgba(255, 255, 255, 0.08);
}

.toast::before {
    display: none;
}

.toast-icon {
    width: 1.85rem;
    height: 1.85rem;
    min-width: 1.85rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.78rem;
    color: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.toast-success .toast-icon { background: #34c759; }
.toast-error .toast-icon { background: #ff3b30; }
.toast-warning .toast-icon { background: #ff9f0a; }
.toast-info .toast-icon { background: #007aff; }

html[data-theme="dark"] .toast-success .toast-icon { background: #30d158; }
html[data-theme="dark"] .toast-error .toast-icon { background: #ff453a; }
html[data-theme="dark"] .toast-warning .toast-icon { background: #ffd60a; color: #1c1c1e; }
html[data-theme="dark"] .toast-info .toast-icon { background: #0a84ff; }

.toast-content {
    flex: 1;
    min-width: 0;
    padding-right: 0.15rem;
}

.toast-title {
    font-weight: 650;
    font-size: 0.9rem;
    line-height: 1.25;
    margin: 0 0 0.12rem;
    color: inherit;
    letter-spacing: -0.01em;
}

.toast-message {
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
    color: rgba(60, 60, 67, 0.78);
    word-wrap: break-word;
}

html[data-theme="dark"] .toast-message {
    color: rgba(235, 235, 245, 0.72);
}

.toast.toast--plain .toast-message {
    font-size: 0.9rem;
    font-weight: 600;
    color: inherit;
    letter-spacing: -0.01em;
}

html[data-theme="dark"] .toast.toast--plain .toast-message {
    color: #f5f5f7;
}

.toast-close {
    background: rgba(120, 120, 128, 0.16);
    border: none;
    color: rgba(60, 60, 67, 0.55);
    cursor: pointer;
    padding: 0;
    border-radius: 999px;
    flex-shrink: 0;
    width: 1.55rem;
    height: 1.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    transition: background 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.toast-close:hover,
.toast-close:focus-visible {
    background: rgba(120, 120, 128, 0.28);
    color: rgba(60, 60, 67, 0.9);
    outline: none;
}

html[data-theme="dark"] .toast-close {
    background: rgba(120, 120, 128, 0.32);
    color: rgba(235, 235, 245, 0.55);
}

html[data-theme="dark"] .toast-close:hover,
html[data-theme="dark"] .toast-close:focus-visible {
    background: rgba(120, 120, 128, 0.48);
    color: rgba(235, 235, 245, 0.9);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    width: 100%;
    transform-origin: left center;
    background: rgba(0, 122, 255, 0.45);
    animation: toastIslandProgress linear forwards;
    opacity: 0.85;
}

.toast-success .toast-progress { background: rgba(52, 199, 89, 0.55); }
.toast-error .toast-progress { background: rgba(255, 59, 48, 0.55); }
.toast-warning .toast-progress { background: rgba(255, 159, 10, 0.6); }
.toast-info .toast-progress { background: rgba(0, 122, 255, 0.55); }

.toast.is-paused .toast-progress {
    animation-play-state: paused;
}

/* Появление: из узкой «челки» сверху */
@keyframes toastIslandIn {
    0% {
        opacity: 0;
        transform: translateY(-118%) scaleX(0.28) scaleY(0.42);
        border-radius: 999px;
    }
    55% {
        opacity: 1;
    }
    78% {
        transform: translateY(2px) scaleX(1.01) scaleY(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scaleX(1) scaleY(1);
        border-radius: 1.35rem;
    }
}

.toast-exit {
    animation: toastIslandOut 0.48s cubic-bezier(0.4, 0, 0.2, 1) forwards !important;
    pointer-events: none;
}

@keyframes toastIslandOut {
    0% {
        opacity: 1;
        transform: translateY(0) scaleX(1) scaleY(1);
        border-radius: 1.35rem;
    }
    100% {
        opacity: 0;
        transform: translateY(-110%) scaleX(0.22) scaleY(0.35);
        border-radius: 999px;
        max-height: 2.2rem;
    }
}

@keyframes toastIslandProgress {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

@media (prefers-reduced-motion: reduce) {
    .toast {
        animation: toastFadeIn 0.2s ease both;
    }
    .toast-exit {
        animation: toastFadeOut 0.18s ease forwards !important;
    }
    @keyframes toastFadeIn {
        from { opacity: 0; transform: translateY(-8px); }
        to { opacity: 1; transform: none; }
    }
    @keyframes toastFadeOut {
        to { opacity: 0; transform: translateY(-8px); }
    }
}

/* Альбом PWA: не залезать под rail слева */
@media (orientation: landscape) {
    html.pwa-standalone .toast-container,
    html.atcarnet-app .toast-container {
        width: min(24rem, calc(100vw - 5.5rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
        padding-left: calc(4.5rem + env(safe-area-inset-left, 0px));
    }
}
