/* ====================================
   MODERN MODAL DIALOG - MFA CHALLENGES
   ==================================== */

/* Modal Variables (inherit from main theme) */
:root {
    --modal-overlay-bg: rgba(0, 0, 0, 0.6);
    --modal-bg: #ffffff;
    --modal-border-radius: 1rem;
    --modal-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --modal-padding: 2rem;
    --modal-max-width: 500px;
}

/* Modal Overlay */
.modal {
    display: none;
}

.modal.is-open {
    display: block;
}

.modal[aria-hidden="false"] .modal__overlay {
    animation: mmfadeIn 0.3s cubic-bezier(0, 0, 0.2, 1);
}

.modal[aria-hidden="false"] .modal__container {
    animation: mmslideIn 0.3s cubic-bezier(0, 0, 0.2, 1);
}

.modal[aria-hidden="true"] .modal__overlay {
    animation: mmfadeOut 0.3s cubic-bezier(0, 0, 0.2, 1);
}

.modal[aria-hidden="true"] .modal__container {
    animation: mmslideOut 0.3s cubic-bezier(0, 0, 0.2, 1);
}

.modal__overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--modal-overlay-bg);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    padding: 1rem;
}

/* Modal Container */
.modal__container {
    background-color: var(--modal-bg);
    padding: 0;
    max-width: var(--modal-max-width);
    width: 100%;
    border-radius: var(--modal-border-radius);
    overflow: hidden;
    box-shadow: var(--modal-shadow);
    position: relative;
    animation: modalPulse 0.5s ease-out;
}

@-webkit-keyframes modalPulse {
    0% { -webkit-transform: scale(0.95); transform: scale(0.95); opacity: 0; }
    50% { -webkit-transform: scale(1.02); transform: scale(1.02); }
    100% { -webkit-transform: scale(1); transform: scale(1); opacity: 1; }
}
@keyframes modalPulse {
    0% {
        transform: scale(0.95);
        opacity: 0;
    }
    50% {
        transform: scale(1.02);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Modal Header */
.modal__header {
    padding: var(--modal-padding);
    padding-bottom: 1rem;
    border-bottom: 1px solid #e5e7eb;
    position: relative;
    background: linear-gradient(135deg, #00B5AD 0%, #00A651 100%);
    color: white;
}

.modal__title {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.25;
    color: white;
    letter-spacing: -0.025em;
}

.modal__close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 0.5rem;
    transition: all 0.2s;
    color: white;
    font-size: 1.5rem;
    line-height: 1;
}

.modal__close:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: rotate(90deg);
}

.modal__close::before {
    content: "×";
    font-size: 2rem;
}

/* Modal Content */
.modal__content {
    padding: var(--modal-padding);
    line-height: 1.6;
    color: #374151;
}

.modal__content p {
    margin: 0 0 1rem 0;
    font-size: 0.9375rem;
}

#ChallengeText {
    background: #f3f4f6;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid #00B5AD;
    margin-bottom: 1.5rem;
    font-size: 0.9375rem;
    color: #1f2937;
    line-height: 1.6;
}

/* Challenge Code Input */
#challengeCodeInput {
    width: 100%;
    padding: 0.875rem 1rem;
    font-size: 1.125rem;
    font-family: 'Courier New', monospace;
    font-weight: 600;
    letter-spacing: 0.25rem;
    text-align: center;
    color: #1f2937;
    background: #ffffff;
    border: 2px solid #d1d5db;
    border-radius: 0.75rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    margin-bottom: 0.5rem;
}

#challengeCodeInput::placeholder {
    letter-spacing: normal;
    color: #9ca3af;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
}

#challengeCodeInput:focus {
    border-color: #00B5AD;
    box-shadow: 0 0 0 3px rgba(0, 181, 173, 0.15);
    transform: scale(1.02);
}

#challengeCodeInput:disabled {
    background: #f3f4f6;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Modal Error */
#modalError {
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0.5rem 0;
}

#modalErrorText {
    color: #ef4444;
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    background: rgba(239, 68, 68, 0.1);
    margin: 0;
    display: none; /* Hidden by default, shown via JavaScript */
}

#modalErrorText:not(:empty) {
    display: inline-block; /* Show only when there's content */
}

@-webkit-keyframes shake {
    0%, 100% { -webkit-transform: translateX(0); transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { -webkit-transform: translateX(-5px); transform: translateX(-5px); }
    20%, 40%, 60%, 80% { -webkit-transform: translateX(5px); transform: translateX(5px); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

/* Modal Footer */
.modal__footer {
    padding: var(--modal-padding);
    padding-top: 1rem;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    align-items: center;
    background: #f9fafb;
    flex-wrap: wrap;
}

#modalFooterButtons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    width: 100%;
    justify-content: flex-end;
}

/* Modal Buttons */
.modal__btn {
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    outline: none;
    position: relative;
    overflow: hidden;
}

.modal__btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.modal__btn:active::before {
    width: 300px;
    height: 300px;
}

/* Primary Button (Submit) */
.modal__btn-primary {
    background: linear-gradient(135deg, #00B5AD 0%, #00A651 100%);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 181, 173, 0.3);
}

.modal__btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 181, 173, 0.4);
}

.modal__btn-primary:active {
    transform: translateY(0);
}

/* Action Button (Resend) */
.modal__btn-action {
    background: #FDB813;
    color: #1f2937;
    box-shadow: 0 4px 6px -1px rgba(253, 184, 19, 0.3);
    font-weight: 700;
}

.modal__btn-action:hover {
    background: #E5A500;
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(253, 184, 19, 0.4);
}

.modal__btn-action:active {
    transform: translateY(0);
}

/* Default Button (Cancel) */
.modal__btn:not(.modal__btn-primary):not(.modal__btn-action) {
    background: #ffffff;
    color: #374151;
    border: 1px solid #d1d5db;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

.modal__btn:not(.modal__btn-primary):not(.modal__btn-action):hover {
    background: #f9fafb;
    border-color: #9ca3af;
    transform: translateY(-1px);
}

/* Modal Loading */
#modalLoadingArea {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
}

#modalLoading {
    width: 32px;
    height: 32px;
    animation: spin 1s linear infinite;
}

@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Animations */
@-webkit-keyframes mmfadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes mmfadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@-webkit-keyframes mmfadeOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes mmfadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@-webkit-keyframes mmslideIn {
    from { -webkit-transform: translateY(-10%); transform: translateY(-10%); opacity: 0; }
    to { -webkit-transform: translateY(0); transform: translateY(0); opacity: 1; }
}
@keyframes mmslideIn {
    from {
        transform: translateY(-10%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@-webkit-keyframes mmslideOut {
    from { -webkit-transform: translateY(0); transform: translateY(0); opacity: 1; }
    to { -webkit-transform: translateY(-10%); transform: translateY(-10%); opacity: 0; }
}
@keyframes mmslideOut {
    from {
        transform: translateY(0);
        opacity: 1;
    }
    to {
        transform: translateY(-10%);
        opacity: 0;
    }
}

/* Responsive Design */
@media only screen and (max-width: 600px) {
    .modal__overlay {
        padding: 0.5rem;
    }
    
    .modal__container {
        max-width: 100%;
        margin: 0 auto;
    }
    
    .modal__header,
    .modal__content,
    .modal__footer {
        padding: 1.5rem;
    }
    
    .modal__title {
        font-size: 1.25rem;
    }
    
    #modalFooterButtons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal__btn {
        width: 100%;
        justify-content: center;
    }
}

/* Landscape Mobile */
@media only screen and (max-height: 600px) and (orientation: landscape) {
    .modal__overlay {
        align-items: flex-start;
        overflow-y: auto;
        padding: 1rem;
    }
    
    .modal__container {
        margin: 1rem auto;
    }
    
    .modal__header,
    .modal__content,
    .modal__footer {
        padding: 1rem;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    .modal__overlay,
    .modal__container,
    .modal__btn,
    #challengeCodeInput {
        animation: none !important;
        transition: none !important;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .modal__container {
        border: 2px solid #000;
    }
    
    #challengeCodeInput {
        border-width: 3px;
    }
    
    .modal__btn {
        border: 2px solid currentColor;
    }
}

/* Focus States */
.modal__btn:focus-visible,
#challengeCodeInput:focus-visible {
    outline: 2px solid #00B5AD;
    outline-offset: 2px;
}



