/* Toast Notifications Component
   ==============================
   Korištenje:
   - Toast.success('Poruka')
   - Toast.error('Poruka')
   - Toast.warning('Poruka')
   - Toast.info('Poruka')

   Tema (tamna kartica, gornja traka, tamni gumbi):
   - Toast.setTheme('inverse');
   - Toast.setTheme('default');  — početna svijetla tema
*/

/* Container za toast poruke — poravnato desno, svaki toast širok koliko treba */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    width: auto;
    max-width: none;
    pointer-events: none;
}

/* Pojedinačni toast — širina po sadržaju (ne širi se praznim prostorom) */
.toast-notification {
    position: relative;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    width: auto;
    max-width: min(94vw, 380px);
    background: #fff;
    border-radius: 12px;
    box-shadow:
        0 4px 6px rgba(26, 26, 46, 0.06),
        0 12px 28px rgba(22, 33, 62, 0.12);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.28s ease;
    pointer-events: auto;
    border-left: 4px solid #2d3748;
    overflow: hidden;
}

/* Tekst + animacija odbrojavanja u jednom bloku */
.toast-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
}

.toast-notification.show {
    transform: translateX(0);
    opacity: 1;
}

.toast-notification.hiding {
    transform: translateX(120%);
    opacity: 0;
}

/* Ikona tipa (SVG unutra) */
.toast-icon {
    width: 36px;
    height: 36px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: inherit;
}

.toast-icon .toast-svg {
    width: 20px;
    height: 20px;
    display: block;
}

/* Tekstualni dio — ne širi polje praznog prostora */
.toast-content {
    flex: 0 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
}

.toast-title {
    font-weight: 600;
    font-size: 16px;
    line-height: 1.3;
    color: #1a1a2e;
}

.toast-message {
    font-size: 15px;
    line-height: 1.4;
    color: #4a5568;
    word-wrap: break-word;
}

.toast-message:empty {
    display: none;
}

.toast-title:only-child {
    margin: 0;
}

/* Zatvori */
.toast-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin: 0;
    padding: 0;
    flex-shrink: 0;
    background: #e8eaf0;
    border: none;
    border-radius: 8px;
    color: #4a5568;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}

.toast-close:hover {
    background: #dce0e8;
    color: #2d3748;
}

.toast-close:focus {
    outline: 2px solid rgba(15, 52, 96, 0.35);
    outline-offset: 2px;
}

.toast-close-icon {
    width: 16px;
    height: 16px;
    display: block;
}

/* Odbrojavanje: uska vertikalna traka odmah uz tekst (visina = visina teksta) */
.toast-progress-rail {
    flex-shrink: 0;
    width: 4px;
    align-self: stretch;
    min-height: 0;
    border-radius: 3px;
    background: #e2e8f0;
    position: relative;
    overflow: hidden;
}

.toast-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    transform-origin: bottom center;
    animation: toast-progress-shrink linear forwards;
}

@keyframes toast-progress-shrink {
    from {
        transform: scaleY(1);
    }
    to {
        transform: scaleY(0);
    }
}

/* Tipovi toast-a */

.toast-notification.toast-success {
    border-left-color: #28a745;
    background: #f0faf4;
}
.toast-notification.toast-success .toast-icon {
    background: #d1f0dc;
    color: #1e7e34;
}

.toast-notification.toast-success .toast-progress {
    background: #28a745;
}

.toast-notification.toast-error {
    border-left-color: #dc3545;
    background: #fff5f6;
}
.toast-notification.toast-error .toast-icon {
    background: #fcd8dc;
    color: #c82333;
}

.toast-notification.toast-error .toast-progress {
    background: #dc3545;
}

.toast-notification.toast-warning {
    border-left-color: #d69e2e;
    background: #fffbeb;
}
.toast-notification.toast-warning .toast-icon {
    background: #fdecc8;
    color: #b7791f;
}

.toast-notification.toast-warning .toast-progress {
    background: #d69e2e;
}

.toast-notification.toast-info {
    border-left-color: #0f3460;
    background: #f2f6fa;
}
.toast-notification.toast-info .toast-icon {
    background: #d3e0ed;
    color: #0f3460;
}

.toast-notification.toast-info .toast-progress {
    background: #0f3460;
}

/* Loading — spinner u ikoni */
.toast-notification.toast-loading {
    border-left-color: #667eea;
    background: #f5f6ff;
}
.toast-notification.toast-loading .toast-icon {
    background: transparent;
    border: 3px solid #e2e8f0;
    border-top-color: #667eea;
    animation: toast-spin 0.75s linear infinite;
    width: 36px;
    height: 36px;
}

/* SPA / minimal loader — samo animacija, bez naslova i gumba za zatvaranje */
.toast-notification.toast-loading.toast-minimal {
    padding: 14px;
    max-width: none;
    border-left: none;
    border-top: 3px solid rgba(40, 167, 69, 0.55);
    background: linear-gradient(145deg, rgba(26, 26, 46, 0.92) 0%, rgba(22, 33, 62, 0.94) 50%, rgba(15, 52, 96, 0.92) 100%);
    box-shadow:
        0 8px 32px rgba(0, 0, 0, 0.35),
        0 0 0 1px rgba(248, 250, 252, 0.08) inset;
}

.toast-notification.toast-loading.toast-minimal .toast-icon {
    position: relative;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    animation: none;
    background: transparent;
    box-shadow: none;
}

.toast-notification.toast-loading.toast-minimal .toast-icon::before,
.toast-notification.toast-loading.toast-minimal .toast-icon::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid rgba(248, 250, 252, 0.15);
}

.toast-notification.toast-loading.toast-minimal .toast-icon::before {
    border-top-color: #28a745;
    border-right-color: rgba(40, 167, 69, 0.45);
    animation: toast-spin 0.85s linear infinite;
}

.toast-notification.toast-loading.toast-minimal .toast-icon::after {
    inset: 9px;
    border-width: 2px;
    border-color: rgba(248, 250, 252, 0.08);
    border-bottom-color: rgba(248, 250, 252, 0.72);
    animation: toast-spin 1.25s linear infinite reverse;
}

@keyframes toast-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .toast-notification.toast-loading.toast-minimal .toast-icon::before,
    .toast-notification.toast-loading.toast-minimal .toast-icon::after {
        animation-duration: 2s;
    }
}

/* ========= Inverzna tema (tamna kartica, akcent GORE, tamni gumbi) ========= */

.toast-container.toast-theme-inverse .toast-notification {
    border-left: none;
    border-top: 4px solid transparent;
    background: #1c1c30;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.5),
        0 14px 36px rgba(0, 0, 0, 0.55);
}

.toast-container.toast-theme-inverse .toast-title {
    color: #f7fafc;
}

.toast-container.toast-theme-inverse .toast-message {
    color: #cbd5e0;
}

.toast-container.toast-theme-inverse .toast-close {
    background: #12121f;
    color: #cbd5e0;
    border: 1px solid #2d3142;
    box-shadow: none;
}

.toast-container.toast-theme-inverse .toast-close:hover {
    background: #252538;
    color: #f7fafc;
    border-color: #3d4159;
}

.toast-container.toast-theme-inverse .toast-close:focus {
    outline-color: rgba(72, 187, 120, 0.45);
}

.toast-container.toast-theme-inverse .toast-progress-rail {
    background: #2d2d44;
}

/* Success */
.toast-container.toast-theme-inverse .toast-notification.toast-success {
    border-top-color: #48bb78;
    background: linear-gradient(180deg, #1f3028 0%, #1c1c30 42%, #181825 100%);
}
.toast-container.toast-theme-inverse .toast-notification.toast-success .toast-icon {
    background: #2d4a3c;
    color: #9ae6b4;
    box-shadow: inset 0 0 0 1px #3d6654;
}
.toast-container.toast-theme-inverse .toast-notification.toast-success .toast-progress {
    background: linear-gradient(90deg, #38a169, #68d391);
}

/* Error */
.toast-container.toast-theme-inverse .toast-notification.toast-error {
    border-top-color: #fc8181;
    background: linear-gradient(180deg, #301f24 0%, #1c1c30 42%, #181822 100%);
}
.toast-container.toast-theme-inverse .toast-notification.toast-error .toast-icon {
    background: #4a2d35;
    color: #feb2b2;
    box-shadow: inset 0 0 0 1px #6b3e4a;
}
.toast-container.toast-theme-inverse .toast-notification.toast-error .toast-progress {
    background: linear-gradient(90deg, #e53e3e, #fc8181);
}

/* Warning */
.toast-container.toast-theme-inverse .toast-notification.toast-warning {
    border-top-color: #f6e05e;
    background: linear-gradient(180deg, #2e2a1e 0%, #1c1c30 42%, #181824 100%);
}
.toast-container.toast-theme-inverse .toast-notification.toast-warning .toast-icon {
    background: #4a442e;
    color: #faf089;
    box-shadow: inset 0 0 0 1px #6b633f;
}
.toast-container.toast-theme-inverse .toast-notification.toast-warning .toast-progress {
    background: linear-gradient(90deg, #d69e2e, #f6e05e);
}

/* Info */
.toast-container.toast-theme-inverse .toast-notification.toast-info {
    border-top-color: #63b3ed;
    background: linear-gradient(180deg, #1a2638 0%, #1c1c30 42%, #181824 100%);
}
.toast-container.toast-theme-inverse .toast-notification.toast-info .toast-icon {
    background: #2c3d52;
    color: #90cdf4;
    box-shadow: inset 0 0 0 1px #3e5570;
}
.toast-container.toast-theme-inverse .toast-notification.toast-info .toast-progress {
    background: linear-gradient(90deg, #0f3460, #63b3ed);
}

/* Loading */
.toast-container.toast-theme-inverse .toast-notification.toast-loading {
    border-top-color: #a3bffa;
    background: linear-gradient(180deg, #222838 0%, #1c1c30 42%, #181824 100%);
}
.toast-container.toast-theme-inverse .toast-notification.toast-loading .toast-icon {
    border: 3px solid #3d4359;
    border-top-color: #a3bffa;
    box-shadow: none;
}

.toast-container.toast-theme-inverse .toast-notification.toast-loading.toast-minimal .toast-icon {
    border: none;
    animation: none;
}

/* Responsive */
@media (max-width: 480px) {
    .toast-container {
        left: 10px;
        right: 10px;
        width: auto;
        max-width: none;
    }

    .toast-notification {
        transform: translateY(-120%);
    }

    .toast-notification.show {
        transform: translateY(0);
    }

    .toast-notification.hiding {
        transform: translateY(-120%);
    }
}
