/* File: frontend/static/css/style.css */
/* UTF-8 encoding */

/* =========================================================
    Gefriertruhe QR - Consolidated Stylesheet (REVISED)
    ========================================================= */

/* =========================================================
    CSS Variablen
    Zentralisiert Farben für bessere Wartbarkeit.
   ========================================================= */
:root {
    --primary-blue: #007bff;
    --primary-cyan: #00bcd4;
    --danger-red: #f44336;
    --success-green: #28a745;
    --light-gray: #f5f5f5;
    --border-color: #ccc;
    --text-color: #333;
    --ios-safe-font: 16px;
}

/* =========================================================
    Body & Layout
   ========================================================= */
body {
    font-family: Arial, sans-serif;
    text-align: center;
    margin: 20px;
    padding-bottom: 140px; /* Platz für den Sticky Footer */
    color: var(--text-color);
    -webkit-text-size-adjust: 100%;
}

h1 { margin-bottom: 20px; }

/* =========================================================
    Globale Button & Formular Styles
   ========================================================= */
.button-container {
    display: flex;
    flex-direction: column;  /* Erzwingt Untereinander-Anzeige */
    align-items: center;
    gap: 12px;               /* Abstand zwischen den Buttons */
    padding: 10px;
    max-width: 400px;        /* Begrenzung für Desktop */
    margin: 0 auto;          /* Zentrierung des Containers */
}

/* Standard Button-Styling */
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 5px;
    padding: 12px 20px;
    min-height: 44px;
    font-size: var(--ios-safe-font);
    font-weight: 600;
    cursor: pointer;
    border-radius: 8px;
    border: none;
    background-color: var(--primary-blue);
    color: white;
    transition: background-color 0.2s, transform 0.1s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    -webkit-tap-highlight-color: transparent;
}
/* Auch für die Quick-Pick Buttons ergänzen */
button,
.js-quick-btn {
    -webkit-tap-highlight-color: transparent;
}

button:active { transform: scale(0.98); }

.btn-cyan { background-color: var(--primary-cyan); color: white; }
.btn-light { background-color: var(--light-gray); color: #333; border: 1px solid #ddd; }
.btn-blue { background-color: var(--primary-blue); color: white; }
.btn-red { background-color: var(--danger-red); color: white; }
.btn-green { background-color: var(--success-green); color: white; }

input, textarea, select {
    font-size: var(--ios-safe-font) !important;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    box-sizing: border-box;
    min-height: 44px;
}

input::placeholder, textarea::placeholder {
    font-size: 14px;
    color: #999;
}

/* =========================================================
    Tabelle & Sticky Header (FINALE LOGIK)
   ========================================================= */

/* Der Container erlaubt horizontales Scrollen, blockiert aber NICHT das vertikale Sticky-Verhalten */
.table-container {
    overflow-x: auto;
    overflow-y: visible !important; 
    display: block;
    margin: 15px 0;
    position: relative;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}

#item-table {
    width: 100%;
    min-width: 750px;
    background-color: white;
    /* Separate ist Pflicht, damit th beim Scrollen am Rand kleben bleibt */
    border-collapse: separate !important; 
    border-spacing: 0;
}

#item-table thead th {
    position: -webkit-sticky;
    position: sticky;
    top: -21px; /* Gleicht body margin 20px aus */
    background-color: #eeeeee !important;
    z-index: 50; /* Muss über den td liegen */
    padding: 12px 5px;
    border-top: 1px solid var(--border-color);
    border-bottom: 2px solid var(--border-color);
    box-shadow: 0 2px 2px rgba(0,0,0,0.1);
}

#item-table th, #item-table td {
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    padding: 10px 5px;
    font-size: 13px;
}

/* Da border-collapse: separate, müssen wir den linken Rand manuell setzen */
#item-table th:first-child, 
#item-table td:first-child {
    border-left: 1px solid var(--border-color);
}

/* Spalten-Spezifika */
/* Spalte 1: Name - Die bedeutendste Spalte (Fett & Breit) */
#item-table th:nth-child(1), 
#item-table td:nth-child(1) {text-align: left; padding-left: 10px; min-width: 130px; width: auto; font-weight: bold;}
/* Alle Spalten ab Spalte 2: Zentriert & kein Umbruch */
#item-table th:nth-child(n+2), 
#item-table td:nth-child(n+2) {white-space: nowrap; text-align: center;}

/* Spezielle Breite für die ID (jetzt Spalte 5, wenn eingeblendet) */
/* Wir nutzen die Klasse .extra-col, damit es unabhängig vom Index bleibt */
#item-table td.extra-col:first-of-type,
#item-table th.extra-col:first-of-type {width: 50px;text-align: center;}

/* Zebra-Look erhalten */
#item-table tr:nth-child(even) { background-color: rgba(0, 0, 0, 0.02); }

/* --- Toggle Logik (wie zuvor besprochen) --- */
.view-compact .extra-col {display: none !important;}
.view-full .extra-col {display: table-cell !important;}
.view-compact {min-width: auto !important;}

/* =========================================================
    Kontextmenü & API Feedback
   ========================================================= */
.context-menu {
    position: absolute;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 1000;
    display: none;
    min-width: 150px;
    overflow: hidden;
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 12px;
    text-align: left;
    background: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    color: var(--text-color);
    margin: 0;
}

.context-menu button:hover { background-color: var(--light-gray); }
.context-menu .delete-btn { color: var(--danger-red) !important; }

.output-box {
    margin-top: 15px;
    background: white;
    border: 1px solid var(--border-color);
    padding: 10px;
    border-radius: 4px;
    display: none;
}

/* =========================================================
    Status & Spezialelemente (Reader, QR, Date-Status)
   ========================================================= */
/* Abgelaufen: Hellrote Zeile */
#item-table tr.item-expired { background-color: #ffebee !important; }
#item-table tr.item-expired td { color: #c62828; }

/* Läuft bald ab: Gelbliche Zeile */
#item-table tr.item-soon { background-color: #fffde7 !important; }
#item-table tr.item-soon td { color: #856404; }

.date-status {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.85em;
    display: inline-block;
}

.date-ok { background-color: #e8f5e9; color: #2e7d32; }
.date-warning { background-color: #fffde7; color: #f57f17; }
.date-expired { background-color: #ffebee; color: #c62828; }


/* Der äußere Rahmen bleibt stabil */
#reader {
    margin: 20px auto;
    width: 280px;      /* Deine gewünschte quadratische Breite */
    height: 280px;     /* Deine gewünschte quadratische Höhe */
    position: relative;
    overflow: hidden;  /* Schneidet das überstehende Video sauber ab */
    border: 3px solid var(--border-color);
    border-radius: 12px;
    background: #000;
}

/* Das Video wird so positioniert, dass es das Quadrat füllt */
#reader video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%); /* Zentriert das Video im Quadrat */
    min-width: 100%;
    min-height: 100%;
    width: auto !important;
    height: auto !important;
    object-fit: cover; /* Wichtig für die Optik, ohne die Maße zu verzerren */
}


#reader::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* Ein riesiger Schatten, der nach innen (inset) drückt */
    /* Erzeugt den Effekt eines dunklen Rahmens mit hellem Zentrum */
    box-shadow: inset 0 0 0 40px rgba(0, 0, 0, 0.5); 
    z-index: 5;
    pointer-events: none; /* Wichtig: Klicks gehen durch zum Video */
}

/* Optional: Vier weiße Ecken als "Sucher-Grafik" */
#reader::after {
    content: "";
    position: absolute;
    top: 40px;
    left: 40px;
    right: 40px;
    bottom: 40px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    z-index: 6;
    pointer-events: none;
}

/* Optional: Ein animierter Scan-Strich für das Feedback */
/*#reader::after {
    content: "";
    position: absolute;
    pointer-events: none;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: rgba(40, 167, 69, 0.5);
    box-shadow: 0 0 8px 2px rgba(40, 167, 69, 0.8);
    animation: scan-line 2.5s infinite linear;
    z-index: 10;
}

@keyframes scan-line {
    0% { top: 0%; }
    50% { top: 100%; }
    100% { top: 0%; }
}
*/




#reader.active { border-color: var(--success-green); }

/*
#reader__scan_region {
    background-color: rgba(0, 0, 0, 0.5) !important;
}
*/

.qrcode-container { display: flex; flex-wrap: wrap; justify-content: center; gap: 20px; }
.qrcode {
    display: flex; flex-direction: column; align-items: center; padding: 10px;
    border: 1px solid var(--border-color); border-radius: 8px; width: 170px;
    transition: transform 0.2s ease;
}
.qrcode:hover { transform: scale(1.05); }

/* =========================================================
    Sticky Footer (Buttons einzeilig auf Mobile)
   ========================================================= */
.sticky-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--border-color);
    padding: 10px 0;
    z-index: 150; /* Über dem Tabellenheader */
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

.sticky-controls .controls {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
}

.sticky-controls button {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    padding: 10px 5px;
    font-size: 13px;
    margin: 0;
    max-width: 150px; /* Begrenzung für Tablets/Desktop */
}

/* =========================================================
    Footer & Versionierung (Clean-up)
   ========================================================= */
footer {
    display: block;
    width: 100%;
    margin-top: 50px;
    padding: 20px 0;
    overflow: visible;
    clear: both;
    color: #666;
    font-size: 0.85em;
}

/* =========================================================
    Modal / Popup System
   ========================================================= */
.modal {
    display: none; /* Standardmäßig versteckt */
    position: fixed;
    z-index: 2000; /* Über allem anderen (auch über dem Sticky Footer) */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Dunkler Hintergrund-Schleier */
    backdrop-filter: blur(3px); /* Edler Unschärfe-Effekt */
}

.modal-content {
    background-color: #fff;
    margin: 20% auto; /* Mittig auf dem Bildschirm */
    padding: 25px;
    border-radius: 12px;
    width: 85%;
    max-width: 350px;
    text-align: center;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
}

/* Der Container für die 3 Buttons (Abbruch, Teil, Ganz) */
#modal-buttons {
    display: flex !important;
    flex-direction: row !important; /* Erzwingt Nebeneinander */
    flex-wrap: nowrap !important;  /* Verbietet Umbruch */
    gap: 6px; 
    margin-top: 20px;
    width: 100%;
    justify-content: center;
}

/* Spezifische Korrektur für Buttons im Modal */
#modal-buttons button {
    flex: 1;
    min-width: 0;            /* Erlaubt Schrumpfen auf schmalen Handys */
    margin: 0;
    padding: 10px 2px;       /* Weniger horizontaler Platz, mehr vertikal */
    font-size: 13px;         /* Einheitliche Größe für Mobile SE */
    display: inline-flex;    /* WICHTIG: Icon und Text in eine Reihe */
    flex-direction: row;     /* Icon neben Text */
    align-items: center;
    justify-content: center;
    gap: 4px;                /* Abstand Icon zu Text */
    white-space: nowrap;     /* Text bleibt in einer Zeile */
    overflow: hidden;        /* Falls Text zu lang, wird er abgeschnitten */
}

/* Optional: Damit die Emojis nicht zu groß werden */
#modal-buttons button span, 
#modal-buttons button i {
    font-size: 1.1em;
    line-height: 1;
}

/* =========================================================
    UI Feedback System (Toasts)
    Nutzt zentrale Variablen für konsistentes Design.
   ========================================================= */

#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11000 !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.toast {
    color: #fff;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 0.95rem;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.4s, transform 0.4s;
    pointer-events: auto;
    white-space: normal;      /* Erlaubt Umbruch */
    max-width: 85vw;          /* Etwas Sicherheitsabstand zum Rand */
    text-align: center;       /* Zentriert bei Mehrzeiligkeit */
    line-height: 1.35;        /* Der goldene Mittelweg für Lesbarkeit */
    word-wrap: break-word;    /* Bricht extrem lange Wörter zur Not hart um */
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* KORREKTUR: Variablen-Mapping für volle Konsistenz */
.toast-success { background-color: var(--primary-cyan) !important; }
.toast-error   { background-color: var(--danger-red) !important; }
.toast-info    { background-color: var(--primary-blue) !important; }

/* =========================================================
    Zusätze für dynamische Portionswahl (utils.js Support)
   ========================================================= */

/* Styling für das dynamische Dropdown im Modal */
#portion-select {
    width: 100%;
    max-width: 200px;
    margin: 10px auto 20px auto;
    display: block;
    text-align: center;
    text-align-last: center; /* Zentriert Text in Safari/Chrome */
    border: 2px solid var(--primary-cyan);
    background-color: #fff;
    font-weight: bold;
    color: var(--text-color);
}

/* Hilfstext im Modal (z.B. Bestandsanzeige) */
.modal-info-text {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 12px;
}

/* Sicherstellung, dass Icons in Modal-Buttons einheitlich wirken */
#modal-buttons button span {
    pointer-events: none; /* Verhindert Klick-Interferenz */
}

/* Unterstützung für ausgeblendete Elemente (z.B. wenn Auswahl = Max) */
.hidden {
    display: none !important;
}

/* =========================================================
    Quick-Pick & Smart-Input Integration
   ========================================================= */

/* Container für die 1-4 Buttons */
.quick-pick-container {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin: 15px 0;
    width: 100%; /* Sicherstellen, dass die volle Breite genutzt wird */
}

/* Die Quick-Pick Buttons selbst */
.js-quick-btn {
    flex: 1;
    min-width: 44px; /* Apple Tap-Target Standard */
    height: 44px;
    margin: 0 !important; /* WICHTIG: Überschreibt das globale margin: 5px */
    background-color: white !important;
    color: var(--primary-cyan) !important;
    border: 2px solid var(--primary-cyan) !important;
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: bold;
    box-shadow: none !important; /* Cleaner Look für Quick-Picks */
    transition: all 0.2s ease;
}

/* Der 'Selected' Status muss stärker sein als die Basis-Klasse */
.js-quick-btn.selected {
    background-color: var(--primary-cyan) !important;
    color: white !important;
}

/* Optimierung des numerischen Inputs (Andere Menge) */
#portion-input {
    width: 100%;
    max-width: 120px;
    text-align: center;
    font-size: 1.2rem !important;
    font-weight: bold;
    border: 2px solid var(--border-color);
    margin: 5px auto;
    display: block;
    min-height: 44px; /* iOS Konformität */
    -webkit-touch-callout: none; 
    -webkit-user-select: all; /* Erlaubt die Selektion, aber unterdrückt das Menü */
}

/* Fokus-Zustand für den Input */
#portion-input:focus {
    border-color: var(--primary-blue);
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

/* =========================================================
    Environment Warning Banner (Automated)
   ========================================================= */

/* Das Banner selbst */
.env-warning-banner {
    display: none; /* Initial versteckt, wird via .is-test-env aktiviert */
    background: repeating-linear-gradient(
        45deg,
        #ffd700,
        #ffd700 10px,
        #000000 10px,
        #000000 20px
    );
    color: #fff;
    text-align: center;
    font-weight: 900;
    font-size: 14px;
    padding: 8px 0;
    position: fixed; /* Fixed sorgt dafür, dass es über dem Body-Margin schwebt */
    top: 0;
    left: 0;
    width: 100%;
    z-index: 9999;
    text-shadow: 1px 1px 2px #000;
    border-bottom: 2px solid #000;
    letter-spacing: 1px;
    pointer-events: none; /* Klicks gehen durch das Banner durch */
}

/* Aktivierungs-Logik: Wenn JS die Klasse am HTML-Tag setzt */
.is-test-env .env-warning-banner {
    display: block;
}

/* Versatz für den Body, damit das Banner nichts verdeckt */
.is-test-env body {
    margin-top: 55px; /* Platz für das Banner schaffen */
}

/* Korrektur für den Sticky-Table-Header, wenn Banner aktiv ist */
.is-test-env #item-table thead th {
    top: -21px; /* Verschiebt den Sticky-Header wie oihne test-env */
}

footer {
    font-size: 0.75rem; /* Etwas kleiner für PWA-Look */
    line-height: 1.5;
}

.version-line b {
    color: var(--primary-blue);
}

/* Fix: Banner-Padding für Mehrzeiligkeit auf extrem kleinen Geräten */
@media (max-width: 320px) {
    .env-warning-banner {
        font-size: 12px;
        padding: 4px 2px;
    }
    .is-test-env body {
        margin-top: 65px; /* Etwas mehr Platz für zweizeiliges Banner */
    }
}

/* Standardmäßig sind die Details versteckt */
.test-details-wrapper {
    display: none;
    background-color: #fff9c4; /* Sanftes Gelb zur Abhebung */
    padding: 10px;
    margin: 10px 0;
    border: 1px dashed #fbc02d;
    border-radius: 8px;
    font-family: monospace; /* Debug-Look */
    font-size: 0.8rem;
}

/* AUTOMATIK: Nur einblenden, wenn wir in einer Testumgebung sind */
.is-test-env .test-details-wrapper {
    display: block;
}
