/* Global Styles */
:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

/* Navigation */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-title {
    font-size: 1.5rem;
    color: var(--primary-color);
}

.nav-links {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.timer {
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--primary-color);
}

/* Container */
.container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.btn-large {
    padding: 1rem 2rem;
    font-size: 1.1rem;
}

.btn.active {
    background: var(--primary-color);
    color: white;
}

/* Authentication Pages */
.auth-box {
    max-width: 400px;
    margin: 4rem auto;
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.auth-box h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--primary-color);
}

.subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-secondary);
}

.auth-link a {
    color: var(--primary-color);
    text-decoration: none;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"] {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group small {
    display: block;
    margin-top: 0.25rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-section {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.form-section h4 {
    margin-bottom: 1rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

/* Radio and Checkbox Groups */
.radio-group, .checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.radio-label, .checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.radio-label:hover, .checkbox-label:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
}

.radio-label input, .checkbox-label input {
    margin-top: 0.25rem;
}

.radio-label span:first-of-type, .checkbox-label span {
    font-weight: 500;
}

.radio-label small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.alert-error {
    background: #fee;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

.alert-success {
    background: #efe;
    color: var(--success-color);
    border: 1px solid var(--success-color);
}

.alert-warning {
    background: #fef3e2;
    color: var(--warning-color);
    border: 1px solid var(--warning-color);
}

/* Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Sections */
.section {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.section h3 {
    margin-bottom: 1rem;
}

/* Exam Card */
.exam-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.exam-card h4 {
    margin-bottom: 0.5rem;
}

.exam-code {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.exam-actions {
    margin-top: 1rem;
}

/* Tables */
.data-table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px; /* Prevent table from being too compressed */
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.data-table th {
    background: var(--background);
    font-weight: 600;
}

.data-table tr:hover {
    background: var(--background);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    background: var(--secondary-color);
    color: white;
}

.badge-success {
    background: var(--success-color);
}

.badge-danger {
    background: var(--danger-color);
}

.badge-warning {
    background: var(--warning-color);
}

.badge-learning {
    background: #28a745;
}

.badge-practice {
    background: #007bff;
}

.badge-exam {
    background: #dc3545;
}

/* Exam Container */
.exam-container {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 1.5rem;
}

/* Question Navigation */
.question-nav {
    background: var(--surface);
    padding: 1rem;
    border-radius: 0.5rem;
    height: fit-content;
    position: sticky;
    top: 1rem;
}

.question-nav h4 {
    margin-bottom: 1rem;
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.question-num {
    display: block;
    padding: 0.5rem;
    text-align: center;
    border: 2px solid var(--border-color);
    border-radius: 0.375rem;
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    transition: all 0.2s;
}

.question-num:hover {
    background: var(--background);
}

.question-num.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.question-num.correct {
    background: #dcfce7 !important;
    border-color: #22c55e !important;
    color: #15803d !important;
}

.question-num.incorrect {
    background: #fee2e2 !important;
    border-color: #ef4444 !important;
    color: #991b1b !important;
}

.question-num.answered {
    background: #e0e7ff !important;
    border-color: #6366f1 !important;
    color: #4338ca !important;
}

.question-num.flagged {
    background: #fef3c7;
    border-color: var(--warning-color);
}

.nav-legend {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.nav-legend > div {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.legend-box {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-radius: 0.25rem;
}

.legend-box.correct {
    background: #dcfce7;
    border-color: #22c55e;
}

.legend-box.incorrect {
    background: #fee2e2;
    border-color: #ef4444;
}

.legend-box.answered {
    background: #e0e7ff;
    border-color: #6366f1;
}

.legend-box.flagged {
    background: #fef3c7;
    border-color: var(--warning-color);
}

/* Question Area */
.question-area {
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
}

.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.question-content {
    margin-bottom: 2rem;
}

.question-text {
    font-size: 1.1rem;
    line-height: 1.8;
    margin-bottom: 1.5rem;
}

/* Options */
.options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.option {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
}

.option:hover {
    background: var(--background);
    border-color: var(--primary-color);
}

.option input[type="radio"] {
    margin-top: 0.25rem;
}

.option-letter {
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    background: var(--background);
    border-radius: 50%;
    font-weight: bold;
}

.option-text {
    flex: 1;
}

.option.correct {
    background: #f0fdf4;
    border-color: var(--success-color);
}

.option.correct .option-letter {
    background: var(--success-color);
    color: white;
}

.option.incorrect {
    background: #fef2f2;
    border-color: var(--danger-color);
}

.option.incorrect .option-letter {
    background: var(--danger-color);
    color: white;
}

/* Feedback */
.feedback {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
}

.feedback.correct {
    background: #f0fdf4;
    border-left: 4px solid var(--success-color);
}

.feedback.incorrect {
    background: #fef2f2;
    border-left: 4px solid var(--danger-color);
}

.feedback strong {
    display: block;
    margin-bottom: 0.5rem;
}

/* Question Actions */
.question-actions {
    display: flex;
    gap: 1rem;
}

/* Exam Navigation */
.exam-navigation {
    display: flex;
    justify-content: space-between;
    padding-top: 1.5rem;
    border-top: 2px solid var(--border-color);
}

/* Results */
.score-summary {
    background: var(--surface);
    padding: 2rem;
    border-radius: 0.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.score-summary.passed {
    border-left: 5px solid var(--success-color);
}

.score-summary.failed {
    border-left: 5px solid var(--danger-color);
}

.score-main {
    text-align: center;
    margin-bottom: 2rem;
}

.score-percentage {
    font-size: 4rem;
    font-weight: bold;
    color: var(--primary-color);
}

.score-status {
    font-size: 1.5rem;
    font-weight: bold;
    margin-top: 0.5rem;
}

.passed .score-status {
    color: var(--success-color);
}

.failed .score-status {
    color: var(--danger-color);
}

.score-details {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    text-align: center;
}

.score-stat .stat-value {
    font-size: 2rem;
    font-weight: bold;
}

.results-actions {
    display: flex;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

/* Review */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.review-question {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.review-options {
    margin: 1.5rem 0;
}

.review-option {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
}

.review-option.correct {
    background: #f0fdf4;
    border-color: var(--success-color);
}

.review-option.incorrect {
    background: #fef2f2;
    border-color: var(--danger-color);
}

.option-badge {
    margin-left: auto;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.explanation {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid var(--primary-color);
}

.explanation strong {
    display: block;
    margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    /* Container adjustments */
    .container {
        padding: 0.5rem;
    }
    
    /* Navbar mobile */
    .navbar {
        padding: 0.75rem 0.5rem;
    }
    
    .nav-container {
        flex-direction: column;
        gap: 0.5rem;
        align-items: flex-start;
    }
    
    .nav-title {
        font-size: 1.25rem;
    }
    
    .nav-links {
        font-size: 0.875rem;
        flex-wrap: wrap;
    }
    
    /* Exam container - stack question nav on top */
    .exam-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .question-nav {
        position: static;
        max-height: none;
        padding: 1rem;
        margin-bottom: 0;
    }
    
    .question-nav h4 {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .question-grid {
        grid-template-columns: repeat(10, 1fr);
        gap: 0.375rem;
        margin-bottom: 0.75rem;
    }
    
    .question-num {
        padding: 0.375rem 0.25rem;
        font-size: 0.875rem;
    }
    
    .nav-legend {
        font-size: 0.7rem;
    }
    
    .legend-box {
        width: 16px;
        height: 16px;
    }
    
    /* Question area */
    .question-area {
        padding: 1rem;
    }
    
    .question-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        margin-bottom: 1rem;
        padding-bottom: 0.75rem;
    }
    
    .question-header h3 {
        font-size: 1.125rem;
    }
    
    .question-text {
        font-size: 1rem;
        line-height: 1.6;
    }
    
    /* Options on mobile */
    .option {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    
    .option-letter {
        min-width: 28px;
        width: 28px;
        height: 28px;
        font-size: 0.875rem;
    }
    
    .option-text {
        font-size: 0.95rem;
    }
    
    /* Question actions */
    .question-actions {
        flex-direction: column;
    }
    
    .question-actions button {
        width: 100%;
    }
    
    /* Navigation buttons */
    .exam-navigation {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .exam-navigation a,
    .exam-navigation form {
        width: 100%;
    }
    
    .exam-navigation button,
    .exam-navigation .btn {
        width: 100%;
        padding: 0.875rem;
        font-size: 1rem;
    }
    
    /* Dashboard mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    /* Exam card mobile */
    .exam-card {
        padding: 1rem;
    }
    
    .exam-card h4 {
        font-size: 1.125rem;
    }
    
    .exam-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .exam-actions .btn {
        width: 100%;
    }
    
    /* Data table mobile - make scrollable */
    .data-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem; /* Extend to screen edges */
        padding: 0 1rem;
    }
    
    .data-table {
        font-size: 0.875rem;
        min-width: 500px;
    }
    
    .data-table th,
    .data-table td {
        padding: 0.5rem;
        white-space: nowrap;
    }
    
    .data-table td:first-child {
        white-space: normal; /* Allow topic names to wrap */
    }
    
    /* Results mobile */
    .score-card {
        padding: 1.5rem;
    }
    
    .score-display {
        font-size: 3rem;
    }
    
    .score-details {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .results-actions {
        flex-direction: column;
    }
    
    .results-actions .btn {
        width: 100%;
    }
    
    /* Review mobile */
    .review-question {
        padding: 1rem;
        margin-bottom: 1rem;
    }
    
    .review-option {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    
    .filter-bar {
        flex-direction: column;
    }
    
    .filter-bar .btn {
        width: 100%;
    }
}

/* Extra small devices (phones in portrait, less than 576px) */
@media (max-width: 576px) {
    .question-grid {
        grid-template-columns: repeat(8, 1fr);
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .nav-title {
        font-size: 1.125rem;
    }
    
    .timer {
        font-size: 1.25rem;
    }
}

/* Alert Messages */
.alert {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    border-left: 4px solid;
}

.alert-success {
    background: #dcfce7;
    border-color: #22c55e;
    color: #15803d;
}

.alert-warning {
    background: #fef3c7;
    border-color: #f59e0b;
    color: #92400e;
}

.alert-warning-section {
    border: 2px solid #fbbf24;
    border-radius: 0.5rem;
    padding: 1.5rem;
    background: #fffbeb;
}

/* In-Progress Exam Cards */
.in-progress-card {
    background: #fefce8;
    border: 2px solid #fbbf24;
}

.progress-info {
    margin: 1rem 0;
}

.progress-info p {
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: #e5e7eb;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(to right, #3b82f6, #2563eb);
    transition: width 0.3s ease;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}
