/* NEU: Layouts – App-Shell (Betrieb), Mobile-Shell (Kunde/Monteur), Plain (Anmeldung), Seitenraster */

/* ------------------------------------------------------------ App-Shell Betrieb */
.app-shell {
    display: grid;
    /* ÄNDERUNG UX: minmax(0, 1fr) – sonst wächst die Spalte mit breitem Inhalt über den Bildschirm hinaus */
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    grid-template-rows: var(--header-height) 1fr;
    grid-template-areas: "sidebar header" "sidebar main";
    height: 100dvh;
    transition: grid-template-columns 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-collapsed .app-shell { grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }

.sidebar {
    grid-area: sidebar;
    display: flex; flex-direction: column;
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    overflow: hidden;
    z-index: 110;
}

.sidebar-brand {
    display: flex; align-items: center; gap: 0.75rem;
    height: var(--header-height); padding: 0 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-inverse); font-weight: 700; font-size: 1rem; letter-spacing: -0.3px;
    white-space: nowrap;
}
.sidebar-brand-icon {
    width: 34px; height: 34px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md); background: var(--info); color: var(--text-inverse);
}

.sidebar-nav { flex: 1; padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.25rem; overflow-y: auto; }

.sidebar-link {
    position: relative;
    display: flex; align-items: center; gap: 0.875rem;
    min-height: 42px; padding: 0.55rem 0.875rem;
    border-radius: var(--radius-md);
    color: var(--text-sidebar); font-weight: 500; white-space: nowrap;
    transition: var(--transition-fast);
}
.sidebar-link i { width: 20px; text-align: center; font-size: 1rem; flex-shrink: 0; }
.sidebar-link:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-inverse); }
.sidebar-link.active { background: rgba(255, 255, 255, 0.1); color: var(--text-inverse); }
.sidebar-link.active::before {
    content: ''; position: absolute; left: -0.75rem; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 var(--radius) var(--radius) 0; background: var(--info);
}

.sidebar-footer { padding: 0.75rem; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.sidebar-collapse-btn {
    width: 100%; min-height: 38px; border-radius: var(--radius-md);
    color: var(--text-sidebar); transition: var(--transition-fast);
}
.sidebar-collapse-btn:hover { background: rgba(255, 255, 255, 0.06); color: var(--text-inverse); }

.sidebar-collapsed .sidebar-link-label,
.sidebar-collapsed .sidebar-brand-text { display: none; }
.sidebar-collapsed .sidebar-link { justify-content: center; padding: 0.55rem; }
.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
.sidebar-collapsed .sidebar-collapse-btn i { transform: rotate(180deg); }

.sidebar-backdrop { display: none; }

.app-header {
    grid-area: header;
    display: flex; align-items: center; gap: 1rem;
    padding: 0 2rem;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    z-index: 100;
}
.app-header .header-menu-btn { display: none; }
.header-title { font-size: 1.05rem; font-weight: 600; letter-spacing: -0.2px; }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 0.375rem; }
.header-notification-btn { position: relative; }
.header-badge {
    position: absolute; top: 2px; right: 0;
    min-width: 18px; height: 18px; padding: 0 5px;
    border-radius: var(--radius-full); background: var(--danger); color: var(--text-inverse);
    font-size: 0.65rem; font-weight: 700; line-height: 18px; text-align: center;
}
.header-user { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.5rem 0 0.75rem; border-left: 1px solid var(--border); margin-left: 0.25rem; }
.header-user-text { display: flex; flex-direction: column; line-height: 1.25; }
.header-user-name { font-weight: 600; font-size: 0.85rem; }
.header-user-role { font-size: 0.72rem; color: var(--text-secondary); }

.app-main {
    grid-area: main;
    overflow-y: auto;
    padding: 2rem 2.5rem;
    background: var(--bg-page);
    animation: fadeIn 0.25s;
}
.app-main:focus-visible { box-shadow: none; }

/* ------------------------------------------------------------ Seitenaufbau */
.page { max-width: 1440px; margin: 0 auto; }
.page-narrow { max-width: 640px; margin: 2rem auto; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.page-title { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.5px; line-height: 1.2; }
.page-subtitle { color: var(--text-secondary); margin-top: 0.25rem; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1.25rem; }

/* ------------------------------------------------------------ Mobile-Shell Kunde/Monteur */
.customer-shell { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg-page); }

.mobile-header {
    position: sticky; top: 0; z-index: 100;
    display: flex; align-items: center; justify-content: space-between; gap: 0.75rem;
    min-height: 60px; padding: 0.5rem 0.75rem 0.5rem 1rem;
    background: var(--bg-header); box-shadow: var(--shadow-sm);
}
.mobile-header-brand { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.mobile-header-logo {
    width: 38px; height: 38px; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-md); background: var(--primary); color: var(--text-inverse);
}
.mobile-header-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.mobile-header-company { font-weight: 700; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mobile-header-title { font-size: 0.8rem; color: var(--text-secondary); }
.mobile-header-actions { display: flex; align-items: center; gap: 0.125rem; }
.mobile-header-actions .btn-icon { width: 44px; height: 44px; }

.customer-main {
    flex: 1;
    width: 100%; max-width: var(--content-max-customer);
    margin: 0 auto;
    padding: 1.25rem 1rem 2rem;
    overflow: visible;
    background: transparent;
}
.has-bottom-nav .customer-main { padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1.5rem); }

.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    height: calc(var(--bottom-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-card); box-shadow: 0 -2px 12px rgba(52, 80, 110, 0.1);
}
.bottom-nav-link {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.2rem;
    color: var(--text-secondary); font-size: 0.72rem; font-weight: 500;
    transition: var(--transition-fast);
}
.bottom-nav-link i { font-size: 1.15rem; }
.bottom-nav-link.active { color: var(--primary); }
:root.dark-mode .bottom-nav-link.active { color: var(--info-dark); }

/* ------------------------------------------------------------ Plain (Anmeldung) */
.plain-shell { min-height: 100dvh; background: var(--bg-page); }
.plain-main { padding: 2rem 1rem 3rem; }

/* ------------------------------------------------------------ Responsive */
@media (max-width: 1024px) {
    .app-shell { grid-template-columns: var(--sidebar-collapsed-width) minmax(0, 1fr); }
    .sidebar-link-label, .sidebar-brand-text { display: none; }
    .sidebar-link { justify-content: center; padding: 0.55rem; }
    .sidebar-brand { justify-content: center; padding: 0; }
    .sidebar-footer { display: none; }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .header-user-text { display: none; }
}

@media (max-width: 768px) {
    .app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "header" "main"; }
    .sidebar {
        position: fixed; top: 0; bottom: 0; left: 0; width: min(var(--sidebar-width), 85vw);
        transform: translateX(-100%); transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: var(--shadow-xl);
    }
    .sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 105; background: rgba(0, 0, 0, 0.45); animation: fadeIn 0.2s; }
    .sidebar-link-label, .sidebar-brand-text { display: inline; }
    .sidebar-link { justify-content: flex-start; padding: 0.55rem 0.875rem; min-height: var(--touch-target); }
    .sidebar-brand { justify-content: flex-start; padding: 0 1.25rem; }
    .app-header .header-menu-btn { display: inline-flex; }
    .app-header { padding: 0 0.75rem; gap: 0.5rem; }
    .header-user { display: none; }
    .app-main { padding: 1.25rem; }
    .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
    .page-title { font-size: 1.35rem; }
}
