/**
 * Authenticated user layout.
 * The dashboard is the reference for the shared content width and gutters.
 * Scope all rules to the user sidebar + main content; public pages, admin,
 * standalone quizzes and full-screen DICOM/PDF canvases retain their layouts.
 */
#sidebar ~ .main-content {
    --rr-user-width: 1200px;
    --rr-sidebar-width: 280px;
    --rr-header-icon: 3rem;
    --rr-header-title: 1.75rem;
    --rr-header-padding: 1rem;
    --rr-breadcrumb-height: 2.75rem;
    --rr-user-gutter: .75rem;
    --rr-user-block: 1rem;
    --rr-user-card-radius: 12px;
    --rr-user-surface: #fff;
    --rr-user-border: #d1d5db;
    --rr-user-shadow: 0 1px 3px rgba(5, 15, 26, .06);
    --rr-user-shadow-hover: 0 4px 12px rgba(5, 15, 26, .08);
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
    min-width: 0;
    min-height: 100vh;
    padding-top: 70px;
    padding-bottom: 80px;
    font-family: 'DM Sans', sans-serif;
    color: var(--ui-text, #050f1a);
    background:
        radial-gradient(circle at 4% 0%, rgba(0, 82, 255, .07) 0%, transparent 42%),
        radial-gradient(circle at 100% 0%, rgba(0, 82, 255, .08) 0%, transparent 35%),
        var(--ui-bg, #f9fafb);
}
@media (min-width: 1025px) {
    #sidebar ~ .main-content {
        --rr-user-width: 1140px;
        --rr-user-gutter: 1.5rem;
        --rr-user-card-radius: 10px;
        width: calc(100% - var(--rr-sidebar-width));
        max-width: calc(100% - var(--rr-sidebar-width));
        margin-left: var(--rr-sidebar-width);
        padding-top: 0;
        padding-bottom: 0;
    }
}

/* New pages use .rr-user-shell. Existing modules use the compatibility
   selectors below until their individual templates can be simplified.
   Only outer page containers are targeted, never the content inside a PDF,
   quiz question, table, modal or embedded viewer. */
#sidebar ~ .main-content > :is(
    .rr-user-shell, .dashboard-shell, .profile-shell, .timeline-shell,
    .greyhub-shell, .dicom-page, main.bg-cream,
    .note-content-area, .resource-content-area,
    [style*="max-width: 1200px"], [style*="max-width:1200px"],
    .p-6:not(.border-b), .px-6.py-6:not(.border-b),
    .px-6.py-8:not(.border-b), .px-6.pb-6:not(.border-b),
    .px-6.py-4:not(.border-b)
) {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: min(100%, var(--rr-user-width)) !important;
    margin-inline: auto !important;
    padding-inline: var(--rr-user-gutter) !important;
}

#sidebar ~ .main-content > :is(
    .rr-user-shell, .dashboard-shell, .profile-shell, .dicom-page,
    main.bg-cream, .note-content-area, .resource-content-area, .p-6:not(.border-b), .px-6.py-6:not(.border-b),
    .px-6.py-8:not(.border-b)
) {
    padding-block: var(--rr-user-block) !important;
}

/* Full-width page chrome is independent of the centered learning shell.
   Legacy module title/breadcrumb rows and new semantic headers use the
   entire main pane (not the viewport, so they never cover the sidebar). */
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header, .rr-user-breadcrumb, nav[aria-label="Breadcrumb"]) {
    box-sizing: border-box;
    width: 100%;
    max-width: none !important;
    margin-inline: 0 !important;
    padding-inline: var(--rr-user-gutter) !important;
    border-radius: 0;
    background: var(--rr-user-surface);
    border-color: var(--rr-user-border);
}

/* Grey Hub and Timeline have an additional sticky header wrapper.
   Remove its outer gutter and apply the same full-width header treatment
   without changing its sticky position or responsive visibility. */
#sidebar ~ .main-content > .sticky:has(> :is(.timeline-topbar, .greyhub-topbar, .rr-user-header)) {
    box-sizing: border-box;
    width: 100%;
    max-width: none;
    margin-inline: 0;
    padding-inline: 0 !important;
    padding-bottom: 0 !important;
}
#sidebar ~ .main-content > .sticky > :is(.timeline-topbar, .greyhub-topbar, .rr-user-header) {
    box-sizing: border-box;
    width: 100%;
    max-width: none !important;
    margin-inline: 0 !important;
    padding-inline: var(--rr-user-gutter) !important;
    border-radius: 0;
    border-inline: 0;
    border-top: 0;
    border-bottom: 1px solid var(--rr-user-border);
    background: var(--rr-user-surface);
    box-shadow: none;
}

/* Exam archives use an extra max-w-5xl wrapper within the outer shell. */
#sidebar ~ .main-content > .px-6.py-8 > .max-w-5xl.mx-auto {
    max-width: none;
}

/* Match dashboard cards, except specialized readers that own their
   viewport, toolbar, sizing, and interaction styles. */
#sidebar ~ .main-content .modern-card:not(.rr-pdf-reader):not(.pdf-viewer) {
    border-radius: var(--rr-user-card-radius);
    border-color: var(--rr-user-border);
    box-shadow: var(--rr-user-shadow);
}
#sidebar ~ .main-content .modern-card:not(.rr-pdf-reader):not(.pdf-viewer):hover {
    box-shadow: var(--rr-user-shadow-hover);
}
@media (min-width: 1025px) {
    #sidebar ~ .main-content .modern-card.p-6:not(.rr-pdf-reader):not(.pdf-viewer) {
        padding: 1.25rem;
    }
    #sidebar ~ .main-content .modern-card.p-8:not(.rr-pdf-reader):not(.pdf-viewer) {
        padding: 1.6rem;
    }
}
#sidebar ~ .main-content :is(a, button, input, textarea, select):focus-visible {
    outline: 2px solid #1d4ed8;
    outline-offset: 2px;
}

/* The shared navigation is a sibling, not a child of .main-content.
   Explicitly set its typeface and protect it from legacy page styles. */
body:has(> #sidebar),
#sidebar, #sidebar ~ .main-content,
.mobile-header, .bottom-navigation, #notificationPanel {
    font-family: 'DM Sans', Arial, sans-serif;
}
#sidebar :is(a, button, span, p, h2, h3, label):not(.fa):not(.fas):not(.far):not(.fab),
.mobile-header :is(a, button, span),
.bottom-navigation :is(a, span),
#notificationPanel :is(a, button, span, p) {
    font-family: inherit;
}
#sidebar {
    background: var(--ui-surface);
    border-right: 1px solid var(--ui-border);
    box-shadow: var(--ui-shadow-1);
    width: 280px;
    position: fixed;
    top: 0;
    height: 100vh;
    z-index: 40;
    transform: none;
    transition: transform .3s ease;
}
#sidebar .sidebar-content {
    display: block;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 100px;
}
#sidebar .sidebar-user-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--ui-surface);
    border-top: 1px solid var(--ui-border);
    padding: 16px;
    box-shadow: 0 -1px 3px rgba(5,15,26,.06);
}
#sidebar .sidebar-link {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    margin: 4px 12px;
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ui-text-secondary);
    font-weight: 500;
    text-decoration: none;
    transform: none;
    background: transparent;
}
#sidebar .sidebar-link:hover {
    background: #f3f4f6;
    border-color: var(--ui-border);
    color: var(--ui-primary);
    transform: none;
}
#sidebar .sidebar-link.active {
    background: rgba(0,82,255,.10);
    border-color: rgba(0,82,255,.25);
    color: var(--ui-primary);
}
#sidebar .sidebar-link.active:hover {
    background: rgba(0,82,255,.14);
}
#sidebar .sidebar-link.submenu-item {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 6px;
    margin-bottom: 2px;
}
#sidebar .sidebar-link:focus-visible,
#sidebar .sidebar-parent-link:focus-visible {
    outline: 2px solid var(--ui-primary);
    outline-offset: -2px;
}
#sidebarOverlay {
    display: block;
    background: rgba(5,15,26,.35);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
}
#sidebarOverlay.show {
    opacity: 1;
    visibility: visible;
}
@media (max-width: 1024px) {
    .mobile-header { display: block; }
    #sidebar {
        transform: translateX(-100%);
        top: 60px;
        height: calc(100vh - 60px);
        height: calc(100dvh - 60px);
        z-index: 50;
    }
    #sidebar.open { transform: translateX(0); }
}
@media (max-width: 640px) {
    #sidebar { width: 100%; max-width: 300px; }
    #sidebar .sidebar-content { padding-bottom: 120px; }
}
@media (max-height: 600px) {
    #sidebar .sidebar-content { padding-bottom: 90px; }
    #sidebar .sidebar-user-info { padding: 12px 16px; }
}

/* Match dashboard surface treatment for legacy learning cards, preserving
   status colors, icons, access states and reader-specific viewports. */
#sidebar ~ .main-content :is(.chapter-card, .category-card, .modern-card):not(.rr-pdf-reader):not(.pdf-viewer):not([class*="bg-"]) {
    background: var(--rr-user-surface);
    border: 1px solid var(--rr-user-border);
    border-radius: var(--rr-user-card-radius);
    box-shadow: var(--rr-user-shadow);
    transition: border-color .2s ease, box-shadow .2s ease, transform .2s ease;
}
#sidebar ~ .main-content :is(.chapter-card, .category-card, .modern-card):not(.rr-pdf-reader):not(.pdf-viewer):hover {
    transform: translateY(-1px);
    border-color: var(--ui-primary);
    box-shadow: var(--rr-user-shadow-hover);
}
#sidebar ~ .main-content :is(.chapter-card, .category-card)::after,
#sidebar ~ .main-content .modern-card:not(.rr-pdf-reader):not(.pdf-viewer)::before {
    content: none;
}
#sidebar ~ .main-content :is(.chapter-card, .category-card):hover .card-icon {
    transform: none;
}
#sidebar ~ .main-content .text-darken { color: var(--ui-text); }
@media (min-width: 1025px) {
    #sidebar ~ .main-content :is(.chapter-card, .category-card).p-6 { padding: 1.25rem; }
    #sidebar ~ .main-content :is(.chapter-card, .category-card).p-8 { padding: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) {
    #sidebar, #sidebar .sidebar-link,
    #sidebar ~ .main-content :is(.chapter-card, .category-card, .modern-card) {
        transition: none;
    }
}

/* Canonical module header metrics. Existing templates have both separate and
   embedded breadcrumbs; both render the same title row and full-width divider. */
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) {
    padding-block: var(--rr-header-padding) !important;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex {
    min-width: 0;
    gap: .75rem;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex > .flex:has(h1) {
    min-width: 0;
    gap: .875rem;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) .flex:has(> h1) {
    min-width: 0;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) h1 {
    font-size: var(--rr-header-title) !important;
    line-height: 1.2;
    font-weight: 700;
    color: var(--ui-text);
    background-image: none;
    -webkit-text-fill-color: currentColor;
    margin: 0;
    overflow-wrap: anywhere;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) h1 + p {
    font-size: .9375rem !important;
    line-height: 1.4;
    color: var(--ui-text-secondary);
    font-weight: 500;
    margin: .25rem 0 0;
    overflow-wrap: anywhere;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) :is(.header-icon-container, .rr-user-header-icon, .icon-wrapper, .w-12.h-12, .w-16.h-16):has(> i) {
    width: var(--rr-header-icon) !important;
    height: var(--rr-header-icon) !important;
    min-width: var(--rr-header-icon) !important;
    min-height: var(--rr-header-icon) !important;
    flex: 0 0 var(--rr-header-icon);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .75rem;
    background: linear-gradient(135deg, #3b82f6, #0052ff);
    color: #fff;
    box-shadow: 0 3px 8px rgba(0,82,255,.18);
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) :is(.header-icon-container, .rr-user-header-icon, .icon-wrapper, .w-12.h-12, .w-16.h-16) > i {
    font-size: 1.125rem;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex > .flex:has(h1) > :not(:first-child) {
    margin-left: 0;
    min-width: 0;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1):has(> nav) {
    padding-bottom: 0 !important;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > nav {
    margin: var(--rr-header-padding) calc(-1 * var(--rr-user-gutter)) 0;
    padding: .625rem var(--rr-user-gutter);
    border-top: 1px solid var(--rr-user-border);
}
#sidebar ~ .main-content > :is(.border-b, .rr-user-breadcrumb):not(:has(h1)):has(> nav),
#sidebar ~ .main-content > nav[aria-label="Breadcrumb"] {
    padding-block: .625rem !important;
    min-height: var(--rr-breadcrumb-height);
    display: flex;
    align-items: center;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header, .rr-user-breadcrumb) > nav,
#sidebar ~ .main-content > nav[aria-label="Breadcrumb"] {
    min-height: var(--rr-breadcrumb-height);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    font-size: .875rem;
    line-height: 1.4;
    color: var(--ui-text-secondary);
    overflow-wrap: anywhere;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header, .rr-user-breadcrumb) > nav > ol {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    row-gap: .25rem;
    min-width: 0;
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header, .rr-user-breadcrumb) > nav a {
    color: var(--ui-primary);
}
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header, .rr-user-breadcrumb) > nav a:hover {
    color: var(--ui-primary-hover);
    text-decoration: underline;
}
#sidebar ~ .main-content .modern-card:not(.rr-pdf-reader):not(.pdf-viewer) .icon-wrapper {
    width: 3rem;
    height: 3rem;
    flex-shrink: 0;
    border-radius: .75rem;
}
#sidebar ~ .main-content > :is(.rr-user-shell, .dicom-page, .note-content-area, .resource-content-area) {
    min-width: 0;
}
#sidebar ~ .main-content .rr-pdf-reader:not(:fullscreen) {
    max-width: 100%;
    min-width: 0;
}
@media (min-width: 1025px) {
    #sidebar ~ .main-content .modern-card:not(.rr-pdf-reader):not(.pdf-viewer) .icon-wrapper {
        width: 42px;
        height: 42px;
    }
}
@media (max-width: 640px) {
    #sidebar ~ .main-content {
        --rr-header-icon: 2.75rem;
        --rr-header-title: 1.375rem;
        --rr-header-padding: .875rem;
    }
    #sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex {
        flex-wrap: wrap;
    }
    #sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex > .flex:has(h1) {
        flex: 1 1 100%;
    }
    #sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1) > .flex > .flex:not(:has(h1)) {
        flex-wrap: wrap;
        min-width: 0;
        max-width: 100%;
    }
}

/* In a separate breadcrumb bar the parent owns the vertical padding.
   Do not apply the minimum height twice to its child navigation. */
#sidebar ~ .main-content > :is(.border-b, .rr-user-breadcrumb):not(:has(h1)):has(> nav) > nav {
    width: 100%;
    min-height: 0;
}
/* Combined headers include the divider in their navigation box, whereas
   separate headers include it in the title box. Keep the two rows equal. */
#sidebar ~ .main-content > :is(.border-b, header, .rr-user-header):has(h1):has(> nav) {
    border-bottom-width: 1px;
}

/* Older listing pages wrap the title row in an additional padded div.
   The outer header already owns its spacing; avoid double gutters. */
#sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) > .px-6.py-8 {
    padding: 0 !important;
}
#sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) > .px-6.py-8 > .max-w-7xl {
    max-width: none;
    margin: 0;
}
#sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) .flex.items-center:has(> div > h1) {
    min-width: 0;
    gap: .875rem;
}
#sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) .flex.items-center:has(> div > h1) > div:has(> h1) {
    margin-left: 0;
    min-width: 0;
}
#sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) .rr-user-header-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    flex-shrink: 0;
    border-radius: .625rem;
    padding: .625rem .875rem;
    font-size: .875rem;
    font-weight: 600;
}
#sidebar ~ .main-content .rr-user-header-action[href] {
    color: white;
    background: var(--ui-primary);
}
#sidebar ~ .main-content .rr-user-header-action[href]:hover {
    background: var(--ui-primary-hover);
}
#sidebar ~ .main-content .rr-user-header-action:not([href]) {
    color: #047857;
    background: #d1fae5;
}
@media (max-width: 640px) {
    #sidebar ~ .main-content > :is(.border-b, .rr-user-header, header):has(h1) .flex.justify-between:has(h1) {
        flex-wrap: wrap;
        gap: .75rem;
    }
}

/* Shared nested navigation: only the current destination is highlighted. */
#sidebar .sidebar-parent-row.has-active-child{color:var(--ui-text-secondary);background:transparent;border-color:transparent;}
#sidebar #grey-hub-submenu{border:0;background:transparent;border-radius:0;margin:0 12px 0 26px;padding:0;visibility:hidden;}
#sidebar #grey-hub-submenu.expanded{visibility:visible;border-left:1px solid var(--ui-border);margin-bottom:4px;}
#sidebar #grey-hub-submenu .sidebar-link{margin:2px 0 2px 9px;padding:8px 12px;min-height:40px;}
#sidebar #grey-hub-submenu .sidebar-link i{margin-left:0;}
#sidebar .sidebar-parent-row:has(.sidebar-parent-link[aria-current="page"]){color:var(--ui-primary);}
