:root {
    --theme-orange: #7c3aed;
    /* Updated Purple Theme */
    --theme-dark: #4c1d95;
    /* Deep Purple */
    --border-color: #000;
    --text-color: #000;
    --surface: #fff;
    --bg-app: #f5f3ff;
    /* Light Purple Tint */
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Roboto', sans-serif;
    background: var(--bg-app);
    margin: 0;
    color: var(--text-color);
}

/* --- Layout --- */
.app-container {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 20px;
    padding: 20px;
    height: 100vh;
    overflow: hidden;
}



.navbar {
    height: 60px;
    background: white;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    padding: 0 20px;
    justify-content: space-between;
}

.btn {
    padding: 8px 16px;
    cursor: pointer;
    border: 1px solid #ccc;
    background: #eee;
}

.btn-primary {
    background: var(--theme-orange);
    color: white;
    border-color: var(--theme-dark);
}

/* --- Input Section --- */
.input-section {
    overflow-y: auto;
    padding-right: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.card {
    background: white;
    border: 1px solid #ddd;
    padding: 15px;
    border-radius: 4px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
}

.card-header h3 {
    margin: 0;
    font-size: 14px;
    text-transform: uppercase;
    color: #555;
}

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

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    color: #333;
    font-family: inherit;
}

.form-grid input:hover,
.form-grid select:hover,
.form-grid textarea:hover {
    border-color: #bdbdbd;
}

.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
    border-color: var(--theme-orange);
    box-shadow: 0 0 0 3px rgba(93, 63, 211, 0.1);
    outline: none;
}

.form-grid textarea {
    grid-column: span 2;
    height: 80px;
    resize: vertical;
}

.row-inputs {
    grid-column: span 2;
    display: flex;
    gap: 5px;
}

/* Subject Row Input */
.subject-row-input {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
    align-items: center;
}

.subject-row-input input {
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    background: #fff;
    font-size: 14px;
    transition: all 0.2s;
}

.subject-row-input input:focus {
    border-color: var(--theme-orange);
    outline: none;
    box-shadow: 0 0 0 2px rgba(93, 63, 211, 0.1);
}

.inp-sub-name {
    flex: 2;
}

.inp-sub-ca,
.inp-sub-exam {
    width: 60px;
    /* Slightly wider */
    text-align: center;
}

/* Traits Input */
.traits-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: center;
}

.trait-row {
    display: contents;
}

.trait-label {
    font-size: 13px;
    align-self: center;
}

.trait-select {
    padding: 4px;
}

/* --- Report Preview (The Paper) --- */
.preview-section {
    background: #525659;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.report-paper {
    background: white;
    width: 210mm;
    min-height: 297mm;
    padding: 10mm;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    font-size: 11px;
    /* Dense information */
}

/* Report Header */
.report-header {
    display: flex;
    gap: 20px;
    margin-bottom: 5px;
}

.logo-box {
    width: 150px;
    height: 150px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    border: none;
}

.school-details {
    flex: 1;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.school-details h1 {
    margin: 0;
    font-size: 32px;
    /* Increased from 24px */
    font-weight: 900;
    /* Extra Bold */
    text-transform: uppercase;
    line-height: 1.2;
}

.school-details p {
    margin: 3px 0;
    font-size: 15px;
    /* Increased */
    font-weight: bold;
}

/* Theme Bars */
.orange-bar {
    background: var(--theme-orange);
    color: black;
    text-align: center;
    font-weight: bold;
    padding: 4px;
    border: 1px solid black;
    text-transform: uppercase;
    font-size: 12px;
    margin-bottom: 5px;
}

.orange-bar-sm {
    background: var(--theme-orange);
    border: 1px solid black;
    border-bottom: none;
    text-align: center;
    font-weight: bold;
    font-size: 10px;
    padding: 2px;
}

/* Info Table (Section A) */
.info-section {
    margin-bottom: 10px;
}

.info-table {
    width: 100%;
    border-collapse: collapse;
    border: 1px solid black;
}

.info-table td {
    border: 1px solid black;
    padding: 2px 5px;
}

.info-table .label {
    background: #fff;
    width: 1%;
    white-space: nowrap;
    font-weight: bold;
    text-align: right;
}

.info-table .val {
    font-weight: bold;
    text-align: center;
}

.info-table .val-lg {
    font-weight: bold;
    text-align: center;
    text-transform: uppercase;
}

.info-table .val-xl {
    font-weight: bold;
    text-align: center;
    font-size: 14px;
}

/* Main Grid */
.main-grid {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1%;
    /* Adjusted to give more gap */
    width: 100%;
    margin-bottom: 5px;
}

/* Columns */
.col-left {
    width: 63%;
    overflow: hidden;
}

.col-right {
    width: 36%;
    overflow: hidden;
}

/* Academic Table */
.academic-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    border: 1px solid black;
    margin-bottom: 10px;
    table-layout: fixed;
    /* Force table to respect container width */
}

.academic-table th {
    border: 1px solid black;
    padding: 2px 4px;
    text-align: center;
    font-weight: bold;
    background: white;
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.academic-table td {
    border: 1px solid black;
    padding: 2px 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    /* Prevent wrapping causing height issues */
}

/* Adjust column width slightly to prioritize subject name */
.col-left {
    overflow: hidden;
    /* Ensure content doesn't bleed out */
}

.vertical-text {
    white-space: nowrap;
    font-size: 9px;
    /* Smaller for headers */
}

/* Simplified from reference to keep readable */

/* Attribute Tables */
.attr-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9px;
    /* Slightly smaller */
    border: 1px solid black;
    table-layout: fixed;
    /* Crucial: prevent expansion */
}

.attr-table th {
    background: white;
    border: 1px solid black;
    padding: 2px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attr-table td {
    border: 1px solid black;
    padding: 2px 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attr-table td:last-child {
    text-align: center;
    font-weight: bold;
    background: var(--theme-orange);
    width: 30px;
    /* Force small width regarding grade */
}

/* Keys Table */
.keys-table-wrapper {
    margin-top: 10px;
}

.keys-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    border: 1px solid black;
    text-align: center;
}

.keys-table td {
    border: 1px solid black;
    padding: 2px;
}

/* Attendance */
.attendance-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 10px;
    border: 1px solid black;
}

.attendance-table td {
    border: 1px solid black;
    padding: 2px 5px;
}

.attendance-table .val-box {
    text-align: center;
    font-weight: bold;
    width: 40px;
}

/* Footer */
.footer-section {
    margin-top: 10px;
}

.comments-grid {
    border: 1px solid black;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.comment-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.cmt-label {
    font-size: 10px;
    font-weight: bold;
    width: 80px;
}

.cmt-line-group {
    flex: 1;
    display: flex;
    gap: 10px;
}

.cmt-line {
    flex: 1;
    border-bottom: 1px solid black;
    font-size: 11px;
    font-weight: bold;
    font-style: italic;
}

.sign-line {
    width: 100px;
    border-top: 1px solid black;
    height: 0;
    position: relative;
    margin-left: 10px;
    margin-top: 15px;
}

.signature-img {
    position: absolute;
    bottom: -5px;
    /* Move it down slightly so the signature baseline hits the line? No, let's try pushing it up a bit if it was overlapping */
    /* If bottom:0 aligns bottom of image to line. */
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    max-height: 30px;
    /* Small but visible */
    width: auto;
    margin-bottom: 1px;
    /* Just above line */
    pointer-events: none;
    mix-blend-mode: multiply;
}

/* Simple Chart */
.chart-container {
    height: 100px;
    border: 1px solid black;
    margin-top: 0;
    padding: 10px;
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
}

/* Print Overrides */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    body {
        margin: 0;
        padding: 0;
        background: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        width: 210mm;
        height: 297mm;
    }

    .no-print,
    .input-section,
    .navbar {
        display: none !important;
    }

    .app-container {
        display: block;
        padding: 0;
        height: auto;
        overflow: visible;
    }

    .preview-section {
        padding: 0;
        background: white;
        display: block;
        width: 100%;
        height: 100%;
    }

    .report-paper {
        box-shadow: none;
        width: 210mm;
        /* Allow height to grow so JS can measure and scale back */
        height: auto;
        min-height: 296mm;
        padding: 5mm;
        margin: 0 auto;
        page-break-after: always;
        overflow: visible;
        position: relative;
    }

    /* Force colors */
    .orange-bar,
    .orange-bar-sm {
        background: var(--theme-orange) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        color: black !important;
    }
}

/* --- Global Config Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.modal-box h3 {
    margin-top: 0;
    color: var(--theme-dark);
    margin-bottom: 20px;
}

.modal-box label {
    text-align: left;
    display: block;
    margin-top: 15px;
    font-weight: bold;
    font-size: 13px;
    color: #555;
}

.modal-box input,
.modal-box select {
    width: 100%;
    padding: 10px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box;
}

.modal-box button {
    margin-top: 25px;
    width: 100%;
    padding: 12px;
    background: var(--theme-orange);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
}

.modal-box button:hover {
    opacity: 0.9;
}