body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f9;
    color: #333;
}

/* Login Overlay */
#login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #2c3e50;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.login-box {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.login-box input {
    padding: 10px;
    font-size: 16px;
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 200px;
}

.login-box button {
    padding: 10px 20px;
    font-size: 16px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.login-box button:hover {
    background-color: #2980b9;
}

.error {
    color: red;
    margin-top: 10px;
}

/* Main Content */
header {
    background-color: #34495e;
    color: white;
    padding: 1rem;
    text-align: center;
}

main {
    padding: 2rem;
    max-width: 800px;
    margin: 0 auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

th,
td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

th {
    background-color: #ecf0f1;
    font-weight: 600;
    color: #2c3e50;
}

tr:hover {
    background-color: #f9f9f9;
}

.hidden {
    display: none;
}


#no-devices {
    text-align: center;
    padding: 20px;
    color: #7f8c8d;
    font-style: italic;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgb(0, 0, 0);
    background-color: rgba(0, 0, 0, 0.4);
}

.modal-content {
    background-color: #fefefe;
    margin: 5% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 900px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Question Styles within Modal */
.question-block {
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 15px;
    overflow: hidden;
}

.question-header {
    padding: 10px 15px;
    background-color: #f8f9fa;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.question-header.status-correct {
    background-color: #d4edda;
    color: #155724;
}

.question-header.status-wrong {
    background-color: #f8d7da;
    color: #721c24;
}

.question-header.status-partial {
    background-color: #fff3cd;
    color: #856404;
}

.q-text {
    font-weight: 600;
    flex-grow: 1;
    margin: 0 15px;
}

.q-points {
    font-weight: bold;
    white-space: nowrap;
}

.question-body {
    padding: 15px;
    background-color: white;
}

.q-addition {
    font-style: italic;
    color: #555;
    margin-bottom: 10px;
    padding: 5px 10px;
    background: #f9f9f9;
    border-left: 3px solid #ccc;
}

.answer-row,
.solution-row {
    margin-bottom: 5px;
    line-height: 1.4;
}

.solution-row {
    color: #27ae60;
    margin-top: 5px;
}

.ai-reason {
    margin-top: 10px;
    padding: 8px;
    background-color: #f0f4ff;
    border-radius: 4px;
    font-size: 0.9em;
    color: #333;
    border-left: 3px solid #3498db;
}

pre {
    background: #f4f4f4;
    padding: 5px;
    border-radius: 3px;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.85em;
    margin: 5px 0;
}

.nav-link {
    color: #3498db;
    text-decoration: none;
    font-size: 0.9em;
    margin-left: 10px;
}

.nav-link:hover {
    text-decoration: underline;
}


/* Document Rendering Styles */
.document-wrapper {
    margin-top: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    overflow: hidden;
    background: #fff;
}

.doc-tabs {
    display: flex;
    background: #f1f1f1;
    border-bottom: 1px solid #ccc;
}

.doc-tab {
    padding: 10px 20px;
    cursor: pointer;
    background: #f1f1f1;
    border: none;
    border-right: 1px solid #ccc;
    font-weight: bold;
    color: #555;
    outline: none;
}

.doc-tab:hover {
    background-color: #ddd;
}

.doc-tab.active {
    background: #fff;
    color: #333;
    border-bottom: 2px solid #3498db;
}

.doc-view {
    display: none;
    padding: 10px;
    position: relative;
    /* Maintain aspect ratio or max width */
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
}

.doc-view.active {
    display: block;
}

.doc-container {
    position: relative;
    width: 100%;
}

.doc-bg {
    width: 100%;
    height: auto;
    display: block;
    pointer-events: none;
}

.doc-field {
    position: absolute;
    /* Border for debugging/visibility similar to editor */
    /* border: 1px solid rgba(0, 0, 0, 0.1); */
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: transparent;
    font-family: 'Segoe UI', sans-serif;
    font-size: 0.9rem;
    /* Adjust based on image scale? responsive font size might be needed */
    padding: 2px 4px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
}

/* Make font responsive to container width using container queries or simplervw/calc? 
   For now, we use a fixed size that looks okay on desktop. 
   Ideally, we would scale font-size with the container. */
.doc-field.text-field {
    color: black;
    font-weight: 500;
}

.back-link {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: #333;
    background-color: #f5f5f5;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    border: 1px solid #ddd;
}

.back-link:hover {
    background-color: #e0e0e0;
    color: #000;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.doc-field.checkbox-field {
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: black;
    border: none;
    /* No underline for checkboxes usually */
}

/* Solution View Styles override */
.doc-view.solution-view .doc-field.text-field {
    color: #27ae60;
    /* Green for solution */
    font-weight: 600;
}

.doc-view.solution-view .doc-field.checkbox-field {
    color: #27ae60;
}

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

header h1 {
    margin: 0;
    font-size: 1.5rem;
}


/* Print Styles - Strict & Clean */
@media print {
    @page {
        margin: 1cm;
        size: A4;
    }

    body {
        margin: 0;
        padding: 0;
        background: white;
        font-size: 11pt;
        /* Readable print size */
        color: black;
    }

    /* --- HIDE UI ELEMENTS --- */
    header,
    #loading,
    #exams-table,
    .modal-header-actions,
    .close-modal,
    .doc-tabs,
    /* Hide document tabs */
    .doc-tab,
    input[type="radio"],
    /* Hide toggle radios */
    input[type="checkbox"],
    /* Hide checkboxes if not part of document */
    label,
    /* Hide labels for toggles */
    .solution-row,
    /* Hide text solutions */
    .solution-view,
    /* Hide visual solutions */
    .q-addition

    /* Optional: hide question addition if redundant, but usually keep */
        {
        display: none !important;
    }

    /* --- RESET MODAL LAYOUT --- */
    .modal {
        display: block !important;
        position: static;
        z-index: auto;
        padding: 0;
        margin: 0;
        width: 100%;
        height: auto;
        overflow: visible;
        background: white !important;
    }

    .modal-content {
        position: static;
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
        background: white !important;
        overflow: visible;
    }

    /* --- ENFORCE ANSWER VISIBILITY --- */
    .answer-view {
        display: block !important;
    }

    /* --- QUESTION BLOCKS --- */
    .question-block {
        border: none;
        border-bottom: 1px solid #ccc;
        margin-bottom: 15px;
        padding-bottom: 10px;
        page-break-inside: avoid;
    }

    .question-header {
        background-color: transparent !important;
        border-bottom: 1px solid #eee;
        color: black;
        font-weight: bold;
        padding: 5px 0;
    }

    /* --- VISUAL DOCUMENTS --- */
    .document-wrapper {
        border: none;
        /* Remove box look */
        margin: 10px 0;
    }

    .doc-container {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        page-break-inside: avoid;
        width: fit-content;
        max-width: 100%;
        margin: 0 auto;
        position: relative;
    }

    .doc-bg {
        max-height: 23cm;
        /* Fit on A4 page if needed */
        width: auto;
        max-width: 100%;
    }

    /* Make document fields clearly legible */
    .doc-field {
        font-weight: bold;
        color: #000 !important;
        /* Force black/dark text for printing */
    }

    .doc-field.text-field {
        color: #000 !important;
        /* Override blue */
    }

    /* Remove extra spacing/scrollbars */
    * {
        overflow: visible !important;
    }
}