/* ============================================
   KrossKontroll — Permanent Sidebar Layout
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --sidebar-width: 260px;
    --sidebar-compact-width: 68px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e8ecf0;
    --sidebar-accent: #008ace;
    --sidebar-accent-light: #e8f4fd;
    --sidebar-text: #3a4a5c;
    --sidebar-text-muted: #8896a4;
    --sidebar-hover-bg: #f0f5fa;
    --sidebar-active-bg: #e8f4fd;
    --sidebar-active-text: #008ace;
    --sidebar-transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --topbar-height: 0px;
}

/* --- App Layout (flex row) --- */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: width var(--sidebar-transition);
    overflow: hidden;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.04);
}

/* --- Sidebar Header --- */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--sidebar-border);
    min-height: 60px;
    flex-shrink: 0;
    background: linear-gradient(135deg, #e8f4fd 0%, #dceefb 100%);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--sidebar-accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar-brand-text {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--sidebar-text);
    letter-spacing: 0.02em;
    transition: opacity var(--sidebar-transition), width var(--sidebar-transition);
}

/* Toggle button */
.sidebar-toggle {
    width: 28px;
    height: 28px;
    border: 1px solid var(--sidebar-border);
    border-radius: 6px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-accent);
    border-color: var(--sidebar-accent);
}

/* --- Sidebar Body (scrollable nav) --- */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
}

/* Thin scrollbar inside sidebar */
.sidebar-body::-webkit-scrollbar {
    width: 4px;
}

.sidebar-body::-webkit-scrollbar-thumb {
    background: #c8d0d8;
    border-radius: 4px;
}

/* --- Section Headers --- */
.sidebar-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
    padding: 16px 20px 6px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity var(--sidebar-transition);
}

/* --- Nav Items --- */
.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-nav-item {
    position: relative;
}

.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.88rem;
    font-weight: 500;
    border-radius: 0;
    transition: all 0.15s ease;
    white-space: nowrap;
    overflow: hidden;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.sidebar-nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-accent);
    text-decoration: none;
}

.sidebar-nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.sidebar-nav-link.disabled-module {
    color: #b8c4ce;
    cursor: not-allowed;
}

.sidebar-nav-link.disabled-module:hover {
    background: transparent;
    color: #b8c4ce;
}

.sidebar-nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: font-size 0.15s ease;
}

.sidebar-nav-text {
    overflow: hidden;
    transition: opacity var(--sidebar-transition), width var(--sidebar-transition);
}

/* Dropdown arrow for expandable items */
.sidebar-nav-arrow {
    margin-left: auto;
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.sidebar-nav-link[aria-expanded="true"] .sidebar-nav-arrow {
    transform: rotate(90deg);
}

/* --- Sub-navigation (dropdowns become collapse lists) --- */
.sidebar-subnav {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #f7f9fb;
}

.sidebar-subnav .sidebar-nav-link {
    padding-left: 52px;
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--sidebar-text);
}

.sidebar-subnav .sidebar-nav-link:hover {
    color: var(--sidebar-accent);
    background: var(--sidebar-active-bg);
}

/* --- Sidebar Footer --- */
.sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 8px 0;
    flex-shrink: 0;
}

/* ============================================
   COMPACT MODE
   ============================================ */
.sidebar.compact {
    width: var(--sidebar-compact-width);
}

/* Hide text, arrows, and section titles completely */
.sidebar.compact .sidebar-brand-text,
.sidebar.compact .sidebar-nav-text,
.sidebar.compact .sidebar-nav-arrow {
    display: none !important;
}

.sidebar.compact .sidebar-section-title {
    display: none !important;
}

.sidebar.compact .sidebar-header {
    justify-content: center;
    padding: 16px 0 12px;
}

.sidebar.compact .sidebar-brand {
    justify-content: center;
    gap: 0;
}

.sidebar.compact .sidebar-toggle {
    display: none;
}

/* Center icons in compact nav links */
.sidebar.compact .sidebar-nav-link {
    justify-content: center;
    padding: 14px 0;
    gap: 0;
}

.sidebar.compact .sidebar-nav-icon {
    font-size: 1.2rem;
    width: auto;
}

/* Force-hide any open collapse panels in compact mode */
.sidebar.compact .collapse,
.sidebar.compact .collapse.show,
.sidebar.compact .collapsing {
    display: none !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Hide subnavs in compact mode */
.sidebar.compact .sidebar-subnav {
    display: none !important;
}

/* Footer links in compact mode */
.sidebar.compact .sidebar-footer .sidebar-nav-link {
    justify-content: center;
    padding: 12px 0;
    gap: 0;
}

/* Compact mode: show expand button at bottom */
.sidebar-expand-btn {
    display: none;
    width: 100%;
    padding: 12px 0;
    border: none;
    background: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: color 0.15s ease;
    font-size: 1rem;
}

.sidebar-expand-btn:hover {
    color: var(--sidebar-accent);
}

.sidebar.compact .sidebar-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--sidebar-border);
}

/* Hide divider text in compact */
.sidebar.compact .sidebar-divider {
    margin: 4px 12px;
}

/* ============================================
   FLYOUT MENU (compact mode dropdowns)
   ============================================ */
.sidebar-flyout {
    display: none;
    position: absolute;
    left: var(--sidebar-compact-width);
    top: 0;
    min-width: 220px;
    background: #fff;
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    box-shadow: 4px 4px 16px rgba(0, 0, 0, 0.1);
    padding: 6px 0;
    z-index: 1060;
}

.sidebar.compact .sidebar-nav-item:hover>.sidebar-flyout {
    display: block;
}

/* Reset styles for links inside flyouts */
.sidebar-flyout .sidebar-nav-link {
    padding: 8px 16px;
    justify-content: flex-start;
    gap: 10px;
}

.sidebar-flyout .sidebar-nav-link .sidebar-nav-icon {
    font-size: 0.9rem;
    width: 20px;
}

.sidebar-flyout .sidebar-nav-link .sidebar-nav-text {
    display: inline !important;
    opacity: 1 !important;
    width: auto !important;
}

/* ============================================
   MAIN CONTENT AREA
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    transition: margin-left var(--sidebar-transition);
    min-height: 100vh;
    padding-top: 16px;
}

/* When sidebar is compact, body gets this class via JS */
body.sidebar-is-compact .main-content {
    margin-left: var(--sidebar-compact-width);
}

/* Override body padding for the new layout */
body.has-sidebar {
    padding-bottom: 80px;
}

/* Fix the footer to the bottom of the viewport, offset by sidebar */
body.has-sidebar #footer {
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 1030;
    transition: left var(--sidebar-transition);
}

body.sidebar-is-compact #footer {
    left: var(--sidebar-compact-width);
}

/* ============================================
   MOBILE TOP BAR + OVERLAY MENU (<768px)
   ============================================ */

/* -- Mobile Top Bar -- */
.mobile-topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: #fff;
    border-bottom: 1px solid var(--sidebar-border);
    z-index: 1050;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.mobile-topbar .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.mobile-topbar .mobile-brand-icon {
    width: 36px;
    height: 36px;
    background: var(--sidebar-accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 1.1rem;
}

.mobile-topbar .mobile-brand-text {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--sidebar-text);
}

/* -- Hamburger Button -- */
.mobile-hamburger {
    width: 40px;
    height: 40px;
    border: none;
    background: none;
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.hamburger-lines {
    width: 24px;
    height: 18px;
    position: relative;
}

.hamburger-lines span {
    display: block;
    position: absolute;
    width: 100%;
    height: 2.5px;
    border-radius: 2px;
    background: var(--sidebar-text);
    left: 0;
    transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
}

.hamburger-lines span:nth-child(1) {
    top: 0;
}

.hamburger-lines span:nth-child(2) {
    top: 50%;
    transform: translateY(-50%);
}

.hamburger-lines span:nth-child(3) {
    bottom: 0;
}

/* Hamburger → X animation */
.mobile-hamburger.is-open .hamburger-lines span:nth-child(1) {
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
}

.mobile-hamburger.is-open .hamburger-lines span:nth-child(2) {
    opacity: 0;
    transform: translateX(10px);
}

.mobile-hamburger.is-open .hamburger-lines span:nth-child(3) {
    bottom: 50%;
    transform: translateY(50%) rotate(-45deg);
}

/* -- Fullscreen Overlay Menu -- */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1045;
}

.mobile-overlay-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 85%;
    max-width: 360px;
    background: #fff;
    overflow-y: auto;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 16px 0 80px;
}

.mobile-overlay.is-open {
    display: block;
}

.mobile-overlay.is-visible .mobile-overlay-backdrop {
    opacity: 1;
}

.mobile-overlay.is-visible .mobile-overlay-content {
    transform: translateX(0);
}

/* -- Mobile Menu Nav Styles -- */
.mobile-overlay .sidebar-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
    padding: 16px 20px 6px;
    margin: 0;
}

.mobile-overlay .sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
}

.mobile-overlay .sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 500;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease;
}

.mobile-overlay .sidebar-nav-link:hover,
.mobile-overlay .sidebar-nav-link:active {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-accent);
    text-decoration: none;
}

.mobile-overlay .sidebar-nav-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.mobile-overlay .sidebar-nav-link.disabled-module {
    color: #b8c4ce;
    cursor: not-allowed;
}

.mobile-overlay .sidebar-nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    flex-shrink: 0;
}

.mobile-overlay .sidebar-nav-arrow {
    margin-left: auto;
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

.mobile-overlay .sidebar-nav-link[aria-expanded="true"] .sidebar-nav-arrow {
    transform: rotate(90deg);
}

.mobile-overlay .sidebar-subnav {
    list-style: none;
    margin: 0;
    padding: 0;
    background: #f7f9fb;
}

.mobile-overlay .sidebar-subnav .sidebar-nav-link {
    padding-left: 52px;
    font-size: 0.86rem;
}

.mobile-overlay .sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 8px 16px;
}

.mobile-overlay .sidebar-footer {
    border-top: 1px solid var(--sidebar-border);
    padding: 8px 0;
    margin-top: 8px;
}

/* Hide flyouts in mobile overlay (use collapse instead) */
.mobile-overlay .sidebar-flyout {
    display: none !important;
}

@media (max-width: 767.98px) {

    /* Hide desktop sidebar */
    .sidebar {
        display: none !important;
    }

    /* Show mobile top bar */
    .mobile-topbar {
        display: flex;
    }

    /* Show mobile overlay */
    .mobile-overlay {
        /* display controlled by JS via .is-open class */
    }

    /* Adjust main content */
    .main-content {
        margin-left: 0 !important;
        padding-top: 72px;
    }

    /* Fix footer */
    body.has-sidebar #footer {
        left: 0 !important;
    }

    body.has-sidebar {
        padding-bottom: 60px;
    }
}

/* Divider line between sections */
.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 4px 16px;
}