
/* =========================================
   GLOBAL MESSAGE BOX
========================================= */

.global-message {
    position: fixed;

    right: 24px;
    bottom: 80px;

    transform: translate3d(calc(100% + 40px), 0, 0);

    width: min(420px, calc(100vw - 48px));
    min-height: 70px;

    display: grid;
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    gap: 12px;

    padding: 13px 16px;

    background: #ffffff;
    color: #263442;

    border: 1px solid #e4e8ed;
    border-right: 4px solid #3979a9;
    border-radius: 13px;

    box-shadow: 0 12px 40px rgba(23, 44, 66, .16);

    z-index: 200000;

    opacity: 0;
    visibility: hidden;

    transition:
        opacity .5s ease,
        transform .6s cubic-bezier(.22, 1, .36, 1),
        visibility 0s linear .6s;

    font-family: Vazirmatn, Tahoma, sans-serif;

    will-change: transform, opacity;
}

.global-message[hidden] {
    display: none !important;
}


/* =========================================
   VISIBLE STATE
========================================= */

.global-message.is-visible {
    opacity: 1;
    visibility: visible;

    transform: translate3d(0, 0, 0);

    transition:
        opacity .5s ease,
        transform .6s cubic-bezier(.22, 1, .36, 1),
        visibility 0s;
}


/* =========================================
   CONFIRMATION LAYOUT
========================================= */

.global-message--confirmation {
    grid-template-columns: 36px minmax(0, 1fr);
}


/* =========================================
   MESSAGE TEXT
========================================= */

.global-message-text {
    font-size: 13px;
    line-height: 2;
    font-weight: 500;
    overflow-wrap: anywhere;
}


/* =========================================
   MESSAGE ICON
========================================= */

.global-message-icon {
    width: 34px;
    height: 34px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 50%;
    font-size: 19px;
    font-weight: bold;
}


/* =========================================
   MESSAGE ACTIONS
========================================= */

.global-message-actions {
    grid-column: 2 / 3;

    display: flex;
    align-items: center;
    gap: 9px;

    margin-top: 8px;
}

.global-message-actions[hidden] {
    display: none !important;
}

.global-message-action {
    min-width: 90px;

    padding: 7px 14px;

    border: 1px solid transparent;
    border-radius: 8px;

    font-family: inherit;
    font-size: 12px;
    font-weight: 600;

    cursor: pointer;

    transition:
        background .2s,
        color .2s,
        border-color .2s,
        transform .2s;
}

.global-message-action:active {
    transform: scale(.97);
}


/* تأیید */

.global-message-confirm {
    background: #27844d;
    color: #ffffff;
}

.global-message-confirm:hover {
    background: #206d40;
}


/* انصراف */

.global-message-cancel {
    background: #f2f4f6;
    color: #59656d;
    border-color: #e2e6e9;
}

.global-message-cancel:hover {
    background: #e7ebee;
}


/* =========================================
   MESSAGE TYPES
========================================= */

.global-message--error {
    border-right-color: #c64d4d;
}

.global-message--error .global-message-icon {
    background: #fff0ef;
    color: #c64d4d;
}

.global-message--error .global-message-icon::before {
    content: "!";
}


.global-message--success {
    border-right-color: #27844d;
}

.global-message--success .global-message-icon {
    background: #edf8f1;
    color: #27844d;
}

.global-message--success .global-message-icon::before {
    content: "✓";
}


.global-message--warning {
    border-right-color: #b98523;
}

.global-message--warning .global-message-icon {
    background: #fff8e8;
    color: #b98523;
}

.global-message--warning .global-message-icon::before {
    content: "!";
}


.global-message--info {
    border-right-color: #3979a9;
}

.global-message--info .global-message-icon {
    background: #edf5fc;
    color: #3979a9;
}

.global-message--info .global-message-icon::before {
    content: "i";
}


/* =========================================
   RESPONSIVE
========================================= */

@media (max-width: 600px) {

    .global-message {
        right: 12px;
        bottom: 24px;

        width: calc(100vw - 24px);

        padding: 11px 12px;
        gap: 9px;
    }

    .global-message-text {
        font-size: 12px;
    }

    .global-message-actions {
        gap: 7px;
    }

    .global-message-action {
        min-width: 80px;
        padding: 7px 11px;
        font-size: 11px;
    }
}


/* =========================================
   ACCESSIBILITY
========================================= */

@media (prefers-reduced-motion: reduce) {

    .global-message,
    .global-message.is-visible {
        transition: none;
    }
}

.global-message-stack {
    position: fixed;
    right: 24px;
    bottom: 80px;
    z-index: 199999;
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: min(420px, calc(100vw - 48px));
    max-height: 65dvh;
    overflow: hidden auto;
    scrollbar-width: none;
    pointer-events: none;
}

body:has(#globalMessage.global-message--confirmation:not([hidden])) .global-message-stack {
    bottom: calc(90px + var(--message-confirmation-height, 96px));
}

.global-message--stacked {
    visibility: visible;
    position: relative;
    inset: auto;
    box-sizing: border-box;
    flex: 0 0 auto;
    width: 100%;
    min-height: calc(62px - 4px * var(--message-stack-compression, 0));
    padding-block: calc(10px - 1px * var(--message-stack-compression, 0));
    grid-template-columns: 28px minmax(0, 1fr);
    gap: 8px;
    transition: opacity .35s ease, transform .35s ease, min-height .2s ease, padding .2s ease;
}

.global-message--stacked.is-visible {
    transition: opacity .35s ease, transform .35s ease, min-height .2s ease, padding .2s ease;
}

.global-message--stacked .global-message-icon {
    width: calc(26px - 1px * var(--message-stack-compression, 0));
    height: calc(26px - 1px * var(--message-stack-compression, 0));
    font-size: 15px;
}

@media (prefers-reduced-motion: reduce) {
    .global-message--stacked,
    .global-message--stacked.is-visible { transition: none; }
}
