:root {
    /* Design Tokens */
    --bg: #fafaf9;
    --surface: #ffffff;
    --surface-2: #f5f5f4;
    --border: #e7e5e4;
    --border-strong: #d6d3d1;
    --text: #1c1917;
    --text-muted: #78716c;
    --text-subtle: #a8a29e;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #ea580c;
    --danger: #dc2626;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
    --shadow: 0 1px 3px rgba(0,0,0,.05), 0 1px 2px rgba(0,0,0,.03);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.08), 0 4px 8px rgba(0,0,0,.04);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    background-image:
        radial-gradient(at 20% 0%, rgba(79,70,229,.05) 0px, transparent 50%),
        radial-gradient(at 80% 100%, rgba(79,70,229,.04) 0px, transparent 50%);
    background-attachment: fixed;
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* App Shell - zentriert */
.app-shell {
    max-width: 1400px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
    width: 40px; height: 40px;
    border-radius: var(--radius);
    background: var(--text);
    color: #fff;
    display: grid; place-items: center;
}
.brand h1 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.brand p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}
.stats-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    box-shadow: var(--shadow-sm);
}
.stats-pill .dot {
    width: 6px; height: 6px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 3px var(--success-soft);
}

/* Grid Layout */
.app-grid {
    display: grid;
    grid-template-columns: minmax(340px, 420px) 1fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .app-grid { grid-template-columns: 1fr; }
    .app-shell { padding: 20px 16px; }
}

/* Panel */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel-head {
    padding: 18px 20px 14px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}
.panel-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}
.panel-head h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}
.panel-head p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

/* Search */
.search-wrap {
    position: relative;
    display: flex;
    align-items: center;
}
.search-wrap svg {
    position: absolute;
    left: 10px;
    color: var(--text-subtle);
    pointer-events: none;
}
.search-wrap input {
    padding: 7px 12px 7px 32px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: inherit;
    background: var(--surface-2);
    width: 180px;
    transition: all .15s ease;
}
.search-wrap input:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* Toolbar */
.table-toolbar {
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.check-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 500;
}
.selection-info {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

/* Leads List */
.leads-list {
    max-height: 62vh;
    overflow-y: auto;
}
.lead-item {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s ease;
}
.lead-item:last-child { border-bottom: 0; }
.lead-item:hover { background: var(--surface-2); }
.lead-item.active {
    background: var(--primary-soft);
    box-shadow: inset 3px 0 0 var(--primary);
}
.lead-item.hidden { display: none; }

.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: grid; place-items: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.lead-info { min-width: 0; }
.lead-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.lead-sub {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.sep { margin: 0 6px; color: var(--text-subtle); }
.email-text { font-family: var(--font-mono); font-size: 11px; }

/* Status Badges */
.status-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.status-neu { background: #dbeafe; color: #1e40af; }
.status-kontaktiert { background: #fef3c7; color: #92400e; }
.status-qualifiziert { background: #ddd6fe; color: #5b21b6; }
.status-angebot { background: #fed7aa; color: #9a3412; }

/* Checkbox */
input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 16px; height: 16px;
    border: 1.5px solid var(--border-strong);
    border-radius: 4px;
    cursor: pointer;
    transition: all .12s ease;
    position: relative;
    background: var(--surface);
    flex-shrink: 0;
}
input[type="checkbox"]:hover { border-color: var(--primary); }
input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}
input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px; top: 1px;
    width: 5px; height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-soft);
}

/* Placeholder Chips */
.placeholder-bar {
    padding: 12px 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.chip {
    font-family: var(--font-mono);
    font-size: 11px;
    padding: 4px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    color: var(--text);
    cursor: pointer;
    transition: all .12s ease;
}
.chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}
.chip-brace { color: var(--primary); font-weight: 600; }

/* Field Labels */
.field-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 14px 20px 6px;
    margin: 0;
}
.field-label-body {
    padding-top: 14px;
    border-top: 1px solid var(--border);
    margin-top: 2px;
}

/* Subject Input */
.subject-wrap { background: var(--surface); }
.subject-row {
    display: flex;
    align-items: stretch;
    padding: 0 20px 14px;
    gap: 8px;
}
.subject-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    background: var(--surface-2);
    outline: none;
    transition: all .12s ease;
}
.subject-input:focus {
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.btn-sm-icon {
    padding: 8px 10px;
    display: grid;
    place-items: center;
}

/* Textarea */
.template-input {
    width: 100%;
    padding: 8px 20px 16px;
    border: 0;
    background: var(--surface);
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
    resize: vertical;
    outline: none;
    border-bottom: 1px solid var(--border);
    min-height: 200px;
}
.template-input:focus {
    background: #fafaf9;
}

/* Preview */
.preview-wrap { padding: 20px; }
.preview-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.recipient-line {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
    font-family: var(--font-mono);
}
.recipient-line strong {
    color: var(--text);
    font-weight: 500;
}

.preview-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    min-height: 240px;
}
.preview-subject-row {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding-bottom: 12px;
    margin-bottom: 12px;
    border-bottom: 1px dashed var(--border-strong);
}
.preview-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}
.preview-subject {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
}
.preview-body {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.65;
    color: var(--text);
    white-space: pre-wrap;
    margin: 0;
}
.preview-body.preview-empty {
    color: var(--text-subtle);
    font-family: var(--font-sans);
    text-align: center;
    padding: 40px 0;
}

/* Buttons */
.btn-group-custom { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-primary, .btn-ghost {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all .12s ease;
    border: 1px solid transparent;
    white-space: nowrap;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79,70,229,.3);
}
.btn-ghost {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
    background: var(--surface-2);
    border-color: var(--border-strong);
}
.btn-primary:disabled, .btn-ghost:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.btn-primary:focus-visible, .btn-ghost:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.count-badge {
    background: rgba(255,255,255,.25);
    padding: 1px 6px;
    border-radius: 100px;
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    margin-left: 2px;
}

.status-line {
    font-size: 12px;
    margin-top: 10px;
    min-height: 16px;
    font-weight: 500;
}
.status-line.success { color: var(--success); }
.status-line.error { color: var(--danger); }

/* Modal */
.modal-content {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.modal-header, .modal-footer {
    border-color: var(--border);
    padding: 16px 20px;
}
.modal-title { font-size: 15px; font-weight: 600; }

.bulk-mail-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: hidden;
}
.bulk-mail-head {
    padding: 10px 14px;
    background: var(--surface-2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.bulk-mail-meta { font-size: 12px; }
.bulk-mail-meta strong { font-weight: 600; }
.bulk-mail-meta .to {
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-left: 8px;
    font-size: 11px;
}
.bulk-mail-actions { display: flex; gap: 6px; }
.bulk-mail-subject {
    padding: 10px 14px;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.bulk-mail-subject strong {
    color: var(--text-muted);
    font-weight: 600;
    margin-right: 6px;
}
.bulk-mail-body {
    padding: 14px;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 0;
    color: var(--text);
}

/* Scrollbar */
.leads-list::-webkit-scrollbar { width: 8px; }
.leads-list::-webkit-scrollbar-track { background: transparent; }
.leads-list::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}
.leads-list::-webkit-scrollbar-thumb:hover { background: var(--text-subtle); }