/* ====================================================
   1. CSS VARIABLEN & THEMES
   ==================================================== */

/* 📸 FUTURE TIMES */
:root, body.theme-foto {
    --bg-body: #D3D3CD;
    --bg-sidebar: #2C302E;
    --bg-card: #E2E2DC;
    --text-main: #2C302E;
    --text-muted: #5B665E; /* Tannengrün */
    --sidebar-text: #E2E2DC;
    --border-color: #CFCFC8;
    
    --accent-main: #517C82; /* Petrol */
    --btn-blue: #517C82;
    --btn-blue-hover: #3e6065;
    --btn-green: #D5E36D;   /* Akzent Grün (Lime) */
    --btn-green-hover: #b8c45d;
    --btn-green-text: #2C302E; /* Dunkles Tannengrün für Lesbarkeit */
    --btn-gray: #A3A39B;
    --btn-gray-text: #2C302E;
    
    --lila-baby: #B3B9EB; /* Für das Dashboard Radar & Icons */
    --icon-orange: #D98C5A; /* Gedämpftes Orange für das Benutzer-Icon */
}

/* 🌙 DARK MODE (Edel, reduziert, Nachtblau) */
body.theme-dark {
    --bg-body: #0A1118;
    --bg-sidebar: #0F1722;
    --bg-card: #131C29;
    --text-main: #D1D5DB;
    --text-muted: #64748B;
    --sidebar-text: #E2E8F0;     
    --border-color: #1E293B;
    
    --accent-main: #38BDF8;
    --btn-blue: #38BDF8;
    --btn-blue-hover: #0EA5E9;
    --btn-green: #34D399;
    --btn-green-hover: #059669;
    --btn-green-text: #0A1118;
    --btn-gray: #475569;
    --btn-gray-text: #94A3B8;
    
    --lila-baby: #818CF8; 
    --icon-orange: #FB923C;
}

/* 🌿 EDITORIAL EARTH (Warme Creme, Salbei & Terrakotta) */
body.theme-editorial {
    --bg-body: #F9F8F6; --bg-sidebar: #7A8B76; --bg-card: #ffffff;
    --text-main: #2C302E; --text-muted: #8E9491; --sidebar-text: #ffffff;
    --border-color: #E8E6E1; --accent-main: #C08465; --btn-blue: #7A8B76;
    --btn-blue-hover: #667562; --btn-green: #C08465; --btn-green-hover: #a66e52;
    --btn-green-text: #ffffff; --btn-gray: #DCDCDC; --btn-gray-text: #2C302E;
    --lila-baby: #D4C4B7; --icon-orange: #E07A5F;
}

/* 🌊 NORDIC OCEAN (Icy Blue, Fjordblau & weiches Apricot) */
body.theme-nordic {
    --bg-body: #F0F4F4; --bg-sidebar: #2B5B61; --bg-card: #ffffff;
    --text-main: #1B2A2C; --text-muted: #7A8D8F; --sidebar-text: #ffffff;
    --border-color: #DDE5E5; --accent-main: #E8A572; --btn-blue: #2B5B61;
    --btn-blue-hover: #1f4347; --btn-green: #E8A572; --btn-green-hover: #cf8e5d;
    --btn-green-text: #ffffff; --btn-gray: #B0C4C4; --btn-gray-text: #1B2A2C;
    --lila-baby: #93B5C6; --icon-orange: #F4A261;
}

/* 🎓 RETRO CAMPUS (Off-White, verwaschenes Stahlblau & Senfgelb) */
body.theme-retro {
    --bg-body: #FDFBF7; --bg-sidebar: #486887; --bg-card: #ffffff;
    --text-main: #2C3E50; --text-muted: #95a5a6; --sidebar-text: #ffffff;
    --border-color: #ecf0f1; --accent-main: #E69A3B; --btn-blue: #486887;
    --btn-blue-hover: #3a546d; --btn-green: #E69A3B; --btn-green-hover: #c9852f;
    --btn-green-text: #ffffff; --btn-gray: #f4f7f8; --btn-gray-text: #2C3E50;
    --lila-baby: #D98880; --icon-orange: #F2CC8F;
}

/* 🍃 NEO MINT (Clean Gray, sattes Mint & Lachsrot) */
body.theme-mint {
    --bg-body: #F7F9F9; --bg-sidebar: #00B8A9; --bg-card: #ffffff;
    --text-main: #2D3436; --text-muted: #636e72; --sidebar-text: #ffffff;
    --border-color: #e2e6e6; --accent-main: #FD7272; --btn-blue: #00B8A9;
    --btn-blue-hover: #00998c; --btn-green: #FD7272; --btn-green-hover: #e85a5a;
    --btn-green-text: #ffffff; --btn-gray: #ecf0f1; --btn-gray-text: #2D3436;
    --lila-baby: #F8B195; --icon-orange: #F67280;
}

/* ====================================================
   2. GLOBALES LAYOUT
   ==================================================== */
* { box-sizing: border-box; }

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background-color: var(--bg-sidebar);
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), background-color 0.4s ease;
    z-index: 100;
}
.sidebar.collapsed { width: 70px; }

.sidebar-header {
    padding: 20px; display: flex; align-items: center; justify-content: space-between; 
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* Neuer Container fürs Logo */
.logo-container { display: flex; align-items: center; gap: 10px; transition: transform 0.2s; }
.sidebar.collapsed .logo-container { cursor: pointer; }
.sidebar.collapsed .logo-container:hover { transform: scale(1.1); }

.sidebar-header .logo { font-weight: 800; font-size: 1.2rem; letter-spacing: 1px; }

/* Wenn eingeklappt: Haus mittig, Hamburger weg */
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 20px 0; }
.sidebar.collapsed .logo { display: none; }
.sidebar.collapsed .toggle-btn { display: none; } 

.toggle-btn { cursor: pointer; font-size: 1.2rem; transition: color 0.2s; opacity: 0.7; }
.toggle-btn:hover { opacity: 1; }

.menu-item {
    display: flex; align-items: center; padding: 12px 25px;
    color: var(--sidebar-text); opacity: 0.7; text-decoration: none;
    cursor: pointer; transition: all 0.2s; border-left: 4px solid transparent;
}
.menu-item:hover, .menu-item.active { opacity: 1; border-left-color: var(--accent-main); background: rgba(255,255,255,0.05); }
.menu-item i { width: 25px; font-size: 1.1rem; margin-right: 15px; text-align: center; }
.sidebar.collapsed .menu-item { padding: 15px 0; justify-content: center; }
.sidebar.collapsed .menu-item i { margin-right: 0; }
.sidebar.collapsed .menu-item span { display: none; }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.top-bar {
    height: 60px; background: var(--bg-card); display: flex; align-items: center;
    justify-content: space-between; padding: 0 30px; box-shadow: 0 2px 5px rgba(0,0,0,0.02);
    z-index: 10; transition: background-color 0.4s ease;
    border-bottom: 1px solid var(--border-color);
}
.content-body { flex: 1; padding: 30px; overflow-y: auto; }
#current-module-title { margin-top: 0; margin-bottom: 25px; font-size: 1.8rem; font-weight: 700; color: var(--text-main); }
#module-container { min-height: 100%; }

/* ====================================================
   3. BUTTONS (Speichern-Buttons immer GEFÜLLT)
   ==================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 18px; border-radius: 8px; font-family: inherit;
    font-size: 0.95rem; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: transparent; 
}

/* Blau/Primär Button */
.btn-blue { border: 2px solid var(--btn-blue); color: var(--btn-blue); }
.btn-blue:hover { background: var(--btn-blue); color: var(--bg-card); transform: translateY(-2px); }

/* Grün/Akzent Button (Lime) - IMMER GEFÜLLT */
.btn-green { 
    background: var(--btn-green); 
    border: 2px solid var(--btn-green); 
    color: var(--btn-green-text, #ffffff); 
}
.btn-green:hover { 
    background: var(--btn-green-hover); 
    border-color: var(--btn-green-hover); 
    color: var(--btn-green-text, #ffffff); 
    transform: translateY(-2px); 
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

/* Grauer Button */
.btn-gray { border: 2px solid var(--btn-gray); color: var(--text-main); }
.btn-gray:hover { background: var(--btn-gray); color: var(--text-main); transform: translateY(-2px); }

.btn i { transition: transform 0.3s; }
.btn:hover i { transform: scale(1.1); }

/* ====================================================
   4. KARTEN & MODALS
   ==================================================== */
.grades-header-bar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-card); padding: 15px; border-radius: 12px;
    margin-bottom: 20px; border: 1px solid var(--border-color); flex-wrap: wrap; gap: 15px;
}
.grades-header-bar select, .grades-header-bar input {
    padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 6px; 
    font-family: inherit; background: var(--bg-body); color: var(--text-main); outline: none;
}

/* Modals */
.modal {
    display: none; position: fixed; z-index: 2000; left: 0; top: 0;
    width: 100%; height: 100%; background-color: rgba(0,0,0,0.6);
    justify-content: center; align-items: center; backdrop-filter: blur(4px);
}
.modal-content {
    background-color: var(--bg-card); padding: 30px; border-radius: 16px;
    width: 400px; max-width: 90%; box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
}
.modal-lg { width: 1100px; max-width: 95%; }
.modal-header { border-bottom: 1px solid var(--border-color); padding-bottom: 15px; margin-bottom: 20px; display: flex; justify-content: space-between; align-items: center;}
.modal-header h3 { margin: 0; color: var(--text-main); }
.close-btn { color: var(--text-muted); font-size: 1.5rem; background: none; border: none; cursor: pointer; }
.close-btn:hover { color: var(--text-main); }

/* Formulare */
.form-group { margin-bottom: 15px; text-align: left; }
.form-group label { display: block; margin-bottom: 5px; font-weight: bold; font-size: 0.9rem; color: var(--text-muted);}
.form-group input, .form-group select, .form-group textarea { 
    width: 100%; padding: 12px; border: 1px solid var(--border-color); background: var(--bg-body); color: var(--text-main);
    border-radius: 6px; box-sizing: border-box; font-family: inherit; outline: none; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent-main); }

/* ====================================================
   5. TABELLEN (Sticky Columns)
   ==================================================== */
.table-container {
    overflow-x: auto; background: var(--bg-card); border-radius: 12px;
    border: 1px solid var(--border-color); max-height: calc(100vh - 200px);
}
.grades-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1000px; color: var(--text-main); }
.grades-table th, .grades-table td {
    border-bottom: 1px solid var(--border-color); border-right: 1px solid var(--border-color);
    padding: 12px; text-align: center; min-width: 140px; white-space: nowrap; background: var(--bg-card);
}
.grades-table th { background: var(--bg-body); font-weight: 600; font-size: 0.9rem; position: sticky; top: 0; z-index: 10; border-top: 1px solid var(--border-color); }
.grades-table .grade-category { font-size: 0.8rem; color: var(--text-muted); display: block; margin-bottom: 3px; }
.grades-table .grade-date { font-size: 0.75rem; opacity: 0.6; }

.grades-table th:nth-child(1), .grades-table td:nth-child(1) { position: sticky; left: 0; min-width: 50px; max-width: 50px; z-index: 5; border-left: 1px solid var(--border-color); }
.grades-table th:nth-child(2), .grades-table td:nth-child(2) { position: sticky; left: 50px; text-align: left; min-width: 180px; max-width: 180px; z-index: 5; }
.grades-table th:nth-child(3), .grades-table td:nth-child(3) { 
    position: sticky; left: 230px; min-width: 100px; max-width: 100px; z-index: 5; 
    background: var(--bg-body) !important; box-shadow: 2px 0 5px rgba(0,0,0,0.03); 
}
.grades-table thead th:nth-child(1), .grades-table thead th:nth-child(2), .grades-table thead th:nth-child(3) { z-index: 15; background: var(--bg-body) !important; }

/* ====================================================
   6. LOGIN OVERLAY
   ==================================================== */
#login-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: radial-gradient(circle at center, var(--bg-card) 0%, var(--bg-sidebar) 100%);
    z-index: 3000; display: flex; justify-content: center; align-items: center;
}
.login-box {
    background: var(--bg-card); padding: 40px; border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2); width: 100%; max-width: 400px;
    text-align: center; border: 1px solid var(--border-color);
}
.login-box h2 { color: var(--text-main); margin-top: 0; margin-bottom: 30px; font-size: 2rem; }
.login-box input {
    width: 100%; padding: 15px; margin-bottom: 20px; border: 1px solid var(--border-color);
    border-radius: 8px; font-family: inherit; font-size: 1rem; box-sizing: border-box;
    background: var(--bg-body); color: var(--text-main); transition: border-color 0.3s;
}
.login-box input:focus { border-color: var(--accent-main); outline: none; }
.login-box button {
    width: 100%; padding: 15px; background: var(--accent-main); color: var(--bg-card);
    border: none; border-radius: 8px; font-weight: bold; cursor: pointer;
    font-size: 1.1rem; transition: transform 0.2s;
}
.login-box button:hover { transform: translateY(-2px); }

/* --- SAFARI DATE-PICKER FIX --- */
input[type="date"]::-webkit-calendar-picker-indicator {
    display: block !important;
    opacity: 1 !important;
    cursor: pointer !important;
    background-color: transparent;
}
input[type="date"] {
    /* Zwingt Safari, das Feld als echtes Datumsfeld zu behandeln */
    -webkit-appearance: textfield !important; 
    min-height: 40px;
}

/* ====================================================
   7. MOBILE OPTIMIERUNG (Smartphones & kleine Tablets)
   ==================================================== */

/* Standard Desktop: Verstecke die Mobile-Elemente */
.mobile-controls { display: none; }
.mobile-only-status { display: none; }

@media screen and (max-width: 768px) {
    
    /* Bestimmte Module komplett ausblenden */
    .hide-on-mobile { display: none !important; }

    /* --- LAYOUT UMBAUEN (Von Links-Rechts auf Oben-Unten) --- */
    #app-container { flex-direction: column !important; }

    /* --- DIE NEUE MOBILE KOPFZEILE (Header) --- */
    .sidebar { 
        width: 100% !important; 
        height: auto !important; 
        flex-direction: column; 
        box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        z-index: 500;
        position: relative; /* Wichtig für das Dropdown */
    }
    
    .sidebar-header { 
        display: flex !important; 
        justify-content: center !important; 
        padding: 15px 20px !important;
        pointer-events: auto; /* Logo IST klickbar am Handy */
        cursor: pointer;
    }
    
    /* Das Logo darf sichtbar sein! */
    .sidebar-header .logo { display: block !important; }
    /* Aber der PC-Hamburger-Button verschwindet */
    .sidebar-header .toggle-btn { display: none !important; }

    /* --- DAS DROPDOWN-MENÜ (Standard: Versteckt) --- */
    .sidebar-menu {
        display: none !important; /* Versteckt */
        flex-direction: column;
        width: 100%;
        background-color: var(--bg-sidebar);
        padding: 0 0 15px 0 !important;
        box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
        position: absolute;
        top: 100%; /* Direkt unter der Kopfzeile ausklappen */
        left: 0;
        z-index: 499;
    }

    /* Wenn auf das Logo geklickt wurde, Menü zeigen */
    .sidebar.mobile-open .sidebar-menu {
        display: flex !important;
    }

    .menu-item {
        padding: 15px 20px !important;
        width: 100%;
        justify-content: flex-start !important; /* Icons linksbündig */
        border-bottom: 1px solid rgba(255,255,255,0.05);
    }
    
    .menu-item span { display: inline-block !important; margin-left: 15px; } /* Text wieder einblenden */

    /* --- CONTENT-BEREICH MOBILE --- */
    .top-bar {
        padding: 15px; 
        height: auto;
    }
    .top-bar > div {
        display: flex !important;
        flex-direction: column;
        width: 100%;
        gap: 10px;
        align-items: center;
    }
    #theme-switcher {
        width: 100%; max-width: 300px; font-size: 0.85rem; text-align: center;
    }
    #display-user-name { font-size: 0.9rem; text-align: center; }
    
    /* --- FUSSZEILE (Footer) LÖSUNG --- */
    .content-body {
        padding: 15px !important; 
        /* Das fette Padding-Bottom entfernt, das den Footer stauchte! */
        padding-bottom: 30px !important; 
    }
    
    /* Dadurch, dass die sidebar nun oben sitzt, hat die main-content mehr Platz. 
       Der Footer rutscht ganz natürlich ans Ende des Inhalts. */
    .main-content {
        height: calc(100vh - 60px) !important; /* 100% minus die Höhe der neuen Kopfzeile */
    }

    #current-module-title { font-size: 1.5rem; margin-bottom: 15px; text-align: center; }

    /* --- RASTER & KACHELN MOBILE --- */
    div[style*="grid-template-columns: 2fr 1fr"],
    div[style*="grid-template-columns: repeat"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 15px !important;
    }
    .dash-column { width: 100% !important; min-height: auto !important; }
    .dashboard-widget, .stats-card {
        width: 100% !important; box-sizing: border-box !important;
        overflow: hidden !important; word-wrap: break-word; 
    }

    /* --- TO-DO EINGABE MOBILE --- */
    #todo > div:last-child {
        flex-direction: column !important; gap: 10px !important;
    }
    #new-todo-title, #new-todo-date, #todo > div:last-child .btn {
        width: 100% !important; box-sizing: border-box;
    }
    
    /* --- MODALS MOBILE --- */
    .modal-content {
        width: 95% !important; padding: 20px !important;
        margin: 10px !important; max-height: 85vh; box-sizing: border-box;
    }
    div[style*="display: grid; grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* --- NEUES ANWESENHEITS-LAYOUT --- */
    .desktop-controls { display: none !important; }
    .mobile-controls { display: block !important; }
    .mobile-only-status { display: block !important; }
    .attendance-card { cursor: pointer; }
    .attendance-card:active { transform: scale(0.98); background: var(--bg-body) !important; }
    
    .table-container {
        width: 100%; overflow-x: auto !important;
        -webkit-overflow-scrolling: touch; border-radius: 8px;
    }
}