:root {
    --primary: #4361ee;
    --secondary: #3a0ca3;
    --success: #4cc9f0;
    --danger: #f72585;
    --light: #f8f9fa;
    --dark: #212529;
    --warning: #ff9e00;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.container {
    width: 100%;
    max-width: 1400px;
    background-color: white;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: auto;
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    min-height: 600px;
}

.header {
    background: linear-gradient(to right, var(--secondary), var(--primary));
    color: white;
    padding: 20px;
    text-align: center;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.header h1 {
    font-size: 28px;
    margin-bottom: 10px;
}

.header p {
    font-size: 16px;
    opacity: 0.9;
}

.header-right {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.timer {
    background: rgba(255, 255, 255, 0.2);
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: bold;
    font-size: 18px;
}

.content {
    padding: 30px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* allow flex children to shrink and enable internal scrolling */
.content,
.admin-content,
.admin-dashboard {
    min-height: 0;
}

.screen {
    display: none;
    width: 100%;
}

.screen.active {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* Make the main admin screen layout side-by-side: sidebar + content */
#adminScreen.active {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
}

.welcome-screen h2 {
    color: var(--dark);
    margin-bottom: 20px;
    font-size: 24px;
}

.welcome-screen p {
    color: #555;
    margin-bottom: 30px;
    line-height: 1.6;
}

.btn {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
    border: none;
    padding: 12px 30px;
    font-size: 16px;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    margin: 5px;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 14px;
    margin: 2px;
}

.btn-primary {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
}

.btn-danger-outline {
    background: transparent;
    border: 2px solid var(--danger);
    color: var(--danger);
}

.btn-danger-outline:hover {
    background: var(--danger);
    color: white;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary);
    color: white;
}

.question-container {
    margin-bottom: 30px;
}

.question-number {
    color: var(--primary);
    font-size: 18px;
    margin-bottom: 10px;
}

.question {
    font-size: 22px;
    color: var(--dark);
    margin-bottom: 25px;
    line-height: 1.4;
}

.options-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
    margin-bottom: 30px;
}

.option {
    background-color: #f8f9fa;
    border: 2px solid #e9ecef;
    border-radius: 10px;
    padding: 15px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.option:hover {
    background-color: #e9ecef;
    border-color: var(--primary);
}

.option.selected {
    background-color: #d6eaf8;
    border-color: var(--primary);
}

.navigation {
    display: flex;
    justify-content: space-between;
}

.score {
    font-size: 48px;
    font-weight: bold;
    color: var(--primary);
    margin: 20px 0;
}

.progress-bar {
    height: 10px;
    background-color: #e9ecef;
    border-radius: 5px;
    margin: 20px 0;
    overflow: hidden;
}

.progress {
    height: 100%;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    width: 0%;
    transition: width 0.5s ease;
}

.warning-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.warning-content {
    background-color: white;
    padding: 30px;
    border-radius: 15px;
    text-align: center;
    max-width: 500px;
    width: 90%;
}

.warning-content h2 {
    color: var(--danger);
    margin-bottom: 15px;
}

.warning-content p {
    margin-bottom: 20px;
    color: #555;
}

.admin-panel {
    background-color: #f8f9fa;
    border-radius: 10px;
    padding: 20px;
    margin-top: 20px;
}

.admin-section {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.admin-section h3 {
    color: var(--dark);
    margin-bottom: 15px;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 10px;
    font-size: 18px;
}

.admin-subsection {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 15px;
    margin-top: 15px;
}

.admin-subsection h4 {
    color: var(--dark);
    margin-bottom: 12px;
    font-size: 15px;
}

.questions-display {
    background: white;
    border: 1px solid #e0e0e0;
}

/* Explicit scrollable areas for long lists */
#questionsList,
#resultsTableContainer {
    max-height: calc(100vh - 320px);
    overflow: auto;
    padding-right: 8px;
    /* avoid content under scrollbar */
}

/* Add bottom padding so last question isn't flush against the container edge */
#questionsList {
    padding-bottom: 80px;
}

/* Extra margin for the last question item so its action buttons remain visible */
.question-item:last-child {
    margin-bottom: 40px;
}

/* Ensure form section is fully visible when editing - controlled by .tab-content.active */
.tab-content.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

#addQuestion .form-section {
    flex-shrink: 0;
    margin-bottom: 20px;
}

.questions-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 16px;
}

.question-item {
    background: white;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.question-item h4 {
    margin-bottom: 10px;
    color: var(--dark);
    font-size: 16px;
}

.question-item ol {
    margin: 0 0 12px 18px;
    padding: 0;
}

.question-item li {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    margin-bottom: 6px;
    padding: 4px 0;
    color: #333;
}

.question-item li.correct-option {
    color: #27ae60;
    font-weight: 700;
    background-color: #f0fdf4;
    padding: 4px 8px;
    border-radius: 4px;
    margin-left: -8px;
}

.question-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
}

.question-actions button {
    padding: 6px 12px;
    font-size: 13px;
    flex: 1;
}

.admin-form-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.admin-form-actions .btn {
    padding: 10px 16px;
}

.admin-form-actions .btn-outline {
    border-radius: 6px;
}

.login-form,
.student-form {
    max-width: 500px;
    margin: 0 auto;
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    align-self: center;
    justify-self: center;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.results-table th,
.results-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.results-table th {
    background-color: #f8f9fa;
    font-weight: 600;
}

.results-table tr:hover {
    background-color: #f5f5f5;
}

.error-message {
    color: var(--danger);
    margin-top: 10px;
    text-align: center;
}

.instructions-list {
    text-align: left;
    margin: 20px 0;
    color: #555;
}

.admin-message {
    margin-bottom: 15px;
    padding: 10px 12px;
    border-radius: 6px;
    display: none;
    font-weight: 600;
}

.admin-message.success {
    background-color: #e6fffa;
    color: #056b5c;
    border: 1px solid #b8f2e6;
    display: block;
}

.admin-message.error {
    background-color: #fff0f6;
    color: #8a1538;
    border: 1px solid #f7c6d1;
    display: block;
}

.logout-btn {
    margin-top: 20px;
}

@media (max-width: 600px) {
    .content {
        padding: 20px;
    }

    .question {
        font-size: 20px;
    }

    .header h1 {
        font-size: 24px;
    }

    .navigation {
        flex-direction: column;
        gap: 10px;
    }

    .navigation button {
        width: 100%;
    }
}

/* Results Table Sorting Styles */
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 5px;
}

.results-header h4 {
    margin: 0;
    color: var(--dark);
}

.btn-danger {
    background: linear-gradient(to right, var(--danger), #c1121f);
}

.btn-danger:hover {
    background: linear-gradient(to right, #c1121f, var(--danger));
}

.results-table th {
    cursor: pointer;
    user-select: none;
    position: relative;
    background: var(--primary);
    color: white;
}

.results-table th:hover {
    background: var(--secondary);
}

.sort-indicator {
    margin-left: 5px;
    font-weight: bold;
}

/* Responsive table */
@media (max-width: 768px) {
    .results-header {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }

    .results-table {
        font-size: 14px;
    }

    .results-table th,
    .results-table td {
        padding: 8px 10px;
    }
}

/* Thank you message and results styling */
.thank-you-message {
    font-size: 18px;
    color: #27ae60;
    font-weight: 500;
    margin: 20px 0;
    text-align: center;
}

.results-summary {
    background: #f8f9fa;
    border-left: 4px solid var(--primary);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
}

/* Admin link styling */
.admin-link-container {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e0e0e0;
}

.admin-link {
    font-size: 13px;
    color: #666;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    transition: all 0.2s ease;
    display: inline-block;
}

.admin-link:hover {
    color: var(--primary);
    background-color: #f5f5f5;
    text-decoration: underline;
}

/* Admin icon button in header */
.admin-icon-btn {
    font-size: 24px;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    cursor: pointer;
    flex-shrink: 0;
}

.admin-icon-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

@media (max-width: 768px) {
    .header-right {
        gap: 10px;
    }

    .admin-icon-btn {
        font-size: 20px;
        width: 40px;
        height: 40px;
    }

    .timer {
        font-size: 14px;
        padding: 6px 12px;
    }
}

/* ===== ADMIN DASHBOARD STYLES ===== */

.admin-dashboard {
    display: flex;
    flex-direction: row;
    gap: 0;
    height: 100%;
    padding: 0;
    background-color: #f5f5f5;
    width: 100%;
    overflow: hidden;
}

.admin-sidebar {
    width: 280px;
    min-width: 280px;
    background: linear-gradient(to bottom, var(--secondary), var(--primary));
    color: white;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
    overflow-y: auto;
    border-right: 2px solid var(--secondary);
    flex-shrink: 0;
}

.admin-logo {
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.admin-logo h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.admin-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    border-radius: 8px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all 0.3s ease;
    background: transparent;
    border: none;
    font-size: 15px;
    font-weight: 500;
    text-align: left;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
    transform: translateX(5px);
}

.nav-item.active {
    background: rgba(255, 255, 255, 0.25);
    color: white;
    border-left: 3px solid white;
    padding-left: 12px;
}

.nav-icon {
    font-size: 18px;
    min-width: 20px;
}

.admin-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    background: white;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* ensure admin-content stretches to match sidebar height */
.admin-content {
    height: 100%;
}

.admin-screen {
    display: none;
}

.admin-screen.active {
    /* Make active admin screens fill the right pane and allow internal scrolling */
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    overflow: auto;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.admin-screen h2 {
    color: var(--dark);
    margin-bottom: 25px;
    font-size: 26px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--primary);
}

/* Dashboard Stats */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.stat-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
}

.stat-card:hover {
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transform: translateY(-3px);
}

.stat-label {
    color: #666;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    color: var(--primary);
    font-size: 36px;
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-unit {
    color: #999;
    font-size: 12px;
}

/* Quick Actions */
.dashboard-quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.quick-action-btn {
    background: white;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 20px;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.quick-action-btn:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
}

.quick-action-btn span {
    font-size: 24px;
}

/* Tabs */
.section-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
    border-bottom: 1px solid #e0e0e0;
}

.tab-btn {
    background: transparent;
    border: none;
    padding: 12px 20px;
    color: #666;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    font-size: 15px;
}

.tab-btn:hover {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-content {
    display: none;
}

.tab-content.active {
    /* already set above for layout; keep as fallback */
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
}

/* Forms */
.admin-form-container,
.form-section {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.form-section h3 {
    color: var(--dark);
    margin-bottom: 20px;
    font-size: 18px;
}

.button-group {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.button-group .btn {
    flex: 1;
}

/* Questions Section */
.questions-section {
    background: white;
}

.results-section {
    background: white;
}

/* Help Text */
.help-text {
    color: #666;
    font-size: 13px;
    margin-top: 5px;
}

.help-text a {
    color: var(--primary);
    text-decoration: none;
}

.help-text a:hover {
    text-decoration: underline;
}

/* Responsive Design for Admin Dashboard */
@media (max-width: 1200px) {
    .admin-sidebar {
        width: 240px;
        min-width: 240px;
    }

    .admin-content {
        padding: 25px;
    }
}

@media (max-width: 1024px) {
    .admin-sidebar {
        width: 220px;
        min-width: 220px;
    }

    .admin-content {
        padding: 20px;
    }
}

@media (max-width: 768px) {
    .admin-dashboard {
        flex-direction: column;
        height: auto;
        overflow: visible;
    }

    .admin-sidebar {
        width: 100%;
        min-width: 100%;
        min-height: auto;
        flex-direction: row;
        border-right: none;
        border-bottom: 2px solid var(--secondary);
        gap: 0;
        padding: 0;
        height: auto;
        flex-shrink: 0;
        overflow-x: auto;
        overflow-y: hidden;
    }

    .admin-logo {
        display: none;
    }

    .admin-nav {
        flex-direction: row;
        overflow-x: auto;
        gap: 0;
        flex: 1;
        padding: 0;
    }

    .nav-item {
        padding: 15px 12px;
        white-space: nowrap;
        border-left: none;
        border-bottom: 3px solid transparent;
        border-radius: 0;
    }

    .nav-item.active {
        border-left: none;
        border-bottom: 3px solid white;
        padding-left: 12px;
    }

    .nav-item:hover {
        transform: none;
    }

    .logout-btn {
        margin-top: 0;
        padding: 12px;
        font-size: 14px;
        border-radius: 0;
        margin: 0;
        white-space: nowrap;
    }

    .admin-content {
        flex: 1;
        padding: 20px;
        overflow-y: auto;
        height: auto;
    }

    .admin-screen h2 {
        font-size: 22px;
    }

    .dashboard-stats,
    .dashboard-quick-actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .section-tabs {
        flex-wrap: wrap;
    }

    .tab-btn {
        padding: 10px 15px;
        font-size: 13px;
    }
}