/* =========================================
   RayLink Layout System
   App Shell, Header, Sidebar, Responsive
   ========================================= */

/* === App Shell === */
.app-shell {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

.app-shell.has-sidebar {
    flex-direction: row;
}

body {
    overflow-x: hidden;
    /* Prevent horizontal scroll from off-canvas sidebar */
}

/* === Header === */
.app-header {
    position: sticky;
    top: 0;
    height: var(--header-height);
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 var(--space-5);
    gap: var(--space-4);
    z-index: 1000;
    /* Increased z-index for floating effect */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    /* Added shadow for floating effect */
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--text-primary);
    text-decoration: none;
}

.header-logo img,
.header-logo svg {
    height: 32px;
    width: auto;
}

.header-spacer {
    flex: 1;
}

.header-user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.header-role-badge {
    padding: var(--space-1) var(--space-3);
    background-color: var(--color-primary-100);
    color: var(--color-primary-700);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    border-radius: var(--radius-full);
}

.header-menu-btn,
.topbar-menu-btn {
    display: none;
    background: none;
    border: none;
    padding: var(--space-2);
    cursor: pointer;
    color: var(--text-secondary);
}

/* === Sidebar === */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-inline-end: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: calc(100vh - var(--header-height));
    position: sticky;
    top: var(--header-height);
    z-index: var(--z-sidebar);
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-4);
    overflow-y: auto;
    overflow-x: hidden;
    /* Prevent horizontal scroll */
}

.nav-group {
    margin-bottom: var(--space-4);
}

.nav-group-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: background-color var(--transition-fast), color var(--transition-fast);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    white-space: nowrap;
    /* Prevent wrapping */
    overflow: hidden;
}

.nav-item span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-item:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background-color: var(--color-primary-50);
    color: var(--color-primary-600);
}

.nav-item svg,
.nav-item .nav-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
    /* Prevent shrinking */
    flex-shrink: 0;
}

.sidebar-footer {
    padding: var(--space-4);
    border-top: 1px solid var(--border-subtle);
}

/* === Main Content === */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.main-content {
    flex: 1;
    padding: var(--space-6);
    max-width: var(--content-max-width);
    width: 100%;
    margin: 0 auto;
}

/* Page Header */
.page-header {
    margin-bottom: var(--space-6);
}

.page-title {
    font-size: var(--font-size-2xl);
    font-weight: var(--font-weight-bold);
    margin: 0 0 var(--space-2);
}

.page-breadcrumb {
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

.page-breadcrumb a {
    color: var(--text-link);
}

.page-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-4);
}

/* Content Grid */
.content-grid {
    display: grid;
    gap: var(--space-5);
}

.content-grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

.content-grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

.content-grid-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* === Mobile Bottom Nav === */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    z-index: var(--z-header);
    padding: 0 var(--space-2);
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-items {
    display: flex;
    height: 100%;
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--font-size-xs);
    min-width: 64px;
}

.mobile-nav-item.active {
    color: var(--color-primary-500);
}

.mobile-nav-item svg {
    width: 24px;
    height: 24px;
}

/* === Auth Layout (Login, Join) === */
.auth-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
    background: linear-gradient(135deg, var(--color-primary-50) 0%, var(--bg-page) 100%);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    padding: var(--space-8);
}

.auth-logo {
    text-align: center;
    margin-bottom: var(--space-6);
}

.auth-logo img,
.auth-logo svg {
    height: 48px;
    width: auto;
}

.auth-title {
    text-align: center;
    margin-bottom: var(--space-6);
}

/* === Responsive Breakpoints === */

/* Tablet */
@media (max-width: 1024px) {

    .content-grid-3,
    .content-grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .app-sidebar {
        width: 200px;
    }
}

/* Mobile Landscape */
@media (max-width: 768px) {
    :root {
        --sidebar-width: 0;
    }

    .app-shell.has-sidebar {
        flex-direction: column;
    }

    .app-sidebar {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 260px;
        z-index: 1100;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .app-sidebar.open,
    .sidebar.open {
        display: flex;
        flex-direction: column;
        transform: translateX(0);
    }

    .mobile-nav {
        display: block;
    }

    .app-main {
        padding-bottom: 80px;
    }

    .main-content {
        padding: var(--space-4);
    }

    .content-grid-2,
    .content-grid-3,
    .content-grid-4 {
        grid-template-columns: 1fr;
    }

    .header-menu-btn,
    .topbar-menu-btn {
        display: block;
        background: none;
        border: none;
        padding: var(--space-2);
        cursor: pointer;
        color: var(--text-secondary);
    }

    .desktop-only {
        display: none;
    }

    .header-logo span {
        display: none;
        /* Hide text on mobile to save space, or reduce size */
    }

    .topbar-role {
        display: none;
    }

    .page-title {
        font-size: var(--font-size-xl);
    }
}

/* Mobile Portrait */
@media (max-width: 480px) {
    .main-content {
        padding: var(--space-3);
    }

    .card-body {
        padding: var(--space-4);
    }

    .page-actions {
        flex-direction: column;
    }

    .page-actions .btn {
        width: 100%;
    }

    .auth-card {
        padding: var(--space-5);
    }
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .mobile-nav {
        height: calc(64px + env(safe-area-inset-bottom));
    }
}
/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar,
.app-sidebar::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track,
.app-sidebar::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb,
.app-sidebar::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background-color: var(--border-subtle);
    border-radius: 20px;
}
