/* Global modal overlay — portaled to document.body */
html.modal-formal-open {
    overflow: hidden;
}

.modal-backdrop-formal {
    position: fixed;
    inset: 0;
    z-index: 6000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(1rem, 3vh, 2rem) clamp(0.75rem, 2vw, 1.5rem);
    box-sizing: border-box;
    background:
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(0, 103, 71, 0.12), transparent 55%),
        rgba(15, 23, 42, 0.62);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: backdropFadeIn 0.28s ease-out;
}

@keyframes backdropFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalEnter {
    from {
        opacity: 0;
        transform: scale(0.94);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-formal {
    position: relative;
    display: flex;
    flex-direction: column;
    width: min(100%, var(--modal-formal-max-width, 800px));
    max-height: min(90vh, calc(100dvh - 2.5rem));
    margin: auto;
    background: #ffffff;
    border-radius: 16px;
    border: 1px solid rgba(0, 103, 71, 0.12);
    box-shadow:
        0 4px 6px rgba(15, 23, 42, 0.04),
        0 24px 48px rgba(15, 23, 42, 0.18),
        0 0 0 1px rgba(255, 255, 255, 0.6) inset;
    overflow: hidden;
    animation: modalEnter 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.modal-formal--wide {
    max-height: min(92vh, calc(100dvh - 2rem));
}

.modal-formal--excel-import {
    width: min(96vw, var(--modal-formal-max-width, 1750px)) !important;
    height: min(94vh, calc(100dvh - 2rem));
    min-height: min(88vh, calc(100dvh - 3rem));
    max-height: min(94vh, calc(100dvh - 2rem));
}

.modal-formal--order-status {
    width: min(98vw, var(--modal-formal-max-width, 1600px)) !important;
    height: min(92vh, calc(100dvh - 2rem));
    max-height: min(92vh, calc(100dvh - 2rem));
}

.modal-formal--order-status .osu-modal-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    background: #fff;
}

.modal-formal--excel-import .modal-body--flush {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 0;
    background: #fff;
}

.modal-formal--excel-import .modal-body--flush > .excel-import-container--parsed {
    flex: 1 1 auto;
    min-height: 0;
}

/* Header */
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.15rem 1.5rem;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafb 100%);
    border-bottom: 1px solid #e8edf0;
    flex-shrink: 0;
    position: relative;
}

.modal-header::after {
    content: '';
    position: absolute;
    inset-inline-start: 0;
    inset-block: 0;
    width: 4px;
    background: linear-gradient(180deg, #059669 0%, #006747 100%);
    border-radius: 0 4px 4px 0;
}

.modal-header-content {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    min-width: 0;
    flex: 1;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.modal-header-actions .excel-header-upload-btn,
.modal-header-actions .excel-upload-reset-btn {
    white-space: nowrap;
}

.modal-icon {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.15rem;
    background: linear-gradient(145deg, #059669 0%, #006747 100%);
    box-shadow: 0 4px 14px rgba(0, 103, 71, 0.28);
}

.modal-icon--info {
    background: linear-gradient(135deg, #006747 0%, #00875f 100%);
    color: #fff;
}

.modal-icon--excel {
    background: linear-gradient(145deg, #10b981 0%, #047857 100%);
    box-shadow: 0 4px 14px rgba(5, 150, 105, 0.35);
}

.modal-icon--danger {
    background: linear-gradient(145deg, #ef4444 0%, #b91c1c 100%);
    box-shadow: 0 4px 14px rgba(220, 38, 38, 0.35);
}

.modal-title-section {
    flex: 1;
    min-width: 0;
}

.modal-title {
    margin: 0;
    font-weight: 700;
    color: #0f172a;
    font-size: 1.2rem;
    line-height: 1.35;
    letter-spacing: -0.02em;
}

.modal-subtitle {
    margin: 0.2rem 0 0;
    color: #64748b;
    font-size: 0.8125rem;
    line-height: 1.45;
}

.modal-close-btn {
    flex-shrink: 0;
    margin-inline-start: auto;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.15s;
}

.modal-close-btn:hover {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
    transform: scale(1.04);
}

/* Body */
.modal-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
    background: #f8fafc;
}

.modal-body--flush {
    padding: 0;
    background: #fff;
}

/* Footer */
.modal-footer {
    flex-shrink: 0;
    padding: 0.875rem 1.5rem;
    background: #fff;
    border-top: 1px solid #e8edf0;
}

.modal-footer-inner {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 0.65rem 0.75rem;
    width: 100%;
}

.modal-footer .btn {
    padding: 0.55rem 1.15rem;
    font-weight: 600;
    font-size: 0.9rem;
    border-radius: 10px;
    transition: transform 0.15s, box-shadow 0.15s;
}

.modal-footer .btn:active:not(:disabled) {
    transform: scale(0.98);
}

.modal-footer .btn-outline-secondary {
    border: 1px solid #cbd5e1;
    color: #475569;
    background: #fff;
}

.modal-footer .btn-outline-secondary:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #334155;
}

.modal-footer .btn-success,
.modal-footer .btn-primary {
    background: linear-gradient(145deg, #059669 0%, #006747 100%);
    border: none;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0, 103, 71, 0.28);
}

.modal-footer .btn-success:hover:not(:disabled),
.modal-footer .btn-primary:hover:not(:disabled) {
    background: linear-gradient(145deg, #047857 0%, #004e38 100%);
    box-shadow: 0 4px 14px rgba(0, 103, 71, 0.35);
    transform: translateY(-1px);
}

.modal-footer .btn-success:disabled,
.modal-footer .btn-primary:disabled {
    opacity: 0.55;
    box-shadow: none;
}

.modal-body .form-label {
    font-weight: 600;
    color: #334155;
    margin-bottom: 0.4rem;
    font-size: 0.875rem;
}

.modal-body .form-control,
.modal-body .form-select {
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.55rem 0.85rem;
    font-size: 0.9rem;
}

.modal-body .form-control:focus,
.modal-body .form-select:focus {
    border-color: #059669;
    box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

/* RTL */
.modal-formal--rtl,
.modal-formal[dir="rtl"] {
    direction: rtl;
    text-align: right;
}

.modal-formal--rtl .modal-header,
.modal-formal[dir="rtl"] .modal-header {
    direction: rtl;
}

.modal-formal--rtl .modal-header::after,
.modal-formal[dir="rtl"] .modal-header::after {
    inset-inline-start: auto;
    inset-inline-end: 0;
    border-radius: 4px 0 0 4px;
}

.modal-formal--rtl .modal-header-content,
.modal-formal[dir="rtl"] .modal-header-content {
    flex-direction: row;
}

.modal-formal--rtl .modal-title,
.modal-formal--rtl .modal-subtitle,
.modal-formal[dir="rtl"] .modal-title,
.modal-formal[dir="rtl"] .modal-subtitle {
    text-align: right;
}

.modal-formal--rtl .modal-footer-inner,
.modal-formal[dir="rtl"] .modal-footer-inner {
    flex-direction: row-reverse;
    justify-content: flex-start;
}

.modal-formal--rtl .modal-body,
.modal-formal[dir="rtl"] .modal-body {
    direction: rtl;
    text-align: right;
}

@media (max-width: 768px) {
    .modal-backdrop-formal {
        padding: 0.65rem;
        align-items: flex-end;
    }

    .modal-formal {
        max-height: min(94vh, calc(100dvh - 1rem));
        border-radius: 16px 16px 0 0;
    }

    .modal-header {
        padding: 1rem 1.15rem;
    }

    .modal-body {
        padding: 1rem 1.15rem;
    }

    .modal-footer {
        padding: 0.75rem 1.15rem 1rem;
    }

    .modal-footer-inner {
        flex-direction: column-reverse;
        align-items: stretch;
    }

    .modal-footer .btn {
        width: 100%;
    }

    .modal-icon {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .modal-title {
        font-size: 1.05rem;
    }
}
