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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f5f5f5;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: #2c3e50;
    color: white;
    padding: 15px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

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

header h1 {
    font-size: 24px;
}

nav a {
    color: white;
    text-decoration: none;
    margin-left: 20px;
    padding: 8px 15px;
    border-radius: 4px;
    transition: background 0.3s;
}

nav a:hover {
    background: rgba(255,255,255,0.1);
}

nav a.active {
    background: #3498db;
}

/* Login */
.login-box {
    max-width: 400px;
    margin: 100px auto;
    background: white;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.login-box h2 {
    margin-bottom: 30px;
    text-align: center;
    color: #2c3e50;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: #555;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #3498db;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-secondary {
    background: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background: #7f8c8d;
}

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

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.card h2 {
    margin-bottom: 15px;
    color: #2c3e50;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.stat-card h3 {
    font-size: 14px;
    color: #7f8c8d;
    margin-bottom: 10px;
}

.stat-card .value {
    font-size: 32px;
    font-weight: bold;
    color: #2c3e50;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: #ecf0f1;
}

th, td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

th {
    font-weight: 600;
    color: #2c3e50;
}

tr:hover {
    background: #f8f9fa;
}

/* Anwesenheitsliste */
.anwesenheit-liste {
    list-style: none;
}

.anwesenheit-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: white;
    margin-bottom: 10px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.anwesenheit-item label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin: 0;
}

.anwesenheit-item input[type="checkbox"] {
    margin-right: 10px;
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* Alerts */
.alert {
    padding: 15px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.alert-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
}

.modal.active {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    border-radius: 8px;
    padding: 30px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-close {
    font-size: 24px;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: #333;
}

/* Utilities */
.mt-1 { margin-top: 10px; }
.mt-2 { margin-top: 20px; }
.mb-1 { margin-bottom: 10px; }
.mb-2 { margin-bottom: 20px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

.flex {
    display: flex;
}

.flex-between {
    justify-content: space-between;
}

.flex-center {
    align-items: center;
}

.gap-1 {
    gap: 10px;
}

.gap-2 {
    gap: 20px;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 768px) {
    /* Container */
    .container {
        padding: 10px;
    }
    
    /* Header */
    header .container {
        flex-direction: column;
        gap: 10px;
        text-align: center;
    }
    
    header h1 {
        font-size: 20px;
    }
    
    /* Navigation */
    nav {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
        gap: 5px;
    }
    
    nav a {
        margin-left: 0;
        padding: 10px 15px; /* Größere Touch-Targets */
        font-size: 14px;
        min-width: 80px;
        text-align: center;
    }
    
    /* Cards */
    .card {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .card h3 {
        font-size: 18px;
    }
    
    /* Dashboard Stats */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-card h3 {
        font-size: 24px;
    }
    
    /* Forms */
    .form-group label {
        font-size: 14px;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Verhindert Auto-Zoom auf iOS */
        padding: 10px; /* Größere Touch-Targets */
    }
    
    .flex.gap-2 {
        flex-direction: column;
        gap: 10px;
    }
    
    .flex.gap-2 > * {
        width: 100%;
    }
    
    .flex.space-between,
    .flex.flex-between {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }
    
    .flex.flex-between h2 {
        text-align: center;
    }
    
    /* Buttons */
    .btn {
        width: 100%;
        padding: 12px;
        font-size: 16px;
        min-height: 44px; /* iOS empfohlene Touch-Größe */
    }
    
    /* Tables - Horizontal Scroll */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -15px; /* Volle Breite nutzen */
        padding: 0 15px;
    }
    
    table {
        font-size: 12px;
        min-width: 600px; /* Verhindert zu enges Layout */
    }
    
    th, td {
        padding: 8px 4px; /* Touch-freundlicher */
        white-space: nowrap;
    }
    
    /* Spezielle Tabellen-Buttons */
    table .btn {
        width: auto;
        padding: 8px 12px; /* Touch-freundlicher */
        font-size: 12px;
        min-height: 36px;
    }
    
    table select {
        font-size: 14px; /* Besser lesbar */
        padding: 6px;
        min-height: 36px;
    }
    
    /* Anwesenheits-Kalender */
    .kalender-grid {
        gap: 5px;
    }
    
    .schueler-row {
        font-size: 12px;
    }
    
    .schueler-name {
        min-width: 100px;
        padding: 8px; /* Touch-freundlicher */
        position: sticky;
        left: 0;
        background: white;
        z-index: 1;
        box-shadow: 2px 0 4px rgba(0,0,0,0.1);
    }
    
    .anwesenheit-zelle {
        width: 50px; /* Größer für Touch */
        height: 50px;
        font-size: 24px;
        cursor: pointer;
        user-select: none; /* Verhindert versehentliche Textauswahl */
    }
    
    /* Rechnungs-Vorschau */
    #vorschauContainer {
        max-height: 60vh;
    }
    
    #vorschauContainer h4 {
        font-size: 16px;
    }
    
    #vorschauContainer ul {
        font-size: 14px;
    }
    
    /* Login-Seite */
    .login-container {
        padding: 20px;
        margin: 20px 10px;
    }
    
    .login-card {
        padding: 20px;
    }
    
    .login-card h2 {
        font-size: 22px;
    }
    
    /* Modal */
    .modal-content {
        width: 95%;
        max-height: 90vh;
        overflow-y: auto;
        margin: 5vh auto;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-close {
        font-size: 32px; /* Größerer Touch-Target */
        width: 36px;
        height: 36px;
        line-height: 36px;
    }
}

/* Sehr kleine Handys */
@media (max-width: 480px) {
    header h1 {
        font-size: 18px;
    }
    
    nav a {
        padding: 8px 12px;
        font-size: 13px;
        min-width: 70px;
    }
    
    .card {
        padding: 10px;
    }
    
    .card h3 {
        font-size: 16px;
    }
    
    table {
        font-size: 11px;
        min-width: 500px;
    }
    
    th, td {
        padding: 6px 3px;
    }
    
    .anwesenheit-zelle {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }
    
    .schueler-name {
        min-width: 80px;
    }
}

/* Landscape Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 15px;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    table {
        font-size: 13px;
    }
}

/* Touch-Optimierungen für alle Geräte */
@media (hover: none) and (pointer: coarse) {
    /* Alle klickbaren Elemente größer machen */
    button,
    .btn,
    a,
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px; /* iOS empfohlen */
    }
    
    /* Checkboxen größer für Touch */
    input[type="checkbox"] {
        width: 20px;
        height: 20px;
        cursor: pointer;
    }
    
    .anwesenheit-zelle:active {
        transform: scale(0.95);
        transition: transform 0.1s;
    }
    
    /* Hover-Effekte deaktivieren */
    .btn:hover,
    nav a:hover,
    .anwesenheit-zelle:hover {
        background-color: inherit;
    }
    
    /* Select Dropdowns größer */
    select {
        padding: 12px;
        font-size: 16px;
    }
}

/* Table Horizontal Scroll Wrapper - immer aktiviert auf Mobile */
@media (max-width: 768px) {
    /* Wrapper für scrollbare Tabellen hinzufügen */
    .card table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .card table thead,
    .card table tbody,
    .card table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }
    
    /* Tabellen-Hinweis für Scroll */
    .card:has(table)::before {
        content: '← Scrollen für mehr →';
        display: block;
        text-align: center;
        font-size: 12px;
        color: #666;
        padding: 5px;
        background: #f0f0f0;
        border-radius: 4px;
        margin-bottom: 10px;
    }
}
