/* ── Variables ────────────────────────────────────────────────────── */
:root {
    --sb-w:  240px;
    --sb-wc:  64px;
    --tb-h:   52px;
}

/* ── Base ─────────────────────────────────────────────────────────── */
body {
    background-color: #f1f5f9;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    color: #1e293b;
    font-size: .925rem;
    margin-left: var(--sb-w);
    padding-top: calc(var(--tb-h) + 1.5rem);
    transition: margin-left .22s ease;
}
body.sb-collapsed {
    margin-left: var(--sb-wc);
}

/* ── Sidebar ──────────────────────────────────────────────────────── */
.crm-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sb-w);
    background: #0f172a;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    overflow: hidden;
    transition: width .22s ease;
    box-shadow: 2px 0 8px rgba(0,0,0,.18);
}
body.sb-collapsed .crm-sidebar {
    width: var(--sb-wc);
}

/* Brand */
.sb-brand {
    display: flex;
    align-items: center;
    height: var(--tb-h);
    padding: 0 1rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
    flex-shrink: 0;
}
.sb-brand-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
}
.sb-logo {
    width: auto;
    flex-shrink: 0;
}
.sb-logo-full {
    height: 28px;
    display: block;
}
.sb-logo-icon {
    height: 32px;
    display: none;
}
body.sb-collapsed .sb-logo-full { display: none; }
body.sb-collapsed .sb-logo-icon { display: block; }

/* Nav links */
.sb-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: .5rem 0;
}
.sb-nav::-webkit-scrollbar { width: 3px; }
.sb-nav::-webkit-scrollbar-track { background: transparent; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.sb-link {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .6rem 1rem;
    margin: .1rem .5rem;
    border-radius: .5rem;
    color: rgba(255,255,255,.62);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background .14s, color .14s;
    overflow: hidden;
}
.sb-link:hover {
    background: rgba(255,255,255,.08);
    color: #fff;
}
.sb-link.active {
    background: rgba(255,255,255,.13);
    color: #fff;
}
.sb-icon {
    font-size: 1.05rem;
    flex-shrink: 0;
    width: 1.25rem;
    text-align: center;
}
.sb-label {
    opacity: 1;
    transition: opacity .12s ease;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.sb-collapsed .sb-label {
    opacity: 0;
    pointer-events: none;
}

/* Nav group (collapsible parent) */
.sb-group-toggle {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .6rem 1rem;
    margin: .1rem .5rem;
    border-radius: .5rem;
    color: rgba(255,255,255,.62);
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background .14s, color .14s;
    overflow: hidden;
    background: none;
    border: none;
    width: calc(100% - 1rem);
    text-align: left;
}
.sb-group-toggle:hover { background: rgba(255,255,255,.08); color: #fff; }
.sb-group-toggle.active { background: rgba(255,255,255,.13); color: #fff; }
.sb-group-toggle .sb-group-arrow {
    margin-left: auto;
    flex-shrink: 0;
    font-size: .7rem;
    opacity: .5;
    transition: transform .18s;
}
.sb-group.open .sb-group-arrow { transform: rotate(90deg); }

.sb-group-children {
    overflow: hidden;
    max-height: 0;
    transition: max-height .22s ease;
}
.sb-group.open .sb-group-children { max-height: 400px; }

.sb-child-link {
    padding-left: 2.7rem !important;
    font-size: .82rem !important;
    opacity: .9;
}

/* In collapsed sidebar: hide children, show toggle icon only */
body.sb-collapsed .sb-group-children { max-height: 0 !important; }
body.sb-collapsed .sb-group-arrow { display: none; }

/* Footer / logout */
.sb-footer {
    flex-shrink: 0;
    padding: .35rem 0 .5rem;
    border-top: 1px solid rgba(255,255,255,.07);
}
.sb-logout:hover {
    background: rgba(220,38,38,.18) !important;
    color: #fca5a5 !important;
}

/* ── Topbar ───────────────────────────────────────────────────────── */
.crm-topbar {
    position: fixed;
    top: 0;
    left: var(--sb-w);
    right: 0;
    height: var(--tb-h);
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem 0 1rem;
    z-index: 1030;
    transition: left .22s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
body.sb-collapsed .crm-topbar {
    left: var(--sb-wc);
}

.tb-toggle {
    background: none;
    border: none;
    padding: .3rem .45rem;
    border-radius: .4rem;
    color: #64748b;
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .14s, color .14s;
}
.tb-toggle:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* Topbar-Suche */
.tb-search {
    flex: 1;
    max-width: 400px;
}
.tb-search-inner {
    position: relative;
    display: flex;
    align-items: center;
}
.tb-search-icon {
    position: absolute;
    left: .65rem;
    color: #94a3b8;
    font-size: .85rem;
    pointer-events: none;
}
.tb-search input {
    width: 100%;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    color: #1e293b;
    font-size: .875rem;
    padding: .38rem .75rem .38rem 2.1rem;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.tb-search input::placeholder { color: #94a3b8; }
.tb-search input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
    background: #fff;
}
.tb-search-clear {
    position: absolute;
    right: .5rem;
    color: #94a3b8;
    font-size: 1.05rem;
    line-height: 1;
    text-decoration: none;
}
.tb-search-clear:hover { color: #374151; }

/* ── Topbar Timer Widget ──────────────────────────────────────────── */
.tb-timer-btn {
    display: flex;
    align-items: center;
    gap: .45rem;
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: .5rem;
    padding: .28rem .75rem;
    font-size: .875rem;
    color: #475569;
    cursor: pointer;
    line-height: 1.4;
    white-space: nowrap;
    transition: background .14s, border-color .14s, color .14s;
}
.tb-timer-btn:hover,
.tb-timer-btn.show {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
}
.tb-timer-btn.running {
    border-color: #fca5a5;
    background: #fff5f5;
    color: #dc2626;
}
.tb-timer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    flex-shrink: 0;
    animation: tbTimerPulse 1.4s infinite;
}
@keyframes tbTimerPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .45; transform: scale(.8); }
}
.tb-timer-val {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    letter-spacing: .01em;
    min-width: 4.2rem;
}
.tb-timer-proj {
    color: #64748b;
    font-weight: 400;
    max-width: 130px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-left: 1px solid #e2e8f0;
    padding-left: .45rem;
    margin-left: .1rem;
}
.tb-timer-dropdown {
    min-width: 290px;
    padding: 0;
    border-radius: .65rem;
    border: 1px solid #e2e8f0;
    box-shadow: 0 6px 20px rgba(0,0,0,.11);
    overflow: hidden;
}
.tb-timer-section {
    padding: .65rem 1rem;
}
.tb-timer-section + .tb-timer-section {
    border-top: 1px solid #f1f5f9;
}
.tb-timer-recent-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem 1rem;
    transition: background .12s;
}
.tb-timer-recent-row:hover { background: #f8fafc; }
.tb-timer-recent-row + .tb-timer-recent-row {
    border-top: 1px solid #f1f5f9;
}
.tb-timer-footer {
    padding: .5rem 1rem;
    border-top: 1px solid #f1f5f9;
    background: #f8fafc;
}

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
    border: 1px solid #e2e8f0;
    border-radius: .75rem;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
    background: #fff;
}

.card-header-label {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: #94a3b8;
    padding: .85rem 1.25rem .5rem;
    border-bottom: 1px solid #f1f5f9;
}

/* ── Stat cards (dashboard) ───────────────────────────────────────── */
.stat-card {
    border-radius: .75rem;
    padding: 1.1rem 1.3rem;
    color: #fff;
    border: none;
}
.stat-card .stat-val {
    font-size: 2.1rem;
    font-weight: 800;
    line-height: 1;
}
.stat-card .stat-lbl {
    font-size: .8rem;
    opacity: .85;
    margin-top: .25rem;
}

/* ── Table ────────────────────────────────────────────────────────── */
.crm-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}
.crm-table thead th {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #64748b;
    background: #f8fafc;
    padding: .65rem .9rem;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}
.crm-table tbody td {
    padding: .7rem .9rem;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
}
.crm-table tbody tr:last-child td { border-bottom: none; }
.crm-table tbody tr:hover td { background-color: #f8fbff; }
.crm-table tbody tr.row-overdue td { background-color: #fff5f5; }
.crm-table tbody tr.row-overdue:hover td { background-color: #ffe8e8; }
.crm-table tbody tr.row-overdue td:first-child { border-left: 3px solid #dc2626; }

/* ── Form ─────────────────────────────────────────────────────────── */
.form-label {
    font-size: .82rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: .3rem;
}
.form-hint {
    font-size: .75rem;
    color: #94a3b8;
    margin-top: .2rem;
}
.form-control, .form-select {
    border-color: #d1d5db;
    border-radius: .5rem;
    font-size: .9rem;
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Rating buttons ───────────────────────────────────────────────── */
.rating-group .btn {
    min-width: 2.4rem;
    font-weight: 600;
    font-size: .85rem;
}

/* ── Kundenkategorie summary box ──────────────────────────────────── */
.kat-summary {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .9rem 1.1rem;
    border-radius: .65rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    margin-bottom: 1.5rem;
}
.kat-summary .kat-badge {
    font-size: 1.4rem;
    font-weight: 800;
    width: 2.8rem;
    height: 2.8rem;
    border-radius: .5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #fff;
}
.kat-summary .kat-info strong { font-size: .95rem; }
.kat-summary .kat-info small  { color: #64748b; font-size: .8rem; }

/* ── Login ────────────────────────────────────────────────────────── */
html.login-page,
html.login-page body {
    height: 100%;
    margin: 0;
    padding: 0;
}
.login-wrap {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
}
.login-card {
    width: 380px;
    border-radius: 1rem;
    border: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
    background: #fff;
    padding: 2.25rem 2rem;
}

/* ── Sortierbare Spaltenköpfe ─────────────────────────────────────── */
th.sortable {
    cursor: pointer;
    user-select: none;
}
th.sortable:hover { background: #eef2f7; }
th.sortable .sort-icon {
    font-size: .65rem;
    color: #94a3b8;
    margin-left: .25rem;
    vertical-align: middle;
}
th.sortable .bi-arrow-up,
th.sortable .bi-arrow-down { color: #2563eb; }

/* ── Tabellen-Live-Filter ─────────────────────────────────────────── */
#filter-row th {
    background: #f1f5f9;
    padding: .4rem .5rem;
    border-bottom: 2px solid #e2e8f0;
}
#filter-row .col-filter {
    font-size: .78rem;
    border-radius: .4rem;
    border-color: #d1d5db;
    background: #fff;
    min-width: 60px;
}
#filter-row .col-filter:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,.1);
}
/* ── Multi-Select Dropdown (Filter-Zeile) ─────────────────────────── */
.ms-dropdown {
    position: relative;
}
.ms-btn {
    width: 100%;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: .78rem;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .5rem center;
    background-size: 12px;
    padding-right: 1.6rem;
}
.ms-menu {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    z-index: 1050;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: .45rem;
    box-shadow: 0 6px 18px rgba(0,0,0,.12);
    min-width: 100%;
    white-space: nowrap;
    display: none;
    padding: .3rem 0;
}
.ms-menu.open { display: block; }
.ms-option {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .8rem;
    font-size: .82rem;
    font-weight: 400;
    color: #374151;
    cursor: pointer;
    margin: 0;
}
.ms-option:hover { background: #f1f5f9; }
.ms-option input[type="checkbox"] { margin: 0; cursor: pointer; }
.ms-count { color: #94a3b8; font-size: .75rem; margin-left: auto; padding-left: .5rem; }

/* ── Verlauf-Panel (rechte Spalte in customer_edit) ──────────────── */
.verlauf-panel {
    position: sticky;
    top: calc(var(--tb-h) + 1rem);
}

.verlauf-scroll {
    max-height: calc(100vh - 280px);
    overflow-y: auto;
    padding-right: 2px;
}

.verlauf-scroll::-webkit-scrollbar {
    width: 4px;
}
.verlauf-scroll::-webkit-scrollbar-track { background: transparent; }
.verlauf-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ── Timeline ─────────────────────────────────────────────────────── */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-item {
    display: flex;
    gap: .85rem;
    position: relative;
    padding-bottom: 1.1rem;
}
.timeline-item:not(:last-child)::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 16px;
    bottom: 0;
    width: 2px;
    background: #e2e8f0;
}
.timeline-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #2563eb;
    flex-shrink: 0;
    margin-top: 5px;
    position: relative;
    z-index: 1;
}
.timeline-body { flex: 1; }
.timeline-meta {
    font-size: .76rem;
    color: #94a3b8;
    margin-bottom: .3rem;
}
.timeline-text {
    background: #f8fafc;
    border: 1px solid #e8edf2;
    border-radius: .5rem;
    padding: .55rem .85rem;
    font-size: .875rem;
    white-space: pre-wrap;
    color: #374151;
    line-height: 1.5;
}

/* ── Custom Select (crm-select) ───────────────────────────────────── */
.crm-sel {
    position: relative;
    display: block;
}
.crm-sel-trigger {
    display: flex;
    align-items: center;
    gap: .45rem;
    width: 100%;
    padding: .375rem 2.25rem .375rem .75rem;
    font-size: .925rem;
    font-weight: 400;
    line-height: 1.5;
    color: #1e293b;
    background-color: #fff;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 16px 12px;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.crm-sel-trigger:focus,
.crm-sel-trigger[aria-expanded="true"] {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 .25rem rgba(13,110,253,.25);
}
.crm-sel-sm .crm-sel-trigger {
    padding: .25rem 2.25rem .25rem .5rem;
    font-size: .875rem;
    border-radius: .25rem;
}
.crm-sel-lbl {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.crm-sel-arrow { display: none; } /* arrow via background-image on trigger */

.crm-sel-dropdown {
    position: absolute;
    top: calc(100% + 3px);
    left: 0;
    right: 0;
    z-index: 1055;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: .375rem;
    box-shadow: 0 6px 20px rgba(0,0,0,.12);
    overflow: hidden;
}
.crm-sel-search {
    display: block;
    width: 100%;
    padding: .45rem .65rem;
    font-size: .875rem;
    border: none;
    border-bottom: 1px solid #e2e8f0;
    border-radius: 0;
    outline: none;
    background: #f8fafc;
}
.crm-sel-search:focus { background: #fff; }
.crm-sel-list {
    max-height: 240px;
    overflow-y: auto;
    padding: .25rem 0;
}
.crm-sel-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .35rem .75rem;
    font-size: .9rem;
    cursor: pointer;
    color: #1e293b;
    transition: background .1s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.crm-sel-item:hover  { background: #f1f5f9; }
.crm-sel-item.active { background: #e0eaff; font-weight: 500; }
.crm-sel-empty {
    padding: .5rem .75rem;
    font-size: .875rem;
    color: #94a3b8;
    font-style: italic;
}
.crm-sel-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0,0,0,.12);
}
