/* Modernes Dashboard-Fundament */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #f8fafc; /* Sehr edles Off-White */
    color: #0f172a;
    margin: 0;
    padding: 40px 20px;
}

/* Die Hauptkarte */
.container-box {
    max-width: 850px;
    margin: 0 auto 30px auto;
    background: #ffffff;
    padding: 40px;
    border-radius: 16px; /* Weiche, moderne Ecken */
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05); /* Ultraleichter Schatten */
}

h3 {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 30px 0;
    letter-spacing: -0.02em;
}

/* Das asymmetrische Grid */
.modern-grid {
    display: grid;
    grid-template-columns: repeat(12, 1fr); /* 12-Spalten-Raster für absolute Kontrolle */
    gap: 24px;
}

/* Formular-Gruppe */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Spaltensteuerung */
.col-4  { grid-column: span 4; }
.col-6  { grid-column: span 6; }
.col-8  { grid-column: span 8; }
.col-12 { grid-column: span 12; }



/* Minimalistische Labels */
.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: #64748b; /* Dezentes Graublau */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Nahtlose, moderne Eingabefelder */
.input-content, select, textarea {
    width: 100%;
    height: 46px;
    padding: 0 16px;
    font-size: 15px;
    color: #0f172a;
    background-color: #f1f5f9; /* Kein weißes Feld auf weißem Grund, sondern softes Grau */
    border: 2px solid transparent; /* Kein harter Rahmen im Ruhezustand */
    border-radius: 10px;
    box-sizing: border-box;
    transition: all 0.2s ease;
}

textarea {
    height: auto;
    padding: 16px;
}

/* Interaktiver Fokus-Effekt */
.input-content:focus, select:focus, textarea:focus {
    outline: none;
    background-color: #ffffff;
    border-color: #3b82f6; /* Aktivierung durch scharfen Akzent */
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

/* Inline-Elemente wie Zeiten */
.flex-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-select {
    width: 80px !important;
    text-align: center;
}

.time-divider {
    font-weight: 500;
    color: #94a3b8;
}

/* Radio-Buttons im Button-Style (Keine winzigen Kreise mehr!) */
.radio-group {
    display: flex;
    gap: 12px;
}

.radio-label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 46px;
    background: #f1f5f9;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 15px;
    color: #475569;
    transition: all 0.2s;
}

.radio-label input {
    display: none; /* Versteckt den hässlichen Standard-Kreis */
}

.radio-label:has(input:checked) {
    background: #e0f2fe;
    color: #0369a1;
    border: 2px solid #0284c7;
}

/* Stellt sicher, dass das eingeblendete Fieldset die volle Breite einnimmt */
/* 1. Im Ruhezustand sind die dynamischen Container unsichtbar */
#ja.item, #email-ja.item2 {
    display: none !important;
}

/* 2. Wenn "Auftrag beendet = Ja" aktiv ist -> Zeige die Positionstabelle als Kasten */
body:has(input[name="itemtype"][value="ja"]:checked) #ja.item {
    display: block !important;
    margin-top: 30px;
}

/* 3. Wenn "Bericht an Kunden = Ja" aktiv ist -> Binde das E-Mail-Feld nahtlos ins Grid ein */
body:has(input[name="itemtype2"][value="email-ja"]:checked) #email-ja.item2 {
    display: block !important;
    grid-column: span 12 !important;
}


/* --- STARTSEITEN DESIGN (DASHBOARD-KACHELN) --- */

/* Zentriert den Inhalt vertikal und horizontal auf der Seite */
.dashboard-wrapper {
    max-width: 900px;
    margin: 40px auto;
    padding: 0 20px;
}

.dashboard-header {
    text-align: center;
    margin-bottom: 40px;
}

.dashboard-header h2 {
    font-size: 26px;
    font-weight: 800;
    color: #0f172a;
    border-bottom: none;
    margin-bottom: 6px;
}

.dashboard-header p {
    margin: 0;
    color: #64748b;
    font-size: 15px;
}

/* 4-spaltiges Layout für den Desktop */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
}

/* Die interaktiven App-Kacheln */
.dashboard-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: #ffffff;
    padding: 30px 20px;
    border-radius: 16px;
    text-decoration: none;
    color: #0f172a;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease-in-out;
    border: 1px solid #f1f5f9;
}

/* Sanfter Zoom- und Schwebe-Effekt am PC */
.dashboard-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 20px -3px rgba(0, 0, 0, 0.08);
    border-color: #cbd5e1;
}

.card-icon {
    font-size: 32px;
    margin-bottom: 16px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 6px;
}

.card-desc {
    font-size: 12px;
    color: #64748b;
    line-height: 1.4;
}

/* 📱 Optimierung für Smartphones (z.B. Galaxy S25) */
@media (max-width: 768px) {
    .dashboard-wrapper {
        margin: 20px auto;
    }
    
    /* Auf Handys werden die Kacheln zu einem übersichtlichen 2er-Raster */
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    
    .dashboard-card {
        padding: 20px 15px;
    }
    
    .card-icon {
        font-size: 28px;
        margin-bottom: 12px;
    }
    
    .card-title {
        font-size: 16px;
    }
	
    .col-4, .col-6, .col-8, .col-12 { grid-column: span 12; } /* Mobile-Fallback */
    
    /* 1. Kasten-Abstände radikal verringern, wenn eine Tabelle darin liegt */
    #ja.container-box {
        padding: 12px 6px !important; /* Nur noch minimaler Rand links und rechts */
    }

    /* 2. Titel-Abstand anpassen */
    #ja.container-box h3 {
        margin-left: 6px;
        margin-bottom: 15px;
    }

    /* 3. Innenabstände der Tabellenzellen verkleinern */
    .table2 th, .table2 td {
        padding: 6px 4px !important; /* Macht die Spalten kompakter */
    }

    /* 4. Eingabefelder in der Tabelle schmaler polstern für mehr Textfläche */
    .table2 .input-content {
        padding: 0 8px !important; /* Weniger Freiraum im Feld selbst */
        height: 40px; /* Leicht reduzierte Höhe für bessere Übersicht */
        font-size: 14px; /* Optimale Schriftgröße für Mobilgeräte */
    }

    /* ================================================================= */
    /* 📱 5. DIE SPALTENBREITEN FÜR HANDYS OPTIMIEREN (BADGE-SYNCHRON)   */
    /* ================================================================= */
    .table2 th:nth-child(1), .table2 td:nth-child(1) {
        width: 18% !important; /* Etwas schmaler für die Menge reicht völlig aus */
    }
    .table2 th:nth-child(2), .table2 td:nth-child(2) {
        width: 76% !important; /* Maximaler, riesiger Platz für das Textfeld + Badge */
    }
    .table2 th:nth-child(3), .table2 td:nth-child(3) {
        width: 6% !important; /* Knackige 10% für das Löschkreuz */
    }

    /* 🔒 FIX: Greift jetzt präzise die 3. Zelle und formatiert das Kreuz daumenfreundlich */
    .table2 td:nth-child(3) button {
        font-size: 16px !important;
        line-height: 1 !important;
        width: 28px !important; /* Feste, runde Breite statt 100% Sprengung */
        height: 28px !important; /* Feste, runde Höhe für perfekte Symmetrie */
        background-color: #fff1f2; /* Ganz softes Alarm-Rot als Kachel-Hintergrund */
        color: #ef4444;
        border-radius: 8px;
        padding: 0 !important;
        margin: 0 auto;
        display: block;
    }


/* Sorgt dafür, dass die Buttons auch in der mobilen Ansicht (z.B. S25) exakt gleich groß bleiben */
    .btn-secondary {
        width: 100% !important;
        font-size: 16px !important;
        font-weight: 600 !important;

    }
	body {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }
    
    .container-box {
        padding: 20px 12px !important; /* Oben/unten 20px, links/rechts schlanke 12px */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    .container-box:has(table) {
        padding-left: 4px !important;
        padding-right: 4px !important;
    }
	
   /* Zwingt den Start- und Endbereich untereinander zu stehen */
    #formular-seite .flex-row {
        flex-wrap: wrap !important;
        gap: 12px 6px !important;
    }
        
    .time-divider {
        font-size: 15px;
        color: #475569;
    }
}

/* Kleinst-Displays (Alte oder sehr kleine Handys hochkant) */
@media (max-width: 400px) {
    .dashboard-grid {
        grid-template-columns: 1fr; /* Alles untereinander */
    }
}

/* --- NEUER BUTTON-PART --- */
/* Erzwingt absolut identische Schrift- und Layoutwerte für beide Buttons */
.btn-secondary {
    background-color: #e2e8f0;
    color: #475569;
    padding: 12px 24px;
    font-size: 16px; /* Einheitliche Schriftgröße */
    font-weight: 600; /* Einheitliche Schriftdicke */
    line-height: 1.5; /* Einheitliche Zeilenhöhe */
    text-decoration: none;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* --- FIXES HORIZONTAL OVERFLOW AND PHANTOM SCROLLING --- */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Clips any phantom invisible elements stretching to the right */
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit; /* Prevents paddings and borders from expanding elements beyond 100% width */
}

/* --- HOCHPRÄZISE STEUERUNG (NUR AUF FORMULAR-SEITEN AKTIV) --- */

/* 1. Setzt den Abstand direkt nach der Überschrift auf ein Minimum */
#formular-seite .container-box h2, 
#formular-seite .container-box h3 {
    margin-bottom: 5px !important;
    padding-bottom: 6px;
}

/* 2. Setzt den vertikalen Grundabstand zwischen den Grid-Zeilen flach auf Null */
#formular-seite .modern-grid {
    gap: 0 24px !important; 
    margin-top: 0 !important;
}

/* 3. Zieht das Label ganz nah an den Wert heran */
#formular-seite .form-group {
    gap: 2px !important;
    margin-bottom: 18px !important; /* Drückt die NÄCHSTE Zeile weiter nach unten */
}

/* 4. Verhindert unsichtbare Abstände beim reinen Text */
#formular-seite .form-group span {
    display: block;
    padding: 0 !important;
    font-size: 16px;
    line-height: 1.4;
}

/* Definiert eine feste, saubere Breite für die Zeit-Dropdowns auf allen Geräten */
.time-select {
    width: 90px !important;
    text-align: center;
}

#canvasDiv {
    position: relative;
    border: 2px dashed #94a3b8;
    height: 180px;
    background-color: white;
    overflow: hidden;
    cursor: crosshair;
}
/* 🔒 FIX: Verhindert, dass das Smartphone beim Unterschreiben die Seite scrollt oder zoomt */
#canvas {
    touch-action: none; 
    user-select: none;
    -webkit-user-select: none;
}

/* ================================================================= */
/* 💎 PREMIUM-DESIGN: SCHWEBENDE RESTBESTANDS-BADGES                */
/* ================================================================= */

/* Das schwebende Label im Eingabefeld positionieren */
.rest-badge {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%); /* Perfekt vertikal zentrieren */
    font-size: 11px;
    font-weight: 700;
    padding: 2px 2px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    pointer-events: none; /* Ignoriert Klicks, damit das Textfeld darunter klickbar bleibt */
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Variante ROT: Wenn 0 Stück verfügbar sind */
.badge-rot {
    background-color: #fee2e2; /* Softes Hellrot */
    color: #ef4444;            /* Scharfes Alarm-Rot */
    border: 1px solid #fca5a5;
}

/* Variante GRÜN: Wenn noch Material offen ist */
.badge-gruen {
    background-color: #dcfce7; /* Softes Hellgrün */
    color: #16a34a;            /* Scharfes Signal-Grün */
    border: 1px solid #86efac;
}