/* Popup overlay */
.popup-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(3, 45, 96, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    overflow-y: auto; /* Enable scrolling */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding: 20px 0; /* Add vertical padding */
}

.popup-overlay.active {
    display: flex;
}

/* Popup container */
.popup-container {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(3, 45, 96, 0.3);
    border: 2px solid rgba(3, 45, 96, 0.1);
    max-width: 550px;
    width: 90%;
    max-height: 90vh; /* Limit height */
    margin: auto; /* Center vertically when scrolling */
    position: relative;
    animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden; /* Hide overflow on container */
    display: flex;
    flex-direction: column;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

/* Close button */
.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    font-size: 28px;
    cursor: pointer;
    color: #4a5568;
    background: rgba(3, 45, 96, 0.05);
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    line-height: 1;
    z-index: 10; /* Above form content */
}

.close-btn:hover {
    background: #032D60;
    color: white;
    transform: rotate(90deg);
}

/* Form wrapper for scrolling */
.popup-form {
    overflow-y: auto; /* Enable scrolling inside form */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding-right: 5px; /* Space for scrollbar */
}

/* Form styling */
.popup-form h2 {
    margin-bottom: 25px;
    color: #032D60;
    font-size: 28px;
    font-weight: 700;
    padding-right: 40px; /* Space for close button */
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: #032D60;
    font-weight: 600;
    font-size: 14px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    background-color: white;
    color: #1f2937;
    transition: all 0.3s ease;
    box-sizing: border-box; /* Include padding in width */
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.form-group select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23032D60' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #1976d2;
    box-shadow: 0 0 0 4px rgba(25, 118, 210, 0.1);
    background-color: #f0f9ff;
}

.form-group input:hover,
.form-group textarea:hover,
.form-group select:hover {
    border-color: #032D60;
}

.submit-btn {
    background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
    color: white;
    padding: 14px 32px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    width: 100%;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(25, 118, 210, 0.3);
}

.submit-btn:hover {
    background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(25, 118, 210, 0.4);
}

.submit-btn:active {
    transform: translateY(0);
}

.submit-btn:disabled {
    background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

/* Message styling */
.message {
    padding: 14px 18px;
    margin-bottom: 20px;
    border-radius: 8px;
    display: none;
    font-weight: 500;
    font-size: 14px;
}

.message.success {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
    border: 2px solid #10b981;
}

.message.error {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    color: #991b1b;
    border: 2px solid #ef4444;
}

.message.show {
    display: block;
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Prevent body scroll when popup is open */
body.popup-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

/* Responsive */
@media (max-width: 768px) {
    .popup-overlay {
        padding: 10px 0; /* Reduce padding on mobile */
        align-items: flex-start; /* Align to top for better scrolling */
    }

    .popup-container {
        padding: 30px 20px;
        width: 95%;
        max-height: 95vh; /* More height on mobile */
        margin: 10px auto; /* Vertical margin for scrolling */
    }

    .popup-form h2 {
        font-size: 24px;
        margin-bottom: 20px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .submit-btn {
        padding: 12px 24px;
        font-size: 15px;
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .popup-overlay {
        padding: 5px 0;
    }

    .popup-container {
        width: 98%;
        padding: 25px 15px;
        border-radius: 12px;
    }

    .popup-form h2 {
        font-size: 20px;
        padding-right: 35px;
    }

    .close-btn {
        width: 32px;
        height: 32px;
        font-size: 24px;
        top: 10px;
        right: 10px;
    }

    .form-group input,
    .form-group textarea,
    .form-group select {
        padding: 10px 14px;
        font-size: 16px;
    }
}