:root {
    --akzent: #2c3e50;
    --sidebar-bg: var(--akzent);
    --sidebar-fg: #fff;
    --sidebar-border: rgba(255,255,255,0.15);
    --sidebar-hover: rgba(255,255,255,0.1);
    --bg: #f4f6f8;
    --border: #dde3e8;
}
* { box-sizing: border-box; }
body {
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    margin: 0;
    color: #222;
}
a { color: var(--akzent); }
.layout { display: flex; min-height: 100vh; }

/* --- Sidebar / Navigation --- */
.sidebar {
    width: 220px;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    padding: 20px 0;
    flex-shrink: 0;
}
.sidebar h1 { font-size: 16px; padding: 0 20px 20px; margin: 0; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-logo { padding: 0 20px 20px; margin: 0 0 10px; border-bottom: 1px solid var(--sidebar-border); }
.sidebar-logo img { max-height: 40px; max-width: 100%; }
.sidebar a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sidebar-fg);
    text-decoration: none;
    padding: 12px 20px;
    opacity: 0.85;
    font-size: 14px;
}
.sidebar a:hover, .sidebar a.active { opacity: 1; background: var(--sidebar-hover); }
.nav-icon { width: 19px; height: 19px; flex-shrink: 0; }

/* Hamburger-Button: nur auf schmalen Bildschirmen sichtbar (siehe Media Query) */
.menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    border: none;
    border-radius: 6px;
    width: 42px;
    height: 42px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.menu-toggle svg { width: 22px; height: 22px; }
.sidebar-overlay { display: none; }

.content { flex: 1; padding: 30px; min-width: 0; }
/* Seiten mit Listen-Tabellen nutzen die volle Bildschirmbreite (kein horizontales Scrollen noetig);
   reine Formular-/Detailseiten bleiben aus Lesbarkeitsgruenden begrenzt. */
.content:not(:has(table.list)) { max-width: 1100px; }
.card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 20px; overflow-x: auto; }
h2 { margin-top: 0; }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
table.list th { background: #f9fafb; font-weight: 600; }
/* Sortierbare Spaltenkoepfe (siehe assets/js/list-tools.js) - Pfeil zeigt die aktive Sortierung,
   sonst dezenter Doppelpfeil als Hinweis, dass geklickt werden kann. */
table.list th.sortable-th { cursor: pointer; user-select: none; position: relative; padding-right: 20px; }
table.list th.sortable-th:hover { background: #f0f2f5; }
table.list th.sortable-th::after { content: '⇅'; position: absolute; right: 6px; opacity: 0.35; font-size: 11px; }
table.list th.sortable-th.sorted-asc::after { content: '▲'; opacity: 0.8; }
table.list th.sortable-th.sorted-desc::after { content: '▼'; opacity: 0.8; }
.list-filter { margin-bottom: 16px; }
.list-filter input[type=text] {
    width: 300px; display: inline-block; padding: 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 16px;
}

.btn {
    display: inline-block;
    background: var(--akzent);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 5px;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    min-height: 40px;
    line-height: 20px;
}
.btn.secondary { background: #7f8c9a; }
.btn.danger { background: #c0392b; }
.btn.small { padding: 6px 12px; font-size: 12px; min-height: 32px; }

form .field { margin-bottom: 14px; }
form label { display: block; font-weight: 600; margin-bottom: 4px; font-size: 13px; }
form input[type=text], form input[type=email], form input[type=password],
form input[type=date], form input[type=number], form select, form textarea {
    width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 5px; font-size: 16px;
}
form input[type=color] { width: 60px; height: 40px; padding: 2px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.aktiv, .badge.bezahlt, .badge.erledigt, .badge.abgerechnet { background: #e3f7e8; color: #1e7e34; }
.badge.offen, .badge.pausiert, .badge.in_bearbeitung, .badge.teilweise_abgerechnet, .badge.versendet { background: #fff3cd; color: #856404; }
.badge.gesperrt, .badge.ueberfaellig, .badge.storniert, .badge.widerrufen { background: #fde2e1; color: #c0392b; }
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.flash.success { background: #e3f7e8; color: #1e7e34; }
.flash.error { background: #fde2e1; color: #c0392b; }
.login-box { max-width: 340px; margin: 100px auto; padding: 16px; }
/* Login-/Passwort-Setzen-Seiten: <body class="auth-page"> zentriert die Box echt vertikal
   und sorgt dafuer, dass ein per Einstellungen gesetzter Verlauf/Bild die volle Bildschirm-
   hoehe abdeckt (statt nur die von margin:100px erzeugte Restlaenge des Inhalts). Bewusst
   ueber eine eigene Klasse statt am globalen body, damit die eingeloggte Ansicht (die schon
   ihr eigenes .layout-Hoehenlayout hat) unveraendert bleibt. */
body.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
body.auth-page .login-box { margin: 0; }

/* Glasoptik (Glassmorphism): nur wenn tatsaechlich ein Hintergrundbild/-verlauf eingestellt ist
   (Klasse "has-bg", siehe login.php) - auf dem normalen flachen Grau waere heller Text/eine
   halbtransparente Flaeche kaum lesbar, das lohnt sich nur vor einem Foto/kraeftigen Verlauf. */
body.auth-page.has-bg .login-box {
    background: rgba(255,255,255,0.14);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
    border: 1px solid rgba(255,255,255,0.35);
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    color: #fff;
}
body.auth-page.has-bg .login-box h2 { color: #fff; }
body.auth-page.has-bg .login-box a { color: #fff; }
body.auth-page.has-bg .login-box form label { color: rgba(255,255,255,0.9); }
body.auth-page.has-bg .login-box form input[type=text],
body.auth-page.has-bg .login-box form input[type=email],
body.auth-page.has-bg .login-box form input[type=password],
body.auth-page.has-bg .login-box select {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.35);
    color: #fff;
}
/* Die aufgeklappte Options-Liste ist ein natives Browser-Popup mit undurchsichtigem Hintergrund
   (kein backdrop-filter moeglich) - erbt sonst die weisse Schriftfarbe des Glas-Selects und waere
   dann weiss auf weiss. Deshalb fuer die Optionen eigene, immer lesbare Farben erzwingen. */
body.auth-page.has-bg .login-box select option {
    background: #fff;
    color: #1a1a1a;
}
body.auth-page.has-bg .login-box form input::placeholder { color: rgba(255,255,255,0.65); }
body.auth-page.has-bg .login-box form input[type=text]:focus,
body.auth-page.has-bg .login-box form input[type=email]:focus,
body.auth-page.has-bg .login-box form input[type=password]:focus {
    background: rgba(255,255,255,0.22);
    outline: none;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.preview-frame { width: 100%; height: 700px; border: 1px solid var(--border); border-radius: 6px; }
.top-actions { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.form-inline-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-inline-row .field { flex: 1; min-width: 220px; margin-bottom: 0; }

/* --- Tabs (z.B. Einstellungen) --- */
.tabs-nav { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); flex-wrap: wrap; }
.tabs-nav button {
    background: none; border: none; padding: 10px 18px; font-size: 14px; cursor: pointer;
    color: #666; border-bottom: 3px solid transparent; margin-bottom: -2px;
}
.tabs-nav button.active { color: var(--akzent); border-bottom-color: var(--akzent); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* --- Durchsuchbare Dropdowns (Kunde/Artikel) --- */
.searchable-select { display: flex; flex-direction: column; gap: 3px; }
.searchable-select-input {
    padding: 4px 8px; font-size: 12px; border: 1px solid var(--border); border-radius: 4px;
    background: #fbfbfb;
}
.searchable-select-input:focus { outline: none; border-color: var(--akzent); background: #fff; }

/* --- Positionszeilen (Artikel-/Leistungseingabe) als übersichtliche Karten statt enger Tabelle --- */
.positionen-liste { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.position-zeile {
    border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; background: #fafbfc;
}
.position-zeile-oben { display: flex; gap: 14px; margin-bottom: 12px; flex-wrap: wrap; }
.position-zeile-oben .such-feld { flex: 0 0 260px; min-width: 200px; }
.position-zeile-oben .bezeichnung-feld { flex: 1; min-width: 220px; }
.position-zeile-oben .beschreibung-feld { flex-basis: 100%; }
.position-zeile-oben .beschreibung-feld textarea { width: 100%; box-sizing: border-box; font: inherit; resize: vertical; }
.position-zeile-unten { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.position-feld { display: flex; flex-direction: column; gap: 3px; }
.position-feld label, .such-feld label, .bezeichnung-feld label, .beschreibung-feld label {
    font-size: 11px; color: #777; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
}
.position-feld input { width: 110px; }
.position-feld.schmal input { width: 78px; }
.position-zeilensumme {
    margin-left: auto; text-align: right; font-size: 13px; color: #444; padding-bottom: 8px; white-space: nowrap;
}
.position-zeilensumme .zeilensumme-wert { font-weight: 700; color: #222; }
.position-entfernen-btn {
    background: none; border: 1px solid var(--border); color: #999; border-radius: 6px;
    width: 34px; height: 34px; font-size: 15px; cursor: pointer; line-height: 1;
}
.position-entfernen-btn:hover { background: #fde2e1; color: #c0392b; border-color: #f3b8b5; }

@media (max-width: 700px) {
    .position-zeile-oben { flex-direction: column; }
    .position-zeile-oben .such-feld { flex: none; }
    .position-feld input { width: 100%; }
    .position-zeilensumme { margin-left: 0; width: 100%; }
}

/* --- Einstellungen: Sekundärnavigation (eigenes Menü pro Belegart) --- */
.settings-layout { display: flex; gap: 24px; align-items: flex-start; }
.settings-subnav { width: 190px; flex-shrink: 0; }
.settings-subnav a {
    display: block; padding: 10px 14px; border-radius: 6px; color: #333;
    text-decoration: none; font-size: 14px; margin-bottom: 2px;
}
.settings-subnav a:hover { background: #f4f6f8; }
.settings-subnav a.active { background: var(--akzent); color: #fff; font-weight: 600; }
.settings-content { flex: 1; min-width: 0; }
@media (max-width: 768px) {
    .settings-layout { flex-direction: column; }
    .settings-subnav { width: 100%; display: flex; flex-wrap: wrap; gap: 6px; }
    .settings-subnav a { flex: 0 0 auto; margin-bottom: 0; }
}

/* ==================================================================
   MOBILE (<= 768px): Sidebar wird zum ausklappbaren Overlay-Menü
   ================================================================== */
@media (max-width: 768px) {
    .layout { display: block; }

    .menu-toggle { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 260px;
        max-width: 80vw;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1000;
        overflow-y: auto;
        padding-top: 70px;
    }
    .sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
    }
    .sidebar-overlay.open { display: block; }

    .content { padding: 70px 16px 24px; max-width: 100%; }

    .grid-2 { grid-template-columns: 1fr; }

    .login-box { margin: 40px auto; max-width: 100%; }

    table.list th, table.list td { font-size: 13px; padding: 8px 6px; }

    .btn { width: 100%; text-align: center; margin-bottom: 6px; }
    .btn.small { width: auto; }
    form { max-width: 100%; }
}

/* Kleine Handys: Sidebar etwas schmaler, Card-Innenabstand reduzieren */
@media (max-width: 400px) {
    .content { padding: 65px 10px 20px; }
    .card { padding: 14px; }
}

.confirm-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.confirm-modal-overlay.open { display: flex; }
.confirm-modal {
    background: #fff;
    border-radius: 8px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.confirm-modal-message { margin: 0 0 20px; font-size: 15px; line-height: 1.4; white-space: pre-line; }
.confirm-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* --- Passwortstärke-Anzeige (assets/js/passwort-staerke.js) --- */
.passwort-staerke { margin: 6px 0 14px; }
.passwort-staerke-balken { height: 5px; background: #eef1f4; border-radius: 3px; overflow: hidden; margin-bottom: 4px; }
.passwort-staerke-fuellung { height: 100%; width: 0; border-radius: 3px; transition: width 0.2s, background 0.2s; }
.passwort-staerke-text { font-size: 12px; font-weight: 600; }
.passwort-match-hinweis { font-size: 12px; margin: -8px 0 14px; min-height: 16px; }

/* Passkeys */
.passkey-hinweis { font-size: 12px; color: #6b7785; margin: 8px 0 0; text-align: center; }
.passkey-umschalter { text-align: center; margin: 14px 0 0; font-size: 13px; }
#passkeyBlock { margin-bottom: 14px; }
.passkey-banner { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; border-left: 4px solid var(--akzent); }
.passkey-banner > div { flex: 1; min-width: 220px; }
.passkey-banner p { margin: 4px 0 0; font-size: 14px; }
body.auth-page.has-bg .login-box .field label, body.auth-page.has-bg .login-box .passkey-hinweis { color: rgba(255,255,255,0.9); }

/* Mehrfachauswahl in Listen */
.bulk-bar { margin: 0 0 12px; }
table.list th.bulk-col, table.list td.bulk-col { width: 1%; padding-right: 0; }
table.list .bulk-col input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
