/* ========================================
   PlayFASA Global Layout System
   ======================================== */

/* CSS Variables for consistent spacing */
:root {
    --header-height: 60px;
    --header-banner-height: 40px;
    --header-total-height: 220px;  /* Updated at runtime from Header.asp */
    --sidebar-width: 250px;
    --main-content-padding: 30px;
    --content-top-offset: 0px; /* flush under header by default */
    --z-header: 100;
    --z-sidebar: 50;
    --z-content: 1;
}

/* ========================================
   Base Layout Structure
   ======================================== */

/* Main container for authenticated pages */
.app-container {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

/* Header stays at top - fixed positioning handled by header.asp */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-total-height);
    z-index: var(--z-header);
}

/* Content wrapper below header */
.app-body {
    display: flex;
    margin-top: var(--header-total-height);  /* Start directly below header */
    padding-top: 0;  /* No padding */
    min-height: calc(100vh - var(--header-total-height));
}

/* ========================================
   Sidebar Navigation
   ======================================== */

.app-sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 50%, #e2e8f0 100%);
    box-shadow: 2px 0 8px rgba(0,0,0,0.12);
    position: fixed;
    left: 0;
    top: var(--header-total-height);
    bottom: 0;
    overflow-y: auto;
    z-index: var(--z-sidebar);
    padding-bottom: 40px;
}

/* Sidebar user info section */
.sidebar-user-info {
    text-align: center;
    padding: 18px 20px 12px 20px;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 0;
}

.sidebar-user-avatar {
    width: 50px;
    height: 50px;
    background: linear-gradient(135deg, #1e3c72, #2a5298);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    margin: 0 auto 3px;
}

.sidebar-user-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0;
    font-size: 14px;
}

.sidebar-user-email {
    font-size: 11px;
    color: #666;
    margin: 0;
}

/* Sidebar navigation styles */
.app-sidebar nav {
    display: block;
    /* Remove unintended gap under user card */
    padding: 0 0 28px;
}

.sidebar-nav-item {
    display: table;
    width: 100%;
    padding: 0;
    margin: 0;
    border: none;
    background: transparent;
    color: #475569;
    text-decoration: none;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    cursor: pointer;
    font: inherit;
    text-align: left;
    -webkit-appearance: none;
    appearance: none;
}

.sidebar-nav-item:hover,
.sidebar-nav-item.is-open {
    background: #f0f4ff;
    border-left-color: #1e3c72;
    color: #1e3c72;
}

.sidebar-nav-item:focus {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}

.sidebar-nav-icon {
    display: table-cell;
    width: 40px;
    padding: 12px 0 12px 16px;
    vertical-align: middle;
    text-align: center;
    font-size: 18px;
}

.sidebar-nav-label {
    display: table-cell;
    padding: 12px 16px 12px 8px;
    vertical-align: middle;
    text-align: left;
    white-space: nowrap;
}

.sidebar-nav-arrow {
    display: table-cell;
    width: 24px;
    padding: 12px 16px 12px 0;
    vertical-align: middle;
    text-align: center;
    font-size: 12px;
}

.sidebar-nav-root-item {
    font-size: 14px;
    font-weight: 700;
}

.sidebar-nav-root-item .sidebar-nav-label {
    font-weight: 700;
}

.sidebar-nav-toggle .sidebar-nav-arrow::after {
    content: "▾";
    transition: transform 0.2s ease;
    display: inline-block;
}

.sidebar-nav-toggle.is-open .sidebar-nav-arrow::after {
    transform: rotate(180deg);
}

.sidebar-nav-group {
    margin: 0;
}

.sidebar-nav-heading {
    display: none;
}

.sidebar-subnav {
    display: none;
}

.sidebar-subnav.is-open {
    display: block;
}

.sidebar-subnav .sidebar-nav-item {
    border-left: none;
    padding: 14px 16px 14px 56px !important;  /* 56px = 40px indent + 16px regular padding */
    text-align: left !important;
    display: block !important;  /* Make it a simple block, not table or flex */
}

.sidebar-subnav .sidebar-nav-item:hover {
    background: #ecf3ff;
}

.sidebar-subnav .sidebar-nav-icon {
    display: none !important;  /* Hide empty icon span in submenu items */
}

.sidebar-subnav .sidebar-nav-label {
    display: inline !important;  /* Override table-cell - make it inline */
    font-size: 14px;
    font-weight: 500;
    padding: 0 !important;  /* Remove padding since parent has it */
    text-align: left !important;
}

.nav-module-list {
    list-style: none;
    /* Ensure no default UL spacing creates a gap */
    margin: 0;
    padding: 0;
}

/* ========================================
   Main Content Area
   ======================================== */

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 0;  /* No padding - content sits flush under header */
    overflow: auto; /* prevent top margin collapse of first child */
    background: #f8fafc;
    min-height: calc(100vh - var(--header-total-height));
}

/* Ensure first visible block sits flush under header */
.app-main > .page-container:first-child,
.app-main > .content-wrapper:first-child,
.app-main > *:first-child {
    margin-top: 0 !important;
}

/* Content wrapper for pages */
.content-wrapper {
    max-width: 1400px;
    margin: 0 auto;
}

/* Page header styles */
.page-header {
    margin-bottom: 24px;
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 8px 0;
}

.page-subtitle {
    font-size: 16px;
    color: #64748b;
    margin: 0;
}

/* ========================================
   Responsive Design
   ======================================== */

/* Mobile: Hide sidebar, show hamburger menu */
@media (max-width: 768px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .app-sidebar.mobile-open {
        transform: translateX(0);
    }
    
    .app-main {
        margin-left: 0;
        padding: 20px;
    }
    
    /* Mobile overlay when sidebar is open */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: var(--header-total-height);
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: calc(var(--z-sidebar) - 1);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* Tablet: Narrower sidebar */
@media (min-width: 769px) and (max-width: 1024px) {
    :root {
        --sidebar-width: 220px;
    }
    
    .app-main {
        padding: 20px;
    }
}

/* ========================================
   Utility Classes
   ======================================== */

/* Hide on mobile */
.hide-mobile {
    display: block;
}

@media (max-width: 768px) {
    .hide-mobile {
        display: none;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block;
    }
}

/* Card component for content sections */
.content-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 20px;
}

.content-card-header {
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
    margin: 0 0 16px 0;
    padding-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
}

/* ========================================
   Layout States
   ======================================== */

/* When sidebar is collapsed (future enhancement) */
.app-body.sidebar-collapsed .app-sidebar {
    width: 60px;
}

.app-body.sidebar-collapsed .app-main {
    margin-left: 60px;
}

/* ==========================================================================
   Global Layout Gap Overrides
   ========================================================================== */

body[data-layout-root] {
    padding-top: 0 !important;
}

body[data-layout-root] #header-spacer {
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    display: none !important;
}

#header-spacer {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

.app-main > *:first-child {
    margin-top: 0 !important;
}

/* Force content to flow below header (no overlay) on global layout pages */
body[data-layout-root] .header-container {
    position: sticky !important;
    top: 0 !important;
}
body[data-layout-root] .app-body {
    margin-top: 0 !important;
    min-height: auto !important;
}

.app-body.sidebar-collapsed .sidebar-nav-label,
.app-body.sidebar-collapsed .sidebar-nav-arrow,
.app-body.sidebar-collapsed .sidebar-user-info {
    display: none;
}

/* Print styles */
@media print {
    .app-sidebar,
    .site-header {
        display: none;
    }
    
    .app-main {
        margin-left: 0;
        padding: 0;
    }
}

/* ========================================
   Global Layout Gap Overrides
   ======================================== */
/* Remove legacy page body padding when global layout (app-body) is present */
body:has(.app-body) {
    padding: 0 !important;
}

/* First page container directly inside app-main should sit flush under header */
.app-main > .page-container:first-of-type {
    margin-top: 0 !important;
}

/* If inner wrapper exists before page-container, still eliminate top gap */
.app-main > *:first-child.page-container {
    margin-top: 0 !important;
}

/* Safety: eliminate accidental top margins on first child */
.app-main > *:first-child {
    margin-top: 0 !important;
}

/* Ensure content is pushed below fixed header on global layout */
body[data-layout-root] .app-body {
    margin-top: var(--header-total-height) !important;
    min-height: calc(100vh - var(--header-total-height)) !important;
}

/* Keep header fixed on global layout */
body[data-layout-root] .header-container {
    position: fixed !important;
    top: 0 !important; left: 0; right: 0;
}
