/* Enhanced 100% Responsive CSS - Complete Rewrite */
/* Mobile-first approach with progressive enhancement */

/* NEW: Custom CSS Variables for Blue and White Palette */
:root {
    --primary-blue: #0d6efd; /* Bootstrap's primary blue */
    --light-blue: #e0f2ff; /* A very light blue for backgrounds/accents */
    --white: #ffffff;
    --dark-text: #212529; /* Standard dark text color (from Bootstrap) */
    --muted-text: #6c757d; /* Standard muted text color (from Bootstrap) */
    --border-color: #dee2e6; /* Standard border color (from Bootstrap) */
    --light-gray-bg: #f8f9fa; /* Light gray for subtle backgrounds */
    --danger-color: #dc3545; /* Bootstrap's danger red */
    --focus-shadow: rgba(13, 110, 253, 0.25); /* Focus shadow using primary blue */
    --container-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075); /* Light shadow for containers */

    /* User's original variables */
    --primary-deep-blue: #000080; /* A very deep, classic blue */
    --secondary-blue: #003366; /* A slightly lighter, but still deep blue */
    /* --light-blue: #e9f2f9; This was duplicated, using the one above */
    --accent-blue: #4a6785; /* A muted blue for subtle accents */
    /* --white: #ffffff; This was duplicated, using the one above */
    --light-gray: #f8f9fa; /* Off-white for subtle backgrounds (same as light-gray-bg) */
    --dark-gray: #343a40; /* Dark gray for general text */
    --shadow-light: 0 4px 15px rgba(0, 0, 128, 0.1); /* Subtle deep blue shadow */
    --shadow-medium: 0 8px 25px rgba(0, 0, 128, 0.15);
    --shadow-heavy: 0 12px 35px rgba(0, 0, 128, 0.2);
}

/* Base styles - Mobile first (320px and up) */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    font-size: 1rem; /* Base font size */
    line-height: 1.6;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--light-blue) 0%, var(--white) 100%); /* Light blue to white gradient */
    min-height: 100vh;
    color: var(--dark-gray);
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
}

/* Enhanced Container Styling */
.container {
    background-color: var(--white);
    padding: 40px;
    border-radius: 12px;
    box-shadow: var(--shadow-medium); /* Using user's variable */
    width: 100%;
    max-width: 900px;
    box-sizing: border-box;
    animation: slideUp 0.8s ease-out forwards;
    margin-top: 20px; /* Add some margin for top/bottom */
    margin-bottom: 20px; /* Add some margin for top/bottom */
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Enhanced Typography */
h1 {
    font-size: 2.8rem;
    color: var(--primary-deep-blue);
    margin-bottom: 30px;
    text-align: center;
    font-weight: 700;
}
.mb-3{
    color: var(--primary-deep-blue);
}

/* Custom Fieldset Styles for a cleaner look */
fieldset {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}
/* Re-style the legend to sit better 
/* --- Final Legend Style: ONLY for visual look and centering the element --- */
legend {
    /* Critical: Use table display to allow margin: auto for centering */
    display: table;
    
    /* Center the legend element itself within the fieldset */
    margin-left: auto; 
    margin-right: auto;
    
    /* Add padding to prevent the text from touching the edges */
    padding: 0 15px; 
    
    /* Keep your font/color settings: */
    font-size: 1.4rem;
    color: var(--secondary-blue);
    font-weight: 600;
    
    /* The rest of the margin/padding will be handled by Bootstrap classes */
    padding-bottom: 0;
    margin-bottom: 0;
    border-bottom: none; /* Must ensure no conflicting borders */
}

/* Form Group Enhancements */
.form-group {
    margin-bottom: 20px;
}

.form-control,
.form-select,
textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid var(--light-blue); /* Light blue border for inputs */
    border-radius: 8px;
    font-size: 1rem;
    color: var(--dark-gray);
    background-color: var(--white);
    transition: all 0.3s ease;
}

.form-control:focus,
.form-select:focus,
textarea:focus {
    border-color: var(--primary-deep-blue);
    box-shadow: 0 0 0 0.25rem rgba(0, 0, 128, 0.25);
    outline: none;
}

/* Labels */
.form-control-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--primary-deep-blue); /* Deep blue for labels */
}

/* Checkbox and Radio styling */
.form-check {
    margin-bottom: 10px;
}

.form-check-input {
    width: 1.25em;
    height: 1.25em;
    margin-top: 0.25em;
    vertical-align: top;
    background-color: var(--white);
    border: 1px solid var(--light-blue);
    appearance: none;
    -webkit-appearance: none;
    transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-check-input:checked {
    background-color: var(--primary-deep-blue);
    border-color: var(--primary-deep-blue);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

.form-check-input:focus {
    box-shadow: 0 0 0 0.25rem rgba(0, 0, 128, 0.25);
}

.form-check-label {
    margin-left: 0.5rem;
    color: var(--dark-gray);
}

/* Buttons */
.btn-primary {
    background-color: var(--primary-deep-blue);
    border-color: var(--primary-deep-blue);
    color: var(--white);
    padding: 12px 25px;
    font-size: 1.1rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.btn-primary:hover {
    background-color: var(--secondary-blue);
    border-color: var(--secondary-blue);
    box-shadow: var(--shadow-light);
}

/* File input specific styling */
.form-control-file {
    padding: 8px 12px;
    border: 1px solid var(--light-blue);
    border-radius: 8px;
    background-color: var(--white);
    color: var(--dark-gray);
    cursor: pointer;
}

.passport-preview-container {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    overflow: hidden;
    margin: 20px auto;
    border: 3px solid var(--primary-deep-blue); /* Deep blue border */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--light-blue); /* Light blue placeholder background */
    box-shadow: var(--shadow-light);
}

.passport-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#passportPlaceholder {
    color: var(--primary-deep-blue); /* Deep blue placeholder text */
    font-size: 1em;
    text-align: center;
}

/* Error messages */
.text-danger {
    color: #dc3545; /* Standard Bootstrap red for errors */
    font-size: 0.875em;
    margin-top: 5px;
    display: block;
}

/* Enhanced link styling */
a {
    color: var(--primary-deep-blue);
    text-decoration: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

a:hover {
    color: var(--secondary-blue);
    text-shadow: 1px 1px 2px rgba(0, 0, 128, 0.1);
}

/* Styling for the dynamically loaded subject checkboxes container */
#assignedSubjectsCheckboxes {
    display: grid;
    /* This creates 4 columns, each taking an equal fraction of available space. */
    grid-template-columns: repeat(4, 1fr);
    gap: 15px; /* Space between grid items */
    padding: 15px; /* Internal padding */
    background-color: var(--light-gray-bg); /* Using your defined variable */
    border-radius: 8px; /* Slightly rounded corners */
    margin-top: 10px; /* Space above the box */
}

#assignedSubjectsCheckboxes .form-check:hover {
    background-color: var(--light-blue);
    transform: translateY(-2px);
}


/* Ensure individual form-check items within the grid are well-aligned */
#assignedSubjectsCheckboxes .form-check {
    display: flex; /* Use flexbox for each checkbox + label */
    align-items: center; /* Vertically align the checkbox and label */
    margin-bottom: 0; /* Remove default margin-bottom from Bootstrap's form-check */
    transition: background-color 0.3s ease, transform 0.3s ease;
}

#assignedSubjectsCheckboxes .form-check-input {
    margin-right: 8px; /* Space between checkbox and label */
}

/* Responsive Design Enhancements */
@media (max-width: 992px) { /* For medium desktops/large tablets */
    #assignedSubjectsCheckboxes {
        grid-template-columns: repeat(3, 1fr); /* 3 columns */
    }
}

@media (max-width: 768px) {
    .container {
        margin: 10px;
        padding: 30px 20px;
    }
    
    h1 {
        font-size: 2rem;
    }
    
    fieldset {
        padding: 15px;
    }
    
    .passport-preview-container {
        width: 150px;
        height: 150px;
    }
    
    .rules-toggle-btn {
        padding: 15px 25px;
        font-size: 1rem;
    }
    
    #passportPlaceholder {
        font-size: 0.8em;
    }

    #assignedSubjectsCheckboxes {
        grid-template-columns: repeat(2, 1fr); /* 2 columns for tablets */
    }
}

@media (max-width: 576px) { /* For small phones */
    #assignedSubjectsCheckboxes {
        grid-template-columns: repeat(1, 1fr); /* 1 column */
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .container {
        padding: 20px 15px;
    }
    
    h1 {
        font-size: 1.8rem;
    }

    fieldset {
        padding: 10px;
    }
    
    legend {
        font-size: 1.2rem;
    }
    
    .btn-primary {
        padding: 10px 20px;
        font-size: 1rem;
    }
    
    .passport-preview-container {
        width: 120px;
        height: 120px;
    }
}

/* Ensure all interactive elements meet minimum touch target size */
button,
.btn,
.form-control,
.form-select,
.form-check-input,
input[type="file"] {
    min-height: 44px; /* WCAG 2.1 - minimum touch target size */
}

/* Accessibility: Focus outline for better navigation */
.form-control:focus,
.form-select:focus,
.form-check-input:focus,
.btn-primary:focus,
.rules-toggle-btn:focus {
    outline: 2px solid var(--primary-deep-blue); /* Using user's variable */
    outline-offset: 2px;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Container query support for modern browsers */
@supports (container-type: inline-size) {
    .container {
        container-type: inline-size;
    }

    @container (max-width: 600px) {
        .form-row {
            flex-direction: column;
        }

        .passport-preview-container {
            width: 100px;
            height: 100px;
        }
    }
}

/* Responsive Grid for Checkbox Groups */
.grid-checkbox-group .form-check {
    background-color: rgba(255, 0, 0, 0.1); /* Light red for visibility */
    border: 1px dashed rgb(89, 0, 255); /* Dashed red border */
    margin: 0; /* Ensure no external margins are pushing them together */
}

.grid-checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); /* Adjust minmax as needed */
    gap: 10px; /* Space between checkboxes */
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--light-gray-bg);
}

/* Specific styling for subjects checkbox container if needed */
#assignedSubjectsCheckboxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Adjust minmax as needed */
    gap: 10px; /* Space between checkboxes */
}

.form-check-input:checked {
    background-color: var(--primary-deep-blue) !important; /* Use !important to ensure override */
    border-color: var(--primary-deep-blue) !important; /* Use !important to ensure override */
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e");
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
}

