/* ==========================================================================
   MMK3 - CRM – Basis-Styles
   ========================================================================== */

:root {
    /* Farbwelt abgestimmt auf das MMK-Logo: Anthrazit #4C4A4B und Grau #8C8C8C */
    --bg: #f2f2f2;
    --surface: #ffffff;
    --surface-2: #f7f7f7;
    --border: #e0e0e0;
    --text: #262526;
    --text-muted: #6f6e6f;
    --primary: #4c4a4b;
    --primary-hover: #333132;
    --primary-soft: #ebebeb;
    --on-primary: #ffffff;
    --logo-grey: #8c8c8c;
    --success: #2a7047;
    --success-soft: #e6f2ea;
    --danger: #b3362d;
    --danger-soft: #f8e9e7;
    --info-soft: #eeeeee;
    --sidebar-bg: #ffffff;
    --sidebar-text: #5c5b5c;
    --sidebar-active: #262526;
    --sidebar-hover: #f2f2f2;
    --sidebar-active-bg: #ebebeb;
    --logo-plate: transparent;
    --logo-pad: 0;
    --focus-ring: rgba(76, 74, 75, .22);
    --radius: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 4px 16px rgba(0, 0, 0, .05);
    --sidebar-w: 248px;
    color-scheme: light;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Dunkles Design – gesetzt von assets/js/theme.js (Systemeinstellung oder Schalter in der Kopfzeile) */
:root[data-theme="dark"] {
        color-scheme: dark; /* auch Scrollleisten, Eingabefelder, Datumsauswahl dunkel */
        --bg: #161616;
        --surface: #1f1f1f;
        --surface-2: #262626;
        --border: #353535;
        --text: #ececec;
        --text-muted: #a3a3a3;
        --primary: #d6d6d6;
        --primary-hover: #ffffff;
        --primary-soft: #333333;
        --on-primary: #161616;
        --logo-grey: #8c8c8c;
        --success: #6fcf97;
        --success-soft: #1d3326;
        --danger: #f08a80;
        --danger-soft: #3a201e;
        --info-soft: #2a2a2a;
        --sidebar-bg: #1b1b1b;
        --sidebar-text: #b5b5b5;
        --sidebar-active: #ffffff;
        --sidebar-hover: #262626;
        --sidebar-active-bg: #303030;
        --logo-plate: #f2f2f2; /* Logo-Anthrazit wäre auf dunklem Grund kaum lesbar */
        --logo-pad: 4px 8px;
        --focus-ring: rgba(214, 214, 214, .25);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
}

/* Schalter Hell/Dunkel: Mond im hellen Design (→ dunkel), Sonne im dunklen (→ hell) */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
.auth-theme { position: fixed; top: 16px; right: 16px; }

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

/* "hidden" muss immer gewinnen – auch gegen eigene display-Regeln (z. B. Tabellenzeilen als Karten). */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
svg { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }

/* Layout ------------------------------------------------------------------ */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    z-index: 30;
    transition: transform .25s ease;
}

.brand {
    display: flex; align-items: flex-end; gap: 10px;
    padding: 4px 10px 22px; margin-bottom: 10px;
    border-bottom: 1px solid var(--border);
    color: inherit;
}
.brand:hover { text-decoration: none; }
.brand-logo {
    display: block; height: 34px; width: auto;
    background: var(--logo-plate); border-radius: 6px;
    padding: var(--logo-pad); box-sizing: content-box;
}
.topbar-logo { display: none; height: 22px; width: auto; background: var(--logo-plate); border-radius: 4px; padding: var(--logo-pad); }
.brand-name {
    color: var(--logo-grey);
    font-weight: 700; font-size: 15px; letter-spacing: 2px;
    line-height: 1; padding-bottom: 3px;
}

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-weight: 500;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-active); text-decoration: none; }
.nav-link.is-active {
    background: var(--sidebar-active-bg); color: var(--sidebar-active); font-weight: 600;
    box-shadow: inset 3px 0 0 var(--primary); /* Akzentbalken wie die dunklen Balken im Logo */
}

.sidebar-footer { margin-top: auto; padding: 10px; font-size: 12px; line-height: 1.5; opacity: .6; }
.auth-footer { margin: 0; text-align: center; font-size: 12px; color: var(--text-muted); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; gap: 12px;
    padding: 16px 32px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.page-title { margin: 0; font-size: 22px; font-weight: 650; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.content { padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 24px; }

.icon-btn {
    display: grid; place-items: center;
    width: 40px; height: 40px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text);
    cursor: pointer;
}
.menu-btn { display: none; }

.backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 20;
}

/* Komponenten ------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}
.card-header h2 { margin: 0; font-size: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
    display: flex; flex-direction: column; gap: 4px;
}
.stat-label { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.stat-link { color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.stat-link:hover, .stat-link:focus-visible { border-color: var(--primary); transform: translateY(-1px); }
.offer-angenommen .stat-value { color: var(--success); }
.offer-abgelehnt .stat-value { color: var(--danger); }
.offer-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
/* Verkaufschancen: Werkzeugleiste, Pipeline, Karten, Fenster */
.opp-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 16px; }
.opp-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.opp-filter input[type="search"] { min-width: 220px; }
.opp-actions { display: flex; gap: 8px; margin-left: auto; }
.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented a { padding: 6px 14px; border-radius: 9px; text-decoration: none; color: var(--text-muted); font-weight: 500; }
.segmented a.is-active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }
.pipeline { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.pipe-col { flex: 1 0 230px; max-width: 320px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; display: flex; flex-direction: column; max-height: calc(100vh - 230px); }
.pipe-col.is-inactive { opacity: .75; }
.pipe-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 2px 8px; align-items: baseline; }
.pipe-sum { flex-basis: 100%; font-size: 13px; display: flex; flex-wrap: wrap; gap: 0 6px; font-variant-numeric: tabular-nums; }
.pipe-cards { padding: 10px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 90px; border-radius: 0 0 14px 14px; }
.pipe-cards.is-over, .pipe-result.is-over { outline: 2px dashed var(--primary); outline-offset: -4px; }
.opp-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; cursor: pointer; }
.opp-card:hover, .opp-card:focus-visible { border-color: var(--primary); outline: none; }
.opp-card[draggable="true"] { cursor: grab; }
.opp-card.is-dragging { opacity: .45; }
.opp-title { font-size: 14px; line-height: 1.3; }
.opp-customer { font-size: 13px; color: var(--text-muted); }
.opp-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.opp-value { font-weight: 600; }
.opp-date.is-overdue { color: var(--danger); font-weight: 600; }
.opp-card-foot { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.opp-card-foot:empty { display: none; }
.avatar.avatar-xs { width: 22px; height: 22px; font-size: 10px; }
.pipe-results { flex: 0 0 160px; display: flex; flex-direction: column; gap: 10px; }
.pipe-result { border: 2px dashed var(--border); border-radius: 14px; padding: 18px 12px; text-align: center; font-weight: 600; display: flex; flex-direction: column; gap: 2px; background: var(--surface); }
.pipe-result small { font-weight: 400; color: var(--text-muted); }
.pipe-result.is-won { color: var(--success); }
.pipe-result.is-lost { color: var(--danger); }
.opp-toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 12px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.opp-toast.is-error { background: var(--danger); color: #fff; }
.opp-table .num { text-align: right; white-space: nowrap; }
.opp-table th a { color: inherit; text-decoration: none; }
.license-dialog.opp-dialog { width: min(860px, calc(100vw - 32px)); }
.opp-dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.opp-dialog .license-dialog-body { overflow: auto; }
.opp-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.opp-grid .field-wide { grid-column: 1 / -1; }
.opp-result label { padding: 6px 14px; }
.opp-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.opp-extra h3 { margin: 0 0 8px; font-size: 15px; }
.opp-extra-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.opp-acts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.opp-due { color: var(--danger); }
.license-dialog-foot.opp-foot { border-top: 1px solid var(--border); padding-top: 14px; gap: 10px; }
.opp-foot-space { flex: 1; }
.license-dialog.opp-lost-dialog { width: min(440px, calc(100vw - 32px)); }
.opp-lost-dialog select { width: 100%; }
.opp-stats .stat-sub .text-danger { font-weight: 600; }
.forecast { padding: 18px 22px 22px; }
.forecast-legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.forecast-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.forecast-bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; align-items: end; height: 170px; border-bottom: 1px solid var(--border); }
.forecast-col { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; outline: none; }
.forecast-bar { width: min(34px, 70%); background: var(--fc-total); border-radius: 4px 4px 0 0; position: relative; min-height: 1px; display: flex; align-items: flex-end; }
.forecast-bar > span { display: block; width: 100%; background: var(--fc-weighted); border-radius: 4px 4px 0 0; }
.forecast-col .forecast-tip { display: none; position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); white-space: nowrap; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 6px 18px rgba(0, 0, 0, .15); z-index: 2; color: var(--text); }
.forecast-col:hover .forecast-tip, .forecast-col:focus .forecast-tip { display: block; }
.forecast-col:nth-child(-n+2) .forecast-tip { left: 0; transform: none; }
.forecast-col:nth-last-child(-n+2) .forecast-tip { left: auto; right: 0; transform: none; }
.forecast-col:hover .forecast-bar, .forecast-col:focus .forecast-bar { filter: brightness(.92); }
.forecast-months { display: grid; grid-template-columns: repeat(12, 1fr); gap: 2px; font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 6px; }
:root { --fc-total: #c9c6c7; --fc-weighted: #4c4a4b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fc-total: #4a4848; --fc-weighted: #d6d3d4; } }
:root[data-theme="dark"] { --fc-total: #4a4848; --fc-weighted: #d6d3d4; }
@media (min-width: 761px) {
    .opp-table td[data-label="Kunde"] a { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
}
.opp-settings-table { width: 100%; border-collapse: collapse; }
.opp-settings-table th, .opp-settings-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.opp-settings-table input[type="text"] { width: 100%; }
.opp-settings-table input[type="number"] { width: 90px; }
.customer-opps { list-style: none; margin: 0; padding: 16px 22px 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
@media (max-width: 760px) {
    .opp-actions { margin-left: 0; }
    .opp-extra { grid-template-columns: 1fr; }
    .pipe-col { flex-basis: 82vw; }
    .pipe-results { position: static; flex-basis: 82vw; flex-direction: row; }
    .pipe-result { flex: 1; }
    .opp-filter input[type="search"] { min-width: 0; flex: 1; }
}

/* Ansprechpartner bearbeiten */
.contacts-toolbar { display: flex; justify-content: flex-end; padding: 16px 22px 0; }
.contact-actions { display: flex; gap: 6px; margin-top: 10px; }
.license-dialog.contact-dialog { width: min(820px, calc(100vw - 32px)); }
.contact-dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.contact-dialog .license-dialog-body { overflow: auto; }
.contact-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.contact-grid .field-wide { grid-column: 1 / -1; }
.contact-more { margin-top: 6px; }
.contact-more summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.contact-more[open] summary { margin-bottom: 10px; }
.contact-foot { gap: 10px; border-top: 1px solid var(--border); padding-top: 14px; }
.license-dialog.contact-history-dialog { width: min(640px, calc(100vw - 32px)); }
.contact-history { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 12px; }
.contact-history-changes { margin-top: 6px; font-size: 13px; border-collapse: collapse; }
.contact-history-changes th { text-align: left; font-weight: 600; padding: 2px 10px 2px 0; white-space: nowrap; }
.contact-history-changes td { padding: 2px 6px; overflow-wrap: anywhere; }

/* Starke DMS: Beleg-PDF */
.dms-btn { white-space: nowrap; }
.dms-btn.is-error { color: var(--danger); }
.license-dialog.dms-dialog { width: min(1100px, calc(100vw - 32px)); max-width: none; height: min(90vh, 1200px); display: none; flex-direction: column; }
.license-dialog.dms-dialog[open] { display: flex; }
.dms-dialog .license-dialog-head { gap: 12px; flex-wrap: wrap; }
.dms-actions { display: flex; align-items: center; gap: 8px; }
.dms-frame { flex: 1; width: 100%; border: 0; background: #525659; border-radius: 0 0 16px 16px; }

/* Mailablage (Dashboard-Kachel) */
.mail-inbox { border: 2px dashed var(--border); box-shadow: none; cursor: pointer; transition: border-color .15s, background .15s; }
.mail-inbox:hover, .mail-inbox:focus-visible, .mail-inbox.is-dragover { border-color: var(--primary); background: var(--primary-soft); outline: none; }
.mail-inbox-icon svg { width: 34px; height: 34px; fill: var(--text-muted); }
.mail-inbox.is-dragover .mail-inbox-icon svg { fill: var(--primary); }
.mail-inbox.is-busy { cursor: progress; }
.mail-inbox.is-error { border-color: var(--danger); }
.mail-inbox.is-error .stat-sub { color: var(--danger); }
.license-dialog.mail-inbox-dialog { width: min(560px, calc(100vw - 32px)); }
.mail-inbox-choices { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; }
.mail-inbox-choice { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; padding: 10px 14px; text-align: left;
    border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.mail-inbox-choice:hover, .mail-inbox-choice:focus-visible { border-color: var(--primary); background: var(--primary-soft); outline: none; }
.offer-table td small { display: block; }
.offer-table .num { text-align: right; white-space: nowrap; }

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 14px;
    border-radius: 10px;
    font-weight: 500; font-size: 14px;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
}
.btn-ghost { color: var(--primary); background: var(--primary-soft); }
.btn-ghost:hover { text-decoration: none; filter: brightness(.97); }

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px; font-weight: 600;
    text-transform: capitalize;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

.avatar {
    width: 34px; height: 34px;
    display: inline-grid; place-items: center;
    border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    font-size: 13px; font-weight: 700;
    flex-shrink: 0;
}

.alert { padding: 12px 16px; border-radius: 12px; font-size: 14px; border: 1px solid var(--border); }
.alert-info { background: var(--info-soft); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--info-soft); color: var(--text); border: 1px solid var(--border); }

/* Lizenz */
.license-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.license-head .badge { margin-left: 8px; vertical-align: middle; }
.license-card { display: flex; flex-direction: column; gap: 16px; padding: 22px 24px; }
.license-facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; font-size: 14px; }
.license-facts dt { color: var(--text-muted); }
.license-facts dd { margin: 0; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.license-notice a { font-weight: 600; margin-left: 6px; }
.license-dialog { width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: 16px;
    background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.license-dialog::backdrop { background: rgba(0, 0, 0, .35); }
.license-dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.license-dialog-head h2 { margin: 0; font-size: 17px; }
.license-dialog-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.license-dialog-body .alert { margin: 6px 0 0; }
.license-dialog-foot { padding: 12px 20px 18px; display: flex; justify-content: flex-end; }
.license-reach { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); margin-bottom: 4px; }
.license-reach div { display: flex; flex-direction: column; gap: 2px; }
.status-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; margin-top: 3px; }
.status-dot.is-ok { background: #1f9d55; box-shadow: 0 0 0 4px rgba(31, 157, 85, .18); }
.status-dot.is-bad { background: #d93025; box-shadow: 0 0 0 4px rgba(217, 48, 37, .18); }
.status-dot.is-wait { background: var(--border); animation: dot-pulse 1s ease-in-out infinite alternate; }
@keyframes dot-pulse { to { opacity: .35; } }
.settings-test { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.settings-test[hidden] { display: none; }
.settings-test div { display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.field-label { font-size: 14px; font-weight: 600; }
.yesno { display: inline-flex; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); align-self: flex-start; }
.yesno label { display: inline-flex; align-items: center; gap: 6px; padding: 6px 16px; border-radius: 9px; font-weight: 500; cursor: pointer; }
.yesno label:has(input:checked) { background: var(--surface); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); font-weight: 600; }
.yesno input { accent-color: var(--primary); }
.settings-state { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.link-button { border: 0; background: none; padding: 0; color: var(--primary); font: inherit; text-decoration: underline; cursor: pointer; }
.license-row { display: flex; justify-content: space-between; gap: 16px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.license-row:last-of-type { border-bottom: 0; }
.license-row strong { text-align: right; }
.license-row.is-over strong { color: var(--danger); }
@media (max-width: 600px) { .license-facts { grid-template-columns: 1fr; } .license-facts dd { margin-bottom: 6px; } }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover { text-decoration: none; background: var(--primary-hover); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; justify-content: center; padding: 11px 14px; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Formulare */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-card { padding: 22px; }
.form-grid { display: grid; gap: 16px 22px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.form-section { margin: 12px 0 0; padding-top: 18px; border-top: 1px solid var(--border); font-size: 15px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 14px; font-weight: 600; }
.field input:not([type="checkbox"]), .field select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2); color: var(--text);
    font: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.field input:disabled, .field select:disabled { opacity: .65; cursor: not-allowed; }
.field-check { justify-content: center; }
.field-check label { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.field-check input { width: 18px; height: 18px; accent-color: var(--primary); }
.field-hint { color: var(--text-muted); font-size: 13px; }
.field-error { color: var(--danger); font-size: 13px; font-weight: 500; }
.has-error input, .has-error select { border-color: var(--danger) !important; }

.danger-zone { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; }
.danger-zone p { margin: 2px 0 0; font-size: 14px; }
.count-left { margin-left: 0; margin-right: auto; }

/* Berechtigungen */
.perm-form { display: flex; flex-direction: column; gap: 16px; }
.perm-checks { display: grid; gap: 6px 18px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.perm-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; min-width: 0; }
.perm-check input { width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }
.perm-check small { margin-left: auto; padding-left: 6px; white-space: nowrap; }
.perm-check input:disabled + span { color: var(--text-muted); }
.perm-hint { margin: 0; font-size: 13px; }
.perm-area { overflow: visible; }
.perm-area-head {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    padding: 16px 22px; cursor: pointer; list-style: none;
}
.perm-area-head::-webkit-details-marker { display: none; }
.perm-area-head::before { content: "▸"; color: var(--text-muted); margin-right: -4px; transition: transform .15s; }
.perm-area[open] > .perm-area-head::before { transform: rotate(90deg); }
.perm-area-head strong { margin-right: auto; }
.perm-area-body { padding: 0 22px 20px; display: flex; flex-direction: column; gap: 14px; border-top: 1px solid var(--border); padding-top: 16px; }
.perm-search { max-width: 360px; }
.perm-group { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px 12px; margin: 0; }
.perm-group legend { padding: 0 6px; }
.perm-group-toggle { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.perm-fields { display: grid; gap: 4px 18px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); margin-top: 6px; }
.perm-field small { font-size: 11px; }
.perm-summary { white-space: normal !important; font-size: 14px; }
.perm-actions { position: sticky; bottom: 0; padding: 12px 0; background: var(--bg); }

/* Benutzer in der Kopfzeile */
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.rep-badge { white-space: nowrap; cursor: help; }
.user-menu form { margin: 0; }
.user-chip { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; color: var(--text); font-weight: 500; font-size: 14px; }
.user-chip:hover { background: var(--surface); text-decoration: none; }
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }

/* Anmeldeseite */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-box { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px; }
.brand-center { justify-content: center; padding: 0 0 8px; margin: 0; border-bottom: 0; }
.brand-center .brand-logo { height: 56px; }
.brand-center .brand-name { font-size: 20px; padding-bottom: 5px; }
.auth-card { padding: 28px; }
.auth-card .form { margin-top: 18px; }
.auth-card .alert { margin-top: 14px; }
.auth-title { margin: 0; font-size: 21px; }
.auth-card > p { margin: 6px 0 0; font-size: 14px; }
.auth-cancel { margin: 14px 0 0; text-align: center; font-size: 14px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 16px 0; color: var(--text-muted); font-size: 13px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.btn-sso { gap: 10px; border: 1px solid var(--border); background: var(--surface); }
.btn-sso svg { width: 18px; height: 18px; flex: none; }
.auth-card > p.auth-help { margin-top: 16px; font-size: 13px; text-align: center; }
.auth-box:has(.totp-qr) { max-width: 460px; }

/* Zwei-Faktor-Anmeldung */
.totp-input { font-size: 22px !important; letter-spacing: 6px; text-align: center; font-variant-numeric: tabular-nums; }
.field-check-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; }
.field-check-inline input { width: 18px; height: 18px; accent-color: var(--primary); }
.totp-steps { margin: 14px 0 0; padding-left: 22px; font-size: 14px; display: flex; flex-direction: column; gap: 6px; }
.totp-qr { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin: 14px 0 4px; }
.totp-qr-code { width: 180px; flex: none; padding: 6px; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.totp-qr-code svg { display: block; width: 100%; height: auto; } /* immer schwarz auf weiß – auch im dunklen Design scannbar */
.totp-qr-alt { flex: 1 1 180px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.totp-secret { font: 600 15px/1.5 ui-monospace, Consolas, monospace; letter-spacing: 1px; word-break: break-all; padding: 8px 10px;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; user-select: all; }
.form-heading { margin: 0; font-size: 18px; display: flex; align-items: center; gap: 10px; }
.totp-confirm { max-width: 320px; }
.totp-box .badge { margin-left: 8px; }

.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.empty { padding: 32px 22px; margin: 0; text-align: center; color: var(--text-muted); }

/* Mini-Liste (Dashboard) */
.mini-list { list-style: none; margin: 0; padding: 6px 0; }
.mini-list li { display: flex; align-items: center; gap: 12px; padding: 10px 22px; }
.mini-list li + li { border-top: 1px solid var(--border); }
.mini-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.mini-main small { color: var(--text-muted); }

/* Toolbar + Suche */
.toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 16px 22px;
    border-bottom: 1px solid var(--border);
}
.search { position: relative; flex: 1 1 260px; max-width: 420px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 18px; height: 18px; }
.search input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface-2); color: var(--text);
    font: inherit;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.count { color: var(--text-muted); font-size: 14px; margin-left: auto; }

/* Tabelle */
.table-wrap { overflow-x: auto; }

/* Große Listen: eigener Scrollbereich in Bildschirmhöhe – die horizontale Scrollleiste ist so
   immer sichtbar (nicht erst am Ende von 250 Zeilen), Kopfzeilen und Hauptspalte bleiben stehen. */
.table-scroll {
    overflow: auto;
    max-height: max(320px, calc(100vh - 230px));
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.table-scroll > .table { border-collapse: separate; border-spacing: 0; } /* nötig für saubere Rahmen bei "sticky" */
.table-scroll > .table > thead { position: sticky; top: 0; z-index: 3; }
.table-scroll > .table > thead th { box-shadow: inset 0 -1px 0 var(--border); }
.table-scroll > .table > tbody > tr > .col-primary,
.table-scroll > .table > thead > tr > .col-primary {
    position: sticky; left: 0; z-index: 1;
    background: var(--surface);
    box-shadow: inset -1px 0 0 var(--border);
}
.table-scroll > .table > thead > tr > .col-primary { z-index: 4; background: var(--surface-2); box-shadow: inset -1px -1px 0 var(--border); }
.table-scroll > .table > tbody > tr:hover > .col-primary,
.table-scroll > .table > tbody > tr.is-open > .col-primary { background: var(--surface-2); }
/* Gruppenüberschrift bleibt beim seitlichen Scrollen links sichtbar */
.table-scroll .group-toggle { position: sticky; left: 0; width: auto; display: inline-flex; }
/* Scrollleisten dezent, aber gut greifbar */
.table-scroll::-webkit-scrollbar { width: 12px; height: 12px; }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 3px solid var(--surface); }
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.table-scroll::-webkit-scrollbar-corner { background: var(--surface); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 22px; text-align: left; white-space: nowrap; }
.table thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted);
}
.table tbody tr + tr td { border-top: 1px solid var(--border); }
.table tbody tr:hover { background: var(--surface-2); }
.name-cell { display: inline-flex; align-items: center; gap: 10px; }
a.name-cell { color: inherit; }
a.name-cell:hover strong { color: var(--primary); text-decoration: underline; }
.row-link { cursor: pointer; }

/* Kundendetail */
.back-link { align-self: flex-start; font-weight: 500; font-size: 14px; }
.customer-head { display: flex; align-items: center; gap: 16px; padding: 20px 22px; }
.customer-head-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.customer-name { font-size: 18px; overflow-wrap: anywhere; }
.customer-contact { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 2px; font-size: 14px; }
.customer-contact-item { display: inline-flex; align-items: center; gap: 6px; min-width: 0; overflow-wrap: anywhere; }
.customer-contact-item svg { width: 16px; height: 16px; color: var(--text-muted); }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }

/* Anrufer-Suche (?page=anruf) */
.call-head { display: flex; align-items: center; gap: 16px; padding: 18px 22px; flex-wrap: wrap; }
.call-head > div { display: flex; flex-direction: column; flex: 1; min-width: 180px; }
.call-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: var(--success-soft); color: var(--success); }
.call-icon svg { width: 24px; height: 24px; fill: currentColor; }
.call-number { font-size: 24px; letter-spacing: .02em; }
.call-search { display: flex; gap: 8px; }
.call-search input { width: 200px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
    color: var(--text); font: inherit; outline: none; }
.call-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.call-hit { display: flex; align-items: flex-start; gap: 16px; padding: 20px 22px; }
.call-hit-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.call-hit-main .badge { align-self: flex-start; }
.call-facts { display: flex; flex-wrap: wrap; gap: 6px 24px; margin: 6px 0 2px; }
.call-facts dt { font-size: 12px; color: var(--text-muted); }
.call-facts dd { margin: 0; }
.call-actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
@media (max-width: 760px) {
    .call-hit { flex-wrap: wrap; }
    .call-actions { width: 100%; }
    .call-search, .call-search input { width: 100%; }
}

.tabs {
    display: flex; gap: 4px;
    padding: 0 14px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.tab {
    all: unset;
    cursor: pointer;
    padding: 14px 12px 12px;
    font-weight: 500; font-size: 14px;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
.tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -4px; border-radius: 6px; }

.tab-count {
    display: inline-block; min-width: 20px;
    margin-left: 4px; padding: 0 6px;
    border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: 12px; text-align: center; color: var(--text-muted);
}
.tab[aria-selected="true"] .tab-count { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.tab-alert { padding: 18px 22px; }

.contacts {
    list-style: none; margin: 0; padding: 18px 22px;
    display: grid; gap: 16px;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}
.contact { border: 1px solid var(--border); border-radius: 12px; padding: 16px; background: var(--surface-2); }
.contact-head { display: flex; align-items: center; gap: 12px; }
.contact-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.contact-lines {
    margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--border);
    display: grid; grid-template-columns: auto 1fr; gap: 6px 14px;
    font-size: 14px;
}
.contact-lines dt { color: var(--text-muted); }
.contact-lines dd { margin: 0; overflow-wrap: anywhere; }
.badge-plain { text-transform: none; }

/* Filterzeile & Gruppierung ------------------------------------------------ */
.table thead tr.filter-row th {
    padding: 6px 10px 8px;
    background: var(--surface-2);
    text-transform: none; letter-spacing: 0;
    border-bottom: 1px solid var(--border);
}
.col-filter {
    width: 100%; min-width: 60px;
    padding: 5px 8px;
    border: 1px solid var(--border); border-radius: 7px;
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 13px; font-weight: 400;
    outline: none;
}
.col-filter:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.col-filter.is-active { border-color: var(--primary); background: var(--primary-soft); }
.group-select { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.group-select select {
    padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); color: var(--text); font: inherit; outline: none;
}
.group-select select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.table tbody tr.group-row > th {
    padding: 0;
    background: var(--primary-soft);
    border-top: 1px solid var(--border);
    text-align: left;
}
.table tbody tr.group-row:hover { background: transparent; }
.group-toggle {
    all: unset; box-sizing: border-box; cursor: pointer;
    display: flex; align-items: center; gap: 6px; width: 100%;
    padding: 9px 22px;
    font-size: 13px; color: var(--text-muted); font-weight: 500;
}
.group-toggle strong { color: var(--text); }
.group-toggle::before { content: "▾"; width: 12px; color: var(--text-muted); transition: transform .15s; }
.group-toggle[aria-expanded="false"]::before { transform: rotate(-90deg); }
.group-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.group-count {
    margin-left: 4px; padding: 0 8px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: 12px; color: var(--text-muted);
}

/* Konfigurierbare Spalten ------------------------------------------------- */
.table thead th, .rev-table thead th { position: relative; }
table.is-fixed { table-layout: fixed; }
table.is-fixed th, table.is-fixed td { overflow: hidden; text-overflow: ellipsis; }
table.is-fixed .name-cell { max-width: 100%; min-width: 0; }
table.is-fixed .name-cell strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.col-resizer {
    position: absolute; top: 0; right: 0;
    width: 10px; height: 100%;
    cursor: col-resize;
    touch-action: none;
    z-index: 1;
}
.col-resizer::after {
    content: "";
    position: absolute; top: 25%; bottom: 25%; right: 4px;
    width: 2px; border-radius: 1px;
    background: var(--primary);
    opacity: 0; transition: opacity .15s;
}
thead th:hover .col-resizer::after, .col-resizer:hover::after { opacity: .5; }
.is-resizing, .is-resizing * { cursor: col-resize !important; user-select: none; }
.is-resizing .col-resizer::after { opacity: 1; }

.col-picker { position: relative; display: flex; flex-wrap: wrap; gap: 8px; }
.btn:disabled { opacity: .45; cursor: default; filter: none; }
/* Offenes Spalten-Fenster nicht von der Karte abschneiden lassen (z. B. bei kurzen Listen) */
.card:has(.col-picker-panel:not([hidden])) { overflow: visible; }
.col-picker-panel {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 25;
    width: 320px; max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .18);
}
.col-picker-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.col-picker-status { font-size: 12px; color: var(--success); }
.col-picker-status.is-error { color: var(--danger); }
.col-picker-search { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px 4px; font-size: 12px; }
.col-picker-search input {
    width: 100%; padding: 7px 10px;
    border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); color: var(--text); font: inherit; font-size: 14px; outline: none;
}
.col-picker-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.col-group { margin-left: auto; padding-left: 6px; font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.details-group {
    margin: 0; padding: 16px 22px 8px;
    font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted);
}
.details-group:not(:first-child) { border-top: 1px solid var(--border); margin-top: -1px; }
.col-picker-list { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow-y: auto; }
.col-picker-list li {
    display: flex; align-items: center; gap: 6px;
    padding: 4px 6px; border-radius: 8px;
    background: var(--surface);
}
.col-picker-list li:hover { background: var(--surface-2); }
.col-picker-list li.is-dragging { opacity: .5; outline: 2px dashed var(--primary); }
.col-picker-list label { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; padding: 4px 0; }
.col-picker-list input { width: 16px; height: 16px; accent-color: var(--primary); flex-shrink: 0; }
.col-picker-list input:disabled + span { color: var(--text-muted); }
.drag-handle { cursor: grab; color: var(--text-muted); padding: 0 2px; user-select: none; }
.move-btn {
    width: 28px; height: 28px;
    display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: 7px;
    background: var(--surface); color: var(--text);
    cursor: pointer; font-size: 13px;
}
.move-btn:disabled { opacity: .35; cursor: default; }
.move-btn:not(:disabled):hover { border-color: var(--primary); color: var(--primary); }
.move-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.col-picker-foot {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 14px 12px; border-top: 1px solid var(--border);
}
.col-picker-foot small { font-size: 12px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 8px; }
.panel-toolbar { display: flex; justify-content: flex-end; padding: 14px 22px 0; }

/* Aktivitäten */
.activities { transition: opacity .15s; }
.activities.is-loading { opacity: .5; pointer-events: none; }
.activities .empty.is-error, .act-history .is-error { color: var(--danger); }
.act-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.act-toolbar .count { margin-left: auto; }
.act-form { margin: 16px 22px 4px; padding: 16px 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
    display: flex; flex-direction: column; gap: 14px; }
.act-form-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.act-types { display: flex; flex-wrap: wrap; gap: 6px; }
.act-type input { position: absolute; opacity: 0; pointer-events: none; }
.act-type span {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px;
    border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
    font-size: 14px; cursor: pointer; user-select: none;
}
.act-type input:checked + span { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.act-type input:focus-visible + span { box-shadow: 0 0 0 3px var(--focus-ring); }
.field-wide { grid-column: 1 / -1; }
.field textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
    background: var(--surface); color: var(--text); font: inherit; resize: vertical; outline: none;
}
.field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.act-form .field input:not([type="checkbox"]), .act-form .field select { background: var(--surface); }
.act-followup { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 22px; }
.act-followup-fields { display: flex; flex-wrap: wrap; gap: 12px 18px; }
.act-followup-fields .field { min-width: 220px; }
.act-timeline { list-style: none; margin: 0; padding: 8px 22px 18px; }
.act-month { margin: 14px 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.act-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.act-month + .act-item { border-top: 0; }
.act-icon {
    width: 34px; height: 34px; flex-shrink: 0; display: grid; place-items: center;
    border-radius: 50%; background: var(--primary-soft); font-size: 16px;
}
.act-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.act-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.act-subject { overflow-wrap: anywhere; }
.act-meta { font-size: 13px; }
.act-text { font-size: 14px; overflow-wrap: anywhere; padding: 6px 0 2px; }
.act-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.act-actions .btn-sm { padding: 3px 9px; font-size: 12px; }
.act-delete:hover { background: var(--danger-soft); color: var(--danger); }
.act-due { font-size: 13px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.act-due.is-overdue { color: var(--danger); background: var(--danger-soft); border-color: transparent; font-weight: 600; }
.act-due.is-today { color: var(--text); border-color: var(--primary); font-weight: 600; }
.act-due.is-done { color: var(--success); background: var(--success-soft); border-color: transparent; }
.act-item.is-done .act-subject { color: var(--text-muted); }
.act-history { margin: 6px 0 0; padding: 8px 12px; list-style: none; font-size: 13px; background: var(--surface-2); border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
.customer-next-task { display: inline-block; margin-top: 4px; font-size: 14px; color: var(--text); text-decoration: none; }
.customer-next-task:hover { text-decoration: underline; }
.customer-next-task.is-overdue { color: var(--danger); font-weight: 600; }
.text-danger { color: var(--danger) !important; }
.task-list li { gap: 10px; }
.task-list .act-icon { width: 30px; height: 30px; font-size: 14px; }

/* Anhänge & Mail-Ansicht */
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.link-label { all: unset; color: var(--primary); text-decoration: underline; cursor: pointer; }
.link-label:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }
.act-attach { display: flex; flex-direction: column; gap: 8px; }
.act-drop {
    display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px;
    padding: 14px 16px; border: 2px dashed var(--border); border-radius: 12px;
    background: var(--surface); font-size: 14px; transition: border-color .15s, background .15s;
}
.act-drop small { flex-basis: 100%; }
.act-drop-icon { font-size: 20px; }
.act-drop:focus-within { border-color: var(--primary); }
.activities.is-dragover .act-drop, .activities.is-dragover .act-form { border-color: var(--primary); background: var(--primary-soft); }
.activities.is-dragover { outline: 2px dashed var(--primary); outline-offset: -6px; border-radius: 12px; }
.act-drop-hint { margin: 0; font-size: 13px; }
.act-files { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.act-files li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.act-files a, .act-files .link-label { overflow-wrap: anywhere; }
.act-file-dl { text-decoration: none; color: var(--text-muted); }
.act-file-dl:hover { color: var(--primary); }
.act-files-edit:empty { display: none; }
.act-files-edit li { padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }

.mail-viewer {
    width: min(960px, calc(100vw - 32px)); height: min(88vh, 900px); padding: 0;
    border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.mail-viewer[open] { display: flex; flex-direction: column; }
.mail-viewer::backdrop { background: rgba(0, 0, 0, .45); }
.mail-close { position: absolute; top: 12px; right: 12px; }
.mail-head { padding: 18px 60px 12px 22px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 3px; font-size: 14px; }
.mail-subject { margin: 0 0 6px; font-size: 18px; overflow-wrap: anywhere; }
.mail-row { display: grid; grid-template-columns: 60px 1fr; gap: 8px; overflow-wrap: anywhere; }
.mail-note { margin: 8px 0 0; font-size: 13px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.mail-frame { flex: 1; width: 100%; border: 0; background: #fff; min-height: 200px; }
.mail-foot { padding: 12px 22px 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; align-items: flex-start; max-height: 30%; overflow: auto; }
.mail-embedded { white-space: pre-wrap; font: inherit; font-size: 13px; margin: 6px 0 0; padding: 8px; background: var(--surface-2); border-radius: 8px; }
.is-error { color: var(--danger); }

/* Kundenbelege */
.documents { transition: opacity .15s; }
.documents.is-loading { opacity: .5; pointer-events: none; }
.documents .empty.is-error { color: var(--danger); }
.doc-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    padding: 14px 22px; border-bottom: 1px solid var(--border);
}
.doc-toolbar .count { margin-left: auto; }
.doc-filter { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.doc-filter select {
    padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
    background: var(--surface-2); color: var(--text); font: inherit; outline: none;
}
.doc-filter select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--focus-ring); }
.doc-row.is-expandable { cursor: pointer; }
.doc-row.is-open > td { background: var(--surface-2); }
.doc-toggle {
    all: unset; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
    font-weight: 500; white-space: nowrap;
}
.doc-toggle::before { content: "▸"; color: var(--text-muted); transition: transform .15s; }
.doc-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.doc-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.table .doc-positions > td { padding: 0 22px 14px; background: var(--surface-2); white-space: normal; border-top: 0; }
.pos-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.table .pos-table th, .table .pos-table td { padding: 7px 12px; text-align: left; vertical-align: top; white-space: normal; }
.table .pos-table tbody tr:hover { background: transparent; }
.table .pos-table .num { text-align: right; white-space: nowrap; }
.table .pos-table thead th {
    background: transparent; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.pos-table tbody tr + tr td { border-top: 1px solid var(--border); }
/* Positionsarten: Gruppe (Überschrift), Text, Summe; Einrückung nach Gliederungsebene */
.table .pos-table td[data-col="text"], .table .pos-table td.pos-span { padding-left: calc(12px + var(--pos-level, 0) * 22px); }
.table .pos-table .pos-group td { background: var(--surface-2); }
.pos-group .pos-no { color: var(--text-muted); margin-right: 8px; font-variant-numeric: tabular-nums; }
.pos-span small { display: block; }
.pos-longtext { margin-top: 2px; color: var(--text); line-height: 1.45; }
.pos-text .pos-longtext { color: var(--text-muted); }
.table .pos-table .pos-sum td { font-weight: 700; border-top: 1px solid var(--text-muted); }
.pos-sum-label { color: var(--text); }
.doc-note { margin: 0; padding: 10px 22px 0; font-size: 13px; }
.doc-filtered { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px 22px 18px; border-top: 1px solid var(--border); font-size: 14px; }

/* Karte */
.map-box { padding: 18px 22px 20px; display: flex; flex-direction: column; gap: 12px; }
.map-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.map-head > div:first-child { display: flex; flex-direction: column; }
.map-links { display: flex; flex-wrap: wrap; gap: 8px; }
.map {
    height: 440px;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface-2);
    position: relative; z-index: 0; isolation: isolate; /* Leaflet-Ebenen nicht über Kopfzeile/Seitenleiste */
    overflow: hidden;
}
.map .leaflet-popup-content { font: inherit; font-size: 14px; color: #262526; }
.map-status { margin: 0; font-size: 13px; }
.map-status.is-error { color: var(--danger); }
@media (max-width: 720px) { .map { height: 320px; } }

/* Umsätze */
.stats-inline { padding: 18px 22px 4px; }
.stats-inline .stat-card { box-shadow: none; background: var(--surface-2); }
.stat-value-sm { font-size: 20px; }
.rev-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.rev-table th, .rev-table td { padding: 10px 22px; text-align: left; white-space: nowrap; }
.rev-table .num { text-align: right; }
.rev-table thead th {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--text-muted);
}
.rev-table tbody tr + tr > * { border-top: 1px solid var(--border); }
.rev-table tbody th { font-weight: 500; }
.rev-period > * { background: var(--surface-2); font-size: 14px; }
.rev-period th { padding-left: 46px; color: var(--text-muted); }
.rev-table tfoot > tr > * { border-top: 2px solid var(--border); font-weight: 700; }
.rev-toggle {
    all: unset; cursor: pointer;
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 600;
}
.rev-toggle::before { content: "▸"; color: var(--text-muted); width: 12px; transition: transform .15s; }
.rev-toggle[aria-expanded="true"]::before { transform: rotate(90deg); }
.rev-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }
.rev-note { margin: 0; padding: 12px 22px 18px; font-size: 13px; }

.details { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.details-row { padding: 14px 22px; border-bottom: 1px solid var(--border); }
.details dt { color: var(--text-muted); font-size: 13px; font-weight: 500; }
.details dd { margin: 2px 0 0; overflow-wrap: anywhere; }

.sort-btn {
    all: unset;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px;
}
.sort-btn::after { content: "↕"; opacity: .35; font-size: 11px; }
.sort-btn[data-dir="asc"]::after { content: "↑"; opacity: 1; }
.sort-btn[data-dir="desc"]::after { content: "↓"; opacity: 1; }
.sort-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 4px; }

/* Responsive -------------------------------------------------------------- */

/* Mittlere Bildschirme: kompaktere Tabellen, damit mehr Spalten ohne Scrollen passen */
@media (max-width: 1280px) {
    .table th, .table td { padding: 10px 14px; }
    .group-toggle { padding: 8px 14px; }
    .toolbar, .doc-toolbar { padding: 12px 16px; }
}

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .main { margin-left: 0; }
    .menu-btn { display: grid; }
    .topbar-logo { display: block; }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .backdrop { display: block; }
    .topbar { padding: 12px 16px; }
    .page-title { font-size: 18px; }
    .act-due { white-space: normal; }
    .user-chip-name { display: none; }
    .user-chip { padding: 4px; }
    .rep-badge-label { display: none; }
    .content { padding: 20px 16px 40px; }
}

/* Tabelle wird auf kleinen Displays zu Karten */
@media (max-width: 720px) {
    .table thead { display: none; }
    .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
    .table tbody tr { padding: 14px 18px; }
    .table tbody tr + tr td { border-top: 0; }
    .table tbody tr + tr { border-top: 1px solid var(--border); }
    .table td {
        display: flex; justify-content: space-between; align-items: center; gap: 12px;
        padding: 5px 0;
        white-space: normal;
        text-align: right;
    }
    .table td::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-size: 13px;
        text-align: left;
    }
    /* Positionen eines Belegs in der Kartenansicht als eigener Block */
    .table .doc-positions > td { display: block; padding: 0 0 6px; }
    .table .doc-positions > td::before { display: none; }
    .table .pos-table thead { display: none; }
    .table .pos-table, .table .pos-table tbody, .table .pos-table tr, .table .pos-table td { display: block; width: 100%; }
    .table .pos-table tbody tr { padding: 8px 10px; }
    .table .pos-table td { padding: 1px 0; text-align: left !important; }
    .table .pos-table td[data-col="text"], .table .pos-table td.pos-span { padding-left: calc(var(--pos-level, 0) * 14px); }
    .table .pos-table .pos-sum td:empty { display: none; }
    .table .pos-table td::before { display: none; }
    .doc-toolbar .count { margin-left: 0; }
    /* Kartenansicht: kein eigener Scrollbereich, nichts "klebt" */
    .table-scroll { max-height: none; overflow: visible; scrollbar-gutter: auto; }
    .table-scroll > .table > tbody > tr > .col-primary { position: static; box-shadow: none; background: transparent; }
    .table-scroll .group-toggle { position: static; width: 100%; display: flex; }
    .table tbody tr.group-row { padding: 0; }
    .table tbody tr.group-row > th { display: block; }
    .group-toggle { padding: 9px 18px; }
    .table .col-primary { padding-bottom: 10px; }
    .table .col-primary::before { display: none; }
    /* Gespeicherte Spaltenbreiten gelten nur in der Tabellenansicht, nicht für Karten */
    .table.is-fixed { width: 100% !important; table-layout: auto; }
    .table.is-fixed td { overflow: visible; }
    .col-resizer { display: none; }
    .col-picker-panel { position: fixed; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; }
    .count { margin-left: 0; }
    .stat-value { font-size: 26px; }
}
