:root {
    --primary: #1a365d;
    --primary-light: #2c5282;
    --accent: #e53e3e;
    --bg: #f7fafc;
    --card: #ffffff;
    --text: #2d3748;
    --muted: #718096;
    --border: #e2e8f0;
    --success: #38a169;
    --warning: #d69e2e;
    --danger: #e53e3e;
    --note-bad: #dc3545;
    --note-ok: #0d6efd;
    --note-bg-bad: #fde8e8;
    --note-bg-good: #e8f5e8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary-light); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout */
.app-header { background: var(--primary); color: white; padding: 0.75rem 1.5rem; display: flex; justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 100; box-shadow: 0 2px 4px rgba(0,0,0,.1); }
.app-header h1 { font-size: 1.2rem; font-weight: 600; }
.app-header .user-info { display: flex; align-items: center; gap: 1rem; font-size: 0.9rem; }
.app-header .user-info span { opacity: 0.8; }
.app-header button { background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.3); padding: 0.3rem 0.8rem; border-radius: 4px; cursor: pointer; font-size: 0.85rem; }
.app-header button:hover { background: rgba(255,255,255,.25); }

.sidebar { width: 240px; background: var(--card); border-right: 1px solid var(--border); height: calc(100vh - 52px); position: fixed; top: 52px; overflow-y: auto; padding: 1rem 0; }
.sidebar .nav-group { margin-bottom: 1rem; }
.sidebar .nav-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 0.5rem 1rem 0.25rem; font-weight: 700; }
.sidebar .nav-item { display: block; padding: 0.45rem 1rem; font-size: 0.9rem; color: var(--text); cursor: pointer; border-left: 3px solid transparent; transition: all 0.15s; }
.sidebar .nav-item:hover { background: var(--bg); color: var(--primary); }
.sidebar .nav-item.active { background: #ebf4ff; color: var(--primary); border-left-color: var(--primary); font-weight: 600; }

.main-content { margin-left: 240px; padding: 1.5rem; min-height: calc(100vh - 52px); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem; margin-bottom: 1rem; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.card h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--primary); border-bottom: 2px solid var(--border); padding-bottom: 0.5rem; }
.card h3 { font-size: 1rem; margin-bottom: 0.75rem; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th, td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f1f5f9; font-weight: 600; color: var(--primary); position: sticky; top: 0; font-size: 0.8rem; }
tr:hover { background: #f8fafc; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Notes color coding */
.note-bad { color: var(--note-bad); font-weight: 700; background: var(--note-bg-bad); padding: 0.1em 0.3em; border-radius: 3px; }
.note-ok { color: var(--note-ok); font-weight: 600; }
.note-good { color: #1a8c1a; font-weight: 600; background: var(--note-bg-good); padding: 0.1em 0.3em; border-radius: 3px; }
.note-6 { color: #8b0000; font-weight: 700; background: #fff5f5; }
.note-5 { color: #e53e3e; font-weight: 700; }
.note-4 { color: #d69e2e; font-weight: 600; }

/* Forms */
.form-group { margin-bottom: 0.75rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.25rem; color: var(--muted); }
input[type="text"], input[type="password"], input[type="number"], input[type="file"], select, textarea {
    width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.9rem; font-family: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(44,82,130,.15); }

.btn { display: inline-block; padding: 0.5rem 1rem; border: none; border-radius: 4px; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: all 0.15s; font-family: inherit; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #2f855a; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }

.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.btn-group .btn { flex-shrink: 0; }

/* Stats */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat-box { background: var(--bg); border-radius: 8px; padding: 1rem; text-align: center; border: 1px solid var(--border); }
.stat-box .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--primary); }
.stat-box .stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Login */
.login-container { max-width: 400px; margin: 100px auto; }
.login-container .card { padding: 2rem; }
.login-container h2 { text-align: center; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal { background: white; border-radius: 8px; padding: 1.5rem; width: 90%; max-width: 600px; max-height: 80vh; overflow-y: auto; }
.modal h2 { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* Print Header (hidden on screen, shown on print) */
.print-header { display: none; }

/* Bericht inline charts */
.bericht-inline-chart { display: block; margin: 0.5rem auto 1rem; }
.bericht-chart-img { display: block; margin: 0.5rem auto 1rem; }

/* Print orientation */
@page { size: portrait; margin: 1cm; }
body.print-landscape @page, .print-landscape { }
@media print {
    body.print-landscape { }
}
@page landscape { size: landscape; }
body.print-landscape @page { size: landscape; }

/* Print */
@media print {
    .sidebar, .app-header, .btn, .btn-group, .filter-bar, .no-print, .chart-container { display: none !important; }
    .no-print-field { display: none !important; }
    select.no-print-field { display: none !important; }
    .main-content { margin-left: 0 !important; padding: 0 !important; }
    body { background: white; }
    table { font-size: 0.75rem; border-collapse: collapse; }
    th, td { padding: 0.3rem 0.5rem; border: 1px solid #ccc !important; }
    th { background: #f0f0f0 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    tr { border-bottom: 1px solid #ccc; }
    .card { box-shadow: none; border: none; margin-bottom: 0.5rem; padding: 0.5rem 0; }
    .print-section { page-break-inside: auto; }
    .print-section > h2, .print-section > h3 { page-break-after: avoid; }
    .print-section > table { page-break-inside: auto; }
    .print-section > .chart-container, .bericht-chart-card { page-break-inside: avoid; }
    .print-section > .table-scroll { page-break-inside: auto; }
    .card h2 { font-size: 1rem; border-bottom: 2px solid #333; padding-bottom: 0.3rem; }
    .stat-grid { gap: 0.5rem; }
    .stat-box { border: 1px solid #ccc; padding: 0.5rem; }
    .note-bad { color: #dc3545 !important; background: #fde8e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .note-ok { color: #0d6efd !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .note-good { color: #1a8c1a !important; background: #e8f5e8 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .badge { border: 1px solid #999; }
    .print-header { display: block !important; text-align: center; margin-bottom: 1.5rem; padding-bottom: 0.5rem; border-bottom: 2px solid #333; }
    .print-header h1 { font-size: 1.4rem; color: #1a365d; margin-bottom: 0.2rem; }
    .print-header h2 { font-size: 1.1rem; color: #333; margin-bottom: 0.2rem; font-weight: 400; }
    .print-header h3 { font-size: 0.95rem; color: #555; font-weight: 400; }
    .page-break { page-break-before: always; }
    .bericht-chart-card { page-break-inside: avoid; }
    .bericht-chart-img { max-width: 100% !important; height: auto !important; page-break-inside: avoid; }
    .bericht-inline-chart { display: none !important; } /* hide canvases in print - images replace them */
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
}

/* Chart container */
.chart-container { width: 100%; max-width: 800px; margin: 1rem auto; }
.chart-container canvas { max-width: 100%; }

/* Inline filters */
.filter-bar { display: flex; gap: 0.75rem; align-items: end; flex-wrap: wrap; margin-bottom: 1rem; padding: 1rem; background: #f1f5f9; border-radius: 8px; }
.filter-bar .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }
.filter-bar .form-group label { font-size: 0.75rem; }
.filter-bar select, .filter-bar input { padding: 0.4rem; font-size: 0.85rem; }

/* Toggle */
.view-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; margin-bottom: 1rem; }
.view-toggle button { padding: 0.4rem 1rem; border: none; background: white; cursor: pointer; font-size: 0.85rem; border-right: 1px solid var(--border); }
.view-toggle button:last-child { border-right: none; }
.view-toggle button.active { background: var(--primary); color: white; }

/* Badge */
.badge { display: inline-block; padding: 0.15rem 0.5rem; border-radius: 10px; font-size: 0.75rem; font-weight: 600; }
.badge-red { background: #fed7d7; color: #c53030; }
.badge-blue { background: #bee3f8; color: #2b6cb0; }
.badge-green { background: #c6f6d5; color: #276749; }
.badge-gray { background: #e2e8f0; color: #4a5568; }
.badge-yellow { background: #fefcbf; color: #975a16; }
.status-select { padding: 0.2rem 0.3rem; border-radius: 4px; font-size: 0.8rem; border: 1px solid #ccc; cursor: pointer; }
.status-nicht_entschieden { background: #e2e8f0; color: #4a5568; border-color: #cbd5e0; }
.status-durchgefallen { background: #fed7d7; color: #c53030; border-color: #feb2b2; }
.status-auf_probe { background: #fefcbf; color: #975a16; border-color: #fbd38d; }
.status-nachpruefung_bestanden { background: #c6f6d5; color: #276749; border-color: #9ae6b4; }

/* Scrollable table wrapper */
.table-scroll { overflow-x: auto; max-width: 100%; }

/* Toast */
.toast { position: fixed; top: 70px; right: 20px; padding: 0.75rem 1.25rem; border-radius: 6px; color: white; font-size: 0.9rem; z-index: 2000; animation: slideIn 0.3s; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ==================== HOME TILES ==================== */
.home-container { max-width: 900px; margin: 0 auto; padding: 2rem 1.5rem; min-height: 100vh; display: flex; flex-direction: column; }
.home-header { text-align: center; margin-bottom: 2.5rem; }
.home-header h1 { font-size: 1.8rem; color: var(--primary); margin-bottom: 0.5rem; }
.home-user { display: flex; justify-content: center; align-items: center; gap: 1rem; margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
.home-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1.5rem; flex: 1; }
.home-tile { background: var(--card); border: 2px solid var(--border); border-radius: 12px; padding: 2rem 1.5rem; text-align: center; cursor: pointer; transition: all 0.2s; box-shadow: 0 2px 8px rgba(0,0,0,0.04); }
.home-tile:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(0,0,0,0.1); transform: translateY(-2px); }
.tile-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.tile-title { font-size: 1.15rem; font-weight: 700; color: var(--primary); margin-bottom: 0.5rem; }
.tile-desc { font-size: 0.85rem; color: var(--muted); line-height: 1.4; }

/* Header back button */
.header-back-btn { background: rgba(255,255,255,.15); color: white; border: 1px solid rgba(255,255,255,.3); padding: 0.3rem 0.7rem; border-radius: 4px; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.header-back-btn:hover { background: rgba(255,255,255,.3); }

/* Footer */
.app-footer { text-align: center; padding: 1rem; font-size: 0.8rem; color: var(--muted); border-top: 1px solid var(--border); margin-top: auto; }
.app-footer a { color: var(--primary-light); margin: 0 0.5rem; }

/* LK form checkboxes */
.form-group input[type="checkbox"] { margin-right: 0.4rem; }

/* ==================== PRESENTATION MODE ==================== */
.pres-overlay { position: fixed; inset: 0; z-index: 9999; overflow: hidden; display: flex; flex-direction: column; font-family: 'Segoe UI', system-ui, sans-serif; }
.pres-overlay * { box-sizing: border-box; }
#pres-content { flex: 1; overflow-y: auto; display: flex; align-items: center; justify-content: center; padding: 2vh 3vw; }
.pres-nav { position: fixed; bottom: 0; left: 0; right: 0; display: flex; justify-content: center; align-items: center; gap: 2rem; padding: 1rem; opacity: 0; transition: opacity 0.3s; z-index: 10000; pointer-events: none; }
.pres-nav.visible { opacity: 1; pointer-events: auto; }
.pres-arrow { width: 50px; height: 50px; border-radius: 50%; font-size: 1.4rem; cursor: pointer; display: flex; align-items: center; justify-content: center; transition: background 0.2s; border: none; }
#pres-counter { font-size: 0.9rem; min-width: 80px; text-align: center; }

.pres-slide { max-width: 1100px; width: 100%; }
.pres-title-slide { text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; }
.pres-title-slide h1 { font-size: clamp(2rem, 4vw, 3rem); margin-bottom: 0.5rem; }
.pres-title-slide h2 { font-size: clamp(1.2rem, 2.5vw, 1.8rem); margin-bottom: 1rem; font-weight: 400; }
.pres-title-slide .pres-subtitle { font-size: 1.1rem; }
.pres-logo { max-height: clamp(40px, 8vh, 90px); }

/* Beamer div-based layout */
.pres-student-slide { display: flex; flex-direction: column; height: 92vh; max-height: 92vh; }
.pres-top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8vh; gap: 1rem; }
.pres-school-name { font-size: clamp(1.1rem, 2vw, 1.6rem); font-weight: 700; }
.pres-card { flex: 1; border: 2px solid; border-radius: 10px; overflow: hidden; font-size: clamp(1.15rem, 2.1vw, 1.7rem); line-height: 1.25; display: flex; flex-direction: column; }
.pres-row { border-bottom: 2px solid; }
.pres-row:last-child { border-bottom: none; }
/* Row 1: Name 70 / Lehrkraft 30, no vertical border */
.pres-name-row { display: flex; align-items: stretch; }
.pres-name-row > .pres-name-cell { flex: 0 0 70%; padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); display: flex; align-items: center; font-size: clamp(1.4rem, 2.8vw, 2.2rem); line-height: 1.2; }
.pres-name-row > .pres-lk-cell { flex: 0 0 30%; padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); display: flex; align-items: center; justify-content: flex-end; font-size: clamp(1.15rem, 2.1vw, 1.7rem); font-weight: 600; }
/* Row 2: Noten full width */
.pres-noten-cell { padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); font-size: clamp(1.15rem, 2.1vw, 1.7rem); line-height: 1.6; }
/* Rows 3-7: Label 42 / Value 58, with vertical border */
.pres-split { display: flex; align-items: stretch; }
.pres-split > .pres-label { flex: 0 0 42%; padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); border-right: 2px solid; display: flex; align-items: center; font-size: clamp(1rem, 1.8vw, 1.35rem); line-height: 1.2; }
.pres-split > .pres-value { flex: 0 0 58%; padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); display: flex; align-items: center; font-size: clamp(1.1rem, 2vw, 1.5rem); font-weight: 600; line-height: 1.2; }
.pres-label em { font-style: italic; }
/* Row 8: Anmerkung full width */
.pres-anmerkung { padding: clamp(0.3rem, 0.8vh, 0.6rem) clamp(0.5rem, 1vw, 1rem); font-size: clamp(1rem, 1.8vw, 1.3rem); line-height: 1.25; }
.pres-footer { text-align: left; font-size: clamp(0.65rem, 1.1vw, 0.85rem); margin-top: 0.8vh; }

/* === LIGHT THEME === */
.pres-theme-light { background: #fff; color: #1a1a1a; }
.pres-theme-light .pres-nav { background: rgba(240,240,240,0.9); }
.pres-theme-light .pres-arrow { background: rgba(0,0,0,0.08); color: #333; border: 1px solid #ccc; }
.pres-theme-light .pres-arrow:hover { background: rgba(0,0,0,0.15); }
.pres-theme-light #pres-counter { color: #666; }
.pres-theme-light .pres-title-slide h1 { color: #1a365d; }
.pres-theme-light .pres-title-slide h2 { color: #333; }
.pres-theme-light .pres-title-slide .pres-subtitle { color: #888; }
.pres-theme-light .pres-school-name { color: #1a365d; }
.pres-theme-light .pres-card { border-color: #222; }
.pres-theme-light .pres-row { border-color: #222; }
.pres-theme-light .pres-split > .pres-label { border-color: #222; }
.pres-theme-light .pres-footer { color: #555; }

/* === DARK THEME === */
.pres-theme-dark { background: #0d1117; color: #e6edf3; }
.pres-theme-dark .pres-nav { background: rgba(0,0,0,0.6); }
.pres-theme-dark .pres-arrow { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid rgba(255,255,255,0.25); }
.pres-theme-dark .pres-arrow:hover { background: rgba(255,255,255,0.22); }
.pres-theme-dark #pres-counter { color: rgba(255,255,255,0.5); }
.pres-theme-dark .pres-title-slide h1 { color: #fff; }
.pres-theme-dark .pres-title-slide h2 { color: #a0c4ff; }
.pres-theme-dark .pres-title-slide .pres-subtitle { color: rgba(255,255,255,0.4); }
.pres-theme-dark .pres-school-name { color: #a0c4ff; }
.pres-theme-dark .pres-card { border-color: rgba(255,255,255,0.35); }
.pres-theme-dark .pres-row { border-color: rgba(255,255,255,0.35); }
.pres-theme-dark .pres-split > .pres-label { border-color: rgba(255,255,255,0.35); }
.pres-theme-dark .pres-footer { color: rgba(255,255,255,0.3); }
.pres-theme-dark .pres-logo { filter: brightness(1.2); }

@media (max-width: 768px) {
    .pres-card { font-size: 0.9rem; }
    .pres-name-cell { font-size: 1rem !important; }
    .pres-noten-cell { font-size: 0.95rem !important; }
    .home-tiles { grid-template-columns: 1fr; }
}

@media print {
    .pres-overlay { display: none !important; }
    .home-container { display: none !important; }
    .app-footer { display: none !important; }
}
