/* FMS Layout */
.fms-app { display: flex; min-height: 100vh; }

.fms-sidebar {
    width: var(--fms-sidebar-width);
    background: var(--fms-bg-sidebar) !important;
    position: fixed; top: 0; left: 0; height: 100vh;
    overflow-y: auto; overflow-x: hidden; z-index: 1000;
    transition: width var(--fms-transition);
    display: flex; flex-direction: column;
}
.fms-sidebar-brand {
    padding: 12px 16px;
    font-size: var(--fms-text-xl); font-weight: 700;
    letter-spacing: -0.5px;
    border-bottom: 1px solid rgba(0,0,0,0.08) !important;
    flex-shrink: 0;
    color: #1a1a1a !important;
}
.fms-sidebar-nav { flex: 1; padding: var(--fms-space-sm) 0; overflow-y: auto; }
.fms-nav-section {
    padding: 12px 16px 4px;
    margin-top: 4px;
    font-size: var(--fms-text-xs); font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.8px;
    color: #6b7280 !important;
}
.fms-nav-section .bi-chevron-down { transition: transform 0.2s; color: #9ca3af; }
.fms-nav-section[aria-expanded="false"] .bi-chevron-down { transform: rotate(-90deg); }
.fms-nav-item {
    display: block; padding: 6px 16px;
    color: #374151 !important; font-size: var(--fms-text-sm);
    transition: all var(--fms-transition); border-left: 3px solid transparent;
}
.fms-nav-item:hover { color: #111827 !important; background: rgba(0,0,0,0.05) !important; }
.fms-nav-item.active {
    color: #111827 !important; background: rgba(0,0,0,0.08) !important;
    border-left-color: #2563eb !important; font-weight: 500;
}
.fms-nav-item i { width: 20px; margin-right: var(--fms-space-sm); font-size: var(--fms-text-md); color: #6b7280; }
.fms-nav-item.active i { color: #2563eb; }
.fms-sidebar-footer {
    padding: var(--fms-space-md) var(--fms-space-lg);
    border-top: 1px solid rgba(0,0,0,0.08) !important; flex-shrink: 0;
}

/* Sidebar dark mode overrides */
[data-theme="dark"] .fms-sidebar-brand { color: #ffffff !important; border-bottom-color: rgba(255,255,255,0.08) !important; }
[data-theme="dark"] .fms-nav-section { color: rgba(255,255,255,0.5) !important; }
[data-theme="dark"] .fms-nav-section .bi-chevron-down { color: rgba(255,255,255,0.4); }
[data-theme="dark"] .fms-nav-item { color: rgba(255,255,255,0.75) !important; }
[data-theme="dark"] .fms-nav-item:hover { color: #ffffff !important; background: rgba(255,255,255,0.08) !important; }
[data-theme="dark"] .fms-nav-item.active { color: #ffffff !important; background: rgba(255,255,255,0.12) !important; }
[data-theme="dark"] .fms-nav-item i { color: rgba(255,255,255,0.5); }
[data-theme="dark"] .fms-nav-item.active i { color: #60a5fa; }
[data-theme="dark"] .fms-sidebar-footer { border-top-color: rgba(255,255,255,0.08) !important; }

.fms-main {
    margin-left: var(--fms-sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: calc(100vw - var(--fms-sidebar-width));
    overflow-x: hidden;
}
.fms-topbar {
    height: var(--fms-topbar-height); background: var(--fms-bg-topbar);
    border-bottom: 1px solid var(--fms-border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 var(--fms-space-lg); position: sticky; top: 0; z-index: 100; flex-shrink: 0;
}
.fms-topbar-left, .fms-topbar-right { display: flex; align-items: center; gap: var(--fms-space-md); }
.fms-content {
    flex: 1;
    padding: var(--fms-space-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Report wrapper */
.fms-report-wrapper { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.fms-report-header, .fms-report-filters, .fms-report-controls { flex-shrink: 0; margin-bottom: var(--fms-space-md); }
.fms-report-controls { margin-bottom: var(--fms-space-sm); }
.fms-table-container {
    flex: 1;
    overflow: auto;
    border: 1px solid var(--fms-border);
    border-radius: var(--fms-radius);
    min-height: 0;
    min-width: 0;
    max-width: 100%;
}
.fms-report-footer { flex-shrink: 0; margin-top: var(--fms-space-sm); }

/* Universal sidebar toggle button */
.fms-sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--fms-border);
    border-radius: var(--fms-radius);
    background: var(--fms-bg-card);
    color: var(--fms-text);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1rem;
}
.fms-sidebar-toggle:hover {
    background: var(--fms-bg);
    border-color: var(--fms-text-secondary);
}

/* Sidebar toggle — single mechanism for all devices */
.fms-sidebar {
    transition: transform 0.25s ease;
}

body.sidebar-hidden .fms-sidebar {
    transform: translateX(-100%);
}
body.sidebar-hidden .fms-main {
    margin-left: 0;
    max-width: 100vw;
}
body.sidebar-hidden .fms-main {
    transition: margin-left 0.25s ease, max-width 0.25s ease;
}

/* Sidebar close button — visible only on mobile */
.fms-sidebar-close {
    display: none;
    margin-left: auto;
    background: transparent;
    border: 0;
    color: inherit;
    font-size: 1.1rem;
    line-height: 1;
    padding: 6px 10px;
    border-radius: var(--fms-radius);
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s ease, background 0.15s ease;
}
.fms-sidebar-close:hover { opacity: 1; background: rgba(0,0,0,0.06); }
[data-theme="dark"] .fms-sidebar-close:hover { background: rgba(255,255,255,0.08); }

/* Mobile — sidebar is overlay, not pushing content */
@media (max-width: 768px) {
    .fms-sidebar {
        position: fixed !important;
        top: 0;
        left: 0;
        z-index: 1050;
        height: 100vh;
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin-left: 0 !important;
        transform: translateX(-100%);
    }
    body.sidebar-visible-mobile .fms-sidebar {
        transform: translateX(0) !important;
    }
    .fms-sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
    .fms-main {
        margin-left: 0;
        max-width: 100vw;
    }
    .fms-content { padding: var(--fms-space-md); }

    /* Hide verbose topbar elements on mobile */
    .fms-topbar-user-name,
    .fms-topbar-admin-badge,
    .fms-topbar-logout-text {
        display: none !important;
    }
    /* Hide sync button in topbar on mobile — sync is available in report page */
    .fms-topbar .fms-topbar-sync,
    .fms-topbar .fms-btn[onclick*="openSyncSidebar"],
    .fms-topbar button[onclick*="openSyncSidebar"] {
        display: none !important;
    }
    /* Compact topbar */
    .fms-topbar {
        padding: 0 12px;
    }
    .fms-topbar-right {
        gap: 6px;
    }
}

/* Desktop — sidebar pushes content */
@media (min-width: 769px) {
    .fms-sidebar {
        transform: translateX(0);
    }
}

/* Overlay for mobile */
#fmsSidebarOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1040;
    display: none;
}
