.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(8px);
    padding: 20px;
}

.modal-overlay.is-open {
    display: flex;
}

.modal-box {
    position: relative;
    width: min(620px, 100%);
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 22px;
    box-shadow: 0 30px 80px rgba(2, 8, 23, 0.25);
    animation: modalIn 0.18s ease-out;
    border: 1px solid #e2e8f0;
}

.modal-box.modal-large {
    width: min(980px, calc(100% - 32px));
}

.modal-box:focus-visible {
    outline: 2px solid #0f766e;
    outline-offset: 2px;
}

.modal-header {
    flex: 0 0 auto;
    padding: 24px 28px 18px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
    margin: 0;
    font-size: clamp(24px, 3vw, 30px);
    line-height: 1.1;
    color: #0f172a;
}

.modal-header p {
    margin: 8px 0 0;
    color: #64748b;
    line-height: 1.45;
}

.modal-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 24px 28px;
    overflow-y: auto;
}

.modal-body > :first-child {
    margin-top: 0;
}

.modal-body > :last-child {
    margin-bottom: 0;
}

.modal-body form {
    display: grid;
    gap: 12px;
}

.modal-body label {
    font-weight: 600;
    color: #0f172a;
    font-size: 14px;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    color: #0f172a;
    background: #ffffff;
}

.modal-body textarea {
    min-height: 120px;
    resize: vertical;
}

.modal-body input[type="date"] {
    width: 100%;
    box-sizing: border-box;
}

.modal-body input:focus,
.modal-body select:focus,
.modal-body textarea:focus {
    outline: none;
    border-color: #0f766e;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.modal-footer {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: #ffffff;
    padding: 16px 28px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid #e2e8f0;
}

.modal-hidden-submit {
    display: none !important;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 18px;
    border: none;
    background: transparent;
    color: #334155;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    color: #0f172a;
}

.modal-overlay .modal-btn {
    min-height: 42px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    padding: 0 16px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: transform 0.18s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

.modal-footer .btn {
    min-height: 42px;
}

.modal-overlay .modal-btn:hover {
    transform: translateY(-1px);
}

.modal-overlay .modal-btn-primary {
    background: #0f766e;
    border-color: #0f766e;
    color: #ffffff;
}

.modal-overlay .modal-btn-primary:hover {
    filter: brightness(0.96);
    box-shadow: 0 12px 24px rgba(15, 118, 110, 0.22);
}

.modal-overlay .modal-btn-neutral {
    background: #ffffff;
    color: #0f172a;
}

.modal-overlay .modal-btn-danger {
    background: #dc2626;
    border-color: #dc2626;
    color: #ffffff;
}

.modal-overlay .modal-btn-danger:hover {
    filter: brightness(0.95);
    box-shadow: 0 12px 24px rgba(220, 38, 38, 0.24);
}

.modal-alert {
    border-radius: 12px;
    border: 1px solid transparent;
    padding: 12px 14px;
    font-size: 14px;
    margin-bottom: 12px;
}

.modal-alert-success {
    background: #ecfdf3;
    border-color: #86efac;
    color: #065f46;
}

.modal-alert-error {
    background: #fff1f2;
    border-color: #fda4af;
    color: #9f1239;
}

.modal-alert-warning {
    background: #fffbeb;
    border-color: #fcd34d;
    color: #92400e;
}

.modal-alert-info {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.modal-errors {
    margin-bottom: 12px;
    border-radius: 10px;
    border: 1px solid #fda4af;
    background: #fff1f2;
    color: #9f1239;
    padding: 10px 12px;
    font-size: 14px;
}

.modal-errors ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.modal-form-loading {
    opacity: 0.7;
    pointer-events: none;
}

.modal-variant-danger .modal-header h2 {
    color: #991b1b;
}

.modal-variant-danger #modalSubtitle {
    color: #b91c1c;
    font-weight: 500;
}

.modal-variant-success .modal-header h2 {
    color: #065f46;
}

.modal-variant-warning .modal-header h2 {
    color: #92400e;
}

.modal-variant-info .modal-header h2 {
    color: #1d4ed8;
}

body.modal-open {
    overflow: hidden;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 640px) {
    .modal-overlay {
        align-items: flex-end;
        padding: 0;
    }

    .modal-box {
        width: 100%;
        max-height: 92vh;
        border-radius: 24px 24px 0 0;
    }

    .modal-header,
    .modal-body {
        padding-left: 20px;
        padding-right: 20px;
    }

    .modal-footer {
        padding: 14px 20px 20px;
        flex-direction: column-reverse;
    }

    .modal-footer .modal-btn {
        width: 100%;
    }

    .modal-footer .btn {
        width: 100%;
    }
}
