:root {
    /* Brand Colors: Vibrant Indigo / Purple theme */
    --brand-primary: #4f46e5;
    --brand-primary-hover: #4338ca;
    --brand-secondary: #0ea5e9;
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border-color: #e2e8f0;

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-blur: blur(12px);

    color-scheme: light dark;
}

[data-bs-theme="dark"] {
    --bg-color: #0b0f19;
    --surface-color: #151b2c;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border-color: #222a3e;

    /* Glassmorphism */
    --glass-bg: rgba(21, 27, 44, 0.85);
    --brand-primary: #6366f1;
    --brand-primary-hover: #4f46e5;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    -webkit-font-smoothing: antialiased;
    /* Enough room so content clears the fixed mobile bottom nav (including iOS safe area) */
    padding-bottom: calc(3.5rem + env(safe-area-inset-bottom));
    min-height: 100vh;
}

@media (min-width: 768px) {
    body {
        padding-bottom: 0;
    }
}

/* Top App Bar Header */
.app-header {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1020;
    padding: 1rem 0;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.header-brand {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--brand-primary);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Desktop Navigation Links */
.app-header .nav-link-desktop {
    color: var(--text-color);
    opacity: 0.75;
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    padding: 0.4rem 0.85rem;
    border-radius: 20px;
    transition: all 0.15s ease-in-out;
    display: inline-flex;
    align-items: center;
}

.app-header .nav-link-desktop:hover {
    color: var(--brand-primary);
    opacity: 1;
    background-color: rgba(13, 110, 253, 0.08);
}

.app-header .nav-link-desktop.active {
    color: var(--brand-primary) !important;
    opacity: 1;
    background-color: rgba(13, 110, 253, 0.12);
    font-weight: 700;
}

.app-header .nav-link-admin {
    color: var(--bs-danger);
    opacity: 0.85;
    font-weight: 700;
    font-size: 0.95rem;
    text-decoration: none;
    padding: 0.4rem 0.85rem;
    border-radius: 20px;
    transition: all 0.15s ease-in-out;
    display: inline-flex;
    align-items: center;
}

.app-header .nav-link-admin:hover {
    color: var(--bs-danger);
    opacity: 1;
    background-color: rgba(220, 53, 69, 0.1);
}

.app-header .nav-link-admin.active {
    color: var(--bs-danger) !important;
    opacity: 1;
    background-color: rgba(220, 53, 69, 0.15);
    text-decoration: none;
}

/* Card / Container styles for a premium look */
.premium-card {
    background: var(--surface-color);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Subtle interactive animations */
.interactive:active {
    transform: scale(0.97);
}

/* Bottom Mobile Navigation Shell */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    z-index: 1030;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.35rem 0;
    padding-top: 0.35rem;
    padding-bottom: calc(0.35rem + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.03);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.3rem 0.5rem;
    border-radius: 10px;
    transition: all 0.2s ease;
    gap: 0.15rem;
}

.nav-item i {
    font-size: 1.1rem;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.nav-item.active {
    color: var(--brand-primary);
}

.nav-item.active i {
    transform: translateY(-2px);
}

/* Buttons overrides */
.btn-primary {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
    border-radius: 12px;
    font-weight: 600;
    padding: 0.6rem 1.2rem;
    box-shadow: 0 4px 6px -1px rgba(79, 70, 229, 0.3);
    transition: all 0.2s;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--brand-primary-hover);
    border-color: var(--brand-primary-hover);
    transform: translateY(-1px);
}

/* Pill-Buttons einheitlich polstern.
   Bootstrap gibt .btn nur 0.75rem horizontal; bei rounded-pill draengt der Text
   dadurch an die runden Enden. Bisher wurde das je Template per px-3/px-4
   nachgezogen – was .btn-primary (eigene Polsterung) und die outline/light
   Varianten (Bootstrap-Default) unterschiedlich aussehen liess.
   Bootstrap-Utilities tragen !important und gewinnen weiterhin, wo bewusst
   abweichend gepolstert wird (z.B. px-5). Der FEK-Filter bringt ueber
   #fek-filter-container .btn eigene Werte mit und bleibt unberuehrt. */
.btn.rounded-pill {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.btn.rounded-pill.btn-sm {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Badges richten Icon und Text gemeinsam mittig aus.
   .badge bringt line-height: 1 mit, Icons sitzen auf der Grundlinie und wirken
   dadurch zu tief. inline-flex zentriert beides sauber.
   Achtung beim Aendern von Badges: In Flex-Containern entfernt der Browser
   fuehrende/abschliessende Leerzeichen der Textknoten – Abstaende deshalb ueber
   me-1 (Icons) bzw. &nbsp; (vor verschachtelten <span>) setzen, nicht ueber ein
   normales Leerzeichen. */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Runde Icon-Buttons zentrieren ihr Icon selbst.
   Vorher wurde das je Template mit "padding-top: 10px" angenaehert – das
   verrutscht, sobald Schriftgroesse oder Icon wechseln. Die Groesse kommt
   weiterhin aus dem Template (width/height). */
.btn.rounded-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* Utility */
.gradient-text {
    background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.non-gradient-text {
    color: var(--brand-primary);
}

/* Desktop: hide mobile nav */
@media (min-width: 768px) {
    .mobile-nav {
        display: none !important;
    }
}

/* Custom FEK Selectable Cards */
.fek-card {
    position: relative;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.165, 0.84, 0.44, 1);
    border: 1px solid var(--border-color) !important;
    background-color: var(--surface-color) !important;
    user-select: none;
}

.fek-card:hover {
    border-color: var(--brand-primary) !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.fek-card:active {
    transform: translateY(1px) scale(0.97);
}

/* When the checkbox inside is checked */
.fek-card:has(input:checked) {
    background-color: rgba(79, 70, 229, 0.08) !important;
    border-color: var(--brand-primary) !important;
    color: var(--brand-primary) !important;
    border-width: 2px !important;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.12);
}

/* Style the checkbox itself with a margin and brand color */
.fek-card input[type="checkbox"] {
    margin-right: 10px;
    cursor: pointer;
    accent-color: var(--brand-primary);
}

/* Modern Rating Buttons Style */
.rating-btn-group .rate-btn, .rate-btn {
    border-radius: 12px;
    border-width: 2px !important;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.rating-btn-group .rate-btn:hover, .rate-btn:hover {
    transform: translateY(-2px) scale(1.05);
}

.rating-btn-group .rate-btn:active, .rate-btn:active {
    transform: translateY(1px) scale(0.95);
}

/* Glow effects for active states */
.rate-btn.btn-secondary {
    box-shadow: 0 4px 10px rgba(108, 117, 125, 0.3);
}

.rate-btn.btn-warning {
    box-shadow: 0 4px 12px rgba(255, 193, 7, 0.4);
}

.rate-btn.btn-info {
    box-shadow: 0 4px 12px rgba(13, 202, 240, 0.4);
    color: white !important;
}

.rate-btn.btn-success {
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.4);
}

.rate-btn.btn-primary {
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

/* FEK Filter Pills */
#fek-filter-container .btn {
    padding: 0.6rem 1.2rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#fek-filter-container .btn:hover {
    transform: translateY(-1px);
}

/* Card hover animation */
.clickable-card {
    transition: transform 0.2s cubic-bezier(0.165, 0.84, 0.44, 1), box-shadow 0.2s ease, border-color 0.2s ease;
}
.clickable-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 20px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -4px rgba(0, 0, 0, 0.12) !important;
    border-color: var(--brand-primary) !important;
}

/* Grid fade-in animation */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
#students-grid {
    animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Dark mode styles for OpenStreetMap on Leaflet */
[data-bs-theme="dark"] .leaflet-container {
    filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

/* Ensure premium cards and components adapt correctly to dark mode */
.category-card, .category-card .accordion-button {
    background-color: var(--surface-color) !important;
    color: var(--text-main) !important;
}
.topic-row {
    background-color: var(--surface-color) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}
.focus-areas-dashboard {
    background-color: var(--surface-color) !important;
    border-color: var(--border-color) !important;
}
.focus-inner {
    background-color: var(--surface-color) !important;
    border-color: var(--border-color) !important;
}
[data-bs-theme="dark"] .focus-inner.bg-light {
    background-color: rgba(255, 255, 255, 0.03) !important;
    border-color: var(--border-color) !important;
}
[data-bs-theme="dark"] .bg-light {
    background-color: var(--surface-color) !important;
}
[data-bs-theme="dark"] .bg-body-secondary {
    background-color: #1a2236 !important;
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .modal-content {
    background-color: var(--surface-color) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
}
[data-bs-theme="dark"] .modal-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}
[data-bs-theme="dark"] input.form-control, 
[data-bs-theme="dark"] select.form-select,
[data-bs-theme="dark"] textarea.form-control {
    background-color: #1a2236 !important;
    border-color: var(--border-color) !important;
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] input.form-control:focus, 
[data-bs-theme="dark"] select.form-select:focus,
[data-bs-theme="dark"] textarea.form-control:focus {
    border-color: var(--brand-primary) !important;
    box-shadow: 0 0 0 0.25rem rgba(99, 102, 241, 0.25) !important;
}
[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--surface-color) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3) !important;
}
[data-bs-theme="dark"] .dropdown-item {
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: rgba(255, 255, 255, 0.05) !important;
}
[data-bs-theme="dark"] .dropdown-divider {
    border-color: var(--border-color) !important;
}
[data-bs-theme="dark"] .table {
    color: var(--text-main) !important;
    --bs-table-bg: transparent !important;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.03) !important;
}

/* Sticky mobile sub-header for student name (evaluate page) */
.sticky-student-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1019;
    display: flex;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
    padding: 0.5rem 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transform: translateY(-100%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    overflow: hidden;
    white-space: nowrap;
}

.sticky-student-bar.visible {
    transform: translateY(0);
    opacity: 1;
}

/* Custom transparent buttons for input groups */
.btn-transparent {
    background-color: transparent !important;
    border: 0;
    color: var(--text-muted) !important;
    transition: color 0.15s ease-in-out;
}
.btn-transparent:hover, .btn-transparent:focus {
    color: var(--brand-primary) !important;
}

/* Global border color overrides for dark mode utilities */
[data-bs-theme="dark"] .border,
[data-bs-theme="dark"] .border-start,
[data-bs-theme="dark"] .border-end,
[data-bs-theme="dark"] .border-top,
[data-bs-theme="dark"] .border-bottom,
[data-bs-theme="dark"] .dropdown-divider {
    border-color: var(--border-color) !important;
}

/* Automatically map bg-white utility class to dark surface color in dark mode (except QR Code) */
[data-bs-theme="dark"] .bg-white:not(.qrcode-container):not(.js-qrcode) {
    background-color: var(--surface-color) !important;
}

/* Override text color utilities in dark mode to ensure readable contrast */
[data-bs-theme="dark"] .text-dark {
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .text-muted {
    color: var(--text-muted) !important;
}
[data-bs-theme="dark"] .text-secondary {
    color: var(--text-muted) !important;
}

/* Indigo-Akzent fuer Lehrplan und Fahraufgaben (Teil B).
   Lag vorher nur im <style>-Block von curriculum.html und fehlte damit
   auf der Fahraufgaben-Seite, die dieselben Klassen verwendet. */
.bg-indigo-subtle { background-color: #e0e7ff; }
.text-indigo { color: #4f46e5; }

/* Dark mode overrides for settings / curriculum views and tables */
[data-bs-theme="dark"] .bg-indigo-subtle {
    background-color: rgba(99, 102, 241, 0.15) !important;
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .sortable-drag {
    background-color: var(--surface-color) !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5) !important;
}
[data-bs-theme="dark"] .btn-light {
    background-color: #21283d !important;
    border-color: var(--border-color) !important;
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .btn-light:hover, [data-bs-theme="dark"] .btn-light:focus {
    background-color: #2b334d !important;
    color: var(--text-main) !important;
}
[data-bs-theme="dark"] .table-light {
    --bs-table-bg: #1a2236 !important;
    --bs-table-color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

/* =======================================================================
   Wiederverwendbare Utilities
   Ersetzen Inline-Styles und lange Utility-Ketten, die vorher in vielen
   Templates wortgleich wiederholt wurden.
   ======================================================================= */

/* Runder Icon-Container (siehe templates/includes/icon_circle.html) */
.icon-circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}
.icon-circle-sm { width: 40px; height: 40px; font-size: 1.1rem; }
.icon-circle-md { width: 48px; height: 48px; font-size: 1.2rem; }
.icon-circle-lg { width: 50px; height: 50px; font-size: 1.25rem; }
.icon-circle-xl { width: 60px; height: 60px; font-size: 1.5rem; }
.icon-circle-xxl { width: 80px; height: 80px; font-size: 2.5rem; }

/* Kleines Großbuchstaben-Label über Formularfeldern
   (ersetzt: form-label fw-semibold text-muted small text-uppercase) */
.form-label-mini {
    display: inline-block;
    margin-bottom: 0.5rem;
    font-size: 0.875em;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* Runder Zurück-Button in Seitenköpfen */
.btn-circle {
    width: 45px;
    height: 45px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Horizontal scrollbare Tab-Leiste (Admin-, Einstellungs- und FEK-Tabs) */
.scroll-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1px;
}

/* Horizontale Pill-Leiste ohne sichtbare Scrollbar (FEK-Filter im Dashboard) */
.scroll-pills {
    display: flex;
    flex-wrap: nowrap;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.25rem;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.scroll-pills::-webkit-scrollbar { display: none; }

/* Read-only Ergebnistabellen der Probeprüfungen
   (vorher wortgleich in exam_detail.html und exam_shared.html) */
.result-table th,
.result-table td { text-align: center; vertical-align: middle; }
.result-table th.task-col,
.result-table td.task-col { text-align: left; min-width: 200px; }
.comp-head { font-size: .7rem; text-transform: uppercase; }

/* =======================================================================
   Erkundungskarte ("Nebel des Krieges")
   Vorher im <style>-Block von exploration/includes/student_map.html.
   ======================================================================= */

/* Weiche, wolkige Nebelkanten statt harter Polygon-Ränder */
.fog-layer {
    filter: blur(12px);
}

/* Aufgedeckte Gebiete leuchten leicht (Spiel-Effekt) */
.revealed-zone {
    filter: drop-shadow(0 0 8px rgba(25, 135, 84, 0.9));
}

/* Runde Status-Badges auf den Gebieten (✓ erkundet / ? unentdeckt) */
.zone-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.95rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    border: 2px solid #fff;
}
.zone-badge-visited {
    background: #198754;
    color: #fff;
}
.zone-badge-unknown {
    background: #1e293b;
    color: #facc15;
}

/* Ladeanzeige der Live-Suche (HTMX-Indikator).
   Vorher im <style>-Block von students/includes/search.html. */
@keyframes spin { to { transform: rotate(360deg); } }
#search-spinner { display: none; }
#search-spinner.htmx-request { display: inline-flex; }
.spin-icon { animation: spin 0.7s linear infinite; display: inline-block; }
