/* Datei: /assets/css/app.css */

:root {
    --bg: #f5f2ed;
    --panel: #fffaf3;
    --panel-strong: #f0e5d7;
    --text: #2f251d;
    --muted: #76685c;
    --line: #dacdbe;
    --accent: #0f8d5a;
    --accent-strong: #0b7047;
    --danger: #b42318;
    --warn: #a15c00;
    --ok: #147a43;
    --shadow: 0 12px 28px rgba(49, 39, 30, .09);
    --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

body { font-size: 14px; }

.topbar {
    max-width: 1480px;
    margin: 18px auto 0;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar h1, .login-box h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: -.02em;
}

.topbar p { margin: 3px 0 0; color: var(--muted); }

.wrap {
    max-width: 1480px;
    margin: 0 auto 40px;
    padding: 0 18px 30px;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin: 16px 0;
}

.panel h2 { margin: 0 0 10px; font-size: 18px; }
.panel.success { border-color: rgba(20, 122, 67, .3); }
.panel.error { border-color: rgba(180, 35, 24, .35); }

.muted { color: var(--muted); }

.btn {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 11px;
    padding: 8px 12px;
    min-height: 36px;
    background: var(--panel-strong);
    color: var(--text);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    font-weight: 600;
}

.btn:hover { filter: brightness(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; }

.alert {
    border-radius: 12px;
    padding: 10px 12px;
    margin: 10px 0;
    border: 1px solid var(--line);
}
.alert-error { background: #fff0ee; color: var(--danger); border-color: #efb5ad; }
.alert-warn { background: #fff5e5; color: var(--warn); border-color: #f1c37e; }

.upload-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    align-items: start;
}

.upload-card {
    display: grid;
    gap: 4px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px dashed #bea98f;
    background: #fffdf9;
}

.upload-card.required { border-style: solid; border-color: var(--accent); }
.upload-title {
    font-weight: 700;
    font-size: 14px;
    line-height: 1.15;
}
.upload-sub {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.15;
}
.upload-card input {
    width: 100%;
    font-size: 13px;
}
.upload-form .btn {
    justify-self: start;
    grid-column: 1 / -1;
    min-height: 34px;
    padding: 7px 12px;
    margin-top: 3px;
}

.section-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
}
.section-head h2 { margin: 0; }
.section-head p { margin: 4px 0 0; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}
.stat {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px;
    background: #fffdf9;
}
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); }

.table-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fffdf9;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th, td {
    padding: 8px 9px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
    white-space: nowrap;
}

th {
    background: var(--panel-strong);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

tr:last-child td { border-bottom: none; }

.small-table { max-width: 850px; }

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eee4d7;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}
.status-new { background: #e4f5eb; color: var(--ok); }
.status-exists { background: #ece7df; color: #61564b; }
.status-change { background: #fff0cc; color: #805300; }
.status-duplicate,
.status-duplicate_name { background: #ffe3d6; color: #974000; }
.status-conflict { background: #ffe9e7; color: var(--danger); }
.status-check { background: #fff0cc; color: #805300; }
.status-skipped { background: #ececec; color: #777; }
.badge.full { background: #ffe9e7; color: var(--danger); }
.badge.ok { background: #e4f5eb; color: var(--ok); }

.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.toolbar input,
.toolbar select,
.field input {
    min-height: 36px;
    border-radius: 10px;
    border: 1px solid var(--line);
    padding: 7px 10px;
    background: #fff;
    color: var(--text);
}

.export-bar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px;
    background: #fffdf9;
    border: 1px solid var(--line);
    border-radius: 14px;
    margin-bottom: 10px;
}

.contacts-table-wrap { max-height: 72vh; }
.contacts-table th { position: sticky; top: 0; z-index: 2; }
.contacts-table td small {
    display: block;
    color: var(--muted);
    margin-top: 3px;
    white-space: normal;
    max-width: 520px;
}
.contacts-table td:nth-child(9) { white-space: normal; min-width: 320px; }
.contacts-table tr.hidden { display: none; }

.downloads {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.download-card {
    display: grid;
    gap: 4px;
    padding: 13px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #fffdf9;
    color: var(--text);
    text-decoration: none;
}
.download-card span { color: var(--muted); font-size: 13px; }
.download-card:hover { border-color: var(--accent); }

.login-page {
    display: grid;
    place-items: center;
    padding: 20px;
}
.login-box {
    width: min(420px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 22px;
}
.field { display: grid; gap: 6px; margin: 14px 0; }
.field span { font-weight: 700; }
.field input { width: 100%; }

@media (max-width: 900px) {
    .upload-form, .stats-grid, .downloads { grid-template-columns: 1fr; }
    .section-head { flex-direction: column; }
    .topbar { align-items: flex-start; }
}

/* Kompakte Kontaktvorschau ohne horizontalen Scroll */
.contacts-table-wrap {
    overflow-x: hidden;
    max-height: 72vh;
}

.contacts-table {
    table-layout: fixed;
    width: 100%;
}

.contacts-table th,
.contacts-table td {
    padding: 5px 6px;
    line-height: 1.18;
    font-size: 13px;
    vertical-align: middle;
    white-space: normal;
    overflow: hidden;
    text-overflow: ellipsis;
    border-right: 1px solid var(--line);
}

.contacts-table th:last-child,
.contacts-table td:last-child {
    border-right: none;
}

.contacts-table th {
    font-size: 11px;
    letter-spacing: .025em;
}

.contacts-table th:nth-child(1),
.contacts-table td:nth-child(1) {
    width: 34px;
    text-align: center;
}

.contacts-table th:nth-child(2),
.contacts-table td:nth-child(2) {
    width: 146px;
}

.contacts-table th:nth-child(3),
.contacts-table td:nth-child(3) {
    width: 108px;
}

.contacts-table th:nth-child(4),
.contacts-table td:nth-child(4),
.contacts-table th:nth-child(5),
.contacts-table td:nth-child(5) {
    width: 14%;
}

.contacts-table th:nth-child(6),
.contacts-table td:nth-child(6) {
    width: 132px;
    white-space: nowrap;
}

.contacts-table th:nth-child(7),
.contacts-table td:nth-child(7) {
    width: 112px;
    white-space: nowrap;
}

.contacts-table th:nth-child(8),
.contacts-table td:nth-child(8) {
    width: 22%;
    white-space: nowrap;
}

.contacts-table th:nth-child(9),
.contacts-table td:nth-child(9) {
    width: auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-table td:nth-child(9) small {
    display: block;
    max-width: none;
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-table .badge {
    min-height: 20px;
    padding: 1px 7px;
    font-size: 11px;
}

.contacts-table input[type="checkbox"] {
    width: 15px;
    height: 15px;
}

.contacts-table td.cell-changed {
    background: #fff0cc;
    font-weight: 600;
}

.contacts-table td.cell-webmail-only {
    background: #f5efe7;
}

.contacts-table .value-sl {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-table .value-old {
    display: block;
    margin-top: 1px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1100px) {
    .contacts-table th,
    .contacts-table td {
        font-size: 12px;
        padding: 4px 5px;
    }

    .contacts-table th {
        font-size: 10px;
    }

    .contacts-table th:nth-child(2),
    .contacts-table td:nth-child(2) {
        width: 132px;
    }

    .contacts-table th:nth-child(3),
    .contacts-table td:nth-child(3) {
        width: 96px;
    }

    .contacts-table th:nth-child(6),
    .contacts-table td:nth-child(6) {
        width: 118px;
    }

    .contacts-table th:nth-child(7),
    .contacts-table td:nth-child(7) {
        width: 100px;
    }
}


.contacts-table .hint-main {
    vertical-align: middle;
}

.contacts-table .copy-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    margin-left: 5px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #fffdf9;
    color: var(--muted);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
    vertical-align: middle;
}

.contacts-table .copy-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.contacts-table .copy-btn.copied {
    border-color: var(--accent);
    background: #e4f5eb;
    color: var(--ok);
}


/* Kopierbutton nur bei handlungsrelevanten SL-Werten sauber sichtbar halten */
.contacts-table .value-sl {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.contacts-table .value-sl .value-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contacts-table .value-sl .copy-btn {
    flex: 0 0 auto;
    margin-left: 0;
}


/* Hinweiszeile: Text kurz halten, Adress-Kopierbutton sichtbar lassen */
.contacts-table .hint-line {
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.contacts-table .hint-line .hint-main {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.contacts-table .hint-line .copy-btn {
    flex: 0 0 auto;
    margin-left: 0;
}

/* Zusatzspalte hinter Festnetz: weitere/geschäftliche Telefonnummern */
.contacts-table th:nth-child(4),
.contacts-table td:nth-child(4),
.contacts-table th:nth-child(5),
.contacts-table td:nth-child(5) {
    width: 12.5%;
}

.contacts-table th:nth-child(6),
.contacts-table td:nth-child(6) {
    width: 124px;
    white-space: nowrap;
}

.contacts-table th:nth-child(7),
.contacts-table td:nth-child(7) {
    width: 108px;
    white-space: nowrap;
}

.contacts-table th:nth-child(8),
.contacts-table td:nth-child(8) {
    width: 118px;
    white-space: nowrap;
}

.contacts-table th:nth-child(9),
.contacts-table td:nth-child(9) {
    width: 20%;
    white-space: nowrap;
}

.contacts-table th:nth-child(10),
.contacts-table td:nth-child(10) {
    width: auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contacts-table td:nth-child(10) small {
    display: block;
    max-width: none;
    margin-top: 2px;
    font-size: 11px;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1100px) {
    .contacts-table th:nth-child(6),
    .contacts-table td:nth-child(6) {
        width: 112px;
    }

    .contacts-table th:nth-child(7),
    .contacts-table td:nth-child(7) {
        width: 96px;
    }

    .contacts-table th:nth-child(8),
    .contacts-table td:nth-child(8) {
        width: 104px;
    }
}


/* Tabellen-Feinschliff: schmalere Namen, Geschäftlich-Spalte, Sortierung, Hinweis-Modal */
.contacts-table th,
.contacts-table td {
    padding: 4px 6px;
    line-height: 1.15;
}

.contacts-table th:nth-child(1),
.contacts-table td:nth-child(1) {
    width: 34px;
}

.contacts-table th:nth-child(2),
.contacts-table td:nth-child(2) {
    width: 132px;
}

.contacts-table th:nth-child(3),
.contacts-table td:nth-child(3) {
    width: 90px;
}

.contacts-table th:nth-child(4),
.contacts-table td:nth-child(4) {
    width: 13%;
}

.contacts-table th:nth-child(5),
.contacts-table td:nth-child(5) {
    width: 12%;
}

.contacts-table th:nth-child(6),
.contacts-table td:nth-child(6) {
    width: 126px;
    white-space: nowrap;
}

.contacts-table th:nth-child(7),
.contacts-table td:nth-child(7) {
    width: 110px;
    white-space: nowrap;
}

.contacts-table th:nth-child(8),
.contacts-table td:nth-child(8) {
    width: 112px;
    white-space: nowrap;
}

.contacts-table th:nth-child(9),
.contacts-table td:nth-child(9) {
    width: 22%;
    white-space: nowrap;
}

.contacts-table th:nth-child(10),
.contacts-table td:nth-child(10) {
    width: auto;
    min-width: 0;
    white-space: nowrap;
}

.contacts-table .sort-btn {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .025em;
    padding: 0;
    width: 100%;
    text-align: left;
    cursor: pointer;
}

.contacts-table .sort-btn::after {
    content: '';
    display: inline-block;
    margin-left: 4px;
    color: var(--muted);
}

.contacts-table .sort-btn[data-sort-dir="asc"]::after {
    content: '▲';
}

.contacts-table .sort-btn[data-sort-dir="desc"]::after {
    content: '▼';
}

.contacts-table .hint-info-btn {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fffdf9;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.contacts-table .hint-info-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(34, 27, 21, .45);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-card {
    width: min(680px, 100%);
    max-height: min(78vh, 720px);
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel-strong);
}

.modal-close {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 9px;
    width: 30px;
    height: 30px;
    background: #fffdf9;
    color: var(--text);
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.modal-body {
    margin: 0;
    padding: 14px;
    max-height: calc(min(78vh, 720px) - 56px);
    overflow: auto;
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.35;
}

@media (max-width: 1100px) {
    .contacts-table th:nth-child(2),
    .contacts-table td:nth-child(2) {
        width: 124px;
    }

    .contacts-table th:nth-child(3),
    .contacts-table td:nth-child(3) {
        width: 84px;
    }

    .contacts-table th:nth-child(6),
    .contacts-table td:nth-child(6) {
        width: 116px;
    }

    .contacts-table th:nth-child(7),
    .contacts-table td:nth-child(7),
    .contacts-table th:nth-child(8),
    .contacts-table td:nth-child(8) {
        width: 98px;
    }
}


/* Hinweis-Modal: Details lesbarer */
.modal-body {
    tab-size: 2;
}


/* Spaltenkorrektur: E-Mail kompakter, Hinweis breiter */
.contacts-table th:nth-child(9),
.contacts-table td:nth-child(9) {
    width: 260px;
    max-width: 260px;
    white-space: nowrap;
}

.contacts-table th:nth-child(10),
.contacts-table td:nth-child(10) {
    width: auto;
    min-width: 260px;
    white-space: nowrap;
}

.contacts-table td:nth-child(9),
.contacts-table td:nth-child(10) {
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1100px) {
    .contacts-table th:nth-child(9),
    .contacts-table td:nth-child(9) {
        width: 220px;
        max-width: 220px;
    }

    .contacts-table th:nth-child(10),
    .contacts-table td:nth-child(10) {
        min-width: 220px;
    }
}


/* Startseite: Aktivitätsprüfung */
.activity-upload-form {
    grid-template-columns: minmax(280px, 520px);
}

.import-details summary {
    cursor: pointer;
    font-weight: 800;
    font-size: 17px;
    margin-bottom: 10px;
}

.activity-stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.activity-table-wrap {
    max-height: 76vh;
}

.activity-table th:nth-child(1),
.activity-table td:nth-child(1) { width: 112px; }

.activity-table th:nth-child(2),
.activity-table td:nth-child(2) { width: 13%; }

.activity-table th:nth-child(3),
.activity-table td:nth-child(3) { width: 12%; }

.activity-table th:nth-child(4),
.activity-table td:nth-child(4) { width: 112px; white-space: nowrap; }

.activity-table th:nth-child(5),
.activity-table td:nth-child(5) { width: 78px; white-space: nowrap; text-align: right; }

.activity-table th:nth-child(6),
.activity-table td:nth-child(6) { width: 92px; white-space: nowrap; text-align: right; }

.activity-table th:nth-child(7),
.activity-table td:nth-child(7) { width: 96px; white-space: nowrap; }

.activity-table th:nth-child(8),
.activity-table td:nth-child(8) { width: 24%; white-space: nowrap; }

.activity-table th:nth-child(9),
.activity-table td:nth-child(9) { width: auto; min-width: 220px; white-space: nowrap; }

.priority {
    display: inline-flex;
    align-items: center;
    min-height: 20px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    background: #ece7df;
    color: #61564b;
}

.priority-hoch {
    background: #ffe9e7;
    color: var(--danger);
}

.priority-mittel {
    background: #fff0cc;
    color: #805300;
}

.activity-status-active {
    background: #e4f5eb;
    color: var(--ok);
}

.activity-status-followup {
    background: #fff0cc;
    color: #805300;
}

.activity-status-inactive {
    background: #ffe3d6;
    color: #974000;
}

.activity-status-lost,
.activity-status-no_visit {
    background: #ffe9e7;
    color: var(--danger);
}

@media (max-width: 1100px) {
    .activity-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .activity-table th:nth-child(8),
    .activity-table td:nth-child(8) {
        width: 18%;
    }
}


/* Startseite: Kundenaktivität unter dem Import kompakter darstellen */
.activity-start-panel {
    margin-top: 12px;
}

.activity-start-panel .activity-upload-form {
    grid-template-columns: minmax(280px, 520px);
}
