:root {
  --primary: #4285f4;
  --primary-dark: #3367d6;
  --bg: #f0f2f5;
  --card: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --success: #16a34a;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: #cbd5e1;
  --header-bg: #1e293b;
  --header-text: #ffffff;
}

/* --- GRUNDLAGEN & RESET --- */
html {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    height: -webkit-fill-available;
}

*, *::before, *::after {
    box-sizing: border-box; /* WICHTIG: Padding vergrößert Elemente nicht mehr */
}

body { 
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  margin: 0; 
  padding: 0;
  
  /* STICKY FOOTER SETUP */
  display: flex; 
  flex-direction: column;
  width: 100%;
  overflow-x: hidden;
  min-height: -webkit-fill-available;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- HEADER & NAV --- */
.app-header {
    background-color: var(--header-bg); 
    color: var(--header-text);
    padding: 0.8rem 1.5rem; 
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1); 
    width: 100%; 
    flex-wrap: wrap; 
    gap: 1rem; 
    position: sticky; 
    top: 0; 
    z-index: 1000;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 1.2rem; font-weight: 600; color: #fff; }

.main-nav { display: flex; gap: 5px; }
.nav-btn {
    background: transparent; border: none; color: #94a3b8; padding: 8px 16px;
    border-radius: 6px; cursor: pointer; font-size: 0.95rem; font-weight: 500;
    transition: all 0.2s; display: flex; align-items: center; gap: 8px;
}
.nav-btn:hover { background-color: rgba(255,255,255,0.1); color: #fff; }
.nav-btn.active { background-color: var(--primary); color: #fff; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }

/* --- CONTENT WRAPPER (STICKY FOOTER LOGIC) --- */
.app-content {
    flex: 1; /* Nimm den verfügbaren Platz ein -> Drückt Footer nach unten */
    width: 100%; 
    max-width: 900px; 
    margin: 0 auto; 
    padding: 20px;
    display: flex; 
    flex-direction: column;
}

.view-section { display: none; animation: fadeIn 0.3s ease-in-out; }
.view-section.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

h2 { 
    border-bottom: 2px solid #e2e8f0; padding-bottom: 10px; margin-bottom: 20px; 
    color: var(--text); font-size: 1.5rem;
}

/* --- FORM GRID & INPUTS --- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
.full-width { grid-column: span 2; }
.form-group { margin-bottom: 15px; display: flex; flex-direction: column; gap: 6px; }

label { display: block; font-weight: 600; font-size: 0.9rem; color: #475569; }

select, input[type="text"], input[type="number"], textarea {
  width: 100%; padding: 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 16px; background: #fff;
  transition: border-color 0.2s; outline: none; font-family: inherit;
}
select:focus, input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1); }

/* --- CHECKBOX GROUP --- */
.checkbox-group { display: flex; gap: 10px; flex-wrap: wrap; }
.checkbox-btn { flex: 1; min-width: 45%; position: relative; }
.checkbox-btn input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; }
.checkbox-btn label {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px; background: #fff; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; font-weight: 600; color: var(--text-muted); transition: all 0.2s;
  user-select: none; width: 100%; height: 100%; /* Fix für Flex-Height */
}
.checkbox-btn input:checked + label {
  background: #eff6ff; color: var(--primary); border-color: var(--primary);
  box-shadow: 0 2px 4px rgba(66, 133, 244, 0.15);
}

/* --- ACCORDION --- */
details { background: #fff; border-radius: 8px; margin-bottom: 15px; border: 1px solid var(--border); overflow: hidden; }
summary {
  padding: 12px 15px; font-weight: 600; cursor: pointer; color: var(--text); background: #f8fafc;
  list-style: none; display: flex; align-items: center; justify-content: space-between;
  user-select: none; transition: background 0.2s;
}
summary:hover { background: #f1f5f9; }
summary::after { content: '+'; font-size: 1.2em; font-weight: bold; color: var(--text-muted); }
details[open] summary::after { content: '-'; }
details[open] summary { border-bottom: 1px solid var(--border); }
.details-content { padding: 20px; background: #fff; }

/* --- BUTTONS --- */
.primary-btn {
    width: 100%; margin-top: 20px; padding: 14px; background-color: var(--primary);
    color: white; border: none; border-radius: 8px; font-size: 1.1rem;
    font-weight: bold; cursor: pointer; transition: background 0.2s, transform 0.1s;
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.primary-btn:hover { background-color: var(--primary-dark); }
.primary-btn:active { transform: scale(0.98); }
.primary-btn:disabled { background-color: #94a3b8; cursor: not-allowed; }

/* --- KPI CARDS --- */
.kpi-grid { display: flex; gap: 15px; margin-bottom: 25px; }
.kpi-card { 
    flex: 1; background: #fff; padding: 15px; border-radius: 12px; 
    text-align: center; border: 1px solid var(--border); 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.kpi-val { font-size: 1.8rem; font-weight: 800; color: var(--text); display: block; line-height: 1.2; }
.kpi-label { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }

/* --- HISTORY & LISTS --- */
.toolbar {
    display: flex; align-items: center; justify-content: flex-end; 
    gap: 10px; margin-bottom: 15px;
}

.filter-select {
    height: 40px; padding: 0 35px 0 15px; border-radius: 20px; 
    border: 1px solid var(--border); background: #fff;
    font-size: 0.9rem; font-weight: 600; color: var(--text); outline: none; cursor: pointer;
    background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%2364748b%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
    background-repeat: no-repeat; background-position: right 12px top 50%; background-size: 10px auto;
    -webkit-appearance: none; appearance: none;
}
.filter-select:hover { border-color: var(--primary); }

.refresh-btn {
    height: 40px; width: 40px; border-radius: 50%; border: 1px solid var(--border);
    background: #fff; color: var(--text-muted); flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.2s; font-size: 1rem;
}
.refresh-btn:hover { background: #f1f5f9; color: var(--primary); border-color: var(--primary); transform: rotate(45deg); }

.list-container { display: flex; flex-direction: column; gap: 12px; }

.history-item { 
    background: white; padding: 15px; border-radius: 12px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); border: 1px solid #e2e8f0;
    display: block; /* Für sauberes Layout der inneren Blöcke */
    transition: transform 0.1s;
}
.history-item:hover { transform: translateY(-2px); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); }

.history-info { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.history-info strong { font-size: 1.05rem; color: var(--text); }
.history-meta { font-size: 0.85rem; color: var(--text-muted); }

.badge {
    background: #e2e8f0; color: #475569; padding: 3px 8px;
    border-radius: 6px; font-size: 0.75rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: 0.5px;
}

/* --- ACTION BUTTONS & FOOTER --- */
.history-footer {
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    margin-top: 15px; 
    padding-top: 10px; 
    border-top: 1px solid #f1f5f9;
}

.action-group { display: flex; gap: 5px; }

.action-btn { 
    background: #f1f5f9; color: var(--text); border: 1px solid #e2e8f0;
    width: 40px; height: 40px; border-radius: 8px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
    transition: all 0.2s; text-decoration: none;
    /* Reset Link Styles */
    text-decoration: none;
}
.action-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-del:hover { background: var(--danger); color: #fff !important; border-color: var(--danger); }

/* Spezialanpassung für Gallery Button */
.gallery-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px; 
    border-radius: 8px; border: none; font-weight: bold;
    cursor: pointer; transition: all 0.2s; color: white;
    font-size: 0.9rem; line-height: 1;
}
.gallery-btn.has-images { background-color: #0ea5e9; }
.gallery-btn.has-images:hover { background-color: #0284c7; }
.gallery-btn.no-images { background-color: #f1f5f9; color: #94a3b8; cursor: default; }

/* Die ausklappbare Galerie */
.scan-gallery {
    display: none; background: #f8fafc; padding: 10px; margin-top: 10px;
    border-radius: 8px; border: 1px solid #e2e8f0;
}
.scan-gallery.open { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 10px; }

.scan-thumb {
    width: 100%; aspect-ratio: 1; object-fit: cover;
    border-radius: 6px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    cursor: zoom-in; transition: transform 0.2s;
}
.scan-thumb:hover { transform: scale(1.05); border-color: var(--primary); }


/* --- SCANNER --- */
.scanner-box { 
    background: #fff; padding: 40px 20px; border-radius: 12px; text-align: center; 
    border: 2px dashed #cbd5e1; margin-bottom: 20px; 
    transition: border-color 0.2s;
}
.scanner-box:hover { border-color: var(--primary); }
.camera-btn { 
    display: inline-block; background: var(--primary); color: white; 
    padding: 12px 24px; border-radius: 50px; cursor: pointer; 
    font-weight: bold; font-size: 1.1rem; box-shadow: 0 4px 6px rgba(66, 133, 244, 0.3);
}
.hint { color: var(--text-muted); font-size: 0.95rem; margin-top: 15px; }

#scan-preview-img { max-width: 100%; max-height: 500px; border-radius: 8px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); display: block; margin: 0 auto 15px; }
.result-box { margin-top: 20px; display: none; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }

/* --- MESSAGES & SPINNER --- */
.success-box { background: #dcfce7; color: #166534; padding: 15px; border-radius: 8px; text-align: center; font-weight: bold; margin-bottom: 15px; border: 1px solid #bbf7d0; }
.summary-box { font-size: 0.95rem; color: var(--text); background: #f8fafc; padding: 15px; border-radius: 8px; border: 1px solid #e2e8f0; margin-bottom: 15px; line-height: 1.6; }
.pdf-link { display: block; text-decoration: none; background: #fff; border: 2px solid var(--primary); padding: 12px; border-radius: 8px; color: var(--primary); font-weight: bold; text-align: center; transition: all 0.2s; }
.pdf-link:hover { background: var(--primary); color: white; }

.spinner { 
    border: 4px solid #f3f3f3; border-top: 4px solid var(--primary); border-radius: 50%; 
    width: 40px; height: 40px; animation: spin 1s linear infinite; margin: 30px auto; 
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* --- FOOTER --- */
.app-footer { 
    background-color: #f8fafc; 
    color: var(--text-muted); 
    text-align: center; 
    padding: 20px; 
    font-size: 0.85rem; 
    border-top: 1px solid var(--border); 
    width: 100%; 
    margin-top: auto; /* Zwingt den Footer nach unten im Flex-Container */
}

/* --- QR Reader --- */
#html5-qrcode-select-camera {
    display: none !important;
}

#reader {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: none !important; /* Entfernt Standard-Rahmen der Lib */
}
#reader video { object-fit: cover; border-radius: 8px; }

#reader__dashboard_section_csr span, 
#reader__dashboard_section_swaplink {
    display: none !important;
}

/* --- SCAN RESULT TABLE --- */
.scan-table {
    width: 100%; border-collapse: collapse; font-size: 0.95rem;
    background: white; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden;
}
.scan-table th { background: #f1f5f9; text-align: left; padding: 10px; font-size: 0.85rem; color: #64748b; }
.scan-table td { padding: 10px; border-bottom: 1px solid #f1f5f9; }
.scan-table tr:last-child td { border-bottom: none; }

.status-err { background-color: #fef2f2; }
.status-ok { background-color: #f0fdf4; }

/* --- MOBILE & RESPONSIVE --- */
@media (max-width: 600px) {
    .app-header { flex-direction: column; align-items: stretch; padding: 10px; gap: 10px; }
    .brand { justify-content: center; }
    .main-nav { justify-content: space-between; background: rgba(255,255,255,0.05); padding: 4px; border-radius: 8px; }
    .nav-btn { flex: 1; justify-content: center; padding: 8px; font-size: 0.85rem; }
    
    .form-grid { grid-template-columns: 1fr; }
    .full-width { grid-column: span 1; }
    
    .toolbar { flex-wrap: wrap; }
    .filter-select { flex-grow: 1; }
    
    .kpi-grid { gap: 10px; }
    .kpi-val { font-size: 1.4rem; }
    
    .history-item { padding: 10px; }
    .history-actions { margin-top: 10px; justify-content: flex-end; }
}

/* --- DIVIDER (ODER) --- */
.divider {
    display: flex; 
    align-items: center; 
    text-align: center;
    margin: 20px 0; 
    color: #94a3b8; 
    font-size: 0.85rem; 
    letter-spacing: 1px;
    text-transform: uppercase;
}

.divider::before, .divider::after {
    content: ''; 
    flex: 1; 
    border-bottom: 1px solid #e2e8f0;
}

.divider span { 
    padding: 0 10px; 
}

/* --- SCANNER PREVIEW & ANALYZE BUTTON FIX --- */

#scan-preview-area {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* Bildbegrenzung, damit es nicht das Layout sprengt */
#scan-preview-img {
    max-width: 100%;
    max-height: 60vh; /* Verhindert, dass riesige Bilder den Button wegschieben */
    object-fit: contain;
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    margin-bottom: 20px;
    background: #fff;
}

/* Der Container für den Button */
#scan-preview-area .actions {
    width: 100%;
}

/* Der Analysieren Button im "Primary" Style */
#btn-analyze {
    display: flex;                /* Flexbox für saubere Zentrierung von Icon + Text */
    align-items: center;
    justify-content: center;
    gap: 10px;                    /* Abstand zwischen Lupe und Text */
    
    width: 100%;                  /* Volle Breite auf dem Handy */
    padding: 16px;                /* Große Touch-Fläche */
    
    background-color: var(--primary);
    color: white;
    
    font-size: 1.1rem;
    font-weight: bold;
    border: none;
    border-radius: 12px;          /* Modernere, rundere Ecken */
    
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(66, 133, 244, 0.2);
    transition: all 0.2s ease;
}

#btn-analyze:active {
    transform: scale(0.98);       /* Klick-Effekt */
    background-color: var(--primary-dark);
}

/* Falls du FontAwesome Icons nutzt, hier sicherstellen, dass sie nicht kleben */
#btn-analyze i {
    font-size: 1.2rem;
}

/* --- ENTWICKLER MODUS --- */
/* Elemente mit dieser Klasse sind standardmäßig unsichtbar */
.dev-only { 
    display: none !important; 
}

/* Wenn der Body die Klasse 'dev-mode' hat, werden sie sichtbar */
body.dev-mode .dev-only { 
    display: inline-flex !important; 
}