:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --border: #e2e5ea;
    --text: #1a1d23;
    --muted: #6b7280;
    --primary: #1f6feb;
    --primary-hover: #1957c7;
    --danger: #b4232c;
    --success: #137a3e;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------------- header ---------------- */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.brand { font-size: 15px; }
.user { display: flex; gap: 14px; align-items: center; }
.link { color: var(--primary); }

/* ---------------- layout ---------------- */
.app-main {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 20px;
    padding: 20px;
    min-height: calc(100vh - 56px);
}
.sidebar {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 14px;
    align-self: start;
}
.sidebar h3 {
    margin: 0 0 10px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.form-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    font: inherit;
}
.form-btn:hover { background: #f0f3f8; }
.form-btn.active { background: #e6efff; color: var(--primary); font-weight: 600; }

.content {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    box-shadow: var(--shadow);
}

/* ---------------- toolbar ---------------- */
.toolbar {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
}
.filters, .actions { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.filters .grow { flex: 1 1 200px; }
.filters input[type="date"], .filters input[type="search"] {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    color: var(--text);
    background: white;
}

.btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }
.btn-secondary { background: white; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #f5f7fb; }

.status { min-height: 18px; font-size: 12px; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

/* ---------------- table ---------------- */
.table-wrap { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th, td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    background: #fbfcfd;
    position: sticky;
    top: 0;
}
td.num { color: var(--muted); width: 32px; }
.source-badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    background: #e8eefc;
    color: var(--primary);
}
.source-badge.manual { background: #f1e9d9; color: #8a5a00; }
.source-badge.form   { background: #dcfce7; color: #137a3e; }
.empty-leads { text-align: center; padding: 40px; color: var(--muted); }
.actions-cell { width: 32px; text-align: right; }
.btn-delete {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.btn-delete:hover { background: #fde8ea; color: var(--danger); }
.btn-delete:disabled { opacity: 0.4; cursor: wait; }

.btn-archive, .btn-restore {
    border: 0;
    background: transparent;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}
.btn-archive { color: var(--danger); }
.btn-archive:hover { background: #fde8ea; color: #8a1a1a; }
.btn-restore { color: var(--success); }
.btn-restore:hover { background: #dcfce7; color: #0a5a2a; }
.btn-archive:disabled, .btn-restore:disabled { opacity: 0.4; cursor: wait; }

.btn-edit-lead {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    margin-right: 2px;
}
.btn-edit-lead:hover { background: #e8eefc; color: var(--primary); }

#edit-dialog h4 {
    margin: 14px 0 6px 0;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
#edit-dialog .grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 0;
}
#edit-dialog { max-width: 560px; width: 95vw; max-height: 90vh; overflow-y: auto; }
@media (max-width: 540px) {
    #edit-dialog .grid-2 { grid-template-columns: 1fr; }
}

.note-cell { max-width: 240px; }
.note-text {
    cursor: text;
    display: inline-block;
    min-width: 60px;
    padding: 2px 4px;
    border-radius: 4px;
    color: var(--text);
}
.note-text:hover { background: #f1f5f9; }
.note-edit {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--primary);
    border-radius: 4px;
    font: inherit;
    color: var(--text);
    background: white;
}

.toggle-archived {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
    padding: 0 8px;
    cursor: pointer;
    user-select: none;
}
.toggle-archived input { width: 14px; height: 14px; cursor: pointer; }

.email-cell { white-space: nowrap; text-align: center; }
.email-sent {
    color: var(--success);
    font-weight: 600;
    margin-right: 4px;
}
.btn-send {
    border: 1px solid var(--primary);
    background: white;
    color: var(--primary);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
}
.btn-send:hover { background: var(--primary); color: white; }
.btn-resend {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 22px;
    height: 22px;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}
.btn-resend:hover { background: #e8eefc; color: var(--primary); }
.btn-send:disabled, .btn-resend:disabled { opacity: 0.5; cursor: wait; }

.whatsapp-cell { text-align: center; white-space: nowrap; }
.btn-whatsapp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    text-decoration: none;
    background: transparent;
    color: #25D366; /* WhatsApp green */
}
.btn-whatsapp:hover {
    background: #d9fdd3;
    text-decoration: none;
    color: #128C7E;
}

.icon-th {
    text-align: center;
    color: var(--muted);
}
.icon-th.wa {
    color: #25D366;
}
.icon-th svg {
    vertical-align: middle;
    display: inline-block;
}

.btn-edit, .btn-delete-user {
    border: 0;
    background: transparent;
    color: var(--muted);
    width: 26px;
    height: 26px;
    border-radius: 6px;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    margin-left: 2px;
}
.btn-edit:hover { background: #e8eefc; color: var(--primary); }
.btn-delete-user:hover { background: #fde8ea; color: var(--danger); }

.role-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 11px;
    background: #e2e8f0;
    color: #334155;
}
.role-badge.admin { background: #dcfce7; color: #137a3e; }

.app-main.single { grid-template-columns: 1fr; }

dialog .checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 14px;
}
dialog .checkbox input {
    width: 16px;
    height: 16px;
}

/* ---------------- login ---------------- */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
    padding: 32px;
    text-align: center;
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px 0; font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin: 20px 0 12px; text-align: left; }
.login-card label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.login-card input {
    padding: 9px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    color: var(--text);
}
.login-card button { margin-top: 6px; padding: 10px; justify-content: center; }
.login-card .g_id_signin { margin: 24px auto 16px; display: inline-block; }
.error {
    background: #fde8ea;
    color: var(--danger);
    padding: 10px;
    border-radius: 6px;
    margin: 12px 0;
    font-size: 13px;
    text-align: left;
}

/* ---------------- dialog ---------------- */
dialog {
    border: 0;
    border-radius: 12px;
    padding: 24px;
    min-width: 340px;
    box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.35); }
dialog h3 { margin: 0 0 16px 0; }
dialog label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: var(--muted);
    gap: 3px;
    margin-bottom: 10px;
}
dialog input, dialog textarea {
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    color: var(--text);
}
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 8px;
}

.empty-state {
    background: var(--surface);
    grid-column: 1 / -1;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 32px;
    text-align: center;
}
.empty-state code {
    background: #f2f4f8;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

/* ---------------- selection / reminder mail ---------------- */
.select-th, .select-cell {
    width: 36px;
    text-align: center;
}
.select-th input,
.select-cell input.lead-select {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}
#btn-reminder { gap: 6px; }
#btn-reminder.hidden { display: none !important; }

/* Desktop: header checkbox is the source of truth for "select all".
   The toolbar mobile toggle stays hidden. */
.select-all-mobile { display: none; }

/* ---------------- header hamburger (desktop hidden) ---------------- */
.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
}
.menu-toggle:hover { background: #f0f3f8; }
.menu-toggle span {
    display: block;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform 0.2s, opacity 0.2s;
}
body.nav-open .menu-toggle span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
body.nav-open .menu-toggle span:nth-child(2) { opacity: 0; }
body.nav-open .menu-toggle span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* ---------------- mobile sticky action bar (hidden on desktop) ---------------- */
.action-bar-mobile { display: none; }

/* ---------------- responsive ---------------- */

/* ============== TABLET (≤ 900px) ============== */
@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 5;
        padding: 8px 10px;
    }
    .sidebar h3 { display: none; }
    .sidebar ul {
        flex-direction: row;
        overflow-x: auto;
        gap: 6px;
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }
    .form-btn {
        white-space: nowrap;
        padding: 8px 14px;
        border-radius: 999px;
        background: #f0f3f8;
    }
    .form-btn.active {
        background: var(--primary);
        color: white;
    }
    .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
    .filters, .actions { width: 100%; }
    .filters .grow { flex: 1 1 100%; }
}

/* ============== PHONE (≤ 640px) ============== */
@media (max-width: 640px) {
    /* --- header: brand + hamburger inline, links collapse --- */
    .app-header {
        padding: 8px 14px;
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
        flex-wrap: nowrap;
        gap: 8px;
        position: relative;
        z-index: 30;
    }
    .brand {
        font-size: 14px;
        flex: 1 1 auto;
        min-width: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .brand .muted { display: none; }

    /* hamburger appears */
    .menu-toggle { display: flex; flex: 0 0 auto; }

    /* user nav collapses into a slide-down panel */
    .user {
        position: absolute;
        top: 100%;
        right: 8px;
        left: 8px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 12px;
        box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 6px;
        margin-top: 6px;
        opacity: 0;
        transform: translateY(-8px);
        pointer-events: none;
        transition: opacity 0.18s, transform 0.18s;
    }
    body.nav-open .user {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
    .user .link {
        display: block;
        padding: 12px 14px;
        border-radius: 8px;
        font-size: 15px;
        min-height: 44px;
        line-height: 20px;
    }
    .user .link:hover { background: #f0f3f8; text-decoration: none; }
    .user .user-name {
        padding: 8px 14px 10px;
        font-size: 12px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 4px;
        order: -1; /* show name at top of dropdown */
    }

    .app-main { padding: 10px; gap: 10px; }
    .content { padding: 12px; }
    .content > h2 { font-size: 17px; }

    /* --- filters: compact + full-width --- */
    .filters { gap: 8px; }
    .filters label { font-size: 11px; flex: 1 1 calc(50% - 4px); }
    .filters .grow { flex: 1 1 100%; }
    .filters input[type="date"],
    .filters input[type="search"],
    .filters select {
        width: 100%;
        font-size: 16px; /* prevents iOS auto-zoom on focus */
        padding: 10px 12px;
        min-height: 44px;
    }
    .filters select { -webkit-appearance: none; appearance: none;
        background: white url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%236b7280' d='M0 0l6 8 6-8z'/></svg>") right 10px center/12px no-repeat;
        padding-right: 32px;
    }

    /* --- actions: full-width primary buttons --- */
    .actions {
        gap: 8px;
        flex-wrap: wrap;
    }
    .actions .btn,
    .filters .btn {
        flex: 1 1 calc(50% - 4px);
        min-height: 44px;
        justify-content: center;
        font-size: 14px;
    }
    .actions #btn-pdf { flex-basis: 100%; }
    .toggle-archived {
        flex: 1 1 100%;
        justify-content: center;
        padding: 8px;
        background: #f0f3f8;
        border-radius: 6px;
        min-height: 44px;
    }

    /* --- TABLES → CARDS --- */
    .table-wrap { overflow-x: visible; }
    table, tbody, tr { display: block; width: 100%; }
    thead { display: none; }
    tr {
        margin-bottom: 10px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        padding: 10px 12px;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    }
    td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        padding: 6px 0;
        border-bottom: 1px solid #f0f3f8;
        text-align: right;
        min-height: 32px;
        font-size: 13px;
    }
    td:last-child { border-bottom: 0; }
    td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--muted);
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        text-align: left;
        font-weight: 500;
    }
    /* Cells without a meaningful label collapse the pseudo */
    td[data-label=""]::before { content: none; }

    /* The "Name" cell becomes a card header — full width, big, no label */
    #leads-table td[data-label="Name"],
    #users-table td[data-label="Name"],
    #forms-table td[data-label="Bezeichnung"] {
        font-size: 16px;
        font-weight: 600;
        text-align: left;
        padding-bottom: 8px;
        margin-bottom: 4px;
        border-bottom: 1px solid var(--border);
        display: block;
    }
    #leads-table td[data-label="Name"]::before,
    #users-table td[data-label="Name"]::before,
    #forms-table td[data-label="Bezeichnung"]::before { display: none; }
    #leads-table td[data-label="Name"] .muted { font-weight: 400; }

    /* Hide noisy index column on phones */
    #leads-table td.num,
    #forms-table td.num { display: none; }

    /* Note cell: stack label/value vertically since notes can be long */
    .note-cell { flex-wrap: wrap; }
    .note-cell .note-text { text-align: left; flex: 1 1 100%; max-width: 100%; }
    .note-edit { width: 100%; }

    /* Source / Email-status / WhatsApp: keep value tight on the right */
    .email-cell, .whatsapp-cell { justify-content: space-between; }
    .source-badge { padding: 2px 10px; }

    /* Actions row: span the full card width and center the buttons. */
    .actions-cell {
        justify-content: flex-end;
        gap: 6px;
        padding-top: 10px !important;
        margin-top: 4px;
        border-top: 1px solid var(--border);
        border-bottom: 0;
    }
    .actions-cell::before { display: none; }

    /* --- bigger touch targets for icon buttons --- */
    .btn-edit, .btn-delete, .btn-delete-user, .btn-delete-form,
    .btn-archive, .btn-restore, .btn-edit-lead,
    .btn-share, .btn-copy, .btn-qr, .btn-unlock-user,
    .btn-resend, .btn-send {
        width: 40px; height: 40px;
        font-size: 16px;
    }
    .btn-whatsapp { width: 40px; height: 40px; }

    /* --- dialogs become bottom sheets --- */
    dialog {
        max-width: 100vw;
        width: 100vw;
        max-height: 92vh;
        margin: auto auto 0 auto;
        border-radius: 16px 16px 0 0;
        padding: 18px 16px max(20px, env(safe-area-inset-bottom)) 16px;
        animation: sheet-in 0.22s ease-out;
    }
    dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
    @keyframes sheet-in {
        from { transform: translateY(100%); }
        to   { transform: translateY(0); }
    }
    /* Drag handle visual hint */
    dialog::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 2px;
        margin: -4px auto 12px;
    }
    dialog input, dialog textarea, dialog select {
        font-size: 16px; /* iOS no-zoom */
        padding: 10px 12px;
    }
    dialog .grid-2 { grid-template-columns: 1fr; }
    .dialog-actions {
        position: sticky;
        bottom: 0;
        background: var(--surface);
        margin: 12px -16px -8px;
        padding: 12px 16px;
        border-top: 1px solid var(--border);
        flex-direction: column-reverse;
        gap: 8px;
    }
    .dialog-actions .btn {
        width: 100%;
        min-height: 48px;
        justify-content: center;
    }

    /* Login card — keep it card-shaped, not full-screen */
    .login-card { padding: 24px 20px; border-radius: 12px; }

    /* Status messages get a touch more breathing room */
    .status { padding: 4px 0; font-size: 13px; }

    /* --- Sticky mobile action bar (index.php only) --- */
    .action-bar-mobile {
        display: flex;
        gap: 8px;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        z-index: 20;
        padding: 10px 12px;
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: saturate(160%) blur(10px);
        -webkit-backdrop-filter: saturate(160%) blur(10px);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 14px rgba(15, 23, 42, 0.06);
    }
    .action-bar-mobile.hidden { display: none; }
    .action-bar-btn {
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 48px;
        padding: 10px 14px;
        border-radius: 12px;
        border: 1px solid transparent;
        font: inherit;
        font-weight: 600;
        font-size: 15px;
        cursor: pointer;
        text-decoration: none;
    }
    .action-bar-btn:hover { text-decoration: none; }
    .action-bar-btn-primary { background: var(--primary); color: white; }
    .action-bar-btn-primary:hover { background: var(--primary-hover); }
    .action-bar-btn-secondary { background: white; color: var(--text); border-color: var(--border); }
    .action-bar-btn-secondary:hover { background: #f5f7fb; }
    .action-bar-icon { font-size: 18px; line-height: 1; }

    /* Add bottom padding to <main> so the sticky bar doesn't cover the last card */
    .app-main { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }

    /* Hide the desktop versions of these buttons on mobile (they're in the sticky bar) */
    #btn-add, #btn-pdf { display: none !important; }

    /* ============== EVENTBRITE-STYLE COMPACT CARDS ============== */
    /* By default each card shows only Name + E-Mail + Eingegangen-Datum.
       Tap the card to reveal phone, birthdate, note, source, status, actions. */

    /* Hide non-essential cells in the collapsed (default) state */
    #leads-table tr > td[data-label="Telefon"],
    #leads-table tr > td[data-label="Geburtsdatum"],
    #leads-table tr > td[data-label="Notiz"],
    #leads-table tr > td[data-label="Quelle"],
    #leads-table tr > td[data-label="E-Mail-Status"],
    #leads-table tr > td[data-label="WhatsApp"],
    #leads-table tr > td[data-label="Kurs"],
    #leads-table tr > td.actions-cell {
        display: none;
    }

    /* Compact styling for the three always-visible cells */
    #leads-table tr:not(.expanded) td[data-label="E-Mail"] {
        text-align: left;
        justify-content: flex-start;
        padding: 2px 0 0 0;
        border-bottom: 0;
        font-size: 13px;
        min-height: auto;
    }
    #leads-table tr:not(.expanded) td[data-label="E-Mail"]::before {
        display: none;
    }
    #leads-table tr:not(.expanded) td[data-label="E-Mail"] a {
        color: var(--primary);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
    }
    #leads-table tr:not(.expanded) td[data-label="Eingegangen"] {
        text-align: left;
        justify-content: flex-start;
        padding: 4px 0 0 0;
        border-bottom: 0;
        font-size: 12px;
        color: var(--muted);
        min-height: auto;
    }
    #leads-table tr:not(.expanded) td[data-label="Eingegangen"]::before {
        display: none;
    }

    /* The Name card-header keeps its big-bold treatment, but tighten spacing */
    #leads-table tr:not(.expanded) td[data-label="Name"] {
        padding-bottom: 4px;
        margin-bottom: 0;
        border-bottom: 0;
    }

    /* Whole card is tappable + chevron hint on the right */
    #leads-table tr {
        cursor: pointer;
        position: relative;
        padding-right: 36px;
        transition: padding 0.15s;
        -webkit-tap-highlight-color: rgba(31, 111, 235, 0.08);
    }
    #leads-table tr::after {
        content: '';
        position: absolute;
        top: 18px;
        right: 16px;
        width: 8px;
        height: 8px;
        border-right: 2px solid var(--muted);
        border-bottom: 2px solid var(--muted);
        transform: rotate(45deg);
        transition: transform 0.2s;
        pointer-events: none;
    }
    #leads-table tr.expanded::after {
        transform: rotate(-135deg);
        top: 22px;
    }

    /* Reveal cells when expanded */
    #leads-table tr.expanded > td[data-label="Telefon"],
    #leads-table tr.expanded > td[data-label="Geburtsdatum"],
    #leads-table tr.expanded > td[data-label="Notiz"],
    #leads-table tr.expanded > td[data-label="Quelle"],
    #leads-table tr.expanded > td[data-label="E-Mail-Status"],
    #leads-table tr.expanded > td[data-label="WhatsApp"],
    #leads-table tr.expanded > td[data-label="Kurs"],
    #leads-table tr.expanded > td.actions-cell {
        display: flex;
    }

    /* Subtle "tap to see more" affordance: a thin line below the visible
       summary when collapsed, indicating there's more to discover */
    #leads-table tr:not(.expanded) {
        padding-bottom: 14px;
    }

    /* Slightly lighter shadow when expanded to suggest "lifted" state */
    #leads-table tr.expanded {
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08);
        border-color: #cdd6e4;
    }

    /* === Selection checkbox positioning on mobile cards === */
    /* The .select-cell is rendered as a normal td in markup; on mobile we
       lift it out of the flex flow and pin it to the top-left of the card.
       Tap target is the larger surrounding area, not just the 16px square. */
    #leads-table tr {
        padding-left: 44px;
    }
    #leads-table tr > td.select-cell {
        position: absolute;
        top: 0;
        left: 0;
        width: 40px;
        height: 100%;
        min-height: 44px;
        padding: 14px 0 0 14px !important;
        margin: 0;
        border: 0;
        display: flex;
        align-items: flex-start;
        justify-content: flex-start;
    }
    #leads-table tr > td.select-cell::before { display: none; }
    #leads-table tr > td.select-cell input.lead-select {
        width: 20px;
        height: 20px;
        accent-color: var(--primary);
    }

    /* The mobile "Alle" toggle in the toolbar */
    .select-all-mobile { display: flex; }

    /* Reminder button — make it stand out a bit when selection > 0 */
    #btn-reminder {
        background: rgba(31, 111, 235, 0.08);
        color: var(--primary);
        border-color: rgba(31, 111, 235, 0.25);
    }
    #btn-reminder:hover { background: rgba(31, 111, 235, 0.16); }

    /* === Bearbeiten / Archivieren als ausgeschriebene Buttons === */
    /* Inside expanded lead cards, the tiny ✎ / 🗄 / ↩ icon buttons become
       full-text labeled pills, side-by-side. Text is pulled from the
       existing `title` attribute via ::after — no JS change needed. */

    /* The cell directly above the actions row would otherwise paint its own
       border-bottom right next to the actions-cell border-top — that double
       hairline read as a stray short stripe on devices where one of the
       two greys was anti-aliased differently. Drop the redundant border. */
    #leads-table tr.expanded > td:nth-last-child(2) {
        border-bottom: 0;
    }

    #leads-table .actions-cell {
        flex-direction: row;
        justify-content: stretch;
        gap: 8px;
        padding: 14px 0 4px 0 !important;
        margin-top: 0;
        border-top: 1px solid var(--border);
        border-bottom: 0;
    }
    #leads-table .actions-cell .btn-edit-lead,
    #leads-table .actions-cell .btn-archive,
    #leads-table .actions-cell .btn-restore {
        flex: 1;
        width: auto;
        height: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 0 14px;
        border: 1px solid var(--border);
        background: white;
        border-radius: 10px;
        font-size: 15px;
        font-weight: 500;
        color: var(--text);
        margin: 0;
    }
    #leads-table .actions-cell .btn-edit-lead::after,
    #leads-table .actions-cell .btn-archive::after,
    #leads-table .actions-cell .btn-restore::after {
        content: attr(title);
        font-size: 14px;
        font-weight: 500;
    }
    #leads-table .actions-cell .btn-edit-lead {
        color: var(--primary);
        border-color: rgba(31, 111, 235, 0.25);
        background: rgba(31, 111, 235, 0.06);
    }
    #leads-table .actions-cell .btn-edit-lead:hover,
    #leads-table .actions-cell .btn-edit-lead:active {
        background: rgba(31, 111, 235, 0.13);
    }
    #leads-table .actions-cell .btn-archive {
        color: var(--danger);
        border-color: rgba(180, 35, 44, 0.22);
        background: rgba(180, 35, 44, 0.05);
    }
    #leads-table .actions-cell .btn-archive:hover,
    #leads-table .actions-cell .btn-archive:active {
        background: rgba(180, 35, 44, 0.12);
    }
    #leads-table .actions-cell .btn-restore {
        color: var(--success);
        border-color: rgba(19, 122, 62, 0.25);
        background: rgba(19, 122, 62, 0.06);
    }
    #leads-table .actions-cell .btn-restore:hover,
    #leads-table .actions-cell .btn-restore:active {
        background: rgba(19, 122, 62, 0.13);
    }
}

/* ============== EXTRA NARROW (≤ 380px) ============== */
@media (max-width: 380px) {
    .filters label { flex: 1 1 100%; }
    .actions .btn, .filters .btn { flex-basis: 100%; }
}
