/* ===============================
   CSS Variables & Reset
   =============================== */
:root {
    --primary-color: #4361ee;
    --primary-dark: #3651d4;
    --secondary-color: #7209b7;
    --success-color: #06d6a0;
    --danger-color: #ef476f;
    --warning-color: #ffd166;
    --info-color: #118ab2;
    --dark-color: #1d3557;
    --light-color: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #868e96;
    --gray-700: #495057;
    --gray-800: #343a40;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.3s ease;
}

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

.hidden {
    display: none !important;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--dark-color);
    line-height: 1.5;
}

/* ===============================
   App Container
   =============================== */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--light-color);
    display: flex;
    flex-direction: column;
}

/* ===============================
   OpenCV Loading Banner
   =============================== */
.opencv-loading-banner {
    background: linear-gradient(135deg, #ffd166, #ffb347);
    color: var(--dark-color);
    padding: 8px 16px;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.opencv-loading-banner.ready {
    background: linear-gradient(135deg, var(--success-color), #04b78a);
    color: white;
}

.opencv-loading-banner.error {
    background: linear-gradient(135deg, var(--danger-color), #d63a5e);
    color: white;
}

.opencv-loading-banner.hidden {
    display: none;
}

/* ===============================
   Header
   =============================== */
.app-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow-md);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.app-header .subtitle {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-top: 5px;
}

/* ===============================
   Navigation
   =============================== */
.main-nav {
    display: flex;
    background: white;
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: var(--gray-600);
    font-size: 0.7rem;
    cursor: pointer;
    transition: var(--transition);
    gap: 4px;
}

.nav-btn i {
    font-size: 1.2rem;
}

.nav-btn:hover {
    background: var(--gray-100);
    color: var(--primary-color);
}

.nav-btn.active {
    color: var(--primary-color);
    background: rgba(67, 97, 238, 0.1);
    border-bottom: 3px solid var(--primary-color);
}

/* ===============================
   Main Content
   =============================== */
.main-content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    padding-bottom: 80px;
}

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===============================
   Cards
   =============================== */
.welcome-card,
.form-card,
.scan-card,
.results-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-md);
}

.welcome-card h2,
.form-card h2,
.scan-card h2,
.results-card h2 {
    font-size: 1.2rem;
    color: var(--dark-color);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===============================
   Exam List
   =============================== */
.exam-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.exam-item {
    background: var(--gray-100);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: var(--transition);
}

.exam-item:hover {
    background: var(--gray-200);
}

.exam-item-info h3 {
    font-size: 1rem;
    color: var(--dark-color);
    margin-bottom: 4px;
}

.exam-item-info p {
    font-size: 0.8rem;
    color: var(--gray-600);
}

.exam-item-actions {
    display: flex;
    gap: 8px;
}

.exam-item-actions button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-icon-secondary {
    background: var(--gray-300);
    color: var(--gray-700);
}

.btn-icon-danger {
    background: var(--danger-color);
    color: white;
}

.btn-icon-success {
    background: var(--success-color);
    color: white;
}

.btn-icon-info {
    background: var(--info-color);
    color: white;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--gray-600);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    margin-bottom: 16px;
}

/* ===============================
   Forms
   =============================== */
.exam-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 6px;
}

.form-group input,
.form-group select {
    padding: 12px 14px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: white;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
}

.wrong-penalty-input {
    display: flex;
    align-items: center;
    gap: 10px;
}

.wrong-penalty-input input {
    width: 80px;
    text-align: center;
}

.wrong-penalty-input .penalty-hint {
    font-size: 0.8rem;
    color: var(--gray-600);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.checkbox-group,
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.checkbox-label,
.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 12px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.checkbox-label:hover,
.radio-label:hover {
    background: var(--gray-200);
}

.checkbox-label input,
.radio-label input {
    width: 18px;
    height: 18px;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-600);
    margin-top: 4px;
}

/* ===============================
   Buttons
   =============================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--gray-300);
}

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

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

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

.btn-warning {
    background: var(--warning-color);
    color: var(--dark-color);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 16px;
}

/* After-save action buttons */
.after-save-actions {
    background: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: var(--radius-sm);
    padding: 12px;
    animation: fadeIn 0.3s ease;
}

.after-save-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 10px;
    text-align: center;
}

.after-save-buttons {
    display: flex;
    gap: 8px;
}

.after-save-buttons .btn {
    flex: 1;
    font-size: 0.82rem;
    padding: 10px 8px;
}

.btn-accent {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger-color);
    border: 2px solid var(--danger-color);
}

.btn-danger-outline:hover {
    background: var(--danger-color);
    color: white;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===============================
   Answer Key Form
   =============================== */
.exam-info-banner {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.booklet-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.booklet-tab {
    padding: 10px 20px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.booklet-tab.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.answer-key-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
}

.answer-key-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: white;
    border-radius: var(--radius-sm);
    border: 1px solid var(--gray-200);
}

.answer-key-item .question-num {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--dark-color);
    min-width: 30px;
    text-align: center;
}

.answer-key-item .answer-options {
    display: flex;
    gap: 8px;
    flex: 1;
}

.answer-key-item .answer-option {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    color: var(--dark-color);
}

.answer-key-item .answer-option:hover {
    border-color: var(--primary-color);
    background: var(--gray-100);
}

.answer-key-item .answer-option.selected {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* ===============================
   Answer Key Grid (Yeni Tasarım)
   =============================== */
.answer-key-grid {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    overflow: visible;
    margin-bottom: 16px;
}

.ak-header-row {
    display: flex;
    align-items: center;
    background: var(--primary-color);
    color: white;
    padding: 8px 0;
    font-weight: 700;
    font-size: 0.85rem;
}

.ak-header-num {
    min-width: 44px;
    text-align: center;
    flex-shrink: 0;
}

.ak-header-opt {
    flex: 1;
    text-align: center;
}

.ak-row {
    display: flex;
    align-items: center;
    padding: 4px 0;
    border-bottom: 1px solid var(--gray-200);
    transition: background 0.15s;
}

.ak-row:last-child {
    border-bottom: none;
}

.ak-row-even {
    background: var(--gray-50, #f9fafb);
}

.ak-row:hover {
    background: #eef2ff;
}

.ak-num {
    min-width: 44px;
    text-align: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--gray-700);
    flex-shrink: 0;
}

.ak-options {
    display: flex;
    flex: 1;
    gap: 0;
}

.ak-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 8px 4px;
    transition: all 0.15s;
    position: relative;
}

.ak-option input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ak-option span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid var(--gray-300);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-600);
    background: white;
    transition: all 0.15s;
}

.ak-option:hover span {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: #eef2ff;
}

.ak-option.selected span {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.35);
}

@media (max-width: 480px) {
    .ak-option span {
        width: 30px;
        height: 30px;
        font-size: 0.8rem;
    }
    .ak-num {
        min-width: 36px;
        font-size: 0.8rem;
    }
}

/* ===============================
   Answer Sheet Preview
   =============================== */
.booklet-select-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.booklet-select-container select {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
}

.answer-sheet-preview {
    background: white;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    text-align: center;
}

.answer-sheet-preview canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--gray-200);
}

/* ===============================
   Form Generator
   =============================== */
.section-desc {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-bottom: 16px;
    line-height: 1.5;
}

.fg-preview-area {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-300);
}

.fg-preview-area.hidden {
    display: none;
}

.fg-preview-area h3 {
    margin-bottom: 12px;
    font-size: 1.05rem;
    color: var(--gray-800);
}

.fg-canvas-wrapper {
    background: white;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    text-align: center;
    margin-bottom: 16px;
}

.fg-canvas-wrapper canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--gray-200);
}

.answer-sheet {
    margin: 0 auto;
    padding: 10px;
    background: white;
    font-family: Arial, sans-serif;
    border: 2px solid #000;
    box-sizing: border-box;
}

.sheet-horizontal {
    width: 20cm;
}

.sheet-vertical {
    width: 12cm;
}

/* Header Section */
.sheet-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 8px;
    border-bottom: 2px solid #000;
    margin-bottom: 10px;
}

.exam-title {
    font-size: 0.9rem;
    font-weight: bold;
    margin: 0;
    flex: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qr-code-container #qr-code {
    display: inline-block;
}

.qr-code-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid #ddd;
    margin-top: 12px;
}

.qr-code-large {
    display: inline-block;
}

.qr-code-large img {
    max-width: 100%;
    height: auto;
}

.qr-code-label {
    font-size: 0.65rem;
    font-weight: 500;
    color: #333;
    text-align: center;
    margin: 0;
    letter-spacing: 0.5px;
}

.header-logo {
    max-width: 50px;
    max-height: 50px;
    object-fit: contain;
}

/* Three Column Body */
.sheet-body {
    display: flex;
    gap: 10px;
    align-items: stretch;
}

.column {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Column 1: Student Info */
.column-1 {
    width: 150px;
    justify-content: space-between;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.info-item label {
    font-size: 0.65rem;
    font-weight: bold;
}

.info-input {
    border-bottom: 1px solid #000;
    height: 16px;
}

.info-item.signature {
    height: 48px;
    display: flex;
    flex-direction: column;
}

.signature-area {
    border-bottom: 1px solid #000;
    flex: 1;
    min-height: 12px;
}

/* Column 2: Coding */
.column-2 {
    width: 180px;
}

.booklet-block,
.marking-block,
.number-coding-block {
    border: 1.5px solid #000;
    padding: 6px;
    border-radius: 3px;
}

.block-label {
    font-size: 0.65rem;
    font-weight: bold;
    display: block;
    margin-bottom: 4px;
}

/* Booklet */
.booklet-options {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.booklet-option {
    width: 30px;
    height: 30px;
    border: 2px solid #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: bold;
}

/* Marking Example */
.marking-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.marking-row:last-child {
    margin-bottom: 0;
}

.marking-label {
    font-size: 0.6rem;
    font-weight: bold;
    min-width: 50px;
}

.marking-examples {
    display: flex;
    gap: 4px;
}

.bubble-demo {
    width: 18px;
    height: 18px;
    border: 1.5px solid #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
}

.bubble-demo.correct {
    background: #000;
    color: white;
}

/* Student Number */
.number-manual-boxes {
    display: flex;
    gap: 2px;
    margin-bottom: 3px;
}

.manual-box {
    width: 16px;
    height: 18px;
    border: 1.5px solid #000;
    background: white;
}

.number-bubbles {
    display: flex;
    gap: 2px;
}

.digit-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
}

.digit-bubble {
    width: 16px;
    height: 16px;
    border: 1px solid #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: bold;
}

/* Column 3: Answers */
.column-3 {
    flex: 1;
}

.column-title {
    font-size: 0.7rem;
    font-weight: bold;
    text-align: center;
    border-bottom: 1.5px solid #000;
    padding-bottom: 1px;
    margin: 0 0 1px 0;
}

.answers-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-wrap: wrap;
    max-height: calc(10 * 60px);
    height: 450px;
    align-content: flex-start;
}

.answer-row {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 20px;
}

.answer-row .q-num {
    font-size: 0.6rem;
    font-weight: bold;
    min-width: 18px;
    text-align: right;
}

.answer-options {
    display: flex;
    gap: 3px;
}

.answer-bubble {
    width: 16px;
    height: 16px;
    border: 1.3px solid #000;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    font-weight: bold;
}

.answer-bubble.marked-answer {
    background-color: #4CAF50;
    border-color: #2E7D32;
}

.answer-bubble.marked-answer .marked-indicator {
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
}

/* ===============================
   Scanner
   =============================== */
.scan-mode-select {
    margin-bottom: 20px;
}

.divider {
    display: flex;
    align-items: center;
    margin: 16px 0;
    color: var(--gray-500);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-300);
}

.divider span {
    padding: 0 12px;
    font-size: 0.85rem;
}

.scanner-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: black;
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

.scanner-container.hidden {
    display: none;
}

.scanner-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 16px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

#optical-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.marker-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scanner-frame {
    width: 250px;
    height: 250px;
    border: 3px solid var(--primary-color);
    border-radius: var(--radius-md);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.close-scanner {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.capture-btn {
    position: absolute;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

/* ===============================
   Debug Preview
   =============================== */

.scan-buttons-row {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.scan-buttons-row .btn {
    flex: 1;
}

.file-preview-container {
    margin-top: 16px;
    background: var(--gray-100);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: center;
}

.file-preview-container.hidden {
    display: none;
}

.file-preview-image {
    max-width: 100%;
    max-height: 400px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    object-fit: contain;
}

.file-preview-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.debug-preview-container {
    margin-bottom: 16px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    padding: 12px;
    text-align: center;
}

.debug-preview-container.hidden {
    display: none;
}

.debug-canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--gray-300);
    margin-bottom: 8px;
}

/* ===============================
   Flagged Questions
   =============================== */
.flagged-questions {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-top: 12px;
}

.flagged-questions.hidden {
    display: none;
}

.flagged-questions h4 {
    font-size: 0.9rem;
    color: #856404;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.flag-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    margin-bottom: 4px;
    background: white;
    border-radius: 4px;
    font-size: 0.85rem;
}

.flag-item .flag-type {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: 600;
}

.flag-type.multi-mark {
    background: var(--danger-color);
    color: white;
}

.flag-type.low-confidence {
    background: var(--warning-color);
    color: var(--dark-color);
}

.flag-type.empty {
    background: var(--gray-400);
    color: white;
}

/* ===============================
   Result Edit Inputs
   =============================== */
.result-edit-input,
.result-edit-select {
    padding: 6px 10px;
    border: 2px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    min-width: 120px;
    text-align: center;
}

.result-edit-input:focus,
.result-edit-select:focus {
    border-color: var(--primary-color);
    outline: none;
}

/* ===============================
   Scan Result
   =============================== */
.scan-result {
    background: var(--gray-100);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-top: 20px;
}

.scan-result.hidden {
    display: none;
}

.scan-result h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--success-color);
    margin-bottom: 16px;
}

.result-details {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: white;
    border-radius: var(--radius-sm);
}

.result-item .label {
    color: var(--gray-600);
}

.result-item .value {
    font-weight: 600;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.result-stats .stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    background: white;
    border-radius: var(--radius-sm);
}

.result-stats .stat i {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

.result-stats .stat span {
    font-size: 1.5rem;
    font-weight: 700;
}

.result-stats .stat small {
    font-size: 0.75rem;
    color: var(--gray-600);
}

.result-stats .correct {
    color: var(--success-color);
}

.result-stats .wrong {
    color: var(--danger-color);
}

.result-stats .empty {
    color: var(--gray-500);
}

.result-summary {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-radius: var(--radius-sm);
    border: 2px solid var(--gray-200);
}

.summary-item .highlight {
    font-size: 1.3rem;
    color: var(--primary-color);
}

/* ===============================
   Results Page
   =============================== */
.results-summary {
    margin: 16px 0;
}

.results-summary.hidden {
    display: none;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 8px;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    text-align: center;
}

.stat-box i {
    font-size: 1.2rem;
    color: var(--primary-color);
    margin-bottom: 4px;
}

.stat-box span {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--dark-color);
}

.stat-box small {
    font-size: 0.7rem;
    color: var(--gray-600);
}

.results-table-container {
    overflow-x: auto;
    margin: 16px 0;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.results-table th,
.results-table td {
    padding: 10px 8px;
    text-align: center;
    border-bottom: 1px solid var(--gray-200);
}

.results-table th {
    background: var(--gray-100);
    font-weight: 600;
    color: var(--gray-700);
    position: sticky;
    top: 0;
}

.results-table tbody tr:hover {
    background: var(--gray-100);
}

.results-table .btn-icon-danger {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
}

/* ===============================
   Toast
   =============================== */
.toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    background: var(--dark-color);
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

/* ===============================
   Loading Overlay
   =============================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--gray-300);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay p {
    margin-top: 16px;
    color: var(--gray-700);
}

/* ===============================
   Modal
   =============================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2500;
    padding: 20px;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
    font-size: 1.1rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--gray-500);
    cursor: pointer;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* ===============================
   Print Styles
   =============================== */
@media print {
    body {
        background: white;
    }
    
    .app-header,
    .main-nav,
    .button-group,
    .booklet-select-container,
    .opencv-loading-banner {
        display: none !important;
    }
    
    .main-content {
        padding: 0;
    }
    
    .form-card {
        box-shadow: none;
        padding: 0;
    }
    
    .answer-sheet-preview {
        border: none;
        padding: 0;
    }
    
    .answer-sheet-preview canvas {
        max-width: 100%;
        border: none;
    }
}

/* ===============================
   Responsive
   =============================== */
@media (max-width: 400px) {
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .summary-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .answers-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .answer-key-form {
        grid-template-columns: repeat(4, 1fr);
    }
}

.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 25px;
}

.auth-header i {
    font-size: 3rem;
    color: var(--primary-color);
    margin-bottom: 10px;
    display: block;
}

.auth-header h1 {
    font-size: 1.5rem;
    color: var(--dark-color);
    margin-bottom: 5px;
}

.auth-header p {
    color: var(--gray-600);
    font-size: 0.9rem;
}

.auth-form .form-group {
    margin-bottom: 20px;
}

.auth-error {
    background: rgba(239, 71, 111, 0.1);
    color: var(--danger-color);
    padding: 12px 15px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
    font-size: 0.9rem;
    color: var(--gray-600);
}

.auth-footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.header-user {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.header-user .user-name {
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.header-user .btn {
    padding: 6px 12px;
    font-size: 0.8rem;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    border-radius: 5px;
    text-decoration: none;
    transition: all 0.3s ease;
}

.header-user .btn:hover {
    background: rgba(255, 255, 255, 0.25);
}
