/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    overflow-y: auto;
    /* Enable scrolling for large modal content */
}

.modal-content {
    background-color: white;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin: auto;
    max-height: 80vh;
    /* Limit modal height */
    overflow-y: auto;
    /* Add scroll if content exceeds height */
}

.payment-modal {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
}

.close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6c757d;
}

.close:hover {
    color: #1a1a1a;
}

.modal h2 {
    margin-bottom: 1.5rem;
    color: #2e7d32;
    text-align: center;
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-semibold);
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.modal-actions .btn-secondary,
.modal-actions .btn-danger {
    margin: 0;
    min-width: 100px;
}

/* Responsive */
@media (max-width: 768px) {
    .modal-content {
        padding: 1.5rem;
        width: 90%;
    }

    .payment-modal {
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 90%;
        margin: 0;
    }

    .modal-footer {
        flex-direction: row;
    }

    .modal-footer button {
        width: auto;
        margin-bottom: 0;
    }

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

    .modal-actions .btn-secondary,
    .modal-actions .btn-danger {
        width: 100%;
    }
}

/* Add Child Modal Font Size Reduction */
#add-child-modal .modal-content {
    font-size: 0.9rem;
}

#add-child-modal h2 {
    font-size: 1.4rem;
}

#add-child-modal input {
    font-size: 0.9rem;
}

#add-child-modal button {
    font-size: 0.9rem;
}

/* Add Child Modal Specific Mobile Optimization */
@media (max-width: 768px) {
    #add-child-modal .modal-content {
        width: 95%;
        max-width: 95%;
        padding: 1rem;
        margin: 1rem;
        max-height: 85vh;
        /* Slightly reduced for mobile */
        overflow-y: auto;
    }

    #add-child-modal h2 {
        font-size: 1.5rem;
        margin-bottom: 1rem;
    }

    #admission-number {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    #search-students-btn {
        width: 100%;
        margin-top: 0.5rem;
    }

    .input-group {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .suggestions-container {
        max-height: 200px;
        margin-top: 0.5rem;
        padding: 0.5rem;
    }

    .suggestion-item {
        padding: 0.5rem;
    }

    .suggestion-item-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .suggestion-item-details {
        flex-direction: column;
        gap: 0.25rem;
        font-size: 0.8rem;
    }

    .selected-students-container {
        margin-top: 0.75rem;
        min-height: 50px;
        padding: 0.5rem;
    }

    .selected-student-tag {
        font-size: 0.75rem;
        padding: 0.2rem 0.5rem;
        margin: 0.15rem;
    }

    .modal-actions {
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 1rem;
    }

    .modal-actions button {
        width: 100%;
        margin: 0;
    }
}

/* Extra small mobile devices */
@media (max-width: 480px) {
    #add-child-modal .modal-content {
        width: 98%;
        padding: 0.75rem;
        margin: 0.5rem;
        max-height: 80vh;
        /* Set max height for very small screens */
        overflow-y: auto;
    }

    #add-child-modal h2 {
        font-size: 1.3rem;
        margin-bottom: 0.75rem;
    }

    .suggestions-container {
        max-height: 150px;
    }

    .suggestion-item {
        padding: 0.4rem;
    }

    .suggestion-item-details {
        font-size: 0.7rem;
    }

    .selected-student-tag {
        font-size: 0.7rem;
        flex-wrap: wrap;
    }
}

/* History Modal Specifics */
.history-modal-content {
    max-width: 800px;
    height: 85vh;
    /* Fixed height relative to viewport */
    display: flex;
    /* Flex layout for sticky header/scrollable body */
    flex-direction: column;
    padding: 0;
    /* Clear padding usually on modal-content */
}

.history-modal-content>h2 {
    margin-top: 1.5rem;
    /* Add back spacing for title */
}

.history-controls {
    padding: 0 1.5rem 1rem 1.5rem;
    flex-shrink: 0;
}

.history-modal-content .close {
    top: 1rem;
    right: 1rem;
}

.history-list.full-list {
    flex-grow: 1;
    overflow-y: auto;
    /* Enable vertical scrolling */
    padding: 0 1.5rem 1.5rem 1.5rem;
    /* Hide scrollbar for Firefox */
    scrollbar-width: none;
    /* Keep scroll behavior smooth */
    -ms-overflow-style: none;
    /* IE and Edge */
}

/* Hide scrollbar for Chrome, Safari and Opera */
.history-list.full-list::-webkit-scrollbar {
    display: none;
}

/* New filter styles */
.filters-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    flex-wrap: wrap;
}

.filters-row .select-wrapper {
    flex: 1;
    min-width: 100px;
}

.filters-row .select-wrapper select {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.9rem;
}

.search-wrapper {
    position: relative;
    margin-bottom: 0.75rem;
}

.search-wrapper input {
    width: 100%;
    padding: 0.5rem 1rem 0.5rem 2.5rem;
    font-size: 0.9rem;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .filters-row {
        flex-direction: row;
    }

    .filters-row .select-wrapper {
        min-width: calc(33.333% - 0.33rem);
    }

    @media (max-width: 576px) {
        .filters-row .select-wrapper {
            min-width: calc(50% - 0.25rem);
        }
    }

    @media (max-width: 400px) {
        .filters-row .select-wrapper {
            min-width: 100%;
        }
    }
}

/* Download Progress Bar */
.download-progress-container {
    flex: 1;
    margin-right: 1.5rem;
    max-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.progress-label {
    font-size: 0.85rem;
    color: #1b5e20;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
}

.progress-track {
    width: 100%;
    height: 8px;
    background-color: #e8f5e9;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #43a047, #1b5e20);
    transition: width 0.3s ease;
}

@media (max-width: 768px) {
    .download-progress-container {
        margin-right: 0.5rem;
        max-width: 150px;
    }
}