.app-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.72);
}

#errorModal {
    z-index: calc(var(--z-modal) + 1);
}

body #error-modal-container {
    position: relative;
    z-index: var(--z-error);
}

.app-modal-dialog {
    width: min(100%, 440px);
    max-height: 100%;
    overflow-y: auto;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--bg-card);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
}

.app-modal-dialog-wide { width: min(100%, 600px); }

.app-modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 20px 0;
}

.app-modal-title {
    margin: 0;
    color: var(--text-main);
    font-size: 22px;
    line-height: 1.15;
    font-weight: var(--heading-weight);
}

.app-modal-close span {
    font-size: 22px;
    line-height: 1;
}

.app-modal-body {
    display: grid;
    gap: 18px;
    padding: 20px;
}

.app-modal-stack {
    display: grid;
    gap: 8px;
}

.app-modal-copy {
    margin: 0;
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.45;
}

.app-modal-copy.is-muted {
    color: var(--text-muted);
}

.captcha-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.captcha-image {
    display: block;
    max-width: calc(100% - 54px);
    height: auto;
    border-radius: 5px;
}

.captcha-refresh-button {
    width: 44px;
    min-height: 44px;
    flex-basis: 44px;
}

.captcha-refresh-button:disabled {
    cursor: wait;
    opacity: 0.5;
}

.captcha-refresh-button span {
    font-size: 26px;
    line-height: 1;
}

.app-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.app-modal-actions .btn {
    min-width: 120px;
}

.app-modal-submit {
    width: 100%;
}

.app-modal-primary-actions {
    display: grid;
    gap: 10px;
}

.app-modal-text-action {
    justify-self: center;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.4;
}

.app-modal-text-action-muted {
    color: var(--text-muted);
}

.app-modal-code-input {
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.28em;
}

.app-modal-notice-icon {
    color: var(--success);
    font-weight: 700;
}

.app-modal-tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.app-modal-tab { min-height: 42px; }

.app-modal-tab.is-active,
.app-modal-tab.is-active:not(:disabled):hover {
    color: var(--bg-main);
    border-color: var(--accent);
    background: var(--accent);
}

.app-modal-form {
    display: grid;
    gap: 18px;
}

.app-modal-message {
    margin: 0;
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.45;
}

@media (max-width: 640px) {
    .app-modal {
        padding: 12px;
    }

    .app-modal-head,
    .app-modal-body {
        padding-left: 16px;
        padding-right: 16px;
    }

    .app-modal-actions {
        flex-direction: column-reverse;
    }

    .app-modal-actions .btn {
        width: 100%;
    }
}

.app-modal-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 13px;
}

.app-modal-divider::before,
.app-modal-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-soft);
}

.app-modal-telegram img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.app-modal-legal {
    margin: -4px 0 0;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
}

.app-modal-legal a {
    color: rgba(203, 213, 225, 0.9);
    text-decoration: underline;
    text-decoration-color: rgba(148, 163, 184, 0.42);
    text-underline-offset: 2px;
}

.app-modal-legal a:hover {
    color: var(--text-main);
    text-decoration-color: rgba(203, 213, 225, 0.8);
}
