/* General Body and Wrapper Styles */
body {
    font-family: Arial, sans-serif;
    background-color: #f4f4f4;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.wrapper {
    background-color: #fff;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 800px;
    text-align: center;
    margin-top: 20px;
    margin-bottom: 20px;
    box-sizing: border-box;
}

h2, h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 1.8em;
}

p {
    line-height: 1.6;
}

/* Form Group and Input Styles */
.form-group {
    margin-bottom: 15px;
    text-align: left;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-size: 0.95em;
}

input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1em;
    box-sizing: border-box;
}

/* --- Button Styling (Unified for Consistency) --- */
.btn {
    display: block; /* Ensures button takes full width if no other width is specified */
    background-color: #007bff;
    color: white;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1.1em;
    /* REMOVE margin-top: 15px; from here. We'll apply margins contextually. */
    text-decoration: none;
    text-align: center;
    transition: background-color 0.3s ease;
    box-sizing: border-box;
}

.btn:hover {
    background-color: #0056b3;
}

.btn-danger {
    background-color: #dc3545;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-secondary {
    background-color: #6c757d;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-save-exit {
    background-color: #ffc107;
    color: #343a40;
}
.btn-save-exit:hover {
    background-color: #e0a800;
}
/* --- End Button Styling --- */


.alert {
    padding: 10px;
    margin-bottom: 15px;
    border-radius: 4px;
}

.alert.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}
.alert.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}


.invalid-feedback {
    color: #dc3545;
    font-size: 0.875em;
    display: block;
    margin-top: 5px;
}

/* CRITICAL: Ensure all input types have consistent styling */
.form-control {
    width: 100%; /* Make input fields take up the full width of their container */
    padding: 10px 12px; /* Consistent padding inside the input */
    border: 1px solid #ccc; /* Consistent border */
    border-radius: 4px; /* Consistent rounded corners */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
    font-size: 16px; /* Consistent font size */
    line-height: 1.5; /* Consistent line height */
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; /* Smooth transitions for focus */
}

/* Focus state for input fields */
.form-control:focus {
    border-color: #007bff; /* Highlight border on focus */
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25); /* Subtle shadow on focus */
}

/* Styling for invalid fields (already in your <style> block, but good to have in main CSS) */
.form-control.is-invalid {
    border-color: #dc3545; /* Red border for invalid fields */
}

/* Styling for invalid feedback messages (already in your <style> block) */
.invalid-feedback {
    color: #dc3545; /* Red text for error messages */
    font-size: 0.875em;
    margin-top: 0.25rem;
    display: block; /* Ensure it appears on its own line */
}

/* Exam specific styles */
.question-container {
    text-align: left;
    margin-top: 20px;
    padding: 20px;
    border: 1px solid #eee;
    border-radius: 8px;
    background-color: #f9f9f9;
}

.question-container p {
    font-size: 1.1em;
    margin-bottom: 15px;
    line-height: 1.5;
}

.answers {
    margin-bottom: 20px;
}

.answer-option {
    padding: 12px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.answer-option:hover:not(.correct):not(.wrong) {
    background-color: #e9e9e9;
}

.answer-option label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 0;
    font-size: 1em;
}

.answer-option input[type="radio"] {
    margin-right: 10px;
    transform: scale(1.3);
    min-width: 20px;
    min-height: 20px;
}

/* --- Flex Container Styles for button groups --- */
.navigation-buttons,
.exam-actions {
    display: flex;
    flex-wrap: wrap; /* Allow buttons to wrap to next line if needed */
    justify-content: space-between; /* Space out items */
    gap: 10px; /* Space between items */
    margin-top: 20px; /* Spacing from elements above */
    flex-direction: row; /* Force them to be in a row by default (desktop & mobile) */
}

/* Button Sizing within these flex containers */
.navigation-buttons .btn,
.exam-actions .btn {
    flex-grow: 1; /* Allow buttons to grow to fill space */
    flex-shrink: 1; /* Allow buttons to shrink */
    flex-basis: 0; /* Important: Allows flex-grow to work properly with multiple items */
    min-width: 120px; /* Minimum width before wrapping */
    margin-top: 0; /* Override default .btn margin-top here */
}

/* Buttons that are directly inside .form-group (like Login/Register submit buttons, Start Exam buttons) */
.form-group .btn {
    width: 100%; /* These should always be full width */
    margin-top: 15px; /* Add margin-top for spacing */
}


.navigation-buttons .btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* Exam card for dashboard */
.exam-card,
.completed-exam-card {
    border: 1px solid #ddd;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 5px;
    text-align: left;
    background-color: #fefefe;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    box-sizing: border-box;
}
.exam-card p,
.completed-exam-card p {
    margin: 5px 0;
    color: #555;
}
.ongoing-exams,
.completed-exams {
    margin-top: 20px;
    margin-bottom: 20px;
}

.completed-exam-card {
    background-color: #e6ffe6;
    border-color: #a3e6a3;
}

/* --- Specific Styling for Buttons inside Exam Cards (Resume Exam, View Summary) --- */
.exam-card .btn {
    width: 100%; /* Make buttons inside cards full width */
    margin-top: 10px; /* Add consistent spacing above the button within the card */
}

/* Ensure the form containing the Resume Exam button also takes full width */
.exam-card form {
    width: 100%;
    margin-top: 10px; /* Add spacing above the form itself */
}
/* Ensure the button inside this form doesn't get double margin-top */
.exam-card form .btn {
    margin-top: 0;
}
/* --- End Specific Styling for Buttons inside Exam Cards --- */


/* Dashboard Specific Button Alignment (Leaderboard, Sign Out) */
.dashboard-button-group {
    margin-top: 20px;
    padding-left: 15px; /* Match exam-card padding */
    padding-right: 15px; /* Match exam-card padding */
    box-sizing: border-box;
    width: 100%; /* Take full width of wrapper */
    max-width: 600px; /* Match wrapper max-width */
    margin-left: auto; /* Center this block */
    margin-right: auto;
    display: flex;
    flex-direction: column; /* Stack buttons vertically */
    gap: 10px; /* Space between buttons */
}
.dashboard-button-group .btn {
    width: 100%; /* Ensure these buttons are full width */
    margin-top: 0; /* Let dashboard-button-group gap handle spacing */
}


/* Leaderboard table */
.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
}
.leaderboard-table th, .leaderboard-table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
    white-space: normal;
}
.leaderboard-table th {
    background-color: #e9ecef;
    color: #333;
    font-weight: bold;
}
.leaderboard-table tr:nth-child(even) {
    background-color: #f8f9fa;
}
.leaderboard-table tr:hover {
    background-color: #f1f1f1;
}

/* CAPTCHA specific styles */
.captcha-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 15px;
}

.captcha-image {
    border: 1px solid #ddd;
    margin-bottom: 10px;
    cursor: pointer;
    max-width: 100%;
    height: auto;
}

.explanation {
    margin-top: 20px;
    padding: 15px;
    background-color: #f0f0f0;
    border-left: 5px solid #007bff;
    text-align: left;
}

.summary-info {
    text-align: left;
    margin-bottom: 30px;
    padding: 15px;
    background-color: #e9f7ef;
    border-left: 5px solid #28a745;
    border-radius: 5px;
}
.summary-info p {
    margin: 5px 0;
    font-size: 1.1em;
}
.question-summary-item {
    margin-bottom: 30px;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 8px;
    background-color: #f9f9f9;
    text-align: left;
}
.question-summary-item h4 {
    margin-top: 0;
    color: #007bff;
}
.question-summary-item .answers div {
    padding: 8px;
    margin-bottom: 5px;
    border-radius: 4px;
    border: 1px solid transparent;
}
.question-summary-item .answers .correct-answer {
    background-color: #d4edda;
    border-color: #28a745;
}
.question-summary-item .answers .user-wrong-answer {
    background-color: #f8d7da;
    border-color: #dc3545;
}
.question-summary-item .explanation {
    margin-top: 15px;
    padding: 10px;
    background-color: #f0f0f0;
    border-left: 5px solid #007bff;
}

/* Media Queries: Only for very small screens if needed, otherwise let flex-wrap handle it */
@media (max-width: 480px) {
    .wrapper {
        padding: 15px;
    }

    h2, h3 {
        font-size: 1.3em;
    }

    .btn {
        font-size: 0.95em;
    }

    /* Force all buttons to stack vertically on very small screens */
    .navigation-buttons,
    .exam-actions {
        flex-direction: column;
        gap: 8px;
    }

    .navigation-buttons .btn,
    .exam-actions .btn {
        min-width: unset;
        width: 100%;
    }

    .dashboard-button-group {
        padding-left: 10px;
        padding-right: 10px;
    }
}