/* ==========================================================================
   CSS DESIGN SYSTEM FOR BHAGWAT VIDYAPEETH MARKSHEET GENERATOR
   ========================================================================== */

/* --- ROOT VARIABLES & THEME --- */
:root {
    --primary: #1e293b;        /* Slate 800 */
    --primary-light: #334155;  /* Slate 700 */
    --primary-dark: #0f172a;   /* Slate 900 */
    --accent: #2563eb;         /* Blue 600 */
    --accent-hover: #1d4ed8;   /* Blue 700 */
    --accent-light: #dbeafe;   /* Blue 50 */
    --success: #059669;        /* Emerald 600 */
    --success-light: #d1fae5;  /* Emerald 50 */
    --warning: #d97706;        /* Amber 600 */
    --danger: #dc2626;         /* Red 600 */
    --danger-light: #fee2e2;   /* Red 50 */
    
    /* Layout */
    --sidebar-width: 260px;
    --card-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --card-shadow-hover: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --border-radius: 12px;
    
    /* Font Families */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-display: 'Outfit', sans-serif;
    --font-serif: 'Georgia', serif;
}

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

body {
    font-family: var(--font-sans);
    background-color: #f8fafc; /* Slate 50 */
    color: #334155;
    overflow: hidden;
    height: 100vh;
    display: flex;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* --- APP CONTAINER LAYOUT --- */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* --- SIDEBAR NAVIGATION --- */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--primary);
    color: #f8fafc;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--primary-light);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 32px;
    color: #60a5fa; /* Blue 400 */
}

.logo-text h2 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.logo-text span {
    font-size: 11px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.sidebar-nav {
    flex: 1;
    padding: 24px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-radius: 8px;
    color: #cbd5e1;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-item:hover {
    background-color: var(--primary-light);
    color: #ffffff;
}

.nav-item.active {
    background-color: var(--accent);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.nav-item .material-icons-round {
    font-size: 22px;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--primary-light);
    background-color: var(--primary-dark);
}

/* --- DESIGN CREDIT STYLES --- */
.design-credit-desktop {
    margin-top: 15px;
    font-size: 10px;
    text-align: center;
    color: #94a3b8;
}

.design-credit-desktop a {
    color: #60a5fa;
    text-decoration: none;
    font-weight: 500;
}

.design-credit-desktop a:hover {
    text-decoration: underline;
}

.design-credit-mobile {
    display: none; /* Hidden on desktop */
}

.mobile-host-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--primary-light);
    padding: 10px 12px;
    border-radius: 8px;
}

.host-details h4 {
    font-size: 11px;
    text-transform: uppercase;
    color: #94a3b8;
    letter-spacing: 0.5px;
}

.host-details p {
    font-size: 13px;
    font-weight: 600;
    color: #60a5fa;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
}

.qr-trigger {
    background-color: var(--primary);
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

.qr-trigger:hover {
    background-color: var(--accent);
}

/* --- MAIN CONTENT & HEADER --- */
.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.app-header {
    background-color: #ffffff;
    padding: 20px 32px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.header-left h1 {
    font-family: var(--font-display);
    font-size: 26px;
    font-weight: 700;
    color: var(--primary-dark);
}

.header-left .subtitle {
    font-size: 14px;
    color: #64748b;
    margin-top: 2px;
}

.toggle-preview-btn {
    display: none; /* Mobile only toggle */
}

/* --- DASHBOARD GRID SYSTEM --- */
.dashboard-grid {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100% - 85px);
}

.editor-pane {
    width: 45%;
    min-width: 450px;
    height: 100%;
    padding: 24px;
    overflow-y: auto;
    border-right: 1px solid #e2e8f0;
    background-color: #f8fafc;
}

.preview-pane {
    width: 55%;
    height: 100%;
    background-color: #475569; /* Slate 600 */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- EDITOR CARDS & FORM ELEMENTS --- */
.tab-pane {
    display: none;
    flex-direction: column;
    gap: 20px;
}

.tab-pane.active {
    display: flex;
}

.card {
    background-color: #ffffff;
    border-radius: var(--border-radius);
    border: 1px solid #e2e8f0;
    box-shadow: var(--card-shadow);
    overflow: hidden;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    background-color: #fafafa;
}

.card-header h3 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
}

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

.card-body {
    padding: 20px;
}

/* Grid helper classes inside forms */
.grid-1 { display: flex; flex-direction: column; gap: 15px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; }
.grid-span-2 { grid-column: span 2; }
.row-layout { display: flex; gap: 12px; align-items: center; }
.flex-1 { flex: 1; }
.flex-column { display: flex; flex-direction: column; }
.justify-center { justify-content: center; }
.align-center { align-items: center; }
.mb-5 { margin-bottom: 5px; }
.mt-10 { margin-top: 10px; }
.p-10 { padding: 10px; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.text-muted { color: #64748b; }
.text-xs { font-size: 12px; }

/* Dual inputs side by side */
.dual-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

/* Sub sections inside card-body */
.sub-section {
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 5px;
    margin-top: 10px;
    grid-column: span 2;
}

.sub-section h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Form Fields */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: 12px;
    font-weight: 600;
    color: #475569;
}

.form-input {
    padding: 10px 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    color: #334155;
    background-color: #ffffff;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* --- BUTTONS --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--accent);
    color: #ffffff;
}

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

.btn-secondary {
    background-color: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
}

.btn-accent {
    background-color: var(--success);
    color: #ffffff;
}

.btn-accent:hover {
    background-color: #047857;
}

.btn-large {
    padding: 14px 28px;
    font-size: 16px;
    border-radius: 10px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-full {
    width: 100%;
}

.btn-icon-only {
    width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 50%;
}

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

.button-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* --- DRAG & DROP ZONE --- */
.drop-zone {
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    padding: 32px 20px;
    text-align: center;
    background-color: #f8fafc;
    transition: all 0.2s;
    cursor: pointer;
}

.drop-zone.active {
    border-color: var(--accent);
    background-color: var(--accent-light);
}

.drop-icon {
    font-size: 48px;
    color: #94a3b8;
    margin-bottom: 12px;
}

.drop-text {
    font-size: 14px;
    font-weight: 500;
    color: #475569;
}

.drop-or {
    font-size: 12px;
    color: #94a3b8;
    margin: 8px 0;
}

.import-actions {
    margin-top: 16px;
    display: flex;
    justify-content: center;
}

.import-status-bar {
    margin-top: 16px;
    padding: 10px 14px;
    background-color: #f1f5f9;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: #94a3b8;
}

.status-indicator.success { background-color: var(--success); }
.status-indicator.warning { background-color: var(--warning); }
.status-indicator.error { background-color: var(--danger); }

.status-text {
    font-size: 13px;
    color: #475569;
}

.badge {
    padding: 4px 10px;
    background-color: #e2e8f0;
    color: #475569;
    font-size: 12px;
    font-weight: 600;
    border-radius: 30px;
}

/* --- STUDENT TABLE LIST --- */
.table-container {
    max-height: 250px;
    overflow-y: auto;
}

.student-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.student-table th {
    position: sticky;
    top: 0;
    background-color: #f1f5f9;
    padding: 10px 12px;
    font-weight: 600;
    color: #475569;
    text-align: left;
    border-bottom: 1px solid #cbd5e1;
    z-index: 1;
}

.student-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    color: #334155;
    cursor: pointer;
}

.student-table tr:hover td {
    background-color: #f8fafc;
}

.student-table tr.active td {
    background-color: var(--accent-light);
    font-weight: 600;
    color: var(--accent-hover);
}

.bulk-actions-area {
    margin-top: 10px;
}

/* --- MARKS INPUT INTERACTIVE GRID --- */
.marks-grid-wrapper, .attendance-grid-wrapper {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
}

.marks-input-table, .attendance-input-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.marks-input-table th, .attendance-input-table th {
    background-color: #f1f5f9;
    color: #475569;
    font-weight: 700;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    white-space: nowrap;
}

.marks-input-table td, .attendance-input-table td {
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    vertical-align: middle;
}

.marks-input-table .form-input, .attendance-input-table .form-input {
    padding: 6px 8px;
    font-size: 12px;
    border-radius: 4px;
    text-align: center;
}

.marks-input-table .form-input.att-input {
    width: 55px;
}

.marks-input-table .col-pa, .marks-input-table .col-nb, .marks-input-table .col-se {
    width: 65px;
}

.marks-input-table .col-exam {
    width: 75px;
}

.term1-hdr { background-color: var(--danger-light) !important; color: var(--danger) !important; }
.term2-hdr { background-color: #f3e8ff !important; color: #7e22ce !important; }

.grid-actions {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
}

/* --- COLOR PICKER GRID --- */
.color-picker-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.color-btn {
    padding: 10px;
    border-radius: 6px;
    border: 2px solid transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: all 0.2s;
    color: #334155;
}

.color-btn:hover {
    transform: translateY(-2px);
}

.color-btn.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.help-text {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 10px;
}

.quick-nav-card {
    background-color: #ffffff;
    padding: 15px;
    border-radius: var(--border-radius);
    border: 1px solid #e2e8f0;
    box-shadow: var(--card-shadow);
    display: flex;
    justify-content: flex-end;
}

/* ==========================================================================
   LIVE PREVIEW PANE STYLES (A4 LAYOUT ON SCREEN)
   ========================================================================== */
.preview-sticky {
    position: sticky;
    top: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.preview-controls {
    background-color: #1e293b;
    color: #ffffff;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--primary-light);
}

.preview-controls h3 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 600;
}

.preview-control-buttons {
    display: flex;
    gap: 8px;
}

.a4-scrollbox {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    justify-content: center;
}

.printable-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* --- THE PHYSICAL A4 PAPER REPRESENTATION --- */
.marksheet-a4-page {
    width: 210mm;
    height: 297mm;
    min-height: 297mm;
    background-color: #FFFDF0; /* dynamic via JS */
    padding: 5mm; /* Reduced outer margin */
    box-sizing: border-box;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    position: relative;
    font-family: var(--font-sans);
    color: #1e293b;
    border-radius: 4px;
    overflow: hidden;
}

.marksheet-double-border {
    border: 3.5px double #1e293b; /* Premium slate double border */
    height: 100%;
    width: 100%;
    padding: 4mm; /* Reduced inner margin */
    box-sizing: border-box;
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Watermark crest */
.watermark-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 320px;
    opacity: 0.07;
    pointer-events: none;
    z-index: 10; /* Bring on top of background card and tables to prevent occlusion */
    object-fit: contain;
}

/* Header metadata */
.header-metadata {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    font-weight: 700;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
    z-index: 2;
}

/* Main School Header */
.marksheet-main-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin-bottom: 5px;
    z-index: 2;
    width: 100%;
    min-height: 70px;
}

.crest-logo-container {
    position: absolute;
    left: 5px; /* Aligns logo to the left side */
    top: 50%;
    transform: translateY(-50%);
    width: 65px;
    height: 65px;
    flex-shrink: 0;
}

.school-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.school-title-area {
    width: 100%;
    text-align: center;
}

.school-title-area h1 {
    font-family: var(--font-display);
    font-size: 26px; /* Centered prominence */
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1.2;
    letter-spacing: 0.5px;
    text-align: center;
}

.school-sub {
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    margin-top: 2px;
    text-align: center;
}

.school-contact {
    font-size: 10px;
    color: #64748b;
    margin-top: 2px;
    text-align: center;
}

.school-udise {
    font-size: 11px;
    font-weight: 700;
    color: #b91c1c; /* Crimson Red */
    margin-top: 3px;
    text-align: center;
}

.divider-line {
    height: 3px;
    border-radius: 2px;
    margin: 4px 0 6px 0;
    z-index: 2;
}

.red-line { background-color: #b91c1c; }

.achievement-title-area {
    text-align: center;
    margin-bottom: 8px;
    z-index: 2;
}

.achievement-title-area h2 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 800;
    color: #ffffff;
    background-color: var(--primary);
    display: inline-block;
    padding: 3px 20px;
    border-radius: 4px;
    letter-spacing: 0.8px;
}

.session-year {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    margin-top: 3px;
}

/* Student Profile Box */
.profile-section-card {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 10px 14px;
    margin-bottom: 15px;
    background-color: rgba(255,255,255,0.7);
    z-index: 2;
    position: relative;
}

.section-title-tag {
    position: absolute;
    top: -8px;
    left: 12px;
    background-color: #2563eb;
    color: #ffffff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 8px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.profile-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    row-gap: 5px;
    column-gap: 10px;
    font-size: 11px;
    margin-top: 4px;
}

.profile-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-item.address-item {
    grid-column: span 3;
}

.profile-item .lbl {
    font-weight: 600;
    color: #64748b;
    margin-right: 4px;
}

.profile-item .val {
    color: #0f172a;
    font-weight: 700;
}

/* Display Tables on Report Card */
.table-section-title {
    font-family: var(--font-display);
    font-size: 11px;
    font-weight: 800;
    color: #ffffff;
    background-color: #0f172a;
    padding: 3px 10px;
    letter-spacing: 0.5px;
    border-radius: 4px 4px 0 0;
    text-transform: uppercase;
    z-index: 2;
    margin-top: 4px;
}

.cocurricular-section-title {
    margin-top: 48px; /* Pushed down to fill first page empty space nicely */
}

.marks-display-table, .coscholastic-display-table, .attendance-display-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    margin-bottom: 15px;
    z-index: 2;
    background-color: rgba(255,255,255,0.8);
}

.marks-display-table th, .marks-display-table td,
.coscholastic-display-table th, .coscholastic-display-table td,
.attendance-display-table th, .attendance-display-table td {
    border: 1px solid #000000;
    padding: 5.5px 6px;
    line-height: 1.25;
}

.marks-display-table th {
    background-color: #f1f5f9;
    font-weight: 700;
    text-align: center;
}

.marks-display-table td {
    vertical-align: middle;
}

.col-subject {
    font-weight: 700;
    text-align: left;
    width: 130px;
}

.term-1-header { background-color: #fee2e2 !important; color: #991b1b; } /* Soft Red */
.term-2-header { background-color: #f3e8ff !important; color: #6b21a8; } /* Soft Purple */
.col-avg { background-color: #ffedd5 !important; color: #9a3412; font-weight: 700; width: 60px; text-align: center; } /* Soft Orange */
.col-grade { background-color: #d1fae5 !important; color: #065f46; font-weight: 700; width: 55px; text-align: center; } /* Soft Green */

.grand-total-row td {
    background-color: #e2e8f0;
    font-weight: 700;
}

/* Co Scholastic Layout */
.coscholastic-display-table th {
    background-color: #f97316; /* Orange title bar */
    color: #ffffff;
    font-weight: 800;
    text-align: center;
    font-family: var(--font-display);
    text-transform: uppercase;
}

.col-activity-lbl {
    width: 180px;
    text-align: left;
    font-weight: 600;
}

/* Co-scholastic subsections background classes */
.coscholastic-display-table tr:nth-child(1) td,
.coscholastic-display-table tr:nth-child(2) td,
.coscholastic-display-table tr:nth-child(3) td {
    background-color: #fef9c3; /* light yellow for games */
}

.coscholastic-display-table tr:nth-child(4) td,
.coscholastic-display-table tr:nth-child(5) td {
    background-color: #dcfce7; /* light green for art & craft */
}

.coscholastic-display-table tr:nth-child(6) td,
.coscholastic-display-table tr:nth-child(7) td {
    background-color: #fef9c3; /* light yellow for music/dance */
}

/* Personality development rows (all TD cells in the right half of the table) */
.coscholastic-display-table td:nth-child(4),
.coscholastic-display-table td:nth-child(5),
.coscholastic-display-table td:nth-child(6) {
    background-color: #dcfce7; /* light green for PD */
}

/* PAGE 2 SPECIFIC LAYOUTS */
.page2-grid-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    height: 100%;
}

.two-column-block {
    display: flex;
    gap: 15px;
}

.column-left {
    width: 50%;
}

.column-right {
    width: 50%;
}

.attendance-display-table th {
    background-color: #ea580c; /* dark orange */
    color: #ffffff;
    font-weight: 700;
    text-align: center;
}

.attendance-display-table td {
    padding: 5.5px 6px;
}

.attendance-display-table tfoot td {
    font-weight: 700;
    background-color: #f1f5f9;
}

.bg-green-accent {
    background-color: #10b981 !important;
    color: #ffffff !important;
}

/* Health status panel */
.health-status-block {
    border: 1.5px solid #000000;
    background-color: rgba(255, 255, 255, 0.8);
    height: calc(100% - 22px);
    display: flex;
    flex-direction: column;
}

.health-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 10px;
    border-bottom: 1px solid #000000;
    font-size: 11px;
}

.health-item:last-child {
    border-bottom: none;
    flex-direction: column;
    flex: 1;
    gap: 3px;
}

.health-label {
    font-weight: 700;
}

.health-value {
    font-weight: 800;
    color: #0f172a;
}

.health-value-box {
    font-weight: 600;
    padding: 3px 0;
}

/* Remarks & Signatures Boxes */
.remarks-wrapper-block {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.remarks-term-box {
    border: 1.5px solid #000000;
    background-color: #fffbeb;
    border-radius: 6px;
    position: relative;
    padding-top: 18px; /* Room for header tag */
}

.remarks-tab-hdr {
    position: absolute;
    top: 0;
    left: 45px;
    background-color: #facc15; /* yellow */
    color: #000000;
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 9px;
    padding: 1px 24px;
    border-radius: 0 0 8px 8px;
    border: 1px solid #000000;
    border-top: none;
}

.remarks-body {
    padding: 10px 16px;
}

.remarks-label {
    font-size: 10px;
    font-weight: 700;
    color: #16a34a; /* green */
    margin-bottom: 2px;
}

.remarks-text {
    font-family: var(--font-serif);
    font-size: 11.5px;
    line-height: 1.35;
    min-height: 42px;
    font-style: italic;
    color: #0f172a;
}

.remarks-signatures-row {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
    padding: 0 5px;
}

.sig-line {
    width: 28%;
    border-top: 1px dashed #000000;
    text-align: center;
    padding-top: 2px;
}

.sig-txt-label {
    font-size: 9px;
    font-weight: 600;
    color: #1e293b;
}

/* Grading Legend and Promotion side-by-side */
.bg-yellow-tint {
    background-color: #fffdf0;
}

.border-dashed {
    border: 1.5px dashed #000000;
}

.border-radius-8 {
    border-radius: 8px;
}

.grading-hdr {
    font-size: 11px;
    color: #d97706;
}

.legends-flex {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.legend-table-box {
    display: flex;
    flex-direction: column;
}

.legend-table-title {
    font-size: 8px;
    font-weight: 800;
    text-align: center;
    background-color: #e2e8f0;
    border: 1px solid #000000;
    border-bottom: none;
    padding: 1px 0;
}

.legend-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 8.5px;
    text-align: center;
}

.legend-table th, .legend-table td {
    border: 1px solid #000000;
    padding: 1px 2px;
}

.legend-table th {
    background-color: #f1f5f9;
}

/* Promotion card style */
.promotion-outline-box {
    background-color: #fffdf0;
    padding: 16px 20px !important;
}

.promo-text {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 8px;
    line-height: 1.4;
}

.val-underlined {
    text-decoration: underline;
    font-weight: 800;
    color: #0f172a;
}

.promotion-signatures-row {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
}

.promo-sig {
    width: 42%;
    text-align: center;
}

.sig-line-top {
    display: block;
    border-top: 1px solid #000000;
    padding-top: 3px;
    font-size: 9.5px;
    font-weight: 700;
}

/* Page footer text */
.page-footer-no {
    position: absolute;
    bottom: 6px;
    right: 15px;
    font-size: 9px;
    font-weight: 700;
    color: #94a3b8;
}

/* --- QR DIALOG POPUP --- */
.qr-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.qr-dialog-overlay.active {
    display: flex;
}

.qr-dialog {
    background-color: #ffffff;
    border-radius: var(--border-radius);
    width: 380px;
    box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.15);
    overflow: hidden;
}

.qr-dialog-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.qr-dialog-header h3 {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
}

.qr-dialog-header .close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #64748b;
}

.qr-dialog-body {
    padding: 24px;
    text-align: center;
}

.qr-dialog-body p {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 16px;
    line-height: 1.4;
}

.qr-code-wrapper {
    margin: 0 auto;
    padding: 15px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    width: 200px;
    height: 200px;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qr-link {
    margin-top: 16px;
    font-family: monospace;
    font-size: 14px;
    font-weight: 700;
    color: var(--accent);
    word-break: break-all;
}


@page {
    size: A4 portrait;
    margin: 0;
}



/* ==========================================================================
   LAYOUT SELECTION DISPLAY STYLES & OPTIMIZATIONS
   ========================================================================== */

/* Layout Display Toggles */
.layout-combined #layout-combined-container {
    display: block !important;
}
.layout-combined #layout-term1-container,
.layout-combined #layout-term2-container {
    display: none !important;
}

.layout-term1 #layout-term1-container {
    display: block !important;
}
.layout-term1 #layout-combined-container,
.layout-term1 #layout-term2-container {
    display: none !important;
}

.layout-term2 #layout-term2-container {
    display: block !important;
}
.layout-term2 #layout-combined-container,
.layout-term2 #layout-term1-container {
    display: none !important;
}

/* Optimization for single-page printing */
.marksheet-a4-page.single-page {
    height: 297mm !important;
    padding: 6mm 10mm !important;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.marksheet-a4-page.single-page .profile-grid {
    gap: 8px 15px !important;
    margin-bottom: 8px !important;
}

.marksheet-a4-page.single-page .profile-section-card {
    padding: 8px 12px !important;
    margin-bottom: 10px !important;
}

.marksheet-a4-page.single-page .marks-display-table {
    margin-bottom: 10px !important;
}

.marksheet-a4-page.single-page .marks-display-table th, 
.marksheet-a4-page.single-page .marks-display-table td {
    padding: 4px 6px !important;
    font-size: 12px !important;
}

.marksheet-a4-page.single-page .two-column-block {
    gap: 15px !important;
    margin-bottom: 8px !important;
}

.marksheet-a4-page.single-page .coscholastic-display-table th,
.marksheet-a4-page.single-page .coscholastic-display-table td,
.marksheet-a4-page.single-page .attendance-display-table th,
.marksheet-a4-page.single-page .attendance-display-table td {
    padding: 3px 5px !important;
    font-size: 11px !important;
}

.marksheet-a4-page.single-page .table-section-title {
    font-size: 11px !important;
    margin-bottom: 4px !important;
    padding: 3px 8px !important;
}

/* Inline layout select styling */
.layout-select-inline {
    background-color: #ffffff;
    color: #0f172a;
    border: 1.5px solid #cbd5e1;
    border-radius: 6px;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.layout-select-inline:focus {
    border-color: var(--accent);
}



/* ==========================================================================
   A4 HEIGHT BOUNDARY SPACING OPTIMIZATIONS (PREVENTS FOOTER/SIGNATURE CLIPPING)
   ========================================================================== */

/* Spacing optimizations for Page 2 of Combined layout */
.marksheet-a4-page.page-2 {
    padding: 4mm 6mm !important;
}

.marksheet-a4-page.page-2 .page2-grid-layout {
    gap: 8px !important;
}

.marksheet-a4-page.page-2 .attendance-display-table th,
.marksheet-a4-page.page-2 .attendance-display-table td {
    padding: 3.5px 5px !important;
    font-size: 10px !important;
}

.marksheet-a4-page.page-2 .attendance-display-table {
    margin-bottom: 8px !important;
}

.marksheet-a4-page.page-2 .health-status-block {
    height: auto !important;
}

.marksheet-a4-page.page-2 .health-status-block table td {
    padding: 3.5px 5px !important;
    font-size: 10px !important;
}

.marksheet-a4-page.page-2 .remarks-wrapper-block {
    gap: 8px !important;
}

.marksheet-a4-page.page-2 .remarks-term-box {
    padding-top: 14px !important;
}

.marksheet-a4-page.page-2 .remarks-body {
    padding: 6px 12px !important;
}

.marksheet-a4-page.page-2 .remarks-text {
    min-height: 24px !important;
    font-size: 11px !important;
    margin-bottom: 2px !important;
    line-height: 1.25 !important;
}

.marksheet-a4-page.page-2 .remarks-signatures-row {
    margin-top: 12px !important;
}

.marksheet-a4-page.page-2 .two-column-block {
    gap: 10px !important;
}

.marksheet-a4-page.page-2 .legend-table th,
.marksheet-a4-page.page-2 .legend-table td {
    padding: 2.5px 4px !important;
    font-size: 9px !important;
}

.marksheet-a4-page.page-2 .promotion-signatures-row {
    margin-top: 20px !important;
}

/* Extra Tight Spacing optimizations for Single Page (Term 1 / Term 2 only) layouts */
.marksheet-a4-page.single-page {
    padding: 4mm 6mm !important;
}

.marksheet-a4-page.single-page .marksheet-double-border {
    padding: 3.5mm !important;
}

.marksheet-a4-page.single-page .profile-section-card {
    padding: 6px 10px !important;
    margin-bottom: 6px !important;
}

.marksheet-a4-page.single-page .marks-display-table {
    margin-bottom: 6px !important;
}

.marksheet-a4-page.single-page .marks-display-table th, 
.marksheet-a4-page.single-page .marks-display-table td {
    padding: 3.5px 5px !important;
    font-size: 11px !important;
}

.marksheet-a4-page.single-page .two-column-block {
    margin-bottom: 6px !important;
    gap: 10px !important;
}

.marksheet-a4-page.single-page .remarks-term-box {
    padding-top: 12px !important;
}

.marksheet-a4-page.single-page .remarks-body {
    padding: 5px 10px !important;
}

.marksheet-a4-page.single-page .remarks-text {
    min-height: 22px !important;
    font-size: 10.5px !important;
    line-height: 1.2 !important;
}

.marksheet-a4-page.single-page .remarks-signatures-row {
    margin-top: 10px !important;
}

/* Hide mobile-only preview close button on desktop */
.hide-preview-btn {
    display: none !important;
}

/* ==========================================================================
   MOBILE RESPONSIVENESS AND SHOW PREVIEW OVERLAY SYSTEM
   ========================================================================== */
@media screen and (max-width: 767px) {
    .app-container {
        flex-direction: column !important;
        height: 100vh !important;
        width: 100vw !important;
        overflow: hidden !important;
    }
    
    .app-sidebar {
        width: 100% !important;
        height: auto !important;
        padding: 8px 12px !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        border-bottom: 1px solid var(--primary-light) !important;
        border-right: none !important;
    }
    
    .sidebar-header {
        padding: 0 !important;
        border-bottom: none !important;
    }
    
    .logo-area {
        gap: 6px !important;
    }
    
    .logo-icon {
        font-size: 24px !important;
    }
    
    .logo-text h2 {
        font-size: 15px !important;
    }
    
    .logo-text span {
        display: none !important;
    }
    
    .sidebar-nav {
        flex-direction: row !important;
        padding: 0 !important;
        margin: 0 0 0 10px !important;
        gap: 6px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        flex: 1 !important;
        justify-content: flex-start !important;
        height: auto !important;
        scrollbar-width: none; /* Hide scrollbar for clean look */
    }
    
    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }
    
    .nav-item {
        padding: 6px 12px !important;
        font-size: 11px !important;
        gap: 4px !important;
        white-space: nowrap !important;
        border-radius: 6px !important;
    }
    
    .sidebar-footer {
        display: none !important; /* Hide WiFi access / QR panel on mobile to save header space */
    }
    
    .design-credit-mobile {
        display: block !important;
        text-align: center !important;
        padding: 15px 0 !important;
        margin-top: 25px !important;
        border-top: 1px dashed #e2e8f0 !important;
        font-size: 10px !important;
        color: #94a3b8 !important;
    }
    
    .design-credit-mobile a {
        color: #3b82f6 !important;
        text-decoration: none !important;
        font-weight: 600 !important;
    }
    
    .design-credit-mobile a:hover {
        text-decoration: underline !important;
    }
    
    .app-content {
        height: calc(100vh - 55px) !important;
        width: 100% !important;
        overflow: hidden !important;
    }
    
    .app-header {
        padding: 8px 15px !important;
        height: 50px !important;
    }
    
    .header-left h1 {
        font-size: 15px !important;
    }
    
    .header-left .subtitle {
        display: none !important; /* Hide subtitle to save vertical header space */
    }
    
    .toggle-preview-btn {
        display: flex !important;
        align-items: center !important;
        gap: 5px !important;
        padding: 6px 12px !important;
        font-size: 12px !important;
        font-weight: 700 !important;
        background-color: var(--accent) !important;
        color: #ffffff !important;
        border: none !important;
        border-radius: 6px !important;
        height: 32px !important;
    }
    
    .dashboard-grid {
        flex-direction: column !important;
        height: calc(100% - 50px) !important;
        position: relative !important;
        overflow: hidden !important;
    }
    
    .editor-pane {
        width: 100% !important;
        min-width: 100% !important;
        height: 100% !important;
        padding: 15px !important;
        border-right: none !important;
    }
    
    .preview-pane {
        position: fixed !important;
        top: 0;
        left: 0;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 9999 !important;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out !important;
    }
    
    .preview-pane.active {
        transform: translateX(0) !important;
    }
    
    .preview-sticky {
        height: 100% !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    .preview-controls {
        padding: 8px 15px !important;
        background-color: #0f172a !important;
        color: white !important;
        height: 48px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }
    
    .hide-preview-btn {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    .a4-scrollbox {
        flex: 1 !important;
        padding: 15px 5px !important;
        overflow-y: auto !important;
        overflow-x: auto !important; /* Enable horizontal scrolling */
        background-color: #1e293b !important;
        display: flex !important;
        justify-content: flex-start !important; /* Align left to scroll right */
        align-items: flex-start !important;
    }
    
    /* Keep A4 marksheet preview at 100% scale (no scaling) */
    .a4-scrollbox .printable-container {
        transform: none !important;
        width: 210mm !important;
        height: auto !important;
        margin: 0 !important;
    }
    
    .a4-scrollbox .printable-container .marksheet-a4-page {
        margin: 0 0 30px 0 !important; /* standard page spacing */
    }
}

/* ==========================================================================
   CONSOLIDATED PRINT MEDIA STYLES
   Placed at the bottom to guarantee overrides over mobile responsive styles
   ========================================================================== */
@media print {
    /* Hide non-printable elements */
    .app-sidebar, 
    .app-header, 
    .editor-pane, 
    .preview-controls, 
    .toggle-preview-btn {
        display: none !important;
    }
    
    /* Reset heights, displays, and overflows on all wrapper containers */
    body, html, .app-container, .app-content, .dashboard-grid, .preview-pane, .preview-sticky, .a4-scrollbox, .printable-container {
        display: block !important;
        width: auto !important;
        height: auto !important;
        overflow: visible !important;
        position: relative !important; /* Forces normal document flow, disabling sticky/absolute clipping */
        transform: none !important; /* Resets any screen-only transformations on print */
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        background: none !important;
        box-shadow: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    .printable-container {
        display: block !important;
    }
    
    .marksheet-a4-page {
        width: 210mm !important;
        height: 297mm !important;
        min-height: 297mm !important;
        page-break-after: always !important;
        page-break-inside: avoid !important;
        margin: 0 auto !important;
        padding: 5mm !important; /* Enforces reduced outer margins */
        box-shadow: none !important;
        border-radius: 0 !important;
        box-sizing: border-box !important;
        position: relative !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    
    /* Ensure last page doesn't spawn blank page */
    .marksheet-a4-page.page-2 {
        page-break-after: avoid !important;
    }
    
    /* Watermark print visibility */
    .watermark-logo {
        opacity: 0.07 !important;
    }

    /* Print page break rules for term 1 and term 2 single page formats */
    .layout-term1 .marksheet-a4-page.page-2,
    .layout-term2 .marksheet-a4-page.page-2 {
        display: none !important;
    }
    
    .layout-term1 #layout-term1-container .marksheet-a4-page,
    .layout-term2 #layout-term2-container .marksheet-a4-page {
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }
}
