/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #22c55e;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 1rem;
    opacity: 0.9;
}

/* Navigation Tabs */
.nav-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 8px;
}

.tab-btn {
    flex: 1;
    min-width: 120px;
    padding: 12px 16px;
    border: none;
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    box-shadow: var(--shadow);
}

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

.tab-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-lg);
}

/* Tab Content */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.card h3 {
    font-size: 1.25rem;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s ease;
    background: var(--surface);
}

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

.form-group input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
}

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

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

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

.btn-secondary:hover {
    background: #475569;
    transform: translateY(-1px);
}

.button-group {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.button-group .btn {
    flex: 1;
    min-width: 140px;
}

/* Sheet Preview */
.sheet-container {
    display: flex;
    justify-content: center;
    margin: 20px 0;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    overflow: auto;
}

#sheet-canvas {
    max-width: 100%;
    height: auto;
    box-shadow: var(--shadow);
}

.note {
    margin-top: 16px;
    padding: 12px;
    background: #fef3c7;
    border-left: 4px solid var(--warning-color);
    border-radius: 4px;
    font-size: 0.9rem;
    color: #92400e;
}

/* Scan Options */
.scan-options {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.scan-options .btn {
    flex: 1;
    min-width: 150px;
}

.icon {
    font-size: 1.2rem;
}

/* Camera View */
.camera-container {
    position: relative;
    width: 100%;
    max-width: 640px;
    margin: 20px auto;
    aspect-ratio: 3/4;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
}

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

#camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.corner-markers {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.marker {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 3px solid #00ff00;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 255, 0, 0.5);
}

.marker.top-left {
    top: 10%;
    left: 10%;
}

.marker.top-right {
    top: 10%;
    right: 10%;
}

.marker.bottom-left {
    bottom: 10%;
    left: 10%;
}

.marker.bottom-right {
    bottom: 10%;
    right: 10%;
}

/* Image Preview */
#captured-image {
    width: 100%;
    max-width: 640px;
    margin: 20px auto;
    display: block;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

/* Processing Result */
.result-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.score-display,
.percentage-display {
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    text-align: center;
}

.score-label,
.percentage-label {
    display: block;
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.score-value,
.percentage-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.answer-details {
    margin-top: 20px;
    max-height: 400px;
    overflow-y: auto;
}

.answer-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.answer-item:last-child {
    border-bottom: none;
}

.answer-item.correct {
    background: #dcfce7;
}

.answer-item.incorrect {
    background: #fee2e2;
}

.answer-number {
    font-weight: 600;
    min-width: 60px;
}

.answer-status {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.answer-status.correct {
    background: var(--success-color);
    color: white;
}

.answer-status.incorrect {
    background: var(--danger-color);
    color: white;
}

.answer-student, .answer-key {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.answer-student strong, .answer-key strong {
    color: var(--text-primary);
}

/* Student Info in Results */
.result-student-info {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
}

.student-info-row {
    font-size: 0.95rem;
    margin-bottom: 4px;
}

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

/* Quiz List */
.quiz-list {
    display: grid;
    gap: 16px;
}

.quiz-item {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.quiz-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.quiz-info h3 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.quiz-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

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

.quiz-actions .btn {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* Student List */
.student-list {
    display: grid;
    gap: 12px;
}

.student-item {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.student-item:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.student-info h3 {
    font-size: 1.05rem;
    margin-bottom: 4px;
}

.student-info p {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

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

.student-actions .btn {
    padding: 8px 16px;
    font-size: 0.9rem;
}

/* 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: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--surface);
    border-radius: 12px;
    padding: 24px;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.modal-actions .btn {
    flex: 1;
}

/* Answer Key Section */
.answer-key-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 2px solid var(--border);
}

.answer-key-options {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.manual-key-entry {
    margin-top: 20px;
}

.key-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 12px;
    max-height: 300px;
    overflow-y: auto;
    padding: 16px;
    background: var(--background);
    border-radius: 8px;
}

.key-input-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: center;
}

.key-question-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.letter-group {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.letter-btn {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.letter-btn:hover {
    border-color: var(--primary-color);
    background: #e8f0fe;
}

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

/* Results List */
.results-list {
    display: grid;
    gap: 16px;
    margin-top: 20px;
}

.result-item {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.result-info h4 {
    font-size: 1.1rem;
    margin-bottom: 4px;
}

.result-info p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.result-score {
    text-align: right;
}

.result-score .score {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.result-score .percentage {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.stat-item {
    padding: 16px;
    background: var(--background);
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Item Analysis */
#item-analysis-content {
    margin-top: 16px;
}

.item-analysis-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

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

.item-number {
    font-weight: 600;
    min-width: 50px;
}

.item-stats {
    display: flex;
    gap: 20px;
    align-items: center;
}

.item-correct {
    color: var(--success-color);
    font-weight: 600;
}

.item-incorrect {
    color: var(--danger-color);
    font-weight: 600;
}

.item-difficulty {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.item-difficulty.easy {
    background: #dcfce7;
    color: #166534;
}

.item-difficulty.medium {
    background: #fef3c7;
    color: #92400e;
}

.item-difficulty.hard {
    background: #fee2e2;
    color: #991b1b;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 12px;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .subtitle {
        font-size: 0.9rem;
    }

    .card {
        padding: 16px;
    }

    .card h2 {
        font-size: 1.25rem;
    }

    .nav-tabs {
        gap: 6px;
    }

    .tab-btn {
        min-width: 100px;
        padding: 10px 12px;
        font-size: 0.85rem;
    }

    .button-group {
        flex-direction: column;
    }

    .button-group .btn {
        width: 100%;
    }

    .result-summary {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .marker {
        width: 40px;
        height: 40px;
    }

    .quiz-item,
    .result-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .quiz-actions,
    .result-score {
        width: 100%;
        justify-content: space-between;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.25rem;
    }

    .card {
        padding: 12px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Print Styles */
@media print {
    .header,
    .nav-tabs,
    .button-group,
    .note {
        display: none !important;
    }

    .sheet-container {
        background: white;
        padding: 0;
    }

    #sheet-canvas {
        box-shadow: none;
    }
}
