/* Automat Lagerverwaltung - Elektro Jüdith GmbH */
:root {
    --primary: #1a4fa0;
    --primary-dark: #153d7a;
    --primary-light: #e8eef8;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --orange: #fd7e14;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #adb5bd;
    --gray-700: #495057;
    --gray-900: #212529;
    --white: #fff;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
}

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    color: var(--primary);
    text-align: center;
    margin-bottom: 8px;
    font-size: 1.5rem;
}

.login-box .subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    font-size: 0.9rem;
    color: var(--gray-700);
}

.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,79,160,0.1);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-success {
    background: var(--success);
    color: var(--white);
}
.btn-success:hover { background: #218838; }

.btn-danger {
    background: var(--danger);
    color: var(--white);
}
.btn-danger:hover { background: #c82333; }

.btn-outline {
    background: transparent;
    border: 1px solid var(--gray-300);
    color: var(--gray-700);
}
.btn-outline:hover { background: var(--gray-200); }

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-block {
    width: 100%;
}

.error-msg {
    background: #f8d7da;
    color: #721c24;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.9rem;
    display: none;
}

.success-msg {
    background: #d4edda;
    color: #155724;
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* ── App Layout ─────────────────────────────────────────────────────────── */
.app-container { display: none; }
.app-container.active { display: block; }

.app-header {
    background: var(--primary);
    color: var(--white);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
}

.app-header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
}

.app-header .user-info .username {
    opacity: 0.9;
}

.app-header .btn-logout {
    background: rgba(255,255,255,0.2);
    color: var(--white);
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}
.app-header .btn-logout:hover { background: rgba(255,255,255,0.3); }

/* ── Tab Navigation ─────────────────────────────────────────────────────── */
.tab-nav {
    background: var(--white);
    display: flex;
    overflow-x: auto;
    border-bottom: 2px solid var(--gray-200);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    -webkit-overflow-scrolling: touch;
}

.tab-nav button {
    flex: 0 0 auto;
    padding: 12px 18px;
    border: none;
    background: none;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab-nav button:hover {
    color: var(--primary);
    background: var(--primary-light);
}

.tab-nav button.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

.tab-content {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Dashboard Cards ────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.dash-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.dash-card .label {
    font-size: 0.85rem;
    color: var(--gray-500);
    margin-bottom: 4px;
}

.dash-card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--gray-900);
}

.dash-card .value.positive { color: var(--success); }
.dash-card .value.warning { color: var(--orange); }
.dash-card .value.danger { color: var(--danger); }

.dash-card.highlight {
    border-left: 4px solid var(--primary);
}

/* ── Automat Grid ───────────────────────────────────────────────────────── */
.automat-visual {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.automat-visual h2 {
    margin-bottom: 16px;
    color: var(--primary);
    font-size: 1.2rem;
}

.automat-grid {
    display: grid;
    gap: 8px;
}

.automat-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.automat-row .row-label {
    width: 30px;
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
    text-align: center;
    flex-shrink: 0;
}

.fach-cell {
    flex: 1;
    min-width: 80px;
    max-width: 140px;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid var(--gray-300);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 6px;
    text-align: center;
    font-size: 0.75rem;
    position: relative;
}

.fach-cell:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.fach-cell .fach-nummer {
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--gray-700);
}

.fach-cell .fach-produkt {
    font-size: 0.7rem;
    color: var(--gray-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.fach-cell .fach-bestand {
    font-weight: 600;
    font-size: 0.8rem;
}

.fach-cell.leer {
    background: var(--gray-200);
    border-color: var(--gray-300);
}

.fach-cell.voll {
    background: #d4edda;
    border-color: var(--success);
}

.fach-cell.mittel {
    background: #fff3cd;
    border-color: var(--warning);
}

.fach-cell.niedrig {
    background: #f8d7da;
    border-color: var(--danger);
}

.fach-cell.inaktiv {
    background: var(--gray-200);
    border-color: var(--gray-300);
    opacity: 0.5;
}

.fach-cell .mhd-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.mhd-badge.rot { background: var(--danger); }
.mhd-badge.orange { background: var(--orange); }
.mhd-badge.gelb { background: var(--warning); }

/* ── Tables ─────────────────────────────────────────────────────────────── */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}

.card h2, .card h3 {
    color: var(--primary);
    margin-bottom: 16px;
    font-size: 1.1rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 10px;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    white-space: nowrap;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

tr:hover td { background: var(--gray-100); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-rot { background: #f8d7da; color: #721c24; }
.badge-orange { background: #ffe5cc; color: #a14e00; }
.badge-gelb { background: #fff3cd; color: #856404; }
.badge-gruen { background: #d4edda; color: #155724; }
.badge-grau { background: var(--gray-200); color: var(--gray-700); }

/* ── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 500px;
    padding: 24px;
    position: relative;
}

.modal h2 {
    color: var(--primary);
    margin-bottom: 16px;
    font-size: 1.2rem;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
}
.modal-close:hover { color: var(--gray-900); }

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ── Verkauf Erfassen ───────────────────────────────────────────────────── */
.verkauf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.verkauf-card {
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.verkauf-card .fach-header .nummer {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
}

.verkauf-card .produkt-name {
    font-size: 0.9rem;
    color: var(--gray-700);
}

.verkauf-card .soll-info {
    font-size: 0.85rem;
    color: var(--gray-500);
}

.verkauf-card .ist-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.verkauf-card .ist-input input {
    width: 80px;
    padding: 8px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 1rem;
    text-align: center;
}

.verkauf-card .differenz {
    font-weight: 600;
    font-size: 0.9rem;
}

.verkauf-card .differenz.hat-verkauf {
    color: var(--danger);
}

/* ── Nachfuellliste ─────────────────────────────────────────────────────── */
.nachfuell-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.nachfuell-item:last-child { border-bottom: none; }

.nachfuell-item .info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nachfuell-item .fach-nr {
    font-weight: 700;
    color: var(--primary);
}

.nachfuell-item .menge {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--danger);
    white-space: nowrap;
}

/* ── Print ──────────────────────────────────────────────────────────────── */
@media print {
    .app-header, .tab-nav, .btn, .no-print { display: none !important; }
    .tab-content { padding: 0; }
    .tab-pane { display: block !important; }
    .card { box-shadow: none; border: 1px solid #ccc; }
    body { background: white; }
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 8px;
        padding: 10px 16px;
    }

    .tab-nav button {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .tab-content {
        padding: 12px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dash-card .value {
        font-size: 1.4rem;
    }

    .fach-cell {
        min-width: 60px;
        font-size: 0.65rem;
    }

    .automat-row .row-label {
        width: 24px;
        font-size: 0.9rem;
    }

    .modal {
        padding: 16px;
        margin: 10px;
    }

    .verkauf-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .login-box {
        padding: 24px;
    }

    table { font-size: 0.8rem; }
    th, td { padding: 8px; }
}

/* ── Utility ────────────────────────────────────────────────────────────── */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-500); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.inline-flex { display: inline-flex; align-items: center; }

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── EAN Scanner ────────────────────────────────────────────────────────── */
#ean-reader {
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    min-height: 200px;
}

#ean-reader video {
    border-radius: 8px;
}

#ean-reader img {
    display: none;
}

#ean-scanner-container {
    position: relative;
    margin-bottom: 12px;
}

#ean-scanner-status {
    font-size: 0.9rem;
    padding: 8px;
}

/* Scanner button icon alignment */
.btn .scan-icon {
    font-size: 1.1em;
    line-height: 1;
}

/* Make scanner modal wider on desktop */
@media (min-width: 768px) {
    #modal-ean-scanner .modal {
        max-width: 600px;
    }
}

/* EAN result product info */
#ean-result-content table {
    margin-top: 8px;
}

#ean-result-content img {
    display: block;
}

/* Highlight animation for verkauf fach */
.verkauf-card[style*="outline"] {
    transition: outline 0.3s ease;
}

/* ── Phase 2: Etiketten Grid ───────────────────────────────────────────── */
.etiketten-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    padding: 8px 0;
}

.etikett-card {
    border: 1px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    background: var(--white);
}

.etikett-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.etikett-qr img {
    display: block;
    margin: 0 auto 8px;
}

.etikett-nummer {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
}

.etikett-produkt {
    font-size: 0.8rem;
    color: var(--gray-500);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Phase 2: Inventur Grid ────────────────────────────────────────────── */
.inventur-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    margin-top: 16px;
}
