/* ============================================================
   BauApp — Modern PWA Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary:           #3478f6;
    --primary-dark:      color-mix(in srgb, var(--primary) 80%, black);
    --primary-subtle:    color-mix(in srgb, var(--primary) 12%, white);
    --primary-color:     var(--primary);
    --primary-color-dark:var(--primary-dark);

    --bg:                #f5f5f7;
    --bg-card:           #ffffff;
    --bg-input:          #ffffff;

    --text:              #1c1c1e;
    --text-secondary:    #6e6e73;
    --text-tertiary:     #aeaeb2;
    --text-dark:         #1c1c1e;

    --border:            rgba(0,0,0,0.08);
    --border-strong:     rgba(0,0,0,0.14);

    --radius-sm:         8px;
    --radius:            12px;
    --radius-lg:         16px;
    --radius-xl:         20px;
    --border-radius:     var(--radius);

    --header-height:     56px;
    --footer-height:     76px;

    --red:   #ff3b30;
    --green: #30d158;
    --amber: #ff9500;
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    /* Verhindert Overscroll/Bounce auf iOS PWA */
    overscroll-behavior: none;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    /* Verhindert horizontales Verschieben */
    overflow-x: hidden;
    overscroll-behavior-x: none;
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   PWA Input-Fix: Verhindert iOS-Zoom und Seiten-Shift bei Tastatur
   ============================================================ */

/* iOS zoomt bei font-size < 16px — daher ALLE Inputs auf min. 16px */
input, select, textarea {
    font-size: 16px !important;
    touch-action: manipulation; /* Verhindert Doppeltipp-Zoom */
}

/* Seite fixieren wenn virtuelle Tastatur offen (iOS PWA) */
@supports (-webkit-touch-callout: none) {
    /* Nur iOS */
    body.keyboard-open {
        position: fixed;
        width: 100%;
    }
}

/* Kein horizontaler Scroll auf Modulseiten */
.app-content {
    overflow-x: hidden;
}

/* ============================================================
   Header
   ============================================================ */
.app-header {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: var(--header-height);
    background: rgba(255,255,255,0.82);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 1000;
}

.app-header .app-logo {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.03em;
    text-decoration: none;
}
.app-header .app-logo span { color: var(--primary); }

.page-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.02em;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    pointer-events: none;
}

/* ============================================================
   Burger Button
   ============================================================ */
.burger-menu-icon {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4.5px;
    width: 36px;
    height: 36px;
    background: var(--bg-input);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0 9px;
    z-index: 1011;
    position: relative;
    transition: background 0.15s;
}
.burger-menu-icon:active { background: var(--border); }
.burger-menu-icon div {
    width: 100%;
    height: 1.5px;
    background: var(--text);
    border-radius: 1px;
    opacity: 0.7;
    transition: all 0.25s;
}

/* ============================================================
   Footer Navigation
   ============================================================ */
.app-footer {
    position: fixed;
    bottom: 0; left: 0;
    width: 100%;
    background: rgba(255,255,255,0.82);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 4px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 1000;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    text-decoration: none;
    color: var(--text-tertiary);
    font-size: 0.65rem;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    transition: color 0.2s;
    letter-spacing: 0.01em;
}
.nav-item i { font-size: 1.2rem; }
.nav-item.active { color: var(--primary); }

/* ============================================================
   Main Content
   ============================================================ */
.app-content {
    padding-top: calc(var(--header-height) + 16px);
    padding-bottom: calc(var(--footer-height) + 16px);
    padding-left: 16px;
    padding-right: 16px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* ============================================================
   Cards
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border);
    padding: 16px;
    margin-bottom: 12px;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 13px 20px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    text-align: center;
    text-decoration: none;
    transition: opacity 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: 0.82; transform: scale(0.98); }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
    background: var(--primary-subtle);
    color: var(--primary);
}

.btn-danger {
    background: #fff0f0;
    color: var(--red);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
}

/* ============================================================
   Forms
   ============================================================ */
.form-group { margin-bottom: 14px; }

.form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="time"],
.form-group input[type="number"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 16px; /* Min 16px verhindert iOS-Zoom */
    font-family: inherit;
    color: var(--text);
    transition: border-color 0.2s, box-shadow 0.15s;
    appearance: none;
    -webkit-appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    background: var(--bg-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

/* ============================================================
   Messages / Alerts
   ============================================================ */
.message-box {
    padding: 12px 14px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.message-error   { background: #fff0f0; color: #c0392b; border: 0.5px solid rgba(192,57,43,0.2); }
.message-success { background: #f0faf4; color: #27ae60; border: 0.5px solid rgba(39,174,96,0.2); }
.message-info    { background: #f0f5ff; color: var(--primary); border: 0.5px solid rgba(52,120,246,0.2); }

/* ============================================================
   Sidebar
   ============================================================ */
.module-sidebar {
    position: fixed;
    top: 0; right: 0;
    height: 100%;
    width: 240px;
    background: var(--bg-card);
    border-left: 0.5px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.32,0.72,0,1);
    padding-top: calc(var(--header-height) + 12px);
    z-index: 999;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    /* Scrollbar dezent */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    -webkit-overflow-scrolling: touch;
}
.module-sidebar::-webkit-scrollbar { width: 4px; }
.module-sidebar::-webkit-scrollbar-track { background: transparent; }
.module-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.module-sidebar.open { transform: translateX(0); }

/* Sektion-Label */
.sn-section-label {
    font-size: .68rem;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 4px 14px 6px;
}

/* Nav-Item */
.sn-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    margin: 0 6px 2px;
    text-decoration: none;
    color: var(--text);
    border-radius: 10px;
    font-size: .88rem;
    font-weight: 500;
    transition: background .12s;
    cursor: pointer;
    border: none;
    background: none;
    width: calc(100% - 12px);
    text-align: left;
}
.sn-item:hover { background: var(--bg); }
.sn-item.nav-active { background: var(--primary-subtle,#e8f0fe); color: var(--primary); font-weight: 600; }

.sn-icon {
    width: 32px; height: 32px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    font-size: .85rem;
    flex-shrink: 0;
}
.sn-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Tools-Toggle */
.sn-tools-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-tertiary);
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 0;
}
.sn-tools-toggle:hover { color: var(--primary); }

/* Logout ans Ende */
.sidebar-logout { padding: 8px 6px 20px; border-top: 0.5px solid var(--border); }
.sn-logout { color: var(--text-secondary); }

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(2px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s;
}
.sidebar-overlay.visible { opacity: 1; pointer-events: auto; }

/* ============================================================
   Module Cards (Dashboard)
   ============================================================ */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
    margin-top: 4px;
}

.module-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border);
    padding: 14px 12px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
    transition: transform 0.15s, border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
}
.module-card:active { transform: scale(0.97); }
.module-card:hover  { border-color: var(--primary); }

.module-card-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.module-card-name {
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1.3;
    letter-spacing: -0.01em;
}

/* Icon-Farben je Modul */
.icon-zeiterfassung    { background: #e8f0fe; color: #3478f6; }
.icon-dokumentation    { background: #e8faf0; color: #30d158; }
.icon-bautagebuch      { background: #fff4e0; color: #ff9500; }
.icon-aufgaben         { background: #fce8f3; color: #ff375f; }
.icon-urlaubsantrag    { background: #eef0fe; color: #5e5ce6; }
.icon-materialbestellung{background: #fef0e0; color: #ff8c00; }
.icon-unterweisung     { background: #e0fef4; color: #0a8a60; }
.icon-unfall           { background: #feeded; color: #ff3b30; }
.icon-fuehrerschein    { background: #e5f6e5; color: #25a244; }
.icon-administration   { background: #f0eefe; color: #7c5cbf; }

/* ============================================================
   Quick Stats (Dashboard)
   ============================================================ */
.quick-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}
.quick-stat {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.quick-stat-icon {
    width: 38px; height: 38px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
}
.quick-stat-label { font-size: 0.72rem; color: var(--text-secondary); margin-bottom: 2px; }
.quick-stat-value { font-size: 0.95rem; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }

/* ============================================================
   Section Labels
   ============================================================ */
.section-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 18px 0 8px;
}

/* ============================================================
   Login Page (kein Header/Footer)
   ============================================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
    background: var(--bg);
}
.login-box {
    width: 100%;
    max-width: 380px;
}
.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo-icon {
    width: 64px; height: 64px;
    background: var(--primary);
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    color: #fff;
    margin-bottom: 14px;
}
.login-logo h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--text);
}
.login-logo p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}
.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 0.5px solid var(--border);
    padding: 24px 20px;
}

/* ============================================================
   Admin Sub-Navigation
   ============================================================ */
.adm-subnav {
    display: flex;
    overflow-x: auto;
    gap: 6px;
    padding: 8px 16px 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin: 0 -16px;
    scroll-snap-type: x mandatory;
}
.adm-subnav::-webkit-scrollbar { display: none; }
.adm-subnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 14px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
    background: var(--bg-card);
    border: 0.5px solid var(--border);
    transition: all .15s;
    flex-shrink: 0;
    scroll-snap-align: start;
}
.adm-subnav-item i { font-size: 1.05rem; }
.adm-subnav-item.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.adm-subnav-item:not(.active):hover { border-color: var(--primary); color: var(--primary); }
.adm-content { padding-top: 4px; }

/* Scroll-Fade rechts als Hinweis */
.adm-subnav-wrap {
    position: relative;
    margin: 0 -16px;
    overflow: hidden;
}
.adm-subnav-wrap::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 32px;
    background: linear-gradient(to left, var(--bg) 30%, transparent);
    pointer-events: none;
}
.adm-subnav-wrap .adm-subnav {
    margin: 0;
    padding: 8px 16px 12px;
}

/* Admin Übersichtskarten */
.adm-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}
.adm-overview-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border);
    padding: 16px 14px;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: border-color .15s, transform .15s;
}
.adm-overview-card:active { transform: scale(0.97); }
.adm-overview-card:hover { border-color: var(--primary); }
.adm-overview-card-icon {
    width: 40px; height: 40px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
}
.adm-overview-card-title { font-size: 0.85rem; font-weight: 600; }
.adm-overview-card-sub   { font-size: 0.75rem; color: var(--text-secondary); margin-top: -6px; }

/* ============================================================
   Settings / Admin Cards — global verfügbar
   ============================================================ */
.settings-card,
.adm-section {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    border: 0.5px solid var(--border);
    padding: 18px 16px;
    margin-bottom: 14px;
}

.settings-card-header,
.adm-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1.5px solid var(--border);
}
.settings-card-header i,
.adm-section-header i {
    font-size: 1.1rem;
    color: var(--primary);
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}
.settings-card-header h3,
.adm-section-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    margin: 0;
    letter-spacing: -0.01em;
}

/* Seitenüberschrift mit Button */
.page-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 0.5px solid var(--border);
    padding: 14px 16px;
    margin-bottom: 12px;
}
.page-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0;
}

/* Kleiner Button */
.btn-sm {
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: var(--radius);
}

/* Status/Bestätigungs-Banner */
.save-confirm {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #f0faf4;
    border: 0.5px solid rgba(39,174,96,0.25);
    border-radius: var(--radius);
    color: #27ae60;
    font-size: 0.88rem;
    font-weight: 500;
    margin-bottom: 12px;
    animation: fadeIn .3s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(-4px)} to{opacity:1;transform:translateY(0)} }

/* Adress-Grid: Straße+Nr, PLZ+Ort nebeneinander */
.addr-grid {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}
.addr-grid-plz {
    display: grid;
    grid-template-columns: 100px 1fr;
    gap: 10px;
}

/* Tabs zentriert */
.det-tabs-centered {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 14px;
}
.det-tab {
    padding: 8px 14px;
    border: 0.5px solid var(--border);
    background: var(--bg-card);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: all .15s;
}
.det-tab.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.det-tab i { margin-right: 4px; font-size: 0.78rem; }

/* tel/email Input-Icon-Wrapper */
.input-icon-wrap {
    position: relative;
}
.input-icon-wrap i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 0.85rem;
    pointer-events: none;
}
.input-icon-wrap input {
    padding-left: 34px !important;
}
.input-icon-wrap .input-valid   { border-color: #27ae60 !important; }
.input-icon-wrap .input-invalid { border-color: #ff3b30 !important; }

/* ============================================================
   Chat-Modul
   ============================================================ */

/* Page-Override: Chat nutzt volle Höhe ohne Padding */
html.page-chat-html,
body.page-chat {
    height: 100%;
    overflow: hidden;
    margin: 0;
    padding: 0;
}
body.page-chat .app-content {
    max-width: none;
    padding: 0;
    margin-top: var(--header-height);
    height: calc(100% - var(--header-height) - var(--footer-height));
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
body.page-chat.chat-active-view .app-content {
    height: calc(100% - var(--header-height) - 70px);
}

/* ─── Layout (3 Spalten) ─── */
.chat-layout {
    display: flex;
    height: 100%;
    background: var(--bg);
    overscroll-behavior: none;
}

/* ─── Sidebar (Spalte 1) ─── */
.chat-sidebar {
    width: 320px;
    min-width: 280px;
    max-width: 380px;
    border-right: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-sidebar-header {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
    align-items: center;
}
.chat-sidebar-search {
    flex: 1;
    position: relative;
}
.chat-sidebar-search i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: 13px;
}
.chat-sidebar-search input {
    width: 100%;
    padding: 8px 10px 8px 32px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 14px;
    background: var(--bg);
    outline: none;
}
.chat-sidebar-search input:focus { border-color: var(--primary); }
.chat-new-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.chat-new-btn:hover { opacity: 0.9; }

/* Tabs */
.chat-tabs {
    display: flex;
    padding: 4px 12px;
    gap: 4px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}
.chat-tabs::-webkit-scrollbar { display: none; }
.chat-tab {
    padding: 5px 10px;
    border: none;
    background: none;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 14px;
    white-space: nowrap;
    font-weight: 500;
}
.chat-tab.active { background: var(--primary); color: #fff; }
.chat-tab:hover:not(.active) { background: var(--bg); }

/* Konversationsliste */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}
.chat-conv-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    align-items: center;
    transition: background 0.15s;
}
.chat-conv-item:hover { background: var(--bg); }
.chat-conv-item.active { background: rgba(52,199,89,0.08); }
.chat-conv-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8f5e9;
    color: #34c759;
    font-weight: 600;
}
.chat-conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-avatar-initials {
    font-size: 15px;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}
.chat-avatar-emoji { font-size: 24px; }
.chat-conv-body { flex: 1; min-width: 0; }
.chat-conv-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.chat-conv-name { font-weight: 600; font-size: 14px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.chat-conv-time { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; flex-shrink: 0; }
.chat-conv-bottom { display: flex; align-items: center; gap: 6px; }
.chat-conv-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.chat-conv-preview em { font-style: normal; color: var(--text-tertiary); }
.chat-draft-label { color: #34c759; font-weight: 500; }
.chat-unread-badge {
    background: #34c759;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
}
.chat-mute-icon { color: var(--text-tertiary); font-size: 11px; }
.chat-pin-icon { color: var(--text-tertiary); font-size: 10px; margin-right: 4px; }
.chat-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #34c759;
    border-radius: 50%;
    margin-right: 4px;
}
.chat-empty-list { padding: 40px 20px; text-align: center; color: var(--text-tertiary); font-size: 14px; }
.chat-loading { padding: 30px; text-align: center; color: var(--text-tertiary); }

/* ─── Main (Spalte 2) ─── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--bg);
    overflow: hidden;
}
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 16px;
}
.chat-empty-state i { font-size: 56px; opacity: 0.3; }
.chat-empty-state p { text-align: center; font-size: 15px; line-height: 1.5; }
.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    z-index: 10;
    min-height: 56px;
}
.chat-back-btn { display: none; }
.chat-header-avatar { width: 40px; height: 40px; border-radius: 50%; overflow: hidden; flex-shrink: 0; display: flex; align-items: center; justify-content: center; background: #e8f5e9; color: #34c759; }
.chat-header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-sub { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 4px; }
.chat-icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}
.chat-icon-btn:hover { background: var(--bg); color: var(--text); }
.chat-icon-btn.recording { color: #ff3b30; animation: chat-pulse 1s infinite; }
@keyframes chat-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* Pinned Bar */
.chat-pinned-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #fffde7;
    border-bottom: 1px solid #fff9c4;
    font-size: 13px;
    color: var(--text-secondary);
}
.chat-pinned-bar i { color: #f9a825; font-size: 12px; }

/* Search Bar */
.chat-search-bar {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}
.chat-search-bar input { flex: 1; padding: 6px 12px; border: 1px solid var(--border); border-radius: 16px; font-size: 13px; outline: none; }
.chat-search-bar input:focus { border-color: var(--primary); }

/* Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
}

/* Date Separator */
.chat-date-sep {
    text-align: center;
    margin: 12px 0;
}
.chat-date-sep span {
    background: rgba(0,0,0,0.06);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    padding: 3px 12px;
    border-radius: 8px;
}

/* Message Bubbles */
.chat-msg {
    display: flex;
    position: relative;
    max-width: 70%;
}
.chat-msg--own { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg--other { align-self: flex-start; }
.chat-msg--system {
    align-self: center;
    max-width: 80%;
    text-align: center;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 4px 12px;
    background: rgba(0,0,0,0.04);
    border-radius: 12px;
    margin: 4px 0;
}
.chat-msg-bubble {
    padding: 8px 12px;
    border-radius: 18px;
    position: relative;
    word-break: break-word;
    min-width: 60px;
}
.chat-msg--own .chat-msg-bubble {
    background: #34c759;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg--other .chat-msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}
.chat-msg-sender { font-size: 12px; font-weight: 600; color: var(--primary); margin-bottom: 2px; }
.chat-msg--own .chat-msg-sender { color: rgba(255,255,255,0.8); }
.chat-msg-text { font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.chat-msg-text a { color: inherit; text-decoration: underline; }
.chat-msg--other .chat-msg-text a { color: var(--primary); }
.chat-msg-deleted { font-size: 13px; color: var(--text-tertiary); }
.chat-msg--own .chat-msg-deleted { color: rgba(255,255,255,0.6); }
.chat-msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    margin-top: 2px;
    opacity: 0.6;
}
.chat-msg--own .chat-msg-meta { color: rgba(255,255,255,0.8); }
.chat-msg--other .chat-msg-meta { color: var(--text-tertiary); }

/* Lesebestätigung Häkchen */
.chat-read-status { margin-left: 3px; font-size: 11px; }
.chat-read-status.sent { opacity: 0.6; }
.chat-read-status.partial { opacity: 0.7; }
.chat-read-status.read { color: #81d4fa; opacity: 1; }
.chat-msg--own .chat-read-status.read { color: #b3e5fc; }

/* Reply */
.chat-msg-reply {
    padding: 6px 10px;
    background: rgba(0,0,0,0.06);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    margin-bottom: 6px;
    font-size: 12px;
    cursor: pointer;
}
.chat-msg--own .chat-msg-reply { background: rgba(255,255,255,0.15); border-left-color: rgba(255,255,255,0.5); }
.chat-msg-reply-name { font-weight: 600; display: block; margin-bottom: 1px; }
.chat-msg-reply-text { color: inherit; opacity: 0.7; }

/* Images */
.chat-msg-image { margin: -4px -4px 4px; }
.chat-msg-image img { max-width: 280px; max-height: 300px; border-radius: 12px; cursor: pointer; display: block; }

/* Files */
.chat-msg-file a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(0,0,0,0.06);
    border-radius: 8px;
    color: inherit;
    text-decoration: none;
    font-size: 13px;
}
.chat-msg--own .chat-msg-file a { background: rgba(255,255,255,0.15); }
.chat-msg-file i { font-size: 20px; }
.chat-file-size { font-size: 11px; color: inherit; opacity: 0.6; margin-left: auto; }

/* Audio Player */
.chat-msg-audio {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
    padding: 4px 0;
}
.chat-audio-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.1);
    color: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.chat-msg--own .chat-audio-play { background: rgba(255,255,255,0.25); }
.chat-audio-play:active { transform: scale(0.93); }
.chat-audio-wave {
    flex: 1;
    height: 6px;
    background: rgba(0,0,0,0.12);
    border-radius: 3px;
    overflow: hidden;
    min-width: 80px;
}
.chat-msg--own .chat-audio-wave { background: rgba(255,255,255,0.25); }
.chat-audio-progress {
    height: 100%;
    width: 0%;
    background: currentColor;
    border-radius: 3px;
    transition: width 0.1s linear;
    opacity: 0.7;
}
.chat-msg--own .chat-audio-progress { background: #fff; }
.chat-audio-time {
    font-size: 11px;
    opacity: 0.7;
    white-space: nowrap;
    min-width: 28px;
}

/* Reactions */
.chat-msg-reactions {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 4px;
}
.chat-reaction {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
    font-size: 14px;
    cursor: pointer;
}
.chat-reaction span { font-size: 11px; color: var(--text-secondary); }
.chat-reaction.mine { border-color: var(--primary); background: rgba(52,199,89,0.08); }
.chat-msg--own .chat-reaction { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.3); }

/* Reaction Picker */
.chat-reaction-picker {
    position: absolute;
    top: -36px;
    right: 0;
    display: flex;
    gap: 2px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 4px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    z-index: 100;
}
.chat-reaction-picker button {
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    padding: 2px;
    border-radius: 50%;
    line-height: 1;
}
.chat-reaction-picker button:hover { background: var(--bg); }

/* Hover Actions */
.chat-msg-actions {
    display: none;
    position: absolute;
    top: -8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2px 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    z-index: 50;
}
.chat-msg--own .chat-msg-actions { left: 0; }
.chat-msg--other .chat-msg-actions { right: 0; }
.chat-msg:hover .chat-msg-actions { display: flex; }
.chat-msg-actions button {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-msg-actions button:hover { background: var(--bg); color: var(--text); }

/* Highlight */
.chat-msg-highlight .chat-msg-bubble { box-shadow: 0 0 0 2px var(--primary); transition: box-shadow 0.3s; }

/* ─── Input Bar ─── */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 8px 8px 12px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
    font-family: inherit;
    line-height: 1.4;
    min-height: 38px;
}
.chat-input:focus { border-color: var(--primary); }
.chat-send-btn {
    width: 38px;
    height: 38px;
    border: none;
    background: #34c759;
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    flex-shrink: 0;
}
.chat-send-btn:disabled { opacity: 0.4; cursor: default; }
.chat-send-btn:not(:disabled):hover { opacity: 0.9; }

/* Reply Preview */
.chat-reply-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-left: 3px solid var(--primary);
}
.chat-reply-content { flex: 1; min-width: 0; }
.chat-reply-content .chat-reply-name { font-weight: 600; font-size: 12px; display: block; color: var(--primary); }
.chat-reply-content .chat-reply-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.chat-reply-close { border: none; background: none; color: var(--text-tertiary); cursor: pointer; font-size: 16px; }

/* Typing */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-card);
}
.chat-typing-dots span { animation: chat-dot 1.4s infinite; }
.chat-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes chat-dot { 0%,60%,100% { opacity: 0.3; } 30% { opacity: 1; } }

/* Scroll to Bottom */
.chat-scroll-bottom {
    position: absolute;
    bottom: 70px;
    right: 16px;
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    z-index: 20;
}
.chat-scroll-bottom:hover { background: var(--bg); }
.chat-scroll-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #34c759;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ─── Info Panel (Spalte 3) ─── */
.chat-info {
    width: 320px;
    border-left: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.chat-info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 15px;
}
.chat-info-content { padding: 16px; }
.chat-info-section { margin-bottom: 24px; }
.chat-info-section h3 { text-align: center; margin: 8px 0; }
.chat-info-section h4 { font-size: 13px; color: var(--text-secondary); margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.chat-info-section p { text-align: center; color: var(--text-secondary); font-size: 13px; }
.chat-info-avatar { text-align: center; font-size: 64px; margin: 8px 0; }
.chat-info-members { display: flex; flex-direction: column; gap: 8px; }
.chat-info-member { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
.chat-info-member-name { flex: 1; font-size: 14px; }
.chat-info-member-name small { color: var(--text-tertiary); }
.chat-info-member-status { font-size: 11px; color: var(--text-tertiary); }
.chat-info-member-status.online { color: #34c759; }
.chat-admin-badge { background: #e8f5e9; color: #34c759; font-size: 10px; padding: 1px 6px; border-radius: 4px; font-weight: 600; }
.chat-avatar-small {
    width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
    display: flex; align-items: center; justify-content: center;
    background: #e8f5e9; color: #34c759; font-weight: 600; font-size: 12px; flex-shrink: 0;
}
.chat-avatar-small img { width: 100%; height: 100%; object-fit: cover; }
.chat-info-media-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.chat-info-media-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; cursor: pointer; }
.chat-info-file { display: flex; align-items: center; gap: 8px; padding: 8px 0; font-size: 13px; color: var(--text); text-decoration: none; border-bottom: 1px solid var(--border); }
.chat-info-file:hover { color: var(--primary); }
.chat-info-file small { color: var(--text-tertiary); margin-left: auto; }

/* ─── Modals ─── */
.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.chat-modal {
    background: var(--bg-card);
    border-radius: 16px;
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.chat-modal-header h3 { margin: 0; font-size: 17px; }
.chat-modal-close { border: none; background: none; font-size: 18px; color: var(--text-secondary); cursor: pointer; }
.chat-modal-tabs { display: flex; border-bottom: 1px solid var(--border); }
.chat-modal-tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}
.chat-modal-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.chat-modal-body { flex: 1; overflow-y: auto; padding: 16px 20px; }
.chat-modal-pane { display: none; }
.chat-modal-pane.active { display: block; }
.chat-modal-search {
    width: 100%;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 12px;
    outline: none;
}
.chat-modal-search:focus { border-color: var(--primary); }
.chat-modal-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    outline: none;
}
.chat-modal-input:focus { border-color: var(--primary); }
.chat-modal-submit { width: 100%; }

/* Contact List */
.chat-contact-list { max-height: 350px; overflow-y: auto; }
.chat-contact-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 4px;
    cursor: pointer;
    border-radius: 8px;
}
.chat-contact-item:hover { background: var(--bg); }
.chat-contact-check { cursor: pointer; }
.chat-contact-check input { margin-right: 4px; }
.chat-contact-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8f5e9;
    color: #34c759;
    font-weight: 600;
    font-size: 13px;
}
.chat-contact-avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-contact-name { font-weight: 500; font-size: 14px; }
.chat-contact-sub { font-size: 12px; color: var(--text-tertiary); }

/* Lightbox */
.chat-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    cursor: pointer;
}
.chat-lightbox img { max-width: 90%; max-height: 90%; object-fit: contain; border-radius: 8px; }
.chat-lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
}

/* Footer Chat Wiggle */
.chat-wiggle {
    animation: chat-wiggle 0.6s ease-in-out;
}
@keyframes chat-wiggle {
    0%   { transform: rotate(0deg); }
    15%  { transform: rotate(-15deg) scale(1.2); }
    30%  { transform: rotate(12deg) scale(1.2); }
    45%  { transform: rotate(-10deg) scale(1.15); }
    60%  { transform: rotate(8deg) scale(1.1); }
    75%  { transform: rotate(-4deg); }
    100% { transform: rotate(0deg); }
}

/* Footer Badge */
.chat-footer-badge {
    position: absolute;
    top: 2px;
    right: -4px;
    background: #ff3b30;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

/* ─── Responsive: Mobile ─── */
@media (max-width: 768px) {
    .chat-sidebar { width: 100%; max-width: none; border-right: none; }
    .chat-main { flex: 1; min-height: 0; }
    .chat-info { width: 100%; }

    .chat-layout .chat-main { display: none; }
    .chat-layout .chat-info { display: none !important; }

    .chat-layout.chat-view-chat .chat-sidebar { display: none; }
    .chat-layout.chat-view-chat .chat-main { display: flex; }
    body.page-chat.chat-active-view .app-footer { display: none !important; }

    .chat-layout.chat-info-open .chat-sidebar { display: none; }
    .chat-layout.chat-info-open .chat-main { display: none; }
    .chat-layout.chat-info-open .chat-info { display: flex !important; }
    body.page-chat.chat-info-view .app-footer { display: none !important; }

    .chat-back-btn {
        display: flex;
        width: 36px;
        height: 36px;
        border: none;
        background: none;
        color: var(--text);
        cursor: pointer;
        font-size: 18px;
        align-items: center;
        justify-content: center;
    }

    .chat-layout:not(.chat-view-chat) .chat-conv-list { padding-bottom: var(--footer-height); }

    .chat-msg { max-width: 85%; }
    .chat-msg-image img { max-width: 220px; }
    .chat-conv-name { max-width: 140px; }
    .chat-msg-actions { display: none !important; }

}

/* Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
    .chat-sidebar { width: 280px; min-width: 240px; }
    .chat-info { width: 280px; }
}
