/* ======================================================================
   UI ENHANCEMENTS
   1. Scroll reveal — animacja wejścia sekcji
   2. Toast notifications — eleganckie komunikaty
   3. Scroll-to-top button — powrót na górę
   Wszystko szanuje prefers-reduced-motion.
====================================================================== */

/* ── 1. SCROLL REVEAL ──────────────────────────────────────────────── */

[data-reveal] {
    opacity: 0;
    translate: 0 28px;
    transition:
        opacity  0.55s cubic-bezier(0.22, 1, 0.36, 1),
        translate 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

[data-reveal].is-visible {
    opacity: 1;
    translate: 0 0;
}

/* Opóźnienia dla kart w gridzie */
[data-reveal-delay="1"] { transition-delay: 0.08s; }
[data-reveal-delay="2"] { transition-delay: 0.16s; }
[data-reveal-delay="3"] { transition-delay: 0.24s; }
[data-reveal-delay="4"] { transition-delay: 0.32s; }
[data-reveal-delay="5"] { transition-delay: 0.40s; }
[data-reveal-delay="6"] { transition-delay: 0.48s; }

/* Wyłącz animacje gdy użytkownik tego woli */
@media (prefers-reduced-motion: reduce) {
    [data-reveal] {
        opacity: 1;
        translate: 0 0;
        transition: none;
    }
}

/* ── 2. TOAST NOTIFICATIONS ────────────────────────────────────────── */

#toast-region {
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(360px, calc(100vw - 40px));
    pointer-events: none;
}

.toast {
    display: grid;
    grid-template-columns: 20px 1fr 28px;
    align-items: start;
    gap: 10px;
    padding: 14px 14px 14px 16px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, 0.96);
    box-shadow:
        0 4px 24px rgba(15, 23, 42, 0.13),
        0 1px 4px  rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    pointer-events: auto;
    /* Animacja wejścia */
    animation: toastIn 0.32s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.toast.is-leaving {
    animation: toastOut 0.24s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; translate: 0 12px; }
    to   { opacity: 1; translate: 0 0;    }
}

@keyframes toastOut {
    from { opacity: 1; translate: 0 0;    }
    to   { opacity: 0; translate: 0 12px; }
}

.toast-icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
    font-size: 11px;
    font-weight: 900;
}

.toast-body {
    min-width: 0;
}

.toast-title {
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1.3;
    color: #152334;
}

.toast-message {
    font-size: 0.82rem;
    line-height: 1.45;
    color: #526273;
    margin-top: 2px;
}

.toast-close {
    appearance: none;
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #8599ae;
    transition: background 0.14s, color 0.14s;
    flex-shrink: 0;
    margin-top: -2px;
    margin-right: -4px;
}

.toast-close:hover {
    background: rgba(15, 23, 42, 0.07);
    color: #152334;
}

.toast-close:focus-visible {
    outline: 2px solid #0f766e;
    outline-offset: 1px;
}

/* Warianty */
.toast-success {
    border-color: rgba(15, 118, 110, 0.2);
    background: rgba(240, 253, 250, 0.97);
}
.toast-success .toast-icon {
    background: rgba(15, 118, 110, 0.12);
    color: #0f766e;
}

.toast-error {
    border-color: rgba(180, 35, 24, 0.2);
    background: rgba(254, 242, 242, 0.97);
}
.toast-error .toast-icon {
    background: rgba(180, 35, 24, 0.1);
    color: #b42318;
}

.toast-warning {
    border-color: rgba(176, 108, 17, 0.2);
    background: rgba(255, 251, 235, 0.97);
}
.toast-warning .toast-icon {
    background: rgba(176, 108, 17, 0.1);
    color: #b06c11;
}

.toast-info {
    border-color: rgba(37, 99, 235, 0.18);
    background: rgba(239, 246, 255, 0.97);
}
.toast-info .toast-icon {
    background: rgba(37, 99, 235, 0.1);
    color: #1d4ed8;
}

/* Pasek postępu */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    border-radius: 0 0 14px 14px;
    background: currentColor;
    opacity: 0.22;
    transform-origin: left;
}

.toast {
    position: relative;
    overflow: hidden;
}

/* Ikony tekst */
.toast-icon-text { line-height: 1; }

/* Ukryj stare flash-stack na rzecz toastów */
.flash-stack {
    display: none;
}

/* Mobile */
@media (max-width: 480px) {
    #toast-region {
        bottom: 16px;
        right: 10px;
        left: 10px;
        width: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .toast,
    .toast.is-leaving {
        animation: none;
    }
}

/* ── 3. SCROLL-TO-TOP ──────────────────────────────────────────────── */

#scroll-to-top {
    position: fixed;
    bottom: 28px;
    right: 24px;
    z-index: 8500;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    border: 1.5px solid rgba(15, 23, 42, 0.1);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow:
        0 4px 18px rgba(15, 23, 42, 0.12),
        0 1px 4px  rgba(15, 23, 42, 0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Stan domyślny: ukryty */
    opacity: 0;
    translate: 0 12px;
    pointer-events: none;
    transition:
        opacity  0.28s ease,
        translate 0.28s ease,
        background 0.18s ease,
        border-color 0.18s ease,
        box-shadow  0.18s ease;
    appearance: none;
    -webkit-appearance: none;
}

#scroll-to-top svg {
    width: 18px;
    height: 18px;
    stroke: #152334;
    stroke-width: 2.2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.18s;
}

#scroll-to-top.is-visible {
    opacity: 1;
    translate: 0 0;
    pointer-events: auto;
}

#scroll-to-top:hover {
    background: rgba(255, 255, 255, 1);
    border-color: rgba(15, 118, 110, 0.3);
    box-shadow:
        0 8px 28px rgba(15, 23, 42, 0.16),
        0 2px 6px  rgba(15, 23, 42, 0.08);
}

#scroll-to-top:hover svg {
    stroke: #0f766e;
}

#scroll-to-top:active {
    translate: 0 2px;
    transition: translate 0.08s ease;
}

#scroll-to-top:focus-visible {
    outline: 2px solid #0f766e;
    outline-offset: 3px;
}

/* Na mobile gdy jest warning strip — przesuń wyżej */
body.home-page #scroll-to-top {
    bottom: 80px;
}

@media (max-width: 760px) {
    #scroll-to-top {
        bottom: 20px;
        right: 16px;
        width: 42px;
        height: 42px;
    }

    body.home-page #scroll-to-top {
        bottom: 76px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #scroll-to-top {
        transition: opacity 0.18s ease;
    }
}
