/* Hauck CRM – Styling (Sidebar-Layout) */
:root {
    --blau:  #1f4e79;
    --grau:  #f4f6f8;
    --rand:  #d9dee3;
    --text:  #1d2733;
    --rot:   #c0392b;
    --gruen: #1e7e34;

    /* Sidebar */
    --csb-bg:      #2d5a8e;
    --csb-accent:  #93c5fd;
    --csb-hover:   rgba(255,255,255,.11);
    --csb-active:  rgba(147,197,253,.22);
    --csb-section: rgba(255,255,255,.55);
    --csb-w:       240px;
    --csb-wc:      58px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--grau);
    line-height: 1.5;
}

/* Sidebar-Anker: fester Platzhalter, wird von nav.js befüllt */
#crm-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--csb-w);
    z-index: 200;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.crm-sidebar {
    position: absolute;
    inset: 0;
    background: var(--csb-bg);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 2px 0 12px rgba(0,0,0,.18);
}

/* Brand header */
.csb-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    min-height: 64px;
    flex-shrink: 0;
}
.csb-logo {
    width: 34px; height: 34px;
    border-radius: 8px;
    background: var(--csb-accent);
    color: #fff;
    font-size: 1.1rem;
    font-weight: 800;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    letter-spacing: -.02em;
}
.csb-brand-text { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
.csb-brand-name { font-size: .88rem; font-weight: 700; color: #f1f5f9; line-height: 1.2; }
.csb-brand-sub  { font-size: .72rem; color: rgba(255,255,255,.45); margin-top: 1px; }
.crm-sidebar.collapsed .csb-brand-text { display: none; }
.crm-sidebar.collapsed .csb-toggle { position: absolute; top: 72px; right: 8px; }
.csb-toggle {
    background: rgba(255,255,255,.08);
    border: none;
    color: rgba(255,255,255,.6);
    width: 24px; height: 24px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    transition: background .12s, color .12s;
}
.csb-toggle:hover { background: rgba(255,255,255,.16); color: #fff; }

/* Search bar */
.csb-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 10px 6px;
    padding: 8px 10px;
    background: rgba(255,255,255,.07);
    border-radius: 8px;
    cursor: pointer;
    transition: background .12s;
    flex-shrink: 0;
    min-height: 38px;
}
.csb-search:hover { background: rgba(255,255,255,.12); }
.csb-search .csb-lbl { font-size: .84rem; color: rgba(255,255,255,.5); flex: 1; }
.csb-kbd {
    font-size: .68rem;
    padding: 1px 5px;
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 4px;
    color: rgba(255,255,255,.35);
    font-family: inherit;
    white-space: nowrap;
}
.crm-sidebar.collapsed .csb-search .csb-lbl,
.crm-sidebar.collapsed .csb-search .csb-kbd { display: none; }
.crm-sidebar.collapsed .csb-search { justify-content: center; padding: 8px 0; margin: 10px 8px 6px; }

/* Nav items */
.csb-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 8px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}
.csb-nav::-webkit-scrollbar { width: 4px; }
.csb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 2px; }

.csb-section {
    font-size: .66rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--csb-section);
    padding: 14px 8px 4px;
    white-space: nowrap;
    overflow: hidden;
}
.crm-sidebar.collapsed .csb-section {
    padding: 12px 0 4px;
    text-align: center;
    font-size: .5rem;
    letter-spacing: .06em;
}

.csb-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    text-decoration: none;
    color: rgba(255,255,255,.72);
    font-size: .875rem;
    font-weight: 500;
    transition: background .1s, color .1s;
    white-space: nowrap;
    overflow: hidden;
    margin-bottom: 1px;
    position: relative;
}
.csb-link:hover {
    background: var(--csb-hover);
    color: #fff;
}
.csb-link.active {
    background: var(--csb-active);
    color: var(--csb-accent);
    font-weight: 600;
}
.csb-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 20%; bottom: 20%;
    width: 3px;
    background: var(--csb-accent);
    border-radius: 0 2px 2px 0;
}

.csb-ico {
    font-size: 1.05rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
    line-height: 1;
}
.csb-lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.crm-sidebar.collapsed .csb-lbl { display: none; }
.crm-sidebar.collapsed .csb-link { padding: 9px 0; justify-content: center; }
.crm-sidebar.collapsed .csb-link.active::before { display: none; }

/* Footer / User */
.csb-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 10px;
    border-top: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
    min-height: 58px;
    overflow: hidden;
}
.csb-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: #3d6fa0;
    color: #e2e8f0;
    font-size: .85rem;
    font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.csb-user-meta { flex: 1; min-width: 0; overflow: hidden; }
.csb-user-name {
    font-size: .82rem; font-weight: 600; color: #f1f5f9;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.csb-user-role { font-size: .7rem; color: rgba(255,255,255,.4); }
.crm-sidebar.collapsed .csb-user-meta { display: none; }
.csb-logout {
    background: rgba(255,255,255,.07);
    border: none;
    color: rgba(255,255,255,.5);
    width: 28px; height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex; align-items: center; justify-content: center;
    padding: 0;
    flex-shrink: 0;
    transition: background .12s, color .12s;
}
.csb-logout:hover { background: rgba(220,38,38,.25); color: #f87171; }
.crm-sidebar.collapsed .csb-footer { justify-content: center; }
.crm-sidebar.collapsed .csb-logout { display: none; }

/* Overlay (mobile) */
.csb-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 199;
}
.csb-overlay.visible { display: block; }

/* Mobile hamburger */
.csb-hamburger {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 198;
    background: var(--csb-bg);
    border: none;
    color: #fff;
    width: 38px; height: 38px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}

/* ── Content area ─────────────────────────────────────────────────────────── */
main {
    margin-left: var(--csb-w);
    padding: 24px 28px 48px;
    min-height: 100vh;
    box-sizing: border-box;
    transition: margin-left .2s ease;
}
.inner { max-width: 1060px; margin: 0 auto; }

/* ── Mobile / Tablet (≤ 768 px) ──────────────────────────────────────────── */
@media (max-width: 768px) {
    /* Sidebar als Slide-over */
    #crm-nav {
        width: 240px !important;
        transform: translateX(-100%);
        transition: transform .22s ease;
    }
    #crm-nav.mobile-open { transform: translateX(0); }
    .csb-hamburger { display: flex; align-items: center; justify-content: center; }
    main { margin-left: 0 !important; padding: 60px 14px 32px; }

    /* Touch-Targets: min. 44 px Höhe */
    button { min-height: 44px; touch-action: manipulation; }
    button.mini { min-height: 36px; }
    button.csb-toggle, button.csb-logout { min-height: unset; }
    a, button { -webkit-tap-highlight-color: transparent; }

    /* iOS: Inputs ≥16px verhindern Auto-Zoom beim Fokus */
    input, textarea, select { font-size: max(1rem, 16px); }

    /* Tabellen scrollbar machen */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-wrap table { min-width: 520px; }

    /* List-Header stapeln */
    .list-head { flex-direction: column; align-items: stretch; gap: 8px; }
    .list-head input { max-width: 100%; }
    .list-head > div { display: flex; flex-wrap: wrap; gap: 6px; }

    /* Karten kompakter */
    .card { padding: 14px; }

    /* Formular-Grid einspaltie */
    .grid { grid-template-columns: 1fr !important; }

    /* Form-Actions umbrechen */
    .form-actions { flex-wrap: wrap; gap: 8px; }

    /* Subzeilen umbrechen */
    .subrow { flex-wrap: wrap; }
    .subrow select { flex: 0 0 100%; }
}

/* ── Kleine Phones (≤ 480 px) ────────────────────────────────────────────── */
@media (max-width: 480px) {
    main { padding: 56px 10px 28px; }
    .card { padding: 12px; }
    th, td { padding: 8px 6px; font-size: .85rem; }
    .inner { max-width: 100%; }
}

/* ── Komponenten (unverändert) ───────────────────────────────────────────── */
.card {
    background: #fff;
    border: 1px solid var(--rand);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 22px;
}
.card h2 { margin: 0 0 14px; font-size: 1.1rem; }
.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}
label { display: flex; flex-direction: column; font-size: .85rem; font-weight: 600; gap: 4px; }
input, textarea, select {
    padding: 9px 10px;
    border: 1px solid var(--rand);
    border-radius: 6px;
    font-size: .95rem;
    font-weight: 400;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--blau); border-color: var(--blau); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
.form-section { margin-top: 1.1rem; }
.form-section-title {
    font-size: .78rem; font-weight: 700; color: #8b96a1;
    text-transform: uppercase; letter-spacing: .06em;
    margin: 0 0 .55rem; padding-bottom: .3rem;
    border-bottom: 1px solid var(--rand);
}
.hint { font-size: .82rem; color: #5a6772; margin: 12px 0; }
.sublist { margin-top: 16px; }
.sublist-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sublist-head h3 { margin: 0; font-size: .92rem; }
.subrow { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.subrow select { flex: 0 0 140px; width: auto; }
.subrow input { flex: 1; width: auto; }
.subrow select { padding: 9px 8px; }
.subrow .remove { flex: 0 0 auto; }
.empty-sub { font-size: .82rem; color: #7a8794; font-style: italic; margin: 0 0 8px; }
.tag-chip {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: .76rem; font-weight: 600; color: #fff; background: #475569;
    margin: 2px 4px 2px 0; white-space: nowrap;
}
.tag-chip.clickable { cursor: pointer; border: 0; }
.tag-suggest { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 2px; }
.tag-suggest .label { font-size: .8rem; color: #7a8794; margin-right: 4px; align-self: center; }
.tag-filter { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 4px; align-items: center; }
.tag-filter .label { font-size: .82rem; color: #5a6772; margin-right: 4px; }
.tag-chip.inactive { background: #e6eaee; color: #5a6772; }
.tag-chip.active-filter { outline: 2px solid #1d2733; outline-offset: 1px; }
button {
    background: var(--blau);
    color: #fff; border: 0;
    padding: 10px 18px; border-radius: 6px;
    font-size: .95rem; cursor: pointer;
    transition: background .12s;
}
button:hover { background: #173b5c; }
.form-actions { display: flex; gap: 10px; align-items: center; }
button.secondary { background: #e6eaee; color: var(--text); }
button.secondary:hover { background: #d4dade; }
.btn-ghost {
    background: #f1f5f9; color: #475569;
    border: 1px solid #e2e8f0; padding: 8px 14px;
    font-size: .85rem; border-radius: 7px;
}
.btn-ghost:hover { background: #e2e8f0; color: #1e293b; }
.row-actions { display: flex; gap: 6px; }
button.mini { padding: 5px 10px; font-size: .82rem; }
button.danger { background: #fff; color: var(--rot); border: 1px solid #e2b6b0; }
button.danger:hover { background: #fbeae8; }
button.edit { background: #fff; color: var(--blau); border: 1px solid #bcd0e2; }
button.edit:hover { background: #eef4fa; }
.message { padding: 10px 12px; border-radius: 6px; margin-bottom: 12px; font-size: .9rem; }
.message.error { background: #fbeae8; color: var(--rot); border: 1px solid #f0c4be; }
.message.success { background: #e6f4ea; color: var(--gruen); border: 1px solid #bfe3c9; }
.list-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.list-head input { max-width: 260px; }
table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--rand); font-size: .92rem; }
th { color: #5a6772; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.muted { color: #7a8794; font-style: italic; }
a.nr-link { color: inherit; text-decoration: none; border-bottom: 1px dashed #94a3b8; }
a.nr-link:hover { color: #3b82f6; border-bottom-color: #3b82f6; }
.collapse-toggle {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; user-select: none;
}
.collapse-toggle h2 { margin: 0; }
.chevron { transition: transform .2s; font-size: .85rem; color: #94a3b8; }
.collapsible-body { overflow: hidden; transition: max-height .3s ease; }
.collapsible-body.closed { max-height: 0 !important; }
