:root {
    --color-focus: #005fcc;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #f9fafb;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --primary: #111827;
    --primary-contrast: #ffffff;
    --secondary-bg: #ffffff;
    --secondary-text: #111827;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --success-text: #065f46;
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #991b1b;
    --badge-bg: #eef2ff;
    --badge-text: #3730a3;
    --badge-off-bg: #f3f4f6;
    --badge-off-text: #5c636e; /* WCAG AA: 5.51:1 on #f3f4f6 */
    /* ── Semantische Button-Farben (WCAG AA ≥ 4.5:1 verifiziert) ── */
    --btn-primary-bg:   #1d4ed8; --btn-primary-text:   #ffffff; /* 8.0:1 */
    --btn-success-bg:   #16a34a; --btn-success-text:   #ffffff; /* 5.0:1 */
    --btn-danger-bg:    #dc2626; --btn-danger-text:    #ffffff; /* 4.7:1 */
    --btn-warning-bg:   #b45309; --btn-warning-text:   #ffffff; /* 5.4:1 */
    --btn-info-bg:      #0369a1; --btn-info-text:      #ffffff; /* 6.5:1 */
    --btn-neutral-bg:   #374151; --btn-neutral-text:   #ffffff; /* 10.0:1 */
    --btn-light-bg:     #f3f4f6; --btn-light-text:     #111827; /* 15.8:1 */
    --shadow: 0 1px 2px rgba(0, 0, 0, .04);
    --radius: 10px;
    --space-1: 8px;
    --space-2: 12px;
    --space-3: 16px;
    --space-4: 18px;
    --space-5: 24px;
    --space-6: 32px;
    --font-size-base: 14px;
    --button-height-mobile: 48px;
    --button-height-tablet: 42px;
    --button-height-desktop: 38px;
    --container-max: 1280px;
}

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, sans-serif;
    font-size: var(--font-size-base);
    line-height: 1.45;
}

.page {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 16px;
}

@media (min-width: 768px) {
    .page {
        padding: 20px;
    }
}

@media (min-width: 1100px) {
    .page {
        padding: 24px;
    }
}

h1, h2, h3 {
    margin-top: 0;
    line-height: 1.2;
}

p {
    margin-top: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

/* Topbar / Navigation */
.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .06);
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px 12px;
}

@media (min-width: 768px) {
    .topbar { padding-left: 20px; padding-right: 20px; }
}
@media (min-width: 1100px) {
    .topbar { padding-left: 24px; padding-right: 24px; }
}

.topbar-row {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

/* ── Brand-Link (Home) ── */
.topbar-brand {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    font-size: .92rem;
    font-weight: 700;
    color: var(--primary, #2563eb);
    letter-spacing: .01em;
    line-height: 1;
    padding: 4px 2px;
    border-radius: 4px;
    white-space: nowrap;
}
.topbar-brand:hover { color: #1d4ed8; text-decoration: none; }
.topbar-brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--primary, #2563eb);
    color: #fff;
    border-radius: 6px;
    font-size: .75rem;
    font-weight: 800;
    letter-spacing: .02em;
    flex-shrink: 0;
}
.topbar-brand-text {
    font-size: .82rem;
    font-weight: 700;
    color: var(--text, #111827);
}
@media (max-width: 480px) {
    .topbar-brand-text { display: none; }
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1 1 560px;
    min-width: 0;
}

.topbar-search-input {
    min-width: 0;
    flex: 1 1 auto;
}

.topbar-search-button {
    flex: 0 0 auto;
}

.topbar-menu-toggle {
    display: none;
    flex: 0 0 auto;
}

.nav-drawer-header {
    display: none;
}

.topbar-filter-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    padding: .3rem .75rem;
    font-size: .82rem;
}
.topbar-filter-toggle.active {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}
@media (max-width: 899px) {
    .topbar-filter-toggle {
        width: auto !important;
        align-self: flex-start;
        min-height: 36px;
    }
}

.topbar-nav-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 0 1 auto;
    min-width: 0;
}

.topbar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
}

.topbar-submenu-panel { display: none; } /* legacy — replaced by .subnav-bar */

.topbar-submenu-list { display: none; } /* legacy */

.subnav-bar {
    background: #fff;
    border-bottom: 2px solid #e5e7eb;
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.subnav-bar::-webkit-scrollbar { display: none; }

.subnav-bar-inner {
    display: inline-flex;
    flex-direction: row;
    align-items: stretch;
    min-width: 100%;
    padding: 0 16px;
}

@media (min-width: 768px)  { .subnav-bar-inner { padding: 0 20px; } }
@media (min-width: 1100px) { .subnav-bar-inner { padding: 0 24px; } }

.subnav-bar-link {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    font-size: .85rem;
    font-weight: 500;
    color: #6b7280;
    text-decoration: none;
    padding: 0 1.1rem;
    height: 44px;
    line-height: 1;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
}

.subnav-bar-link:hover {
    color: #111827;
    border-bottom-color: #d1d5db;
}

.subnav-bar-link.active {
    color: #2563eb;
    font-weight: 600;
    border-bottom-color: #2563eb;
}

.nav-parent-toggle {
    position: relative;
}

.topbar-nav-group {
    position: relative;
}

.topbar-recent {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.topbar-recent-label {
    font-size: 14px;
    color: var(--muted);
}

.topbar-recent-form {
    display: inline-flex;
    margin: 0;
}

.help-menu {
    position: relative;
    display: inline-block;
}

.help-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 220px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    background: #fff;
    border: 1px solid #d0d7de;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 8px;
    z-index: 1000;
}

.help-menu-dropdown.is-open {
    display: block;
}

.help-menu-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.service-menu-divider {
    display: block;
    font-size: .7rem;
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted, #9ca3af);
    padding: .5rem .5rem .1rem;
    margin-top: .25rem;
    border-top: 1px solid var(--border, #e5e7eb);
}

.service-menu-divider:first-child {
    border-top: none;
    margin-top: 0;
}

.help-menu-list .btn {
    text-align: left;
    justify-content: flex-start;
}

/* ── Mobile Drawer-Backdrop ─────────────────────────────────────────────────── */
.nav-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 499;
    -webkit-tap-highlight-color: transparent;
}
.nav-drawer-backdrop.is-open {
    display: block;
}

/* ── Suchlayout: nur auf schmalen Bildschirmen ── */
@media (max-width: 899px) {
    .topbar-row {
        flex-wrap: wrap;
        align-items: center;
        gap: 6px;
    }

    /* Sucheingabe volle Breite */
    .topbar-search {
        flex: 1 1 100%;
        flex-direction: row;
        align-items: center;
        gap: 6px;
    }

    .topbar-search-input {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
    }

    .topbar-search-button {
        flex: 0 0 auto;
        width: auto;
        white-space: nowrap;
    }
}

/* ── Topbar-Shortcuts (Dashboard, Aufgaben) ── */
.topbar-shortcut {
    flex: 0 0 auto;
    padding: .3rem .65rem;
    font-size: .82rem;
    white-space: nowrap;
    gap: 5px;
}
.topbar-shortcut-active {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}
.topbar-shortcut-divider {
    display: inline-block;
    width: 1px;
    height: 20px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 2px;
}
/* Auf schmalen Screens: Shortcut-Labels ausblenden */
@media (max-width: 680px) {
    .topbar-brand-text   { display: none; }
    .topbar-shortcut-label { display: none; }
    .topbar-search-btn-label { display: none; }
}
/* Sehr klein: Shortcuts ausblenden (sind im Drawer) */
@media (max-width: 480px) {
    .topbar-shortcut        { display: none; }
    .topbar-shortcut-divider { display: none; }
}

/* ── Abschnittsüberschriften in Nav-Dropdown ── */
.nav-section-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--muted, #9ca3af);
    padding: .55rem .75rem .2rem 1.4rem;
    pointer-events: none;
    user-select: none;
}

/* ── Menü-Button: immer sichtbar, immer rechts ── */
.topbar-menu-toggle {
    display: inline-flex;
    flex: 0 0 auto;
    margin-left: auto;
    width: auto;
    min-height: 40px;
    white-space: nowrap;
    padding: .3rem .65rem;
    font-size: .85rem;
    font-weight: 600;
}

/* ── Nav-Drawer: alle Bildschirmgrößen ── */
.topbar-nav-group {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: min(300px, 88vw);
    background: var(--bg, #f6f7f9);
    border-left: 1px solid var(--border);
    box-shadow: -6px 0 32px rgba(0, 0, 0, 0.18);
    z-index: 500;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    transform: translateX(110%);
    transition: transform 0.24s ease;
}

.topbar-nav-group.is-open {
    transform: translateX(0);
}

/* ── Drawer-Header ── */
.nav-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .85rem 1rem .75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface, #f8fafc);
    flex-shrink: 0;
}
.nav-drawer-title {
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
    color: var(--muted, #6b7280);
}
.nav-drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg, #fff);
    font-size: 1.2rem;
    color: var(--muted, #6b7280);
    cursor: pointer;
    line-height: 1;
}
.nav-drawer-close:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }

/* ── Nav-Inhalt im Drawer ── */
.topbar-nav {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    gap: 0;
    padding: .5rem 0;
}

.topbar-nav > a.btn,
.topbar-nav > span.btn {
    min-height: 48px;
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    padding: .75rem 1.1rem;
    font-size: .9rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text, #1f2937);
}
.topbar-nav > a.btn.btn-primary,
.topbar-nav > span.btn.btn-primary {
    color: #1d4ed8;
    font-weight: 700;
    border-left: 3px solid #1d4ed8;
    padding-left: calc(1.1rem - 3px);
}

.topbar-nav .nav-group {
    display: block;
    width: 100%;
}
.topbar-nav .nav-group-toggle.btn {
    min-height: 48px;
    width: 100%;
    text-align: left;
    justify-content: space-between;
    padding: .75rem 1.1rem;
    font-size: .9rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text, #111827);
}
.topbar-nav .nav-group-toggle.btn-primary {
    color: #1d4ed8;
    font-weight: 700;
    background: transparent;
    border-left: 3px solid #1d4ed8;
    padding-left: calc(1.1rem - 3px);
}

/* Dropdown inline expandieren */
.nav-group-dropdown {
    position: static !important;
    display: none;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: .25rem 0 .5rem !important;
    background: var(--surface, #f8fafc) !important;
    border-left: 3px solid var(--primary, #2563eb) !important;
    margin-left: .75rem !important;
}
.nav-group.open .nav-group-dropdown { display: block; }

.nav-group-item {
    min-height: 42px;
    padding: .55rem 1rem .55rem 1.1rem !important;
    font-size: .87rem !important;
}

/* Help-Menü + User-Menü im Drawer */
.help-menu {
    width: 100%;
}
.help-menu > .btn,
.help-menu > button {
    min-height: 48px;
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text, #1f2937);
    padding: .75rem 1.1rem;
    font-size: .9rem;
}
.help-menu-dropdown {
    position: static;
    margin-top: 0;
    min-width: 0;
    width: 100%;
    box-shadow: none;
    border: none;
    border-radius: 0;
    border-left: 3px solid var(--border);
    margin-left: .75rem;
    padding: .25rem 0;
}
.help-menu-list .btn,
.help-menu-list a.btn {
    min-height: 42px;
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    padding: .65rem 1.1rem .65rem 1.4rem;
    font-size: .87rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text, #1f2937);
}

.help-context-btn { display: none; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--space-3);
    box-shadow: var(--shadow);
}

.stack > * + * {
    margin-top: var(--space-4);
}

.muted {
    color: var(--muted);
}

.empty {
    padding: 24px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    background: var(--badge-bg);
    color: var(--badge-text);
}

.badge.off {
    background: var(--badge-off-bg);
    color: var(--badge-off-text);
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.alert-success {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.alert-error {
    background: var(--error-bg);
    border-color: var(--error-border);
    color: var(--error-text);
}

.error-list {
    margin: 8px 0 0 18px;
    padding: 0;
}

.actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: var(--space-4);
}

.btn,
button,
input[type="submit"],
input[type="button"] {
    appearance: none;
    border: 1px solid var(--primary);
    border-radius: 10px;
    min-height: var(--button-height-mobile);
    padding: 0 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--primary);
    color: var(--primary-contrast);
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
    touch-action: manipulation;
}

.btn-secondary {
    background: var(--secondary-bg);
    color: var(--secondary-text);
    border-color: var(--border-strong);
}

/* Semantische Farb-Varianten — Kontrast WCAG AA garantiert */
.btn-primary  { background: var(--btn-primary-bg);  color: var(--btn-primary-text);  border-color: var(--btn-primary-bg);  }
.btn-success  { background: var(--btn-success-bg);  color: var(--btn-success-text);  border-color: var(--btn-success-bg);  }
.btn-danger   { background: var(--btn-danger-bg);   color: var(--btn-danger-text);   border-color: var(--btn-danger-bg);   }
.btn-warning  { background: var(--btn-warning-bg);  color: var(--btn-warning-text);  border-color: var(--btn-warning-bg);  }
.btn-info     { background: var(--btn-info-bg);     color: var(--btn-info-text);     border-color: var(--btn-info-bg);     }
.btn-neutral  { background: var(--btn-neutral-bg);  color: var(--btn-neutral-text);  border-color: var(--btn-neutral-bg);  }
.btn-light    { background: var(--btn-light-bg);    color: var(--btn-light-text);    border-color: var(--border-strong);   }

.btn-primary:hover  { background: #1e40af; border-color: #1e40af; color: #ffffff; }
.btn-success:hover  { background: #15803d; border-color: #15803d; color: #ffffff; }
.btn-danger:hover   { background: #b91c1c; border-color: #b91c1c; color: #ffffff; }
.btn-warning:hover  { background: #92400e; border-color: #92400e; color: #ffffff; }
.btn-info:hover     { background: #075985; border-color: #075985; color: #ffffff; }
.btn-neutral:hover  { background: #1f2937; border-color: #1f2937; color: #ffffff; }
.btn-light:hover    { background: #e5e7eb; border-color: #9ca3af;  color: #111827; }

.btn-small {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

@media (min-width: 768px) {
    .btn,
    button,
    input[type="submit"],
    input[type="button"] {
        min-height: var(--button-height-tablet);
        font-size: 14px;
        padding: 0 14px;
    }
}

@media (min-width: 1100px) {
    .btn,
    button,
    input[type="submit"],
    input[type="button"] {
        min-height: var(--button-height-desktop);
        font-size: 13px;
        padding: 0 12px;
    }
}

.filters {
    margin-bottom: var(--space-4);
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

@media (min-width: 768px) {
    .form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .form-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

.form-group {
    min-width: 0;
}

.form-group.full {
    grid-column: 1 / -1;
}

label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    min-height: 48px;
    padding: 10px 12px;
    font-size: 16px;
}

input[type="checkbox"],
input[type="radio"] {
    width: auto;
    min-height: auto;
    padding: 0;
    border: revert;
    border-radius: revert;
    background: revert;
    font-size: revert;
    color: revert;
    appearance: auto;
    -webkit-appearance: auto;
    vertical-align: middle;
    cursor: pointer;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

@media (min-width: 768px) {
    input,
    select,
    textarea {
        min-height: 42px;
        font-size: 15px;
    }
}

@media (min-width: 1100px) {
    input,
    select,
    textarea {
        min-height: 38px;
        font-size: 14px;
    }
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
    background: var(--surface);
}

th,
td {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

th {
    background: var(--surface-soft);
    font-size: 13px;
}

.table-sort-link {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}

.table-sort-link:hover,
.table-sort-link:focus {
    text-decoration: underline;
}

.mobile-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.desktop-only {
    display: none;
}

@media (min-width: 1100px) {
    .desktop-only {
        display: inline;
    }
}

.list-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mb-16 { margin-bottom: 16px; }
.mb-18 { margin-bottom: 18px; }
.mb-24 { margin-bottom: 24px; }

.text-right { text-align: right; }

.page-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

@media (min-width: 768px) {
    .page-header {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.import-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

@media (min-width: 1100px) {
    .import-layout {
        grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
        align-items: start;
    }
}

.preview-card {
    min-height: 680px;
}

.preview-frame {
    width: 100%;
    height: 72vh;
    min-height: 520px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.hidden-submit {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.file-help {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

.sticky-top {
    position: static;
}

@media (min-width: 1100px) {
    .sticky-top {
        position: sticky;
        top: 16px;
    }
}

.contract-detail-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

.contract-preview-card {
    min-height: 680px;
}

.contract-preview-frame {
    width: 100%;
    height: 78vh;
    min-height: 560px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

@media (min-width: 900px) {
    .contract-detail-layout {
        grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
        align-items: start;
    }

    .contract-preview-sticky {
        position: sticky;
        top: 16px;
    }
}

.searchable-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.searchable-select input[type="search"] {
    width: 100%;
}

.select-help {
    font-size: 12px;
    color: var(--muted);
}

/* Tabellen mobil */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.actions-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.actions-bar .btn,
.actions-bar button {
    max-width: 100%;
}

.filters .form-grid {
    align-items: end;
}

@media (max-width: 899px) {
    .filters .form-grid {
        grid-template-columns: 1fr !important;
    }

    .filters .actions-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filters .actions-bar .btn,
    .filters .actions-bar button {
        width: 100%;
    }

    .table-wrap table {
        min-width: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    .table-wrap table thead {
        display: none;
    }

    .table-wrap table,
    .table-wrap tbody,
    .table-wrap tr,
    .table-wrap td {
        display: block;
        width: 100%;
    }

    .table-wrap tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 12px;
        margin-bottom: 12px;
    }

    .table-wrap td {
        border: 0 !important;
        padding: 6px 0 !important;
        text-align: left;
    }

    .table-wrap td::before {
        content: attr(data-label);
        display: block;
        font-size: 12px;
        color: var(--muted);
        margin-bottom: 2px;
    }

    .table-wrap td:last-child {
        padding-top: 10px !important;
    }

    .table-wrap td:last-child .actions-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .table-wrap td:last-child .actions-bar .btn,
    .table-wrap td:last-child .actions-bar button {
        width: 100%;
    }

    .list-meta {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .page-header {
        align-items: stretch;
    }

    .page-header .actions-bar {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Filter */
.filters .filter-grid {
    display: grid;
    gap: 18px 24px;
}

.filters .filter-row {
    display: grid;
    gap: 18px 24px;
    align-items: start;
}

.filters .filter-row-main,
.filters .filter-row-sub {
    grid-template-columns: 1fr;
}

.filters .form-group {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
}

.filters .form-group label {
    margin: 0;
    line-height: 1.25;
    min-height: 1.5em;
}

.filters .form-group input,
.filters .form-group select {
    width: 100%;
}

.filters .filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filters .filter-actions .btn,
.filters .filter-actions button {
    max-width: 100%;
}

@media (max-width: 899px) {
    .filters .filter-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .filters .filter-actions .btn,
    .filters .filter-actions button {
        width: 100%;
    }
}

/* Bestand-Filter kompakter */
.bestand-filter-row {
    grid-template-columns: 1fr;
}

.bestand-filter-row-compact {
    gap: 14px 18px;
}

.filter-actions-inline {
    justify-content: flex-start;
    align-self: end;
}

@media (min-width: 768px) {
    .filters .bestand-filter-row,
    .filters .bestand-filter-row-compact {
        grid-template-columns:
            minmax(220px, 1fr)
            minmax(220px, 1fr)
            minmax(160px, 0.75fr)
            minmax(140px, auto);
        align-items: end;
    }
}

.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

/* Status-Badges */
.badge-status-aktiv {
    background: #ecfdf5;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.badge-status-pausiert {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

.badge-status-gekuendigt,
.badge-status-gekündigt {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fdba74;
}

.badge-status-beendet {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.badge-status-archiviert {
    background: #f9fafb;
    color: #6b7280;
    border: 1px solid #e5e7eb;
}

.pagination {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.pagination .btn {
    min-width: 36px;
    text-align: center;
}

/* Bestand */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
}

@media (min-width: 1100px) {
    .detail-grid {
        grid-template-columns: 1fr 1fr;
        align-items: start;
    }
}

/* Bestand-Übersicht gruppiert */
.bestand-overview {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.bestand-ort-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bestand-ort-heading {
    margin: 0;
    font-size: 20px;
    line-height: 1.2;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-strong);
}

.bestand-liegenschaft-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bestand-liegenschaft-heading {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: baseline;
    padding: 4px 0;
    color: var(--text);
}

.bestand-row-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bestand-row-item {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    box-shadow: var(--shadow);
}

.bestand-row-edit {
    display: flex;
    align-items: flex-start;
}

.bestand-row-edit .btn {
    min-height: 30px;
    padding: 0 10px;
    font-size: 12px;
}

.bestand-row-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bestand-row-title {
    font-weight: 700;
    font-size: 16px;
    line-height: 1.25;
    color: var(--text);
}

.bestand-row-title:hover,
.bestand-row-title:focus {
    text-decoration: underline;
}

.bestand-row-meta,
.bestand-row-submeta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 767px) {
    .bestand-row-item {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .bestand-row-edit {
        order: 2;
    }

    .bestand-row-main {
        order: 1;
    }
}

/* Bestand-Hierarchie */
.hierarchy-tree {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.hierarchy-node {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    background: var(--surface-soft);
}

.hierarchy-node.current {
    border-color: var(--border-strong);
    background: var(--surface);
}

.hierarchy-node-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: center;
    justify-content: space-between;
}

.hierarchy-node-title {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.hierarchy-node-title strong {
    word-break: break-word;
}

.hierarchy-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    color: var(--muted);
    font-size: 14px;
}

.hierarchy-children {
    margin-top: 12px;
    padding-left: 18px;
    border-left: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hierarchy-path {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.hierarchy-path .btn {
    max-width: 100%;
}

@media (max-width: 899px) {
    .hierarchy-children {
        padding-left: 12px;
    }

    .hierarchy-node-header {
        flex-direction: column;
        align-items: stretch;
    }
}

.hierarchy-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.hierarchy-group {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hierarchy-group-title {
    font-weight: 600;
    color: var(--text);
}

.hierarchy-group-count {
    color: var(--muted);
    font-weight: 400;
    margin-left: 6px;
}

/* Feldfehler (WCAG 3.3.1) */
.field-error {
    color: #c0392b;
    font-size: 0.8rem;
    margin: 4px 0 0;
    display: flex;
    align-items: baseline;
    gap: 4px;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #c0392b;
    border-width: 2px;
}

/* ===== WCAG 2.1 AA · BFSG · BITV 2.0 — Barrierefreiheit ===== */

/* Skip-Link (WCAG 2.4.1) – erstes Element im Body, erscheint bei Fokus */
.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    z-index: 9999;
    background: var(--color-focus, #005fcc);
    color: #ffffff;
    padding: 0.5rem 1rem;
    text-decoration: none;
    font-weight: 600;
    border-radius: 0 0 6px 0;
}
.skip-link:focus {
    top: 0;
}

/* Visuell versteckt, für Screenreader sichtbar (WCAG 1.3.1) */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Fokus-Sichtbarkeit (WCAG 2.4.7) – NIEMALS outline:none ohne Ersatz */
:focus-visible {
    outline: 3px solid var(--color-focus, #005fcc);
    outline-offset: 2px;
    border-radius: 2px;
}

/* Animationen reduzieren wenn Nutzer es bevorzugt (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
/* ── Kurzname ausblenden (Daten bleiben in DB, Formularfelder bleiben editierbar) ── */
.bestand-kurzname { display:none }

