.container {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* Shared portal content helpers */
.cards {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.card,
.chart-container,
.products,
.main form {
    width: 100%;
    border-radius: 12px;
}

.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-wrapper::-webkit-scrollbar {
    height: 6px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 999px;
}

.main .page-footer {
    margin-top: auto;
}

.sidebar {
    background: linear-gradient(145deg, #765c31 0%, #b68f47 100%);
    color: white;
    width: 250px;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: background 0.3s ease;
    position: relative;
    box-sizing: border-box;
}

body.dark .sidebar {
    background: linear-gradient(145deg, #2a2a40 0%, #1e1e2f 100%);
}

.sidebar h2 {
    text-align: center;
    margin-bottom: 1rem;
}

/* Ensure clickable logo anchors span the sidebar width */
.sidebar > a {
    display: block;
}

.sidebar > img,
.sidebar > a > img {
    width: 100%;
    align-content: center;
    margin-bottom: 20px;
}

.mobile-menu-icon {
    display: none;
}

.nav-items {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s ease;
    text-decoration: none;
    color: white;
    line-height: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-item svg,
.nav-item img {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    vertical-align: top;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white; /* override global anchor hover color */
}

/* Active sidebar entry */
.nav-item.active {
    background: rgba(255, 255, 255, 0.2);
}

.portal-link {
    margin-top: auto;
    text-align: center;
    font-size: 0.8rem;
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
}

.update-link {
    margin-top: auto;
    text-align: center;
    font-size: 0.8rem;
    position: absolute;
    bottom: 3rem;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
}
.portal-link a {
    color: white;
    text-decoration: none;
    font-size: 0.9em;
    margin: 0 auto;
    display: inline-block;
}
.portal-link img,
.portal-link svg {
    width: 1em;
    height: 1em;
    vertical-align: top;
    margin-right: 0.25rem;
}

.update-link a {
    color: white;
    text-decoration: none;
    font-size: 0.9em;
    display: inline-flex;
    align-items: center;
}

.update-link svg {
    width: 1em;
    height: 1em;
    vertical-align: middle;
    margin-right: 0.25rem;
}

@media (min-width: 769px) {
    .sidebar .nav-items {
        max-height: none;
        overflow: visible;
        display: flex;
        flex-direction: column;
    }
}

@media (max-width: 768px) {
    .container {
        flex-direction: column !important;
        width: 100% !important;
    }

    body {
        overflow-x: hidden;
    }

    body {
        overflow-x: hidden;
    }

    .nav-items {
        overflow: hidden;
        max-height: 0;
        transition: max-height 0.4s ease;
    }

    .sidebar.mobile-open .nav-items {
        max-height: 500px; /* adjust based on content */
        align-items: center; /* center links when menu is open */
    }

    .sidebar {
        width: 100% !important;
        padding: 1rem;
        gap: 0.5rem;
    }

    .sidebar.mobile-open {
        gap: 1rem;
    }

    .sidebar > img,
    .sidebar > a > img {
        width: 60%;
        margin-left: 20%;
        padding-top: 2vw;
    }

    .portal-link {
        position: static;
        margin-top: 1rem;
        text-align: center;
        width: 100%;
        left: auto;
        transform: none;
    }

    .update-link {
        position: static;
        margin-top: 1rem;
    }

    .sidebar:not(.mobile-open) .update-link {
        margin-top: 0.5rem;
    }

    .mobile-menu-icon {
        display: block;
        font-size: 2rem;
        cursor: pointer;
        text-align: center;
        margin-bottom: 0;
    }

    .main {
        padding: 1rem;
        padding-bottom: 0 !important;
        width: 100% !important;
    }

    .nav-item {
        text-align: center;
    }

    .sidebar.mobile-open .nav-item {
        justify-content: center; /* center icon and text */
    }

    .main {
        padding: 1rem !important;
        padding-bottom: 0 !important;
        width: 100% !important;
    }

    .toggle-theme {
        width: 100%;
        margin: 0 0 1rem 0 !important;
        align-self: stretch !important;
    }

    .cards {
        flex-direction: column;
        gap: 0.75rem;
    }

    .card,
    .chart-container,
    .products,
    .main form,
    .table-wrapper {
        padding: 1rem !important;
        min-width: auto !important;
        margin: 0;
    }

    .link-button {
        width: 100%;
        margin-right: 0 !important;
    }

    .table-wrapper table,
    .main table {
        min-width: 100% !important;
        font-size: 0.9rem;
    }

    .page-footer {
        padding-top: 0.5rem;
        padding-bottom: 1rem;
    }
}
