/* ==========================================================================
   CSS Variables & Base Reset
   ========================================================================== */
:root {
    --primary: #2563eb;       /* Blue */
    --primary-hover: #1d4ed8;
    
    --bg-main: #f3f4f6;       /* Light grey back */
    --bg-panel: #ffffff;      
    
    --text-dark: #1f2937;
    --text-muted: #6b7280;
    
    --border-color: #e5e7eb;
    
    /* State Colors */
    --state-answered: #22c55e;     /* Green */
    --state-not-answered: #ef4444; /* Red */
    --state-marked: #a855f7;       /* Purple */
    --state-not-visited: #e5e7eb;  /* Grey */
    
    --font-main: 'Inter', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-main);
    color: var(--text-dark);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent body scroll, panels will handle it */
}

/* ==========================================================================
   Top Header & Navigation
   ========================================================================== */
.top-header {
    background: var(--bg-panel);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    z-index: 10;
}

.exam-title h1 {
    font-size: 1.25rem;
    color: var(--text-dark);
}

.timer {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary);
    background: #eff6ff;
    padding: 5px 15px;
    border-radius: 20px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

.avatar {
    width: 35px;
    height: 35px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.sections {
    background: var(--bg-panel);
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--border-color);
    overflow-x: auto;
}

.section-tab {
    padding: 12px 24px;
    background: transparent;
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
}

.section-tab:hover {
    color: var(--primary);
    background: #f8fafc;
}

.section-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: #eff6ff;
}

/* ==========================================================================
   Main Layout Structure (Grid)
   ========================================================================== */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr 300px;
    gap: 10px;
    padding: 10px;
    flex-grow: 1;      /* Fill remaining height */
    overflow: hidden;  /* Keep panels contained */
}

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.panel-header {
    background: #f9fafb;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
}

.panel-header h2 {
    font-size: 1rem;
    color: var(--text-dark);
    margin: 0;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ==========================================================================
   Internal Panel Scroll Areas
   ========================================================================== */
.passage-content {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
    font-size: 0.95rem;
    line-height: 1.6;
    color: #374151;
}

.question-panel {
    position: relative;
}

.question-content {
    padding: 20px 20px 10px;
    font-size: 1.05rem;
    font-weight: 500;
}

.options-container {
    padding: 0 20px 20px;
    overflow-y: auto;
    flex-grow: 1;
}

/* Radio Option Styling */
.option-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.option-item:hover {
    background: #f3f4f6;
}

.option-item.selected {
    border-color: var(--primary);
    background: #eff6ff;
}

.option-item input[type="radio"] {
    margin-right: 15px;
    transform: scale(1.2);
    cursor: pointer;
}

/* Actions Bar (Footer of center panel) */
.actions-bar {
    border-top: 1px solid var(--border-color);
    padding: 15px 20px;
    background: var(--bg-panel);
    display: flex;
    justify-content: space-between;
}

.btn {
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.btn-review {
    background: transparent;
    color: var(--state-marked);
    border-color: var(--state-marked);
}

.btn-review:hover { background: #fdf4ff; }

.btn-clear {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border-color);
    margin-left: 10px;
}

.btn-clear:hover { background: #f3f4f6; color: var(--text-dark); }

.btn-save {
    background: var(--primary);
    color: white;
}

.btn-save:hover { background: var(--primary-hover); }

/* ==========================================================================
   Sidebar & Palette
   ========================================================================== */
.sidebar-panel {
    display: flex;
    flex-direction: column;
}

.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 15px;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    background: #f9fafb;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.badge {
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 4px;
    color: white;
    font-weight: bold;
    font-size: 0.8rem;
}

/* Color States */
.bg-answered { background: var(--state-answered); }
.bg-not-answered { background: var(--state-not-answered); }
.bg-marked { background: var(--state-marked); }
.bg-not-visited { background: var(--state-not-visited); color: var(--text-dark); border: 1px solid var(--border-color); }

/* Grid of buttons */
.palette-sections {
    padding: 15px;
    overflow-y: auto;
    flex-grow: 1;
}

.palette-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.q-btn {
    height: 35px;
    width: 100%;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--state-not-visited);
    color: var(--text-dark);
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.1s;
    outline: none;
}

.q-btn:hover { transform: scale(1.05); }

.q-btn.active-q { border: 2px solid var(--primary); box-shadow: 0 0 5px rgba(37,99,235,0.4); }

.q-btn.answered { background: var(--state-answered); color: white; border-color: var(--state-answered); }
.q-btn.not_answered { background: var(--state-not-answered); color: white; border-color: var(--state-not-answered); }
.q-btn.marked { background: var(--state-marked); color: white; border-color: var(--state-marked); }

/* Submit Button */
.submit-area {
    padding: 15px;
    border-top: 1px solid var(--border-color);
    background: #f9fafb;
}

.btn-submit {
    width: 100%;
    background: var(--state-answered);
    color: white;
    padding: 12px;
    font-size: 1rem;
}

.btn-submit:hover { background: #16a34a; }

/* Status indicator in center panel */
.status-indicator {
    font-size: 0.8rem;
    padding: 4px 10px;
    border-radius: 20px;
    font-weight: 600;
    background: var(--state-not-visited);
    border: 1px solid var(--border-color);
}

/* ==========================================================================
   Modal Options
   ========================================================================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-panel);
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.result-summary p { margin: 10px 0; text-align: left; }
.result-summary hr { margin: 15px 0; border: none; border-top: 1px solid var(--border-color); }
.text-success { color: var(--state-answered); }
.text-danger { color: var(--state-not-answered); }

/* ==========================================================================
   Responsive (Mobile Settings)
   ========================================================================== */
.mobile-palette-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--primary);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 30px;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 50;
}

@media (max-width: 1024px) {
    .main-layout {
        grid-template-columns: 1fr 300px;
    }
    .passage-panel {
        display: none; /* Hide passage on narrow screens or handle via toggles */
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto; /* Enable page scroll for mobile */
    }

    .main-layout {
        display: flex;
        flex-direction: column;
        overflow: visible;
        padding-bottom: 80px; /* Space for fixed actions */
    }

    .passage-panel {
        display: flex; /* Show passage stacked above question */
        max-height: 250px;
    }

    .question-panel {
        min-height: 400px;
    }

    .actions-bar {
        flex-direction: column;
        gap: 10px;
    }
    
    .left-actions, .right-actions {
        display: flex;
        width: 100%;
        gap: 10px;
    }
    
    .btn {
        flex: 1;
        text-align: center;
        padding: 10px;
    }

    /* Hide Sidebar, Make it a fixed modal drawer */
    .sidebar-panel {
        position: fixed;
        top: 0;
        right: -100%; /* Hidden originally */
        width: 80%;
        max-width: 350px;
        height: 100%;
        z-index: 60;
        transition: right 0.3s ease;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        border-radius: 0;
    }

    .sidebar-panel.show {
        right: 0;
    }

    .mobile-palette-toggle {
        display: block;
    }

    .user-profile div:last-child {
        display: none; /* Hide name on mobile */
    }
}