/*
 * TG Notify - toast messages, confirmation modal and API error popup.
 * Colours follow the dashboard theme (assets/global/css/dashboard/style.css).
 */
:root {
    --tg-red: #CD1B28;
    --tg-dark: #334155;
    --tg-light-black: #4D4D4D;
    --tg-navy: #1e3a5f;
    --tg-grey: #64748b;
    --tg-light-grey: #f1f5f9;
    --tg-success: #15803d;
    --tg-warning: #b45309;
    --tg-font: 'Montserrat', sans-serif;
}

/* ---------- Toast ---------- */
.tg-toast-stack {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20010;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
    max-width: calc(100vw - 32px);
    pointer-events: none;
}

.tg-toast {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    width: max-content;
    min-width: 260px;
    max-width: 420px;
    padding: 12px 12px 12px 16px;
    border-radius: 6px;
    color: #fff;
    background: var(--tg-navy);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18), 0 1px 3px rgba(15, 23, 42, 0.12);
    font-family: var(--tg-font);
    font-size: 14px;
    font-weight: 500;
    letter-spacing: 0.1px;
    line-height: 1.4;
    overflow: hidden;
    pointer-events: auto;
    animation: tg-toast-in 0.25s ease-out;
}

.tg-toast--success { background: var(--tg-success); }
.tg-toast--error   { background: var(--tg-red); }
.tg-toast--warning { background: var(--tg-warning); }
.tg-toast--info    { background: var(--tg-navy); }

.tg-toast.is-leaving {
    animation: tg-toast-out 0.2s ease-in forwards;
}

.tg-toast__icon {
    flex: 0 0 18px;
    display: flex;
    width: 18px;
    height: 18px;
}

.tg-toast__icon svg {
    display: block;
    width: 18px;
    height: 18px;
}

.tg-toast__msg {
    flex: 1 1 auto;
    min-width: 0;
    white-space: pre-line;
    word-break: break-word;
}

/* Long messages: fixed width, icon and close stay on the first line, very long text scrolls */
.tg-toast--multi {
    width: 400px;
    align-items: flex-start;
    padding-top: 13px;
    padding-bottom: 14px;
}

.tg-toast--multi .tg-toast__icon {
    margin-top: 1px;
}

.tg-toast--multi .tg-toast__close {
    margin-top: -4px;
}

.tg-toast--multi .tg-toast__msg {
    max-height: 9.8em; /* ~7 lines */
    overflow-y: auto;
    padding-right: 2px;
    line-height: 1.45;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.5) transparent;
}

.tg-toast__close {
    flex: 0 0 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin-left: 4px;
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: 20px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    opacity: 0.85;
    transition: background-color 0.15s, opacity 0.15s;
}

.tg-toast__close:hover,
.tg-toast__close:focus-visible {
    opacity: 1;
    background: rgba(255, 255, 255, 0.16);
    outline: none;
}

.tg-toast__bar {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 2px;
    width: 100%;
    background: rgba(255, 255, 255, 0.4);
    transform-origin: left center;
    animation: tg-toast-bar linear forwards;
}

.tg-toast:hover .tg-toast__bar {
    animation-play-state: paused;
}

@keyframes tg-toast-in {
    from { opacity: 0; transform: translateX(24px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes tg-toast-out {
    to { opacity: 0; transform: translateX(24px); }
}

@keyframes tg-toast-bar {
    from { transform: scaleX(1); }
    to   { transform: scaleX(0); }
}

/* ---------- Modal (confirm + API error) ---------- */
.tg-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(15, 23, 42, 0.45);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    animation: tg-fade-in 0.15s ease-out;
}

.tg-modal {
    width: 100%;
    max-width: 500px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 32px 28px 26px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.25);
    text-align: center;
    font-family: var(--tg-font);
    color: var(--tg-dark);
    animation: tg-pop-in 0.2s ease-out;
}

.tg-modal__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    margin: 0 auto 18px;
    border: 3px solid var(--tg-red);
    border-radius: 50%;
    color: var(--tg-red);
    font-size: 40px;
    font-weight: 600;
    line-height: 1;
}

.tg-modal__icon--info {
    border-color: var(--tg-navy);
    color: var(--tg-navy);
}

.tg-modal__chip {
    display: inline-block;
    margin-bottom: 12px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--tg-light-grey);
    color: var(--tg-grey);
    font-size: 13px;
}

.tg-modal__chip b {
    color: var(--tg-dark);
}

.tg-modal__title {
    margin: 0 0 8px;
    color: var(--tg-dark);
    font-family: var(--tg-font);
    font-size: 20px;
    font-weight: 600;
    line-height: 1.35;
    word-break: break-word;
}

.tg-modal__text {
    margin: 0;
    color: var(--tg-grey);
    font-size: 15px;
    line-height: 1.55;
    white-space: pre-line;
    overflow-wrap: anywhere; /* long API URLs wrap cleanly */
}

/* ---------- API error popup ---------- */
.tg-modal--error {
    max-width: 480px;
    padding: 34px 32px 28px;
    border-radius: 8px;
}

.tg-modal--error .tg-modal__icon {
    margin-bottom: 20px;
}

.tg-modal--error .tg-modal__title {
    margin-bottom: 6px;
    font-size: 20px;
    font-weight: 600;
}

.tg-modal--error .tg-modal__text {
    color: var(--tg-grey);
    font-size: 14.5px;
}

/* Request / Method / Response details box */
.tg-modal__request {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 18px 0 0;
    padding: 14px 16px;
    border: 1px solid #edf0f4;
    border-radius: 8px;
    background: #fafbfc;
    text-align: left;
    font-size: 13px;
    line-height: 1.45;
}

.tg-modal__request-label {
    margin: 0;
    color: var(--tg-grey);
    font-weight: 500;
}

.tg-modal__request-value {
    margin: 0;
    min-width: 0;
    color: var(--tg-dark);
    font-family: Consolas, 'Courier New', monospace;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.tg-modal__request-value--status {
    color: var(--tg-red);
}

/* first part of an invalid (non-JSON) response, for developers */
.tg-modal__request-value--output {
    max-height: 72px;
    overflow-y: auto;
    color: var(--tg-grey);
    font-weight: 400;
    font-size: 12px;
}
.tg-modal__more {
    margin-top: 6px;
    padding: 0;
    border: 0;
    background: none;
    color: var(--tg-navy);
    font-family: var(--tg-font);
    font-size: 13px;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
}

.tg-modal__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 24px;
}

.tg-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
    justify-content: center;
    padding: 10px 24px;
    border: 0;
    border-radius: 6px;
    color: #fff;
    font-family: var(--tg-font);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}

.tg-btn:hover { opacity: 0.9; }

.tg-btn:focus {
    outline: none;
}

.tg-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(77, 77, 77, 0.18);
}

.tg-btn--primary { background: var(--tg-red); }
.tg-btn--dark    { background: var(--tg-light-black); }

/* ---------- Loader (Notiflix.Loading) ---------- */
.tg-loading {
    position: fixed;
    inset: 0;
    z-index: 20005;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: rgba(15, 23, 42, 0.35);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    animation: tg-fade-in 0.15s ease-out;
}

.tg-loading__spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 255, 255, 0.35);
    border-top-color: var(--tg-red);
    border-radius: 50%;
    animation: tg-spin 0.8s linear infinite;
}

.tg-loading__text {
    padding: 6px 14px;
    border-radius: 6px;
    background: #fff;
    color: var(--tg-dark);
    font-family: var(--tg-font);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
}

@keyframes tg-spin {
    to { transform: rotate(360deg); }
}

@keyframes tg-fade-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes tg-pop-in {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

@media (max-width: 480px) {
    .tg-toast-stack { top: 10px; right: 10px; max-width: calc(100vw - 20px); }
    .tg-toast { min-width: 0; max-width: 100%; }
    .tg-toast--multi { width: 100%; }
    .tg-modal { padding: 26px 18px 20px; }
    .tg-modal__title { font-size: 18px; }
}

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