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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --secondary: #6b7280;
    --secondary-hover: #4b5563;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --border: #e5e7eb;
    --text: #111827;
    --text-muted: #6b7280;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

/* Navbar */
.navbar {
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    height: 56px;
    box-shadow: 0 2px 4px rgba(0,0,0,.15);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: .3px;
    margin-right: 2rem;
    display: flex;
    align-items: center;
    gap: .6rem;
}
.nav-logo {
    height: 36px;
    width: auto;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.25));
}
.nav-links {
    list-style: none;
    display: flex;
    gap: .25rem;
    flex: 1;
}
.nav-links a {
    color: rgba(255,255,255,.85);
    text-decoration: none;
    padding: .4rem .75rem;
    border-radius: var(--radius);
    transition: background .15s;
    display: flex;
    align-items: center;
    gap: .3rem;
}
.nav-links a:hover, .nav-links a.active {
    background: rgba(255,255,255,.15);
    color: #fff;
}

/* Navbar dropdown */
.nav-links { align-items: stretch; }
.nav-dropdown {
    position: relative;
    display: flex;
    align-items: stretch;
}
.nav-dropdown > a {
    display: flex;
    align-items: center;
}
.nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.15);
    min-width: 180px;
    list-style: none;
    z-index: 300;
    border: 1px solid var(--border);
    padding: .35rem 0;
}
.nav-dropdown:hover .nav-dropdown-menu { display: block; }
.nav-dropdown-menu li a {
    display: block;
    padding: .55rem 1rem;
    color: var(--text);
    font-size: 14px;
    border-radius: 0;
}
.nav-dropdown-menu li a:hover, .nav-dropdown-menu li a.active {
    background: #f0f5ff;
    color: var(--primary);
}
.dropdown-arrow { font-size: 11px; opacity: .8; }

/* Navbar right (username + logout) */
.nav-right {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin-left: auto;
    padding-left: 1rem;
}
.nav-username {
    color: rgba(255,255,255,.85);
    font-size: 13px;
    white-space: nowrap;
}
.nav-links-secondary { margin-left: auto; flex: 0; }

/* Mobile navigation */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #fff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: .25rem .5rem;
    margin-left: auto;
}

@media (max-width: 880px) {
    .navbar {
        flex-wrap: wrap;
        height: auto;
        min-height: 56px;
        padding: .5rem 1rem;
    }
    .nav-brand { margin-right: 0; font-size: 1rem; }
    .nav-logo { height: 30px; }
    .nav-toggle { display: block; }

    .nav-links, .nav-links-secondary {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        flex-basis: 100%;
        margin: .5rem 0 0;
        gap: .1rem;
    }
    .navbar.mobile-open .nav-links,
    .navbar.mobile-open .nav-links-secondary { display: flex; }

    .nav-right {
        display: none;
        width: 100%;
        flex-basis: 100%;
        margin: .5rem 0 0;
        padding-top: .5rem;
        border-top: 1px solid rgba(255,255,255,.25);
        justify-content: space-between;
    }
    .navbar.mobile-open .nav-right { display: flex; }

    .nav-dropdown { flex-direction: column; align-items: stretch; }
    .nav-dropdown > a { padding: .65rem .75rem; }
    .nav-dropdown-menu {
        position: static;
        display: block;
        width: 100%;
        box-shadow: none;
        border: none;
        border-radius: 6px;
        margin: .15rem 0 .35rem;
        z-index: auto;
    }
    .nav-dropdown-menu li a { padding-left: 1.5rem; }
    .nav-links a { padding: .65rem .75rem; }

    .container { padding: 1rem; }
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.page-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

/* Card */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

/* Table toolbar */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .875rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #fafafa;
}
.search-input {
    flex: 1;
    max-width: 320px;
    padding: .4rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
.search-input:focus { border-color: var(--primary); }
.row-count { color: var(--text-muted); font-size: 13px; }

/* Table */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: #f9fafb; }
th {
    padding: .6rem 1rem;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
th:last-child { cursor: default; }
th:hover:not(:last-child) { color: var(--text); }
.sort-icon { opacity: .4; font-size: 11px; }
td {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8faff; }
.notes-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}
.actions { white-space: nowrap; }
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem !important;
    font-size: 15px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    text-decoration: none;
    white-space: nowrap;
}
.btn-sm { padding: .3rem .65rem; font-size: 13px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.actions .btn + .btn { margin-left: .35rem; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}
.modal {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
    width: 100%;
    max-width: 580px;
}
.modal-body {
    max-height: calc(90vh - 120px);
    overflow-y: auto;
}
.modal-sm { max-width: 400px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1.1rem; font-weight: 700; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: .25rem;
    border-radius: 4px;
    line-height: 1;
}
.modal-close:hover { color: var(--text); background: var(--border); }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
}

/* Form */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    padding: 1.25rem 1.5rem .5rem;
}
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group-full { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 500; color: var(--text); }
input, textarea, select {
    padding: .45rem .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    color: var(--text);
    background: #fff;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
textarea { resize: vertical; }

/* Artikel-Suche Dropdown */
.search-dropdown {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 2px 8px rgba(0,0,0,.1);
    max-height: 240px;
    overflow-y: auto;
    width: 100%;
    margin-top: 2px;
}
.search-result-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem .85rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f0f5ff; }
.result-number { font-weight: 600; font-size: 13px; color: var(--primary); min-width: 60px; }
.result-name { flex: 1; }
.result-unit { font-size: 12px; color: var(--text-muted); }
.search-result-empty { padding: .75rem 1rem; color: var(--text-muted); font-size: 13px; }

/* Gewählter Artikel */
.selected-article-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f0f5ff;
    border: 1px solid #c7d9ff;
    border-radius: var(--radius);
    padding: .6rem .85rem;
}
.selected-article-info { display: flex; gap: .5rem; align-items: baseline; }
.sel-number { font-weight: 700; font-size: 13px; color: var(--primary); }
.sel-name { font-size: 14px; }
.sel-unit { font-size: 13px; color: var(--text-muted); }

/* Badges */
.badge {
    display: inline-block;
    padding: .15rem .5rem;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge-green  { background: #dcfce7; color: #15803d; }
.badge-red    { background: #fee2e2; color: #b91c1c; }
.badge-blue   { background: #dbeafe; color: #1d4ed8; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-purple { background: #f3e8ff; color: #7e22ce; }
.badge-gray   { background: #f1f5f9; color: #475569; }

/* Checkbox label */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}
.checkbox-label input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Inventar Warnzeilen */
.row-warning { background: #fff7ed !important; }
.row-warning:hover { background: #ffedd5 !important; }
.diff-missing { color: #c2410c; font-weight: 600; }
.diff-ok      { color: #15803d; }

/* Shopping list */
.table-link { color: var(--primary); text-decoration: none; font-weight: 500; }
.table-link:hover { text-decoration: underline; }
.row-purchased td { opacity: .45; text-decoration: line-through; }
tfoot td { border-top: 2px solid var(--border); background: #f9fafb; }

.stock-warning {
    color: #dc2626;
    font-weight: 700;
    font-size: 15px;
}

.form-error {
    margin: 0 1.5rem .5rem;
    padding: .6rem .85rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: var(--danger);
    font-size: 13px;
}

/* Dropdown divider */
.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: .3rem 0;
}

/* Drop zone (Rechnungsupload) */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: #eff6ff;
}
.drop-zone-text p { margin: 0; }

/* Progress bar */
.progress-bar-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    width: 0;
    background: var(--primary);
    border-radius: 999px;
    transition: width .2s;
}

/* Buchhaltung split layout */
.bh-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    align-items: start;
}
.bh-layout.bh-panel-open {
    grid-template-columns: 1fr 380px;
}
.bh-table-wrap { overflow: hidden; }

.bh-row { cursor: pointer; }
.bh-row:hover { background: #f0f5ff !important; }
.bh-row-active { background: #dbeafe !important; }
.bh-captured td { color: var(--text-muted); }

/* Seitenpanel Buchhaltung */
.bh-panel {
    position: sticky;
    top: 72px;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 88px);
    overflow: hidden;
}
.bh-panel-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.bh-panel-img-wrap {
    padding: 1rem 1.25rem .5rem;
    border-bottom: 1px solid var(--border);
    max-height: 320px;
    overflow-y: auto;
    flex-shrink: 0;
}
.bh-panel-form {
    padding: 1rem 1.25rem 1.25rem;
    overflow-y: auto;
    flex: 1;
}
.bh-panel-form .form-group label { font-size: 12px; }

/* Kasse */
.kassenstand-value {
    font-size: 2.25rem;
    font-weight: 800;
    color: #15803d;
    letter-spacing: -.5px;
}
.kassenstand-neg { color: var(--danger); }
.tx-umsatz:hover { background: #f0fdf4 !important; }
.tx-zahlung:hover { background: #fef2f2 !important; }

/* ── Artikel-Kategorien ───────────────────────────────────────────────────── */
.article-row-1 { background: #eff6ff; }
.article-row-2 { background: #f0fdf4; }
.article-row-4 { background: #faf5ff; }
.article-row-5 { background: #fff7ed; }
.article-row-1:hover { background: #dbeafe !important; }
.article-row-2:hover { background: #dcfce7 !important; }
.article-row-4:hover { background: #ede9fe !important; }
.article-row-5:hover { background: #ffedd5 !important; }

.group-header-row td {
    padding: .4rem 1rem !important;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    border-bottom: none !important;
}
.group-header-1 { background: #dbeafe; color: #1d4ed8; }
.group-header-2 { background: #dcfce7; color: #15803d; }
.group-header-4 { background: #ede9fe; color: #6d28d9; }
.group-header-5 { background: #ffedd5; color: #c2410c; }

.legend-dot {
    display: inline-block;
    width: 10px; height: 10px;
    border-radius: 50%;
    margin-right: .35rem;
    flex-shrink: 0;
}
.legend-dot-1 { background: #2563eb; }
.legend-dot-2 { background: #16a34a; }
.legend-dot-4 { background: #7c3aed; }
.legend-dot-5 { background: #ea580c; }

/* ── Dark Mode ────────────────────────────────────────────────────────────── */
body.dark {
    --bg: #0f172a;
    --card-bg: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.3);
}

/* Hardcoded background overrides */
body.dark thead { background: #162032; }
body.dark .table-toolbar { background: #162032; border-bottom-color: #334155; }
body.dark tfoot td { background: #162032; border-top-color: #334155; }
body.dark tbody tr:hover { background: #1e3350 !important; }

/* Inputs */
body.dark input:not([type="checkbox"]):not([type="radio"]),
body.dark textarea,
body.dark select {
    background: #1e293b;
    color: #f1f5f9;
    border-color: #334155;
}
body.dark input:not([type="checkbox"]):not([type="radio"]):focus,
body.dark textarea:focus,
body.dark select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,.2);
}

/* Nav dropdown */
body.dark .nav-dropdown-menu {
    background: #1e293b;
    border-color: #334155;
}
body.dark .nav-dropdown-menu li a { color: #f1f5f9; }
body.dark .nav-dropdown-menu li a:hover,
body.dark .nav-dropdown-menu li a.active {
    background: #1e3350;
    color: #93c5fd;
}
body.dark .dropdown-divider { background: #334155; }

/* Buttons */
body.dark .btn-secondary { background: #334155; color: #f1f5f9; }
body.dark .btn-secondary:hover { background: #475569; }

/* Badges */
body.dark .badge-gray { background: #334155; color: #cbd5e1; }
body.dark .badge-green { background: #14532d; color: #86efac; }
body.dark .badge-blue { background: #1e3a8a; color: #93c5fd; }
body.dark .badge-orange { background: #7c2d12; color: #fdba74; }
body.dark .badge-red { background: #7f1d1d; color: #fca5a5; }
body.dark .badge-purple { background: #4c1d95; color: #d8b4fe; }

/* Warnings */
body.dark .row-warning { background: #2d1c0a !important; }
body.dark .row-warning:hover { background: #3d2610 !important; }
body.dark .diff-missing { color: #f87171; }

/* Artikel-Suche */
body.dark .selected-article-card { background: #1e3350; border-color: #2563eb; }
body.dark .search-dropdown { background: #1e293b; border-color: #334155; }
body.dark .search-result-item { border-bottom-color: #334155; }
body.dark .search-result-item:hover { background: #1e3350; }

/* Errors / alerts */
body.dark .form-error { background: #2d1515; border-color: #7f1d1d; color: #fca5a5; }

/* Drop zone */
body.dark .drop-zone { border-color: #334155; }
body.dark .drop-zone:hover,
body.dark .drop-zone.drag-over { background: #1e293b; border-color: #3b82f6; }

/* Kasse */
body.dark .tx-umsatz:hover { background: #052e16 !important; }
body.dark .tx-zahlung:hover { background: #2d1515 !important; }
body.dark .kassenstand-value { color: #4ade80; }

/* Buchhaltung */
body.dark .bh-row:hover { background: #1e3350 !important; }
body.dark .bh-row-active { background: #1e3a8a !important; }

/* Artikel-Kategorien dark */
body.dark .article-row-1 { background: #1e2e4a; }
body.dark .article-row-2 { background: #162a1e; }
body.dark .article-row-4 { background: #261a3a; }
body.dark .article-row-5 { background: #2a1e10; }
body.dark .article-row-1:hover { background: #1e3a6a !important; }
body.dark .article-row-2:hover { background: #163a26 !important; }
body.dark .article-row-4:hover { background: #32264a !important; }
body.dark .article-row-5:hover { background: #3a2810 !important; }
body.dark .group-header-1 { background: #1e2e4a; color: #93c5fd; }
body.dark .group-header-2 { background: #162a1e; color: #86efac; }
body.dark .group-header-4 { background: #261a3a; color: #d8b4fe; }
body.dark .group-header-5 { background: #2a1e10; color: #fdba74; }
body.dark .bh-panel { background: #1e293b; border-color: #334155; }

/* Modals (already use var(--card-bg) but overlay needs tweak) */
body.dark .modal-overlay { background: rgba(0,0,0,.6); }

/* Dark mode toggle icon in nav */
#darkModeToggle { font-size: 15px; }
