/* ===================================================================
   EASYBAKUS – LAYOUT (App-Shell: Sidebar, Topbar, Main, Footer)
   -------------------------------------------------------------------
   S04/Welle 4: aus dem <style>-Block von Layout/MainLayout.razor
   herausgelöst (dort ~900 Zeilen). Inhalt unverändert; lediglich die
   Razor-Escapes `@@media` wurden zu regulärem `@media`.
   =================================================================== */

    .top-row {
        min-height: 10vh;
        max-height: 15vh;
        height: auto;
        background-color: #0f172a !important;
        border-bottom: 1px solid #1e293b !important;
        display: flex;
        align-items: center;
        padding: 1rem 0;
    }

    .top-row-content {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 2rem;
    }

    .logo-section {
        flex: 0 0 auto;
        display: flex;
        align-items: center;
    }

    .logo {
        height: min(8rem, 10vh);
        max-height: 8rem;
        width: auto;
        object-fit: contain;
        transition: height 0.3s ease;
    }

    .title-section {
        flex: 1;
        text-align: center;
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 2rem;
    }

        .title-section h1 {
            margin: 0;
            font-size: 2rem;
            font-weight: 600;
        }

    .main-nav {
        flex: 1;
        display: flex;
        justify-content: center;
    }

    .auth-section {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    /* Navigation Styles */
    .nav-menu {
        display: flex;
        gap: 2.5rem;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .nav-item {
        position: relative;
    }

    /* Home Dropdown */
    .nav-item.has-dropdown {
        position: relative;
    }

    .nav-item.has-dropdown:hover .nav-dropdown {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .nav-dropdown {
        position: absolute;
        top: 100%;
        left: 0;
        margin-top: 0.5rem;
        background-color: var(--secondary-light);
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        min-width: 220px;
        z-index: 1100;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: all 0.3s ease;
    }

    .nav-dropdown-item {
        display: block;
        padding: 0.9rem 1.2rem;
        color: var(--text-dark);
        text-decoration: none;
        transition: all 0.2s ease;
        cursor: pointer;
        border-bottom: 1px solid var(--primary-transparent-10);
    }

    .nav-dropdown-item:last-child {
        border-bottom: none;
        border-radius: 0 0 8px 8px;
    }

    .nav-dropdown-item:first-child {
        border-radius: 8px 8px 0 0;
    }

    .nav-dropdown-item:hover {
        background-color: var(--primary-transparent-10);
        color: var(--primary-text);
    }

    .nav-link-item {
        color: #e5e7eb;
        text-decoration: none;
        font-weight: 500;
        font-size: 0.95rem;
        padding: 0.5rem 1rem;
        border-radius: 5px;
        transition: all 0.3s ease;
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        position: relative;
    }

        .nav-link-item:hover {
            color: #B0E0B6;
            background-color: rgba(176,224,182,0.1);
            transform: translateY(-2px);
        }

        .nav-link-item::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            width: 0;
            height: 2px;
            background-color: #B0E0B6;
            transition: all 0.3s ease;
            transform: translateX(-50%);
        }

        .nav-link-item:hover::after {
            width: 80%;
        }

        .nav-link-item.active {
            color: #B0E0B6;
            background-color: rgba(176,224,182,0.15);
            font-weight: 600;
        }

            .nav-link-item.active::after {
                width: 80%;
            }

    .dropdown-icon {
        font-size: 0.8rem;
        transition: transform 0.3s ease;
    }

    .nav-item.has-dropdown:hover .dropdown-icon {
        transform: rotate(180deg);
    }

    /* Auth Button (isolated on right) */
    .auth-button {
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 6px;
        padding: 0.5rem 1.2rem;
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        text-decoration: none;
        display: inline-block;
        white-space: nowrap;
    }

    .auth-button:hover {
        background-color: var(--primary-dark);
        transform: translateY(-2px);
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    }

    .contact-section {
        flex: 0 0 auto;
        position: relative;
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    /* User Dropdown */
    .user-menu {
        position: relative;
    }

    .user-button {
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 6px;
        padding: 0.6rem 1.2rem;
        font-size: 1rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.3s ease;
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .user-button:hover {
        background-color: var(--primary-dark);
        transform: translateY(-2px);
    }

    .user-dropdown {
        position: absolute;
        top: 100%;
        right: 0;
        margin-top: 0.5rem;
        background-color: var(--secondary-light);
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        min-width: 220px;
        z-index: 1100;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        transition: all 0.3s ease;
    }

    .user-dropdown.show {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }

    .user-dropdown-item {
        display: block;
        padding: 0.9rem 1.2rem;
        color: var(--text-dark);
        text-decoration: none;
        transition: all 0.2s ease;
        cursor: pointer;
        border-bottom: 1px solid var(--primary-transparent-10);
    }

    .user-dropdown-item:last-child {
        border-bottom: none;
    }

    .user-dropdown-item:hover {
        background-color: var(--primary-transparent-10);
        color: var(--primary-text);
    }

    .user-dropdown-item.danger {
        color: #dc3545;
    }

    .user-dropdown-item.danger:hover {
        background-color: rgba(220, 53, 69, 0.1);
    }

    /* Burger Menu */
    .burger-menu {
        display: none;
        flex-direction: column;
        cursor: pointer;
        padding: 0.5rem;
        z-index: 1001;
        background: transparent;
        border: none;
    }

    .burger-line {
        width: 30px;
        height: 3px;
        background-color: var(--text-dark);
        margin: 4px 0;
        transition: all 0.3s ease;
        border-radius: 2px;
    }

    .burger-menu.active .burger-line:nth-child(1) {
        transform: rotate(-45deg) translate(-5px, 6px);
        background-color: var(--primary-color);
    }

    .burger-menu.active .burger-line:nth-child(2) {
        opacity: 0;
    }

    .burger-menu.active .burger-line:nth-child(3) {
        transform: rotate(45deg) translate(-5px, -6px);
        background-color: var(--primary-color);
    }

    .mobile-nav-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
        pointer-events: none;
    }

        .mobile-nav-overlay.show {
            opacity: 1;
            visibility: visible;
            pointer-events: auto;
        }

    .mobile-nav-menu {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 300px;
        height: 100%;
        background-color: var(--secondary-light);
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.2);
        z-index: 1000;
        transition: right 0.3s ease;
        overflow-y: auto;
        padding: 2rem 1rem;
    }

        .mobile-nav-menu.show {
            right: 0;
        }

        .mobile-nav-menu .nav-menu {
            flex-direction: column;
            gap: 0;
            width: 100%;
        }

        .mobile-nav-menu .nav-item {
            width: 100%;
            border-bottom: 1px solid var(--primary-transparent-10);
        }

        .mobile-nav-menu .nav-link-item {
            display: block;
            width: 100%;
            padding: 1rem;
            font-size: 1.1rem;
            text-align: left;
            border-radius: 0;
        }

                .mobile-nav-menu .nav-link-item::after {
                    display: none;
                }

                .mobile-nav-menu .nav-link-item.danger {
                    color: #dc3545;
                }

            .mobile-category {
                padding: 0.5rem 1rem;
                background-color: var(--primary-transparent-10);
                margin-top: 0.5rem;
            }

            .mobile-category-title {
                color: var(--primary-text);
                font-weight: 700;
                font-size: 0.9rem;
                text-transform: uppercase;
                letter-spacing: 0.5px;
            }

    .current-page-title {
        display: none;
        font-size: 1.1rem;
        font-weight: 600;
        color: var(--primary-text);
    }

    .footer {
        height: auto;
        min-height: 40vh;
        background-color: #0f172a;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 2rem;
        scroll-margin-top: 2rem;
    }

    .footer-title {
        font-size: 4rem;
        font-weight: bold;
        text-align: center;
        width: 100%;
        margin: 0;
        margin-bottom: 1rem;
        color: #B0E0B6;
    }

    .footer-divider {
        width: 100%;
        height: 10px;
        background-color: #B0E0B6;
    }

    .footer-content {
        width: 100%;
        display: flex;
        flex-direction: row;
        gap: 2rem;
        justify-content: space-between;
    }

    .footer-column {
        flex: 1;
        text-align: left;
    }

        .footer-column p {
            margin: 0.5rem 0;
            color: #94a3b8;
        }

    .footer-link {
        color: #B0E0B6;
        text-decoration: none;
        font-weight: 500;
        transition: all 0.3s ease;
    }

        .footer-link:hover {
            color: #e5e7eb;
            text-decoration: underline;
        }

    .scroll-to-top {
        position: fixed;
        bottom: 2rem;
        left: 2rem;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background-color: rgba(176, 224, 182, 0.55);
        color: #0f172a;
        border: 1px solid rgba(176, 224, 182, 0.7);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        cursor: pointer;
        display: none;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 1000;
        transition: all 0.3s ease;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
    }

        .scroll-to-top:hover {
            background-color: rgba(176, 224, 182, 0.85);
            transform: scale(1.1);
        }

        .scroll-to-top.show {
            display: flex;
        }

    /* Mobile Optimierungen — auch fuer Handys im Querformat (niedrig statt schmal),
       damit die oeffentliche Kopfleiste dort ebenfalls das Burger-Menue zeigt. Dieselbe
       Weiche wie fuer die App-Sidebar weiter unten. */
    @media (max-width: 768px), (max-height: 500px) {
        .top-row {
            min-height: 8vh;
            max-height: 12vh;
            padding: 0.8rem 0;
        }

        .top-row-content {
            padding: 0 1rem;
            flex-wrap: nowrap;
            gap: 1rem;
        }

        .logo {
            height: min(4rem, 8vh);
            max-height: 4rem;
        }

        .title-section {
            flex: 1;
        }

            .title-section .main-nav {
                display: none;
            }

            .title-section .auth-section {
                display: none;
            }

        .current-page-title {
            display: block;
        }

        .burger-menu {
            display: flex;
        }

        .footer {
            min-height: auto;
            padding: 1.5rem 1rem;
        }

        .footer-title {
            font-size: 1.8rem;
            margin-bottom: 0.5rem;
        }

        .footer-divider {
            height: 5px;
        }

        .footer-content {
            flex-direction: column;
            gap: 1rem;
        }

        .footer-column p {
            font-size: 0.9rem;
            margin: 0.25rem 0;
        }

        .scroll-to-top {
            width: 45px;
            height: 45px;
            bottom: 1rem;
            left: 1rem;
            font-size: 1.2rem;
        }
    }

    /* Tablet Optimierungen */
    @media (min-width: 769px) and (max-width: 1024px) {
        .top-row {
            min-height: 9vh;
        }

        .logo {
            height: min(6rem, 9vh);
            max-height: 6rem;
        }

        .footer-title {
            font-size: 3rem;
        }

        .nav-menu {
            gap: 1.5rem;
        }

        .nav-link-item {
            font-size: 1rem;
            padding: 0.5rem 1rem;
        }

        .user-button {
            font-size: 0.9rem;
            padding: 0.5rem 1rem;
        }
    }

    /* Desktop Small (1025px - 1366px) */
    @media (min-width: 1025px) and (max-width: 1366px) {
        .logo {
            height: min(7rem, 10vh);
            max-height: 7rem;
        }

        .nav-menu {
            gap: 2rem;
        }

        .nav-link-item {
            font-size: 1.1rem;
            padding: 0.5rem 1rem;
        }
    }

    /* Desktop Medium (1367px - 1600px) */
    @media (min-width: 1367px) and (max-width: 1600px) {
        .logo {
            height: min(8rem, 10vh);
            max-height: 8rem;
        }

        .nav-menu {
            gap: 2.5rem;
        }
    }

    /* ============================================
       Authenticated User Layout: Left Sidebar
       ============================================ */

    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        height: 100vh;
        background-color: var(--secondary-light);
        border-right: 1px solid var(--primary-transparent-10);
        display: flex;
        flex-direction: column;
        z-index: 200;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-logo {
        padding: 0.875rem 1.25rem;
        height: 52px;
        display: flex;
        align-items: center;
        gap: 0.65rem;
        border-bottom: 1px solid var(--primary-transparent-10);
        flex-shrink: 0;
        box-sizing: border-box;
    }

    .sidebar-logo img {
        height: 2rem;
        width: auto;
    }

    .sidebar-logo-text {
        font-size: 0.95rem;
        font-weight: 700;
        color: var(--primary-text);
    }

    .sidebar-top {
        flex: 1;
        padding: 0.5rem 0;
        overflow-y: auto;
    }

    .sidebar-mid {
        padding: 0.5rem 0;
        border-top: 1px solid var(--primary-transparent-10);
        flex-shrink: 0;
    }

    .sidebar-bottom {
        padding: 0.5rem 0;
        border-top: 1px solid var(--primary-transparent-10);
        flex-shrink: 0;
    }

    .sidebar-section-label {
        padding: 0.5rem 1.25rem 0.2rem;
        font-size: 0.7rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.07em;
        color: var(--muted-color, #94a3b8);
        opacity: 0.7;
    }

    .sidebar-link {
        display: flex;
        align-items: center;
        gap: 0.55rem;
        padding: 0.45rem 1.25rem;
        color: var(--text-dark);
        text-decoration: none;
        font-size: 0.875rem;
        font-weight: 500;
        transition: background-color 0.15s ease, color 0.15s ease;
        cursor: pointer;
        white-space: nowrap;
        border: none;
        background: transparent;
        width: 100%;
        text-align: left;
        box-sizing: border-box;
    }

    .sidebar-link:hover {
        background-color: var(--primary-transparent-10);
        color: var(--primary-text);
    }

    .sidebar-link.active {
        background-color: var(--primary-transparent-15);
        color: var(--primary-text);
        font-weight: 600;
    }

    .sidebar-link.danger {
        color: #dc3545;
    }

    .sidebar-link.danger:hover {
        background-color: rgba(220, 53, 69, 0.08);
        color: #dc3545;
    }

    .sidebar-badge {
        margin-left: auto;
        background-color: var(--primary-color);
        color: white;
        font-size: 0.68rem;
        font-weight: 700;
        min-width: 1.2rem;
        height: 1.2rem;
        border-radius: 10px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0 0.3rem;
    }

    .app-main {
        margin-left: 260px;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        /* Stretch in the parent flex row so content uses the full width
           between the fixed sidebar and the viewport edge. min-width:0
           prevents wide children (tables, charts) from forcing the flex
           item past 100% and causing horizontal scroll. */
        flex: 1 1 auto;
        min-width: 0;
    }

    .breadcrumb-bar {
        /* Höhe bündig mit dem Sidebar-Kopf (.sidebar-logo = 52px, box-sizing:
           border-box) → beide Unterkanten liegen auf derselben Linie. */
        height: 52px;
        display: flex;
        align-items: center;
        padding: 0 1.5rem;
        /* S03: bündig zur Navbar (.app-sidebar nutzt ebenfalls var(--secondary-light)) —
           unabhängig vom Sub-Content, da global (nicht innerhalb .analysis-page). */
        background-color: var(--secondary-light);
        border-bottom: 1px solid var(--line);
        border-radius: 0;
        position: sticky;
        /* Unter der festen Mobil-Kopfleiste kleben, nicht dahinter. Mit `top: 0` rutschte
           die Leiste beim Scrollen unter die Kopfleiste und schien durch sie hindurch
           („Easybakus" mit der Pfadangabe blass darüber). Auf dem Desktop ist die
           Variable 0. */
        top: var(--app-topbar-h, 0px);
        z-index: 150;
        width: 100%;
        box-sizing: border-box;
    }

    .content-area {
        flex: 1;
        padding: 1.5rem 1.5rem 0;
        width: 100%;
        box-sizing: border-box;
    }

    .sidebar-group-toggle {
        display: flex;
        align-items: center;
        gap: 0.55rem;
        padding: 0.45rem 1.25rem;
        color: var(--text-dark);
        font-size: 0.875rem;
        font-weight: 500;
        transition: background-color 0.15s ease, color 0.15s ease;
        cursor: pointer;
        white-space: nowrap;
        border: none;
        background: transparent;
        width: 100%;
        text-align: left;
        box-sizing: border-box;
    }

    .sidebar-group-toggle:hover {
        background-color: var(--primary-transparent-10);
        color: var(--primary-text);
    }

    .sidebar-chevron {
        margin-left: auto;
        font-size: 0.7rem;
        transition: transform 0.2s ease;
    }

    .sidebar-chevron.rotated {
        transform: rotate(180deg);
    }

    .sidebar-submenu .sidebar-link {
        font-size: 0.82rem;
        padding: 0.35rem 1.25rem 0.35rem 2.5rem;
        opacity: 0.85;
    }

    .sidebar-submenu .sidebar-link:hover {
        opacity: 1;
    }

    .mobile-topbar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 52px;
        background-color: var(--secondary-light);
        border-bottom: 1px solid var(--secondary-color);
        z-index: 300;
        align-items: center;
        padding: 0 1rem;
        gap: 0.75rem;
    }

    .mobile-topbar-logo img {
        height: 1.75rem;
        width: auto;
    }

    .mobile-topbar-title {
        flex: 1;
        font-size: 0.9rem;
        font-weight: 700;
        color: var(--primary-text);
    }

    .mobile-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 199;
    }

    .mobile-sidebar-overlay.show {
        display: block;
    }

    /* Burger statt fester Sidebar: auf schmalen Schirmen UND auf niedrigen. Ein Handy im
       Querformat ist 800–930 px breit, aber nur 320–430 px hoch — bisher bekam es die
       Desktop-Sidebar, die 260 px der Breite und die ganze Höhe belegte. Die Höhe ist
       das Kriterium: Tablets im Querformat (≥ 744 px hoch) behalten die Sidebar.

       Die beiden Blöcke sind exakte Gegenstücke — (≤ 768 breit ODER ≤ 500 hoch) gegen
       (≥ 769 breit UND ≥ 501 hoch). Wer einen der beiden ändert, muss den anderen
       mitziehen, sonst gibt es Fenstergrößen mit beiden oder keiner Navigation. */
    @media (max-width: 768px), (max-height: 500px) {
        :root {
            /* Höhe der festen Mobil-Kopfleiste. Sticky-Elemente (Breadcrumb, Report-Kopf)
               rechnen sie in ihr `top` ein, sonst kleben sie UNTER der Leiste. */
            --app-topbar-h: 52px;
        }

        .app-sidebar {
            transform: translateX(-100%);
            transition: transform 0.25s ease;
        }

        .app-sidebar.sidebar-open {
            transform: translateX(0);
        }

        .app-main {
            margin-left: 0;
            padding-top: 52px;
        }

        .mobile-topbar {
            display: flex;
        }
    }

    /* Niedrige Schirme: Die Sidebar scrollt als Ganzes. Sonst bekommt der obere Block
       (flex: 1, eigener Scrollbereich) nur den Rest neben den nicht schrumpfenden
       Bloecken darunter — bei 390 px Hoehe ein Schlitz von drei Eintraegen mit eigener
       Scrollleiste, und das Kontomenue ganz unten lag halb ausserhalb des Bildes. */
    @media (max-height: 500px) {
        .app-sidebar .sidebar-top {
            flex: none;
            overflow: visible;
        }
    }

    @media (min-width: 769px) and (min-height: 501px) {
        .app-sidebar {
            transform: translateX(0) !important;
        }

        .mobile-topbar {
            display: none !important;
        }
    }
