/* Darkmode override: Kundenübersicht-Rahmen etwas dunkler + gerundet */
::root.dark .table-wrapper {
    background: color-mix(in srgb, var(--color-bg) 75%, black 25%) !important;
    border-radius: var(--radius-m);
}
/* =======================================================
   1) DESIGN TOKENS (Root System)
======================================================= */

:root {
    /* Layout */
    --container-max: 1400px;

    /* Spacing Scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px; /* ergänzt */

    /* Radius */
    --radius-s: 6px;
    --radius-m: 8px;
    --radius-l: 12px;

    /* Shadows */
    --shadow-card: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-header: 0 2px 6px rgba(0,0,0,0.06);

    /* Colors Light */
    --color-bg: #F7F7F8;
    --color-bg-soft: #FFFFFF;
    --color-bg-hover: #F0F0F0;
    --color-border: #E2E2E2;
    --color-text: #1A1A1A;
    --color-muted: #6A6A6A;

    /* Brand */
    --color-brand: #4F46E5;
    --color-brand-soft: rgba(79, 70, 229, 0.08);

    /* Error */
    --color-error-bg: #FFE6E6;
    --color-error-border: #CC0000;
    --color-error-text: #660000;
}

/* Dark Mode */
:root.dark {
    --color-bg: #111111;
    --color-bg-soft: #1A1A1A;
    --color-bg-hover: #222222;
    --color-border: #333333;
    --color-text: #EDEDED;
    --color-muted: #A0A0A0;

    --color-brand: #818CF8;
    --color-brand-soft: rgba(129, 140, 248, 0.12);

    --color-error-bg: #3A0000;
    --color-error-border: #FF4D4D;
    --color-error-text: #FFFFFF;
}

/* Scrollbar Stabilität */
html {
    scrollbar-gutter: stable both-edges;
}

/* Darkmode Icons */
.icon-dark { display: none; }
.dark .icon-light { display: none; }
.dark .icon-dark { display: inline; }


/* =======================================================
   2) GLOBAL LAYOUT / TYPO
======================================================= */

body {
    font-family: "Inter", sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    margin: 0;
    line-height: 1.4;
    padding-bottom: 20px;
}

.container {
    max-width: var(--container-max);
    margin: 0 auto;
    padding: 0 var(--space-3);
}

h1, h2, h3 {
    margin: var(--space-2) 0;
    font-weight: 600;
}


/* =======================================================
   3) HEADER
======================================================= */

.main-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(245,245,245,0.9);
    backdrop-filter: blur(8px);
    box-shadow: var(--shadow-header);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-2) 0;
}

:root.dark .main-header {
    background: rgba(20,20,20,0.9);
}

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

.logo {
    height: 48px;
    opacity: 0.9;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.icon-btn {
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.2s;
}
.icon-btn:hover { opacity: 1; }


/* =======================================================
   3b) DROPDOWN
======================================================= */

.menu-dropdown { position: relative; }

.menu-trigger {
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
}

.dropdown-content {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-card);
    min-width: 160px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 2000;
}

.menu-dropdown:hover .dropdown-content,
.dropdown-content:hover {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.dropdown-content a {
    display: block;
    padding: var(--space-2) var(--space-3);
    text-decoration: none;
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}
.dropdown-content a:last-child { border-bottom: none; }
.dropdown-content a:hover { background: var(--color-bg-hover); }


/* =======================================================
   4) FORMS
======================================================= */

input,
select,
textarea {
    padding: var(--space-2);
    border-radius: var(--radius-s);
    border: 1px solid var(--color-border);
    background: var(--color-bg-soft);
    color: var(--color-text);
    font-size: 0.9rem;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--color-brand);
    outline-offset: 1px;
}

input[readonly] {
    opacity: 0.7;
}

/* Fehlerzustände */
input.error,
select.error,
textarea.error {
    background: var(--color-error-bg) !important;
    border-color: var(--color-error-border) !important;
    color: var(--color-error-text) !important;
}

.error-text {
    color: var(--color-error-text);
    font-size: 0.8rem;
    margin-top: 2px;
}


/* =======================================================
   5) BUTTONS
======================================================= */

.btn {
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    transition: background 0.2s, transform 0.1s;
}

.btn-primary {
    background: var(--color-brand);
    color: white;
}
.btn-primary:hover { background: #4338CA; }
.btn-primary:active { transform: translateY(1px); }

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


/* =======================================================
   ACTION BAR
======================================================= */

.action-bar {
    margin-top: var(--space-4);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
}

/* =======================================================
   6) TABLES
======================================================= */

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

th, td {
    padding: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    text-align: center;
}

th.left, td.left { text-align: left; }
th.center, td.center { text-align: center; }

.th-inner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

th {
    background: #E0E0E0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}



/* ------------------------------------------
   STICKY LOGIK — funktionierend
------------------------------------------- */

/* Summenzeile sticky direkt unter globalem Header */
.sum-row th {
    position: sticky;
    top: 0;
    z-index: 30;
    background: color-mix(in srgb, var(--color-bg-soft) 70%, black 10%);
}

/* Tabellen-Header sticky unter Summenzeile */
thead tr:nth-child(2) th {
    position: sticky;
    top: 40px; /* Höhe der Summenzeile */
    z-index: 20;
    background: #E0E0E0;
}


/* Hover */
tbody tr:hover {
    background: var(--color-bg-hover);
    transition: background 0.15s ease-in-out;
}

.table-wrapper {
    background: var(--color-bg-soft);
    padding: var(--space-3);
    border-radius: var(--radius-m);
    box-shadow: var(--shadow-card);
    margin: var(--space-3) 0;
    overflow-x: auto;   /* nur horizontal scrollen */
    overflow-y: visible; /* vertikal NICHT scrollen */
    position: relative;
}


:root.dark thead tr:nth-child(2) th {
    background: #222;
}


:root.dark .table-wrapper table tbody tr {
    background: var(--color-bg-soft) !important;
    color: var(--color-text) !important;
}

:root.dark .table-wrapper table tbody tr:hover {
    background: var(--color-bg-hover) !important;
}


:root.dark th {
    background: #222;
    color: #F5F5F5;
}


/* =======================================================
   6b) TABLE COLUMN WIDTHS
======================================================= */

/* Kdnr */
table th:nth-child(1),
table td:nth-child(1) {
    width: 90px;
    min-width: 90px;
}

/* Firma */
table th:nth-child(2),
table td:nth-child(2) {
    width: 15%;
    min-width: 160px;
}

/* Ort */
table th:nth-child(3),
table td:nth-child(3) {
    width: 15%;
    min-width: 140px;
}

/* Checkbox-Spalten (ea, Bild, VKL, PKA, BWA, RWA) */
table th:nth-child(4),
table th:nth-child(5),
table th:nth-child(6),
table th:nth-child(7),
table th:nth-child(8),
table th:nth-child(9),
table td:nth-child(4),
table td:nth-child(5),
table td:nth-child(6),
table td:nth-child(7),
table td:nth-child(8),
table td:nth-child(9) {
    width: 85px;
    min-width: 85px;
    text-align: center;
}

/* Action-Spalte */
table th:nth-child(10),
table td:nth-child(10) {
    width: 60px;
    min-width: 60px;
    text-align: center;
}

/* =======================================================
   7) CARDS
======================================================= */

.card-section {
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    background: var(--color-bg-soft);
}

.detail-card-grid {
    display: grid;
    gap: var(--space-5);
    grid-template-columns: 1fr 1fr; /* Desktop: 2 Spalten */
}

/* Tablet */
@media (max-width: 900px) {
    .detail-card-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

/* Mobile */
@media (max-width: 600px) {
    .detail-card-grid {
        grid-template-columns: 1fr;
    }
}


.card-section.full {
    grid-column: 1 / -1;
}

/* Notizen-Tab: Headline + Button in einer Zeile, Button rechts */
.notes-tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
    flex-wrap: wrap;
    gap: var(--space-2);
}

.notes-tab-header h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Notizen-Filterzeile (eine Zeile, kompakt) */
.notes-filter-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    margin-bottom: var(--space-3);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}

.notes-filter-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--color-muted);
}

.notes-filter-input,
.notes-filter-select {
    min-width: 100px;
    max-width: 140px;
}

/* Notizen-Liste (kompakte Einträge) */
.notes-list-block {
    margin-top: var(--space-2);
}

.notes-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.notes-empty {
    padding: var(--space-4);
    text-align: center;
    color: var(--color-muted);
    font-size: 0.95rem;
}

.notes-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--color-bg-soft);
    transition: background 0.15s;
}

.notes-item:hover {
    background: var(--color-bg-hover);
}

/* Wiedervorlage-Hervorhebung */
.notes-item-soon {
    border-color: #f59e0b; /* orange */
    background: color-mix(in srgb, #f59e0b 8%, var(--color-bg-soft) 92%);
}

.notes-item-overdue {
    border-color: #dc2626; /* rot */
    background: color-mix(in srgb, #dc2626 10%, var(--color-bg-soft) 90%);
}

.notes-item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.notes-item-main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.notes-item-id {
    font-size: 0.85rem;
    color: var(--color-muted);
    flex-shrink: 0;
}

.notes-item-kdnr-firma {
    font-size: 0.8rem;
    color: var(--color-muted);
    flex-shrink: 0;
    max-width: 12em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notes-item-headline {
    font-weight: 600;
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notes-item-right {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 0;
}

.notes-item-badges {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    flex-wrap: wrap;
}

.notes-item-sep {
    width: 30px;
    min-width: 30px;
    align-self: stretch;
    border-left: 1px solid var(--color-border);
    margin-left: var(--space-1);
    margin-right: var(--space-1);
    opacity: 0.7;
}

.notes-item-detail-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-s);
    background: var(--color-bg-hover);
    color: var(--color-text);
    text-decoration: none;
    flex-shrink: 0;
}

.notes-item-detail-btn:hover {
    background: var(--color-brand);
    color: white;
}

.notes-item-meta {
    font-size: 0.8rem;
    color: var(--color-muted);
    margin-top: var(--space-1);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2) var(--space-4);
}

.notes-item-meta span + span::before {
    content: "|";
    margin-right: var(--space-2);
    opacity: 0.6;
}

.notes-item-meta span:first-child::before {
    display: none;
}

.notes-badge-user {
    background: var(--color-bg-hover);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

/* Paging (zentriert, 25 pro Seite) */
.notes-paging {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding: var(--space-3) 0;
}

.notes-paging-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    font-size: 0.9rem;
    color: var(--color-brand);
    text-decoration: none;
    border-radius: var(--radius-s);
}

.notes-paging-btn:hover {
    text-decoration: underline;
}

.notes-paging-info {
    font-size: 0.9rem;
    color: var(--color-muted);
}

.section-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
}

.section-grid > div {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.section-grid input[readonly] {
    background: var(--color-bg-soft);
    opacity: 0.7;
}

.section-grid.three-cols {
    display: grid;
    grid-template-columns: 1fr 2.5fr 1fr;
    gap: var(--space-3);
}

.section-grid.three-cols .wide input {
    width: 100%;
}

.card-section h4 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 1.0rem;        /* 20% kleiner */
    opacity: 0.85;
    white-space: nowrap;      /* Icon + Text in einer Zeile */
    margin-bottom: var(--space-2);
}

.card-section h4 i {
    width: 14px;              /* 20% kleiner */
    height: 14px;
    stroke-width: 1.6;
    opacity: 0.9;
}


/* =======================================================
   8) PAGING
======================================================= */

.paging button {
    padding: var(--space-1) var(--space-3);
    font-size: 0.85rem;
    border-radius: var(--radius-s);
    background: var(--color-brand);
    color: white;
    cursor: pointer;
}

.paging button:hover { background: #4338CA; }

.paging button:disabled {
    background: var(--color-border);
    color: var(--color-muted);
    opacity: 0.6;
    pointer-events: none;
}


/* =======================================================
   9) PAGE HEADER
======================================================= */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.page-header h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
}

.page-header-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}


/* =======================================================
   10) FLASH MESSAGES
======================================================= */

.flash {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-weight: 500;
}

.flash-error {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error-text);
}

.flash-success {
    background: #E5FFE8;
    border: 1px solid #B3FFBF;
    color: #006B1F;
}


/* =======================================================
   11) TABS
======================================================= */

.tabs {
    display: flex;
    flex-wrap: wrap; /* ← das fehlt bei dir */
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.tab {
    flex: 1 1 auto; /* ← erlaubt Umbruch */
    text-align: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    opacity: 0.85;
    text-decoration: none;
    font-weight: 500;
}


.tab:hover { opacity: 1; }

.tab.active {
    background: var(--color-brand);
    border-color: var(--color-brand);
    color: white;
    opacity: 1;
}

.disabled-tab {
    pointer-events: none;
    opacity: 0.4;
    cursor: not-allowed;
}


/* =======================================================
   MODULE ROW (neues kompaktes Layout)
======================================================= */

.module-row {
    display: grid;
    grid-template-columns: 240px 120px 140px 140px 120px;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-m);
    background: var(--color-bg-soft);
    margin-bottom: 8px;
    transition: 0.2s ease;
}

.module-row:hover {
    box-shadow: var(--shadow-card);
}

.module-row.active {
    background: var(--color-brand-soft);
    border-color: var(--color-brand);
}

.module-row.fakt-offen {
    background: var(--color-warning-soft);
}

.mod-activation {
    display: flex;
    align-items: center;
    gap: 10px;
}

.mod-label {
    font-weight: 600;
    min-width: 120px;
}

.mod-bestnr input,
.mod-date input,
.mod-faktura select,
.module-activation {
    width: 100%;
}

.mod-date {
    display: flex;
    flex-direction: column;
}

.mod-date-label {
    font-size: 11px;
    color: var(--color-text-soft);
    margin-bottom: 2px;
    line-height: 1;
}



/* =======================================================
   13) TOGGLE SWITCH
======================================================= */

.toggle-switch {
    appearance: none;
    width: 40px;
    height: 22px;
    background: var(--color-border);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle-switch:checked {
    background: var(--color-brand);
}

.toggle-switch:checked::after {
    transform: translateX(18px);
}


/* =======================================================
   14) LOGIN PAGE
======================================================= */

.login-btn {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--color-brand);
    color: white;
    border: none;
    border-radius: var(--radius-s);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
    margin-top: var(--space-3); /* Abstand zum Passwortfeld */
}

.login-btn:hover {
    background: var(--color-brand-hover);
}

.input-with-icon + .login-btn {
    margin-top: var(--space-4);
}


.login-page {
    display: flex;
    justify-content: center;
    align-items: flex-start; /* statt center */
    min-height: 100vh;
    background: var(--color-bg);
    padding-top: 60px; /* ca. 3 cm auf Desktop */
}


.login-card {
    width: 420px;
    padding: var(--space-5);
    border-radius: var(--radius-m);
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    text-align: center;
}

.login-logo {
    width: 140px;
    margin: 0 auto var(--space-2);
}


/* =======================================================
   15) USER TOOLTIP
======================================================= */

.user-tooltip-wrapper { position: relative; }

.user-tooltip {
    position: absolute;
    top: 120%;
    right: 0;
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-s);
    box-shadow: var(--shadow-card);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: 0.15s ease;
    white-space: nowrap;
}

.user-tooltip-wrapper:hover .user-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-tooltip .role {
    opacity: 0.7;
    font-size: 0.8rem;
}

/* =======================================================
   16) SEARCH GRID
======================================================= */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-3);
}


/* =======================================================
   17) Input with Icon
======================================================= */

.grid > div {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}


.input-with-icon {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-icon input {
    width: 100%;
    padding-right: 38px; /* Platz für Icon */
}

.input-with-icon .icon-button {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    opacity: 0.7;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-with-icon .icon-button:hover {
    opacity: 1;
}

.input-with-icon .icon-button i,
.input-with-icon .icon-button svg {
    width: 18px;
    height: 18px;
    stroke-width: 1.8;
    color: var(--color-brand);
}

/* =======================================================
   DARKMODE FIX: Tabellenkörper wirklich abdunkeln
======================================================= */

:root.dark .table-wrapper table tbody tr,
:root.dark .table-wrapper table tbody td {
    background: var(--color-bg-soft) !important;
    color: var(--color-text) !important;
}
/* Hover im Darkmode */
:root.dark .table-wrapper table tbody tr:hover {
    background: var(--color-bg-hover) !important;
}
/* Tabellenhintergrund selbst */
:root.dark .table-wrapper table {
    background: var(--color-bg-soft) !important;
}
/* Darkmode Footer */
:root.dark tfoot td {
    background: var(--color-bg-soft) !important;
    color: var(--color-text) !important;
    border-top: 1px solid var(--color-border);
}
:root.dark .paging button {
    background: var(--color-bg-hover);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

:root.dark .paging button:hover {
    background: var(--color-bg);
}
:root.dark .paging {
    background: var(--color-bg-soft);
}
:root.dark .table-wrapper {
    background: color-mix(in srgb, var(--color-bg) 85%, black 15%) !important;
}
:root.dark .table-wrapper {
    background: var(--color-bg) !important;
}

@media (max-width: 900px) {

    /* Checkbox-Spalten ausblenden */
    table th:nth-child(n+4):nth-child(-n+14),
    table td:nth-child(n+4):nth-child(-n+14),
    .sum-row th:nth-child(n+4):nth-child(-n+14),
    thead tr:nth-child(2) th:nth-child(n+4):nth-child(-n+14) {
        display: none;
    }

    /* Tabelle darf so breit sein, wie sie braucht */
    table {
        table-layout: auto;
        width: max-content;
        min-width: 100%;
    }

    /* Kdnr */
    table th:nth-child(1),
    table td:nth-child(1) {
        min-width: 80px;
    }

    /* Firma */
    table th:nth-child(2),
    table td:nth-child(2) {
        min-width: 160px;
    }

    /* Ort */
    table th:nth-child(3),
    table td:nth-child(3) {
        min-width: 140px;
    }

    /* Action */
    table th:nth-child(15),
    table td:nth-child(15) {
        min-width: 60px;
        text-align: center;
    }
}

.note-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
    margin-bottom: var(--space-6);
}

.comment-card {
    padding: var(--space-3);
    border-radius: var(--radius-s);
    background: var(--color-bg-soft);
    margin-bottom: var(--space-3);
}

.comment-card.type-1 { border-left: 4px solid var(--color-border); }
.comment-card.type-2 { border-left: 4px solid var(--color-brand); }

/********************************************
 * MODAL OVERLAY
 ********************************************/
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 50px;
    z-index: 999999;
}

/********************************************
 * MODAL CONTENT (Rahmen + max Höhe)
 ********************************************/
.modal-content {
    background: var(--color-bg);
    border-radius: var(--radius-m);
    padding: var(--space-5);
    width: 80%;
    max-width: 1200px;
    max-height: calc(100vh - 100px);
    overflow-x: hidden;
    overflow-y: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    margin: 0 auto 50px auto;
}

/* Notiz-Modal: 95% Breite der Liste, Schrift ~80% */
.modal-content.notes-modal {
    width: 95%;
    max-width: 95%;
    font-size: 0.8rem;
}

.modal-content.notes-modal .modal-header h3,
.modal-content.notes-modal .modal-body,
.modal-content.notes-modal label,
.modal-content.notes-modal input,
.modal-content.notes-modal select,
.modal-content.notes-modal textarea,
.modal-content.notes-modal .tab-btn,
.modal-content.notes-modal .btn {
    font-size: inherit;
}

.modal-content.notes-modal input,
.modal-content.notes-modal select {
    padding: 6px 8px;
}

/* Notiz-Modal Wrapper (Schrift ~80%) */
.notes-modal-wrapper {
    font-size: 0.8rem;
}

/* Forms im Notiz-Modal links einrücken, Focus-Rahmen nicht abgeschnitten */
.notes-modal-wrapper .modal-body {
    padding-left: 16px;
    padding-right: 16px;
}

.notes-modal-wrapper form input:focus,
.notes-modal-wrapper form select:focus,
.notes-modal-wrapper form textarea:focus {
    outline-offset: 2px;
}

.notes-modal-wrapper .modal-header-notes {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    border-bottom: 1px solid var(--color-border);
    padding-bottom: var(--space-2);
}

.notes-modal-wrapper .modal-header-notes h3 {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.notes-modal-wrapper .modal-header-notes .modal-close-x {
    border: none;
    background: transparent;
    color: var(--color-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 var(--space-1);
}

.notes-modal-wrapper .modal-header-notes .modal-close-x:hover {
    color: var(--color-text);
}

.modal-tabs-row {
    align-items: center;
}

.modal-sep {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-2) 0;
}

.modal-small-heading {
    font-size: 0.9em;
    font-weight: 600;
    margin: var(--space-1) 0 var(--space-2) 0;
    opacity: 0.9;
}

.modal-headline-input {
    width: 100%;
    margin-bottom: var(--space-3);
}

.modal-row-compact {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.modal-row-compact label {
    display: block;
    font-size: 0.85em;
    margin-bottom: 2px;
}

.modal-grid-editor {
    grid-template-columns: 1fr 25%;
}

.modal-right-dropzone .notes-dropzone {
    min-height: 100px;
}

.modal-footer-meta {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-top: var(--space-3);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border);
}

.modal-footer-meta div + div {
    margin-top: 2px;
}

/* Kommentar-Formular aufklappbar (oberhalb der Liste) */
.notes-comment-form-wrap {
    display: none;
    margin-bottom: var(--space-3);
    padding: var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    background: var(--color-bg-soft);
}

.notes-comment-form-wrap.open {
    display: block;
}

.notes-comment-form-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.notes-comment-form-text {
    flex: 1;
    min-width: 0;
    width: 90%;
    resize: vertical;
    min-height: 88px;
    font-size: inherit;
}

.notes-comment-form-btns {
    flex: 0 0 auto;
    width: 10%;
    min-width: 90px;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.notes-comment-form textarea {
    font-size: inherit;
}

.modal-comment-btn-wrap {
    margin-left: auto;
}

.modal-comment-add-row {
    justify-content: flex-end;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.9em;
}

/* Kommentar-Karten (7a: Name/Date rechts, Body auf/zu) */
.notes-comment-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    background: var(--color-bg-soft);
}

.notes-comment-meta {
    text-align: right;
    font-size: 0.85em;
    color: var(--color-muted);
}

.notes-comment-name {
    margin-right: var(--space-2);
}

.notes-comment-body {
    margin-top: var(--space-1);
    font-size: 0.95em;
    line-height: 1.4;
    max-height: 4.5em;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.notes-comment-body.expanded {
    max-height: none;
}

.notes-comment-toggle {
    background: none;
    border: none;
    color: var(--color-brand);
    cursor: pointer;
    font-size: 0.85em;
    padding: 2px 0;
    margin-top: 4px;
}

.notes-comment-empty {
    color: var(--color-muted);
    font-size: 0.9em;
    padding: var(--space-3);
}

.notes-comment-error {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--color-error-text);
}

/********************************************
 * MODAL HEADER
 ********************************************/
.modal-header h3 {
    margin: 0;
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    gap: 8px;
}

/********************************************
 * MODAL BODY (eigene Scroll-Zone)
 ********************************************/
.modal-body {
    max-height: calc(100vh - 220px); /* Platz für Header + Footer */
    overflow-y: auto;
    padding: var(--space-3) 12px var(--space-3) 12px; /* Platz für Focus-Rahmen, kein Abschneiden */
    margin-top: var(--space-4);
}

/********************************************
 * MODAL TABS
 ********************************************/
.modal-tabs {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.tab-btn {
    padding: var(--space-2) var(--space-4);
    background: var(--color-bg-soft);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-s);
    cursor: pointer;
}

.tab-btn.active {
    background: var(--color-brand);
    color: white;
    border-color: var(--color-brand);
}

/********************************************
 * GRID LAYOUTS
 ********************************************/
.modal-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-5);
}

.modal-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.modal-left textarea {
    width: 100%;
    height: 180px;
    resize: vertical;
}

.modal-right {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

/********************************************
 * QUILL EDITOR FIXES (Höhe + Scroll)
 ********************************************/
#notes_body_editor .ql-container {
    height: auto !important;
}

#notes_body_editor .ql-editor {
    min-height: 150px;
    max-height: 250px;
    overflow-y: auto;
    font-size: 0.8rem !important;
}
#notes_body_editor .ql-editor p,
#notes_body_editor .ql-editor li {
    font-size: inherit;
}

/********************************************
 * MODAL FOOTER / ACTION BUTTONS
 ********************************************/
.modal-actions {
    position: sticky;
    bottom: 0;
    background: var(--color-bg);
    padding: var(--space-4) 0;
    margin-top: var(--space-5);
    display: flex;
    justify-content: center;
    gap: var(--space-4);
    border-top: 1px solid var(--color-border);
    z-index: 10;
}

/********************************************
 * DROPZONE
 ********************************************/
.modal-right .dropzone {
    height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-m);
    background: var(--color-bg-soft);
    cursor: pointer;
}

/* QUILL – Container-Höhe kontrollieren */
#notes_body_editor.ql-container {
    max-height: 250px !important;
    min-height: 150px;
    overflow-y: auto !important;
}

/* QUILL – Editor-Inhalt (Spezifität gegen quill.snow.css) */
#notes_body_editor.ql-container .ql-editor {
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem !important;
}

/* QUILL – Toolbar fixieren */
#notes_body_editor .ql-toolbar {
    position: sticky;
    top: 0;
    background: var(--color-bg);
    z-index: 5;
}

/* Quill: Bilder im Editor max. 80px hoch, klickbar → Lightbox */
#notes_body_editor .ql-editor img {
    max-height: 80px;
    width: auto;
    height: auto;
    object-fit: contain;
    cursor: pointer;
    border-radius: var(--radius-2);
}

/* Lightbox über Notiz-Modal: Vollbild mit Close rechts oben */
.notes-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 1000000;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    padding: var(--space-4);
}
.notes-image-lightbox.open {
    display: flex;
}
.notes-image-lightbox .notes-lightbox-img {
    max-width: 95vw;
    max-height: 90vh;
    object-fit: contain;
}
.notes-image-lightbox .notes-lightbox-close {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    z-index: 1;
    width: 2.75rem;
    height: 2.75rem;
    border: none;
    border-radius: var(--radius-2);
    background: #fff;
    color: #1a1a1a;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}
.notes-image-lightbox .notes-lightbox-close:hover {
    background: #f0f0f0;
}

.notes-dropzone.dropzone-dragover {
    outline: 2px dashed var(--color-primary);
    background: var(--color-surface-2);
}

/********************************************
 * HEADER-ZEILE: Tabs + Wiedervorlage rechts (gleiche Höhe)
 ********************************************/
.modal-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
    gap: var(--space-4);
}

/* Tabs bleiben wie sie sind */
.modal-tabs {
    display: flex;
    gap: var(--space-3);
}

/* Wiedervorlage rechtsbündig, auf Höhe der Tab-Buttons */
.modal-reminder {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.modal-reminder label {
    margin: 0;
    font-weight: 600;
}

.modal-reminder select {
    padding: 6px 8px;
    font-size: 0.9rem;
}


/* Basis */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-s);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

/* TYPEN */
.badge.type-1 { background: var(--color-bg-soft); color: var(--color-text); border: 1px solid var(--color-border); } /* Allgemein */
.badge.type-2 { background: rgba(0, 120, 255, 0.15); color: #0078ff; } /* Boarding */
.badge.type-3 { background: rgba(0, 200, 120, 0.15); color: #00a86b; } /* Lead */
.badge.type-4 { background: rgba(0, 120, 255, 0.15); color: #0078ff; } /* Sales */
.badge.type-5 { background: rgba(255, 180, 0, 0.15); color: #d48a00; } /* Support */
.badge.type-6 { background: rgba(180, 0, 255, 0.15); color: #a000d4; } /* Development */
.badge.type-7 { background: rgba(255, 0, 80, 0.15); color: #d40040; } /* Bugfix */

/* PRIO */
.badge.prio-1 { background: rgba(0, 200, 120, 0.15); color: #00a86b; } /* Niedrig */
.badge.prio-2 { background: rgba(0, 120, 255, 0.15); color: #0078ff; } /* Normal */
.badge.prio-3 { background: rgba(255, 0, 80, 0.15); color: #d40040; } /* Hoch */

/* STATUS */
.badge.status-1 { background: rgba(0, 120, 255, 0.15); color: #0078ff; } /* Neu */
.badge.status-2 { background: rgba(255, 180, 0, 0.15); color: #d48a00; } /* In Bearbeitung */
.badge.status-3 { background: rgba(0, 200, 120, 0.15); color: #00a86b; } /* Feedback geben */
.badge.status-4 { background: rgba(0, 200, 120, 0.15); color: #00a86b; } /* Feedback abwarten */
.badge.status-5 { background: rgba(120, 120, 120, 0.15); color: #888; } /* Abgewiesen */
.badge.status-6 { background: rgba(0, 200, 120, 0.15); color: #00a86b; } /* Erledigt */



