:root { --primary: #2563eb; --bg-body: #f8fafc; --sidebar-w: 280px; }
[data-bs-theme="dark"] { --primary: #3b82f6; --bg-body: #0f172a; }

body { font-family: 'Inter', sans-serif; background: var(--bg-body); height: 100vh; width: 100vw; overflow: hidden; margin: 0; padding: 0; color: #334155; }

/* BULLETPROOF LAYOUT */
#app { display: flex; flex-direction: row; height: 100vh; width: 100vw; overflow: hidden; }

#sidebar { 
    width: var(--sidebar-w); 
    min-width: var(--sidebar-w); 
    flex-shrink: 0; 
    background: white; 
    border-right: 1px solid #e2e8f0; 
    display: flex; 
    flex-direction: column; 
    z-index: 1040; 
    transition: transform 0.3s ease, width 0.3s ease, min-width 0.3s ease; 
}

#main { 
    flex: 1; 
    min-width: 0; 
    display: flex; 
    flex-direction: column; 
    height: 100vh; 
    position: relative; 
    overflow: hidden; 
}

#main-content-wrapper { 
    flex: 1; 
    min-height: 0;
    overflow-y: auto; 
    overflow-x: hidden; 
    -webkit-overflow-scrolling: touch; 
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

/* ZWINGT JEDE SEITE IN DAS RASTER. BLOCKIERT FIXED-OVERLAYS! */
#main-content-wrapper > div[id^="page-"]:not(.hidden) {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 !important;
    width: 100% !important;
    max-width: 100% !important;
    position: relative !important;
    top: auto !important; left: auto !important; bottom: auto !important; right: auto !important;
    inset: auto !important;
    transform: none !important;
    margin: 0 !important;
    z-index: 1 !important;
}

/* COMPONENTS */
.card-std { background: white; border: none; border-radius: 16px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); margin-bottom: 20px; padding: 24px; }
.nav-btn { width: 100%; text-align: left; padding: 12px 24px; border: none; background: transparent; color: #64748b; font-weight: 500; display: flex; align-items: center; margin-bottom: 4px; border-radius: 0 24px 24px 0; white-space: nowrap; }
.nav-btn:hover { background: #f1f5f9; color: var(--primary); }
.nav-btn.active { background: #eff6ff; color: var(--primary); font-weight: 600; border-right: 3px solid var(--primary); }
.hidden { display: none !important; }

/* NOTIFICATIONS (GLOCKE) */
.notif-dropdown { width: 320px; max-height: 400px; overflow-y: auto; overflow-x: hidden; padding: 0; border-radius: 12px; }
.notif-item { padding: 12px 16px; border-bottom: 1px solid #e2e8f0; cursor: pointer; transition: background 0.2s; }
.notif-item:hover { background: #f8fafc; }
.notif-item:last-child { border-bottom: none; }

/* LOGIN & UI */
#login-overlay { position: fixed; inset: 0; background: #f8fafc; z-index: 9999; display: flex; align-items: center; justify-content: center; }
.avatar-initials { width: 40px; height: 40px; border-radius: 12px; background: #e0e7ff; color: #4338ca; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
#sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1035; display: none; backdrop-filter: blur(2px); }
#sidebar-overlay.show { display: block; }

/* MOBILE ANPASSUNG */
@media (max-width: 991.98px) { 
    #sidebar { 
        position: fixed; 
        top: 0; bottom: 0; left: 0; 
        transform: translateX(-100%); 
        width: 280px; 
        box-shadow: 0 0 20px rgba(0,0,0,0.1); 
    } 
    #sidebar.open, #sidebar.active { transform: translateX(0); } 
    #main { width: 100vw; }
    #main-content-wrapper { padding: 15px; } 
    .card-std { padding: 20px; border-radius: 12px; margin-bottom: 15px; } 
    #tour-map { min-height: 300px; }
    .notif-dropdown { width: 280px; }
}

/* DESKTOP COLLAPSE */
@media (min-width: 992px) {
    body.sidebar-collapsed #sidebar { width: 80px; min-width: 80px; }
    body.sidebar-collapsed .sidebar-text, 
    body.sidebar-collapsed .text-uppercase,
    body.sidebar-collapsed .user-info-box { display: none !important; }
    body.sidebar-collapsed .nav-btn { padding-left: 0; padding-right: 0; justify-content: center; }
    body.sidebar-collapsed .nav-btn i { margin-right: 0 !important; font-size: 1.4rem; }
    body.sidebar-collapsed .sidebar-header { justify-content: center; padding: 1rem 0 !important; }
    body.sidebar-collapsed .sidebar-header img { margin: 0; height: 32px; }
    body.sidebar-collapsed #nav-links { padding-left: 0.5rem; padding-right: 0.5rem; }
}

/* UTIL CLASSES */
.hover-bg:hover { background-color: rgba(0,0,0,0.02); }
.cursor-pointer { cursor: pointer; }
.task-done { text-decoration: line-through; color: #94a3b8; }
.task-prio-1 { border-left: 4px solid #ef4444 !important; } 
.task-prio-2 { border-left: 4px solid #f59e0b !important; } 
.task-prio-3 { border-left: 4px solid #10b981 !important; }

/* SPECIAL CARDS */
.note-card { background: #fffbeb; border: 1px solid #fcd34d; border-radius: 8px; padding: 15px; cursor: pointer; transition: 0.2s; height: 100%; position: relative; overflow:hidden; }
.note-card:hover { transform: translateY(-3px); box-shadow: 0 4px 12px rgba(251, 191, 36, 0.2); }

/* NOTE ATTACHMENTS (MINI FIXED) */
.note-attach-wrapper { position: relative; display: inline-block; margin-right: 5px; margin-bottom: 5px; }
.note-attach-thumb { width: 60px !important; height: 60px !important; min-width: 60px; object-fit: cover; border-radius: 8px; border: 2px solid #e2e8f0; cursor: zoom-in; transition: all 0.2s; background: #fff; display: block; }
.note-attach-thumb:hover { border-color: var(--primary); }
.note-file-link { width: 60px !important; height: 60px !important; min-width: 60px; display: flex; align-items: center; justify-content: center; background: #f1f5f9; border-radius: 8px; border: 2px solid #e2e8f0; color: #64748b; font-size: 1.5rem; text-decoration: none; display: block; }
.note-file-link:hover { background: #e2e8f0; color: var(--primary); }
.note-attach-del { position: absolute; top: -8px; right: -8px; background: #ef4444; color: white; border-radius: 50%; width: 22px; height: 22px; font-size: 14px; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.15); z-index: 20; transition: transform 0.2s; }
.note-attach-del:hover { background: #dc2626; transform: scale(1.1); }

/* CUSTOMER DOCUMENTS PREVIEW */
.doc-card { width: 100px; cursor: pointer; transition: transform 0.2s; margin-bottom: 10px; }
.doc-card:hover { transform: translateY(-3px); }
.doc-thumb-img { width: 100px; height: 100px; object-fit: cover; border-radius: 12px; border: 1px solid #e2e8f0; background: white; }
.doc-thumb-icon { width: 100px; height: 100px; display: flex; align-items: center; justify-content: center; background: #f8fafc; border-radius: 12px; border: 1px solid #e2e8f0; color: #94a3b8; font-size: 2.5rem; }
.doc-card-name { font-size: 0.75rem; text-align: center; margin-top: 6px; font-weight: 600; color: #475569; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* TOUR & CALENDAR */
#tour-map { height: 100%; width: 100%; border-radius: 0; z-index: 1; }
.tour-item { border-left: 3px solid transparent; transition: 0.2s; cursor: pointer; }
.tour-item:hover { background-color: #f8fafc; border-left-color: var(--primary); }
.tour-badge { width: 28px; height: 28px; background: var(--primary); color: white; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: bold; flex-shrink: 0; }

/* FULLCALENDAR OVERRIDES */
.fc-header-toolbar { display: none !important; } 
.fc-col-header-cell { padding: 10px 0 !important; background: #f8fafc; border: none !important; color: #64748b; font-weight: 600; text-transform: uppercase; font-size: 0.75rem; }
.fc-daygrid-day { border: 1px solid #f1f5f9 !important; } 
.fc-event { border: none !important; padding: 2px 4px; font-size: 0.85rem; border-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); } 
.fc-day-today { background-color: #f0f9ff !important; }

/* MINI CALENDAR */
#cal-mini .fc-toolbar-title { font-size: 1rem !important; font-weight: 800; color: #1e293b; padding-left: 5px; } 
#cal-mini .fc-button { padding: 0 !important; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; background: transparent; color: #64748b; border: none; border-radius: 50%; margin: 0 2px; }
#cal-mini .fc-button:hover { background: #f1f5f9; color: var(--primary); } 
#cal-mini .fc-header-toolbar { display: flex !important; margin-bottom: 15px !important; align-items: center; }
#cal-mini .fc-daygrid-day-number { font-size: 0.75rem; text-decoration: none; color: #475569; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; margin: 0 auto; cursor: pointer; }
#cal-mini .fc-daygrid-day-number:hover { background-color: #f1f5f9; border-radius: 50%; } 
#cal-mini .fc-day-today .fc-daygrid-day-number { background: var(--primary) !important; color: white !important; border-radius: 50%; font-weight: bold; }
#cal-mini .fc-daygrid-day, #cal-mini .fc-scrollgrid, #cal-mini .fc-theme-standard td, #cal-mini .fc-theme-standard th { border: none !important; }

/* CHAT STYLES */
.chat-msg { background: white; padding: 10px 15px; border-radius: 12px; max-width: 80%; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.chat-msg.self { background: #eff6ff; align-self: flex-end; border: 1px solid #dbeafe; }
.chat-msg.system { background: #f1f5f9; align-self: center; font-size: 0.85rem; color: #64748b; }
.chat-msg.other { background: #ffffff; align-self: flex-start; border: 1px solid #e2e8f0; }

/* MOBILE & DESKTOP BEHAVIOR */
.mobile-header { display: none; align-items: center; padding: 12px 20px; background: white; border-bottom: 1px solid #e2e8f0; justify-content: space-between; flex-shrink: 0; }

/* DARK MODE OVERRIDES */
[data-bs-theme="dark"] #sidebar { background-color: var(--bs-body-bg) !important; border-color: var(--bs-border-color) !important; }
[data-bs-theme="dark"] .sidebar-header, [data-bs-theme="dark"] .sidebar-bottom-area { border-color: var(--bs-border-color) !important; }
[data-bs-theme="dark"] .nav-btn { color: #adb5bd; }
[data-bs-theme="dark"] .nav-btn:hover { background-color: var(--bs-tertiary-bg); color: var(--bs-body-color); }
[data-bs-theme="dark"] .nav-btn.active { background-color: rgba(59, 130, 246, 0.15); color: var(--primary); border-right-color: var(--primary); }
[data-bs-theme="dark"] .notif-dropdown { background-color: var(--bs-body-bg); border-color: var(--bs-border-color); }
[data-bs-theme="dark"] .notif-item { border-bottom-color: var(--bs-border-color); }
[data-bs-theme="dark"] .notif-item:hover { background-color: var(--bs-tertiary-bg); }

.fade-in { animation: fadeIn 0.3s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }