.theme-toggle {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--outline, #c7c9cf);
    border-radius: 50%;
    background: var(--surface, #fff);
    color: var(--on-surface-variant, #44474e);
    cursor: pointer;
    transition: background .2s ease, color .2s ease, border-color .2s ease, transform .2s ease;
}
.theme-toggle:hover { background: var(--secondary, #f5f7fa); color: var(--primary, #1e88e5); transform: translateY(-1px); }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary, #1e88e5) 35%, transparent); outline-offset: 2px; }
.theme-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.theme-icon-sun { display: none; }
[data-theme="dark"] .theme-icon-moon { display: none; }
[data-theme="dark"] .theme-icon-sun { display: block; }
.theme-toggle-fixed { position: fixed; top: 14px; right: 14px; z-index: 1000; }
.resume-container > header { position: relative; padding-inline: 42px; }
.resume-container > header .theme-toggle { position: absolute; top: -6px; right: 0; }

/* Screen themes must not leak dark surfaces or variables into printed reports. */
@media screen {
[data-theme="dark"] {
    --primary: #66b5ff;
    --primary-dark: #90caf9;
    --secondary: #1c2737;
    --surface: #111a28;
    --on-surface: #e8eef7;
    --on-surface-variant: #b3bfd0;
    --outline: #46556a;
    --grid: #526176;
    --error: #ff8b8b;
    --success: #73d58a;
    --warn-bg: #38252a;
    color-scheme: dark;
}
[data-theme="dark"] body { background: #0b1220; color: var(--on-surface); }
[data-theme="dark"] .card,
[data-theme="dark"] .top-bar,
[data-theme="dark"] .excel-sheet,
[data-theme="dark"] .analytics-report,
[data-theme="dark"] .upload-card,
[data-theme="dark"] .page-footer,
[data-theme="dark"] .profile-dropdown,
[data-theme="dark"] .dialog,
[data-theme="dark"] .confirm-dialog-content { background-color: var(--surface); border-color: var(--outline); box-shadow: 0 8px 24px rgba(0,0,0,.24); }
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea { background-color: #0d1624; color: var(--on-surface); border-color: var(--outline); }
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: #7f8da1; }
[data-theme="dark"] .preview-tabs,
[data-theme="dark"] .mode-switch,
[data-theme="dark"] .mode-chip,
[data-theme="dark"] .preview-tab,
[data-theme="dark"] .btn-sm,
[data-theme="dark"] .btn-outline,
[data-theme="dark"] .footer-link { background-color: #172234; color: var(--on-surface-variant); border-color: var(--outline); }
[data-theme="dark"] .preview-tab.active,
[data-theme="dark"] .mode-chip.active { background-color: #25344b; color: var(--primary); }
[data-theme="dark"] .footer-link.telegram,
[data-theme="dark"] .footer-link.phone,
[data-theme="dark"] .footer-link.email,
[data-theme="dark"] .footer-link.website,
[data-theme="dark"] .footer-link.instagram,
[data-theme="dark"] .footer-link.youtube,
[data-theme="dark"] .footer-link.social { background: #172234; color: var(--on-surface-variant); border-color: var(--outline); }
[data-theme="dark"] .footer-link:hover { background: #25344b; color: var(--on-surface); }
[data-theme="dark"] .btn-secondary,
[data-theme="dark"] .btn-add-student,
[data-theme="dark"] .print-menu,
[data-theme="dark"] .analytics-sheet,
[data-theme="dark"] .analytics-card,
[data-theme="dark"] .analytics-kpi,
[data-theme="dark"] .analytics-pending,
[data-theme="dark"] .analytics-report-header { background: #111a28; color: var(--on-surface); border-color: var(--outline); }
[data-theme="dark"] .analytics-report-header,
[data-theme="dark"] .analytics-kpi,
[data-theme="dark"] .analytics-pending { background: #172234; }
[data-theme="dark"] .analytics-report-title,
[data-theme="dark"] .analytics-kpi strong,
[data-theme="dark"] .analytics-card h3 { color: var(--on-surface); }
[data-theme="dark"] .analytics-kpi span,
[data-theme="dark"] .analytics-card p { color: var(--on-surface-variant); }
[data-theme="dark"] .analytics-narrative { background: #15243a; color: #c6d2e2; border-left-color: var(--primary); }
[data-theme="dark"] .analytics-card svg text { fill: #b3bfd0; }
[data-theme="dark"] .analytics-card svg line { stroke: #46556a; }
[data-theme="dark"] .print-menu button { color: var(--on-surface); }
[data-theme="dark"] .print-menu button:hover { background: #25344b; }
[data-theme="dark"] .input-group input:focus,
[data-theme="dark"] #examSelect:focus,
[data-theme="dark"] #catalogVariant:focus,
[data-theme="dark"] .scores-grid td input:focus { background: #101c2c; }
[data-theme="dark"] .upload-zone:hover { background: #13243a; }
[data-theme="dark"] .footer-version { background: #173253; color: var(--primary); }
[data-theme="dark"] .profile-dropdown-item { border-bottom-color: rgba(255,255,255,.08); }
[data-theme="dark"] .journal-summary { background: #182538; color: var(--on-surface); }
[data-theme="dark"] .summary-item { border-bottom-color: rgba(255,255,255,.09); }
[data-theme="dark"] .summary-item.highlight { border-top-color: rgba(255,255,255,.12); }
[data-theme="dark"] .license-status.valid { background: #173829; color: #8ae2ad; border-color: #2e6848; }
[data-theme="dark"] .license-status.trial { background: #3a311c; color: #f2ca6c; border-color: #6b582a; }
[data-theme="dark"] .license-status.invalid { background: #3b2029; color: #ff9aad; border-color: #713648; }
[data-theme="dark"] .btn-icon:hover,
[data-theme="dark"] .btn-secondary:hover,
[data-theme="dark"] .btn-add-student:hover { background: #25344b; }
[data-theme="dark"] .scores-grid th,
[data-theme="dark"] .scores-grid td { background-color: #111a28; color: var(--on-surface); border-color: var(--grid); }
[data-theme="dark"] .scores-grid thead th,
[data-theme="dark"] .scores-grid tfoot td { background-color: #1a273a; }
[data-theme="dark"] .scores-grid .row-max-scores th.cell-max,
[data-theme="dark"] .scores-grid tfoot .cell-avg,
[data-theme="dark"] .scores-grid tfoot .footer-label,
[data-theme="dark"] .scores-grid .cell-computed,
[data-theme="dark"] .scores-grid .total-cell,
[data-theme="dark"] .scores-grid .percent-cell { background: #1a273a; color: var(--on-surface); }
[data-theme="dark"] .scores-grid td input.score-input,
[data-theme="dark"] .scores-grid td input.student-name-input { background: #0d1624; color: var(--on-surface); caret-color: var(--primary); }
[data-theme="dark"] .scores-grid td input.score-input.filled { background: #142945; }
[data-theme="dark"] .scores-grid td input.score-input:focus,
[data-theme="dark"] .scores-grid td input.student-name-input:focus { background: #162c47; }
[data-theme="dark"] .scores-grid tbody tr:hover td.col-score,
[data-theme="dark"] .scores-grid tbody tr:hover td.col-name { background-color: #172234; }
[data-theme="dark"] .scores-grid tbody tr:hover td.col-score input { background-color: #101c2c; }
[data-theme="dark"] .fill-max-btn,
[data-theme="dark"] .header-fill-all { background: #172234; color: var(--on-surface-variant); border-color: var(--outline); }
[data-theme="dark"] .fill-max-btn:hover,
[data-theme="dark"] .header-fill-all:hover { background: #25344b; border-color: var(--primary); }
[data-theme="dark"] .scores-grid .journal-match { background: #173829; color: #8ae2ad; }
[data-theme="dark"] .scores-grid .journal-mismatch { background: #3b2029; color: #ff9aad; }
[data-theme="dark"] .scores-grid .col-total.grade-excellent,
[data-theme="dark"] .scores-grid .col-percent.grade-excellent,
[data-theme="dark"] .scores-grid .col-total.grade-good,
[data-theme="dark"] .scores-grid .col-percent.grade-good,
[data-theme="dark"] .scores-grid .col-total.grade-warning,
[data-theme="dark"] .scores-grid .col-percent.grade-warning,
[data-theme="dark"] .scores-grid .col-total.grade-danger,
[data-theme="dark"] .scores-grid .col-percent.grade-danger { background: #3a3519; }
[data-theme="dark"] tr:hover td { background-color: #172234; }
}

@media print {
    .theme-toggle { display: none !important; }
    :root { color-scheme: light !important; }
    .excel-sheet, .excel-title, .excel-school-info, .excel-signatures {
        background: #fff !important;
        color: #111 !important;
        box-shadow: none !important;
    }
    .excel-title *, .excel-school-info *, .excel-signatures * { color: #111 !important; }
    [data-theme="dark"] body { background: #fff !important; color: #111 !important; }
    [data-theme="dark"] .scores-grid th,
    [data-theme="dark"] .scores-grid td,
    [data-theme="dark"] .scores-grid thead th,
    [data-theme="dark"] .scores-grid tfoot td { background: #fff !important; color: #111 !important; border-color: #999 !important; }
}
