/* Modern Layout - Sidebar Styles */
/* Used by modern.html */

:root {
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 60px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #e0e0e0;
    --sidebar-text: #333333;
    --sidebar-hover: #f5f5f5;
    --sidebar-active: #e3f2fd;
    --sidebar-active-text: #2874B5;
    --header-height: 60px;
}

body.modern-body {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
}

.modern-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: width 0.3s ease;
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 15px;
    border-bottom: 1px solid var(--sidebar-border);
    box-sizing: border-box;
    flex-shrink: 0;
}

.sidebar-logo {
    height: 60px;
    width: auto;
    background-color: white;
    padding: 5px 10px;
    border-radius: 4px;
    flex-shrink: 0;
    margin-bottom: 10px;
    transition: opacity 0.2s;
}

/* Full logo - shown when expanded */
.sidebar-logo-full {
    display: block;
}

/* Icon logo - hidden when expanded */
.sidebar-logo-icon {
    display: none;
    height: 40px;
    padding: 3px;
}

/* Collapsed state: hide full logo, show icon */
.sidebar.collapsed .sidebar-logo-full {
    display: none;
}

.sidebar.collapsed .sidebar-logo-icon {
    display: block;
    margin-bottom: 0;
}

.sidebar.collapsed .sidebar-header {
    padding: 10px;
}

.sidebar-title {
    font-size: 1em;
    font-weight: 600;
    color: #2874B5;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s, height 0.2s;
    text-align: center;
}

.sidebar.collapsed .sidebar-title {
    opacity: 0;
    height: 0;
    overflow: hidden;
}

/* Toggle Button */
.sidebar-toggle {
    position: absolute;
    top: 45px;
    right: -12px;
    width: 24px;
    height: 24px;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    transition: transform 0.3s, top 0.3s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover);
}

.sidebar.collapsed .sidebar-toggle {
    transform: rotate(180deg);
    top: 25px;
}

.sidebar-toggle svg {
    width: 14px;
    height: 14px;
    stroke: var(--sidebar-text);
}

/* Navigation */
.sidebar-nav {
    flex: 1;
    min-height: 0; /* allow flex child to shrink so overflow-y scroll works */
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 15px 0 20px;
    -webkit-overflow-scrolling: touch;
}

.nav-section {
    margin-bottom: 10px;
}

.nav-section-title {
    padding: 8px 20px;
    font-size: 0.7em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .nav-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
    white-space: nowrap;
    position: relative;
}

.nav-item:hover {
    background: var(--sidebar-hover);
}

.nav-item.active {
    background: var(--sidebar-active);
    color: var(--sidebar-active-text);
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--sidebar-active-text);
}

.nav-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    stroke: currentColor;
}

.nav-label {
    margin-left: 12px;
    overflow: hidden;
    transition: opacity 0.2s, width 0.2s;
}

.sidebar.collapsed .nav-label {
    opacity: 0;
    width: 0;
    margin-left: 0;
}

/* Submenu */
.nav-submenu {
    max-height: 0;
    overflow: hidden;
    /* No max-height transition: it leaves intermediate heights that clip long lists (Resources, Settings). */
    background: rgba(0,0,0,0.02);
}

/*
 * Expanded sidebar: open submenus take their natural height (all links).
 * Scroll only .sidebar-nav — do not cap submenu height.
 */
.sidebar:not(.collapsed) .nav-item-parent.open + .nav-submenu {
    max-height: none;
    overflow: visible;
}

/* Flyout submenu when sidebar is collapsed */
.sidebar.collapsed .nav-submenu {
    display: none;
    position: fixed;
    min-width: 200px;
    max-width: min(320px, calc(100vw - 80px));
    max-height: none;
    background: var(--sidebar-bg);
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.15);
    padding: 8px 0;
    z-index: 1002;
}

.sidebar.collapsed .nav-submenu::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 12px;
    border: 6px solid transparent;
    border-right-color: var(--sidebar-border);
}

.sidebar.collapsed .nav-submenu::after {
    content: '';
    position: absolute;
    left: -5px;
    top: 13px;
    border: 5px solid transparent;
    border-right-color: var(--sidebar-bg);
}

.sidebar.collapsed .nav-item-parent.flyout-open + .nav-submenu {
    display: block;
    max-height: min(90vh, 1200px);
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

/* Submenu text links: wrap so long resource titles are not clipped at sidebar edge */
.nav-submenu .nav-item {
    padding: 10px 16px 10px 44px;
    font-size: 0.9em;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.35;
    min-width: 0;
    align-items: flex-start;
}

/* Flyout submenu items have different padding */
.sidebar.collapsed .nav-submenu .nav-item {
    padding: 10px 16px;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-word;
    line-height: 1.35;
    min-width: 0;
}

.nav-item-parent::after {
    content: '';
    margin-left: auto;
    border: solid var(--sidebar-text);
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 3px;
    transform: rotate(45deg);
    transition: transform 0.3s;
}

.nav-item-parent.open::after {
    transform: rotate(-135deg);
}

.sidebar.collapsed .nav-item-parent::after {
    display: none;
}

/* User Section */
.sidebar-user {
    padding: 15px;
    border-top: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #2874B5;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.user-info {
    margin-left: 10px;
    overflow: hidden;
    transition: opacity 0.2s;
}

.sidebar.collapsed .user-info {
    opacity: 0;
    width: 0;
    margin-left: 0;
}

.user-name {
    font-weight: 500;
    color: var(--sidebar-text);
    font-size: 0.9em;
    white-space: nowrap;
}

.user-role {
    font-size: 0.75em;
    color: #888;
    white-space: nowrap;
}

/* Main Content */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    max-width: calc(100vw - var(--sidebar-width));
    overflow-x: hidden;
}

.sidebar.collapsed ~ .main-wrapper {
    margin-left: var(--sidebar-collapsed-width);
    max-width: calc(100vw - var(--sidebar-collapsed-width));
}

.main-content {
    flex: 1;
    padding: 20px;
    background: #f8f9fa;
    overflow-x: auto;
    box-sizing: border-box;
}

/* Ensure tables and grids respect container width */
.main-content .gridjs-container {
    max-width: 100%;
    overflow-x: auto;
}

/* Override desktop-table display:table which breaks flex layout */
/* Applies to <div class="desktop-table"> visibility wrappers */
.main-content .desktop-table {
    display: block;
    width: 100%;
    overflow-x: auto;
}

/* Restore display:table for actual <table> elements */
.main-content table.desktop-table {
    display: table;
}

/* Grid container divs (like #eventsGrid, #notesGrid) */
.main-content [id$="Grid"] {
    width: 100%;
    overflow-x: auto;
}

/* Grid.js specific fixes for sidebar layout */
.main-content .gridjs-table {
    width: 100%;
    min-width: 600px; /* Minimum width before scrolling */
    table-layout: auto;
}

/* Allow text wrapping and ellipsis for table cells */
.main-content .gridjs-th,
.main-content .gridjs-td {
    white-space: normal;
    word-wrap: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Constrain wider content columns */
.main-content .gridjs-td:nth-child(2) {
    max-width: 150px;
}

/* Scrollbar styling for overflow containers */
.main-content .gridjs-container::-webkit-scrollbar,
.main-content .desktop-table::-webkit-scrollbar,
.main-content [id$="Grid"]::-webkit-scrollbar {
    height: 8px;
}

.main-content .gridjs-container::-webkit-scrollbar-thumb,
.main-content .desktop-table::-webkit-scrollbar-thumb,
.main-content [id$="Grid"]::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.main-content .gridjs-container::-webkit-scrollbar-thumb:hover,
.main-content .desktop-table::-webkit-scrollbar-thumb:hover,
.main-content [id$="Grid"]::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* Mobile Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: white;
    border-bottom: 1px solid var(--sidebar-border);
    z-index: 998;
    padding: 0 15px;
    align-items: center;
    justify-content: space-between;
}

.mobile-header-title {
    font-size: 1.1em;
    font-weight: 600;
    color: #2874B5;
}

.hamburger {
    display: none;
    flex-direction: column;
    justify-content: space-around;
    width: 28px;
    height: 22px;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}

.hamburger span {
    width: 28px;
    height: 3px;
    background-color: #333;
    border-radius: 3px;
    transition: all 0.3s ease;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .mobile-header {
        display: flex;
    }
    
    .hamburger {
        display: flex;
    }
    
    .sidebar {
        transform: translateX(-100%);
        width: var(--sidebar-width);
    }
    
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .sidebar.collapsed {
        width: var(--sidebar-width);
    }
    
    .sidebar-toggle {
        display: none;
    }
    
    .main-wrapper {
        margin-left: 0;
        padding-top: var(--header-height);
        max-width: 100vw;
    }
    
    .sidebar.collapsed ~ .main-wrapper {
        margin-left: 0;
        max-width: 100vw;
    }
}

@media print {
    .main-wrapper,
    .sidebar.collapsed ~ .main-wrapper {
        margin-left: 0 !important;
        max-width: 100% !important;
        padding-top: 0 !important;
    }
    .mobile-header {
        display: none !important;
    }
}

/* Tooltip for collapsed sidebar */
.nav-item[data-tooltip] {
    position: relative;
}

.sidebar.collapsed .nav-item[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    background: #333;
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 0.85em;
    white-space: nowrap;
    margin-left: 10px;
    z-index: 1002;
}

.sidebar.collapsed .nav-item[data-tooltip]:hover::before {
    content: '';
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 6px solid transparent;
    border-right-color: #333;
    margin-left: -2px;
    z-index: 1002;
}
