/* Define cascade layers for predictable specificity management */
@layer reset, tokens, typography, base, components, utilities, states;

/*
  Josh's Custom CSS Reset
  https://www.joshwcomeau.com/css/custom-css-reset/
*/
@layer reset {
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    * {
        margin: 0;
    }

    @media (prefers-reduced-motion: no-preference) {
        html {
            interpolate-size: allow-keywords;
        }
    }

    body {
        line-height: 1.5;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    img,
    picture,
    video,
    canvas,
    svg {
        display: block;
        max-width: 100%;
    }

    input,
    button,
    textarea,
    select {
        font: inherit;
    }

    p,
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        overflow-wrap: break-word;
    }

    p {
        text-wrap: pretty;
    }
    h1,
    h2,
    h3,
    h4,
    h5,
    h6 {
        text-wrap: balance;
    }

    #root,
    #__next {
        isolation: isolate;
    }
}

/* ============================================
   Project Styles
   ============================================ */

@layer tokens {
    :root {
        color-scheme: light;

        /* Material color roles (light) */
        --md-sys-color-background: #f6f7fb;
        --md-sys-color-on-background: #111827;

        --md-sys-color-surface: #ffffff;
        --md-sys-color-surface-variant: #ebeef8;
        --md-sys-color-surface-tint: rgba(79, 91, 207, 0.1);

        --md-sys-color-on-surface: #111827;
        --md-sys-color-on-surface-variant: #374151;

        --md-sys-color-outline: #9ca3af;
        --md-sys-color-outline-variant: #d1d5db;
        --md-sys-color-outline-strong: #6b7280;

        --md-sys-color-primary: #4338ca;
        --md-sys-color-on-primary: #ffffff;
        --md-sys-color-primary-container: #3730a3;
        --md-sys-color-on-primary-container: #e0e7ff;

        --md-sys-color-primary-rgb: 67, 56, 202;
        --md-sys-color-primary-container-rgb: 55, 48, 163;
        --md-sys-color-on-primary-rgb: 255, 255, 255;
        --md-sys-color-on-primary-container-rgb: 224, 231, 255;

        --md-sys-color-error: #b91c1c;
        --md-sys-color-on-error: #ffffff;

        --md-sys-color-success: #15803d;
        --md-sys-color-on-success: #ffffff;

        --md-sys-color-inverse-surface: #1e293b;
        --md-sys-color-inverse-on-surface: #f1f5f9;

        --md-sys-elevation-level1: 0 2px 6px rgba(18, 25, 62, 0.3);
        --md-sys-elevation-level2: 0 4px 12px rgba(18, 25, 62, 0.08);
        --md-sys-elevation-level2-hover: 0 4px 12px rgba(37, 44, 106, 0.3);
    }

    :root.dark-mode {
        color-scheme: dark;

        --md-sys-color-background: #0f172a;
        --md-sys-color-on-background: #f8fafc;

        --md-sys-color-surface: #1e293b;
        --md-sys-color-surface-variant: #334155;
        --md-sys-color-surface-tint: rgba(99, 102, 241, 0.15);

        --md-sys-color-on-surface: #f8fafc;
        --md-sys-color-on-surface-variant: #e2e8f0;

        --md-sys-color-outline: #475569;
        --md-sys-color-outline-variant: #64748b;
        --md-sys-color-outline-strong: #94a3b8;

        --md-sys-color-primary: #818cf8;
        --md-sys-color-on-primary: #1f2937;
        --md-sys-color-primary-container: #a5b4fc;
        --md-sys-color-on-primary-container: #1e1b4b;

        --md-sys-color-primary-rgb: 129, 140, 248;
        --md-sys-color-primary-container-rgb: 165, 180, 252;
        --md-sys-color-on-primary-rgb: 31, 41, 55;
        --md-sys-color-on-primary-container-rgb: 30, 27, 75;

        --md-sys-color-error: #fca5a5;
        --md-sys-color-on-error: #1f2937;

        --md-sys-color-success: #86efac;
        --md-sys-color-on-success: #102a16;

        --md-sys-color-inverse-surface: #f1f5f9;
        --md-sys-color-inverse-on-surface: #0f172a;

        --md-sys-elevation-level1: 0 2px 6px rgba(8, 15, 35, 0.7);
        --md-sys-elevation-level2: 0 12px 30px rgba(8, 15, 35, 0.45);
        --md-sys-elevation-level2-hover: 0 8px 24px rgba(99, 102, 241, 0.35);
    }
}

@layer typography {
    :root {
        /* Font families */
        --md-ref-typeface-plain:
            "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
        --md-ref-typeface-mono:
            "JetBrains Mono", "SFMono-Regular", Consolas, monospace;

        /* Material-inspired type scale */
        --md-sys-typescale-display-large-size: clamp(1.8rem, 3vw, 2.4rem);
        --md-sys-typescale-display-large-line-height: 1.2;
        --md-sys-typescale-display-large-weight: 600;

        --md-sys-typescale-headline-small-size: 1.5rem;
        --md-sys-typescale-headline-small-line-height: 1.3;
        --md-sys-typescale-headline-small-weight: 600;

        --md-sys-typescale-title-large-size: 1.25rem;
        --md-sys-typescale-title-large-line-height: 1.4;
        --md-sys-typescale-title-large-weight: 600;

        --md-sys-typescale-title-medium-size: 1.1rem;
        --md-sys-typescale-title-medium-line-height: 1.4;
        --md-sys-typescale-title-medium-weight: 600;

        --md-sys-typescale-title-small-size: 1rem;
        --md-sys-typescale-title-small-line-height: 1.4;
        --md-sys-typescale-title-small-weight: 600;

        --md-sys-typescale-body-large-size: 1rem;
        --md-sys-typescale-body-large-line-height: 1.6;
        --md-sys-typescale-body-large-weight: 400;

        --md-sys-typescale-body-medium-size: 0.95rem;
        --md-sys-typescale-body-medium-line-height: 1.5;
        --md-sys-typescale-body-medium-weight: 400;

        --md-sys-typescale-body-small-size: 0.85rem;
        --md-sys-typescale-body-small-line-height: 1.4;
        --md-sys-typescale-body-small-weight: 400;

        --md-sys-typescale-label-large-size: 0.9rem;
        --md-sys-typescale-label-large-line-height: 1.4;
        --md-sys-typescale-label-large-weight: 500;

        --md-sys-typescale-label-medium-size: 0.8rem;
        --md-sys-typescale-label-medium-line-height: 1.4;
        --md-sys-typescale-label-medium-weight: 500;

        --md-sys-typescale-label-small-size: 0.78rem;
        --md-sys-typescale-label-small-line-height: 1.3;
        --md-sys-typescale-label-small-weight: 600;
    }
}

@layer components {
    /* Loading screen */
    .loading-screen {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: var(--md-sys-color-surface);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
        opacity: 1;
        transition: opacity 0.4s ease-out;
    }
}

.loading-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.loading-spinner {
    color: var(--md-sys-color-primary);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    color: var(--md-sys-color-on-surface);
    font-size: var(--md-sys-typescale-body-large-size);
    margin: 0;
}

@layer base {
    body {
        margin: 0;
        height: 100vh;
        display: flex;
        flex-direction: column;
        font-family: var(--md-ref-typeface-plain);
        font-size: var(--md-sys-typescale-body-large-size);
        line-height: var(--md-sys-typescale-body-large-line-height);
        font-weight: var(--md-sys-typescale-body-large-weight);
        background: var(--md-sys-color-background);
        color: var(--md-sys-color-on-background);
        overflow: hidden;
    }

    body.light-mode {
        color-scheme: light;
    }
}

@layer components {
    .site-header {
        padding: 1.5rem clamp(1rem, 4vw, 3rem);
        background: linear-gradient(
            135deg,
            var(--md-sys-color-primary-container),
            var(--md-sys-color-primary)
        );
        color: var(--md-sys-color-on-primary);
        box-shadow: var(--md-sys-elevation-level1);
    }

    .header-bar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
    }

    .header-actions {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .theme-toggle {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.4rem 0.8rem;
        background: rgba(var(--md-sys-color-on-primary-rgb), 0.15);
        border: 1px solid rgba(var(--md-sys-color-on-primary-rgb), 0.2);
        border-radius: 999px;
        color: var(--md-sys-color-on-primary);
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        font-weight: var(--md-sys-typescale-body-small-weight);
        cursor: pointer;
        transition:
            background 0.2s ease,
            border-color 0.2s ease,
            transform 0.2s ease;
    }

    .theme-toggle:hover,
    .theme-toggle:focus-visible {
        background: rgba(var(--md-sys-color-on-primary-rgb), 0.2);
        border-color: rgba(var(--md-sys-color-on-primary-rgb), 0.3);
        transform: translateY(-1px);
    }

    .theme-toggle:focus-visible {
        outline: none;
        box-shadow: 0 0 0 2px rgba(var(--md-sys-color-on-primary-rgb), 0.4);
    }

    .theme-toggle-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .theme-toggle-icon svg {
        display: block;
    }

    .theme-toggle-icon svg.icon-moon {
        display: none;
    }

    .theme-toggle-icon--dark svg.icon-sun {
        display: none;
    }

    .theme-toggle-icon--dark svg.icon-moon {
        display: block;
    }

    .theme-toggle-label {
        white-space: nowrap;
    }

    .site-header h1 {
        margin: 0;
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: var(--md-sys-typescale-display-large-size);
        line-height: var(--md-sys-typescale-display-large-line-height);
        font-weight: var(--md-sys-typescale-display-large-weight);
    }

    .badge {
        background: rgba(var(--md-sys-color-on-primary-rgb), 0.15);
        border-radius: 999px;
        padding: 0.2rem 0.75rem;
        font-size: var(--md-sys-typescale-label-small-size);
        line-height: var(--md-sys-typescale-label-small-line-height);
        font-weight: var(--md-sys-typescale-label-small-weight);
        letter-spacing: 0.05em;
        text-transform: uppercase;
    }

    .tagline {
        margin: 0.5rem 0 0;
        font-size: var(--md-sys-typescale-body-large-size);
        line-height: var(--md-sys-typescale-body-large-line-height);
        color: var(--md-sys-color-on-primary-container);
        opacity: 0.95;
    }

    .layout {
        display: grid;
        grid-template-columns: minmax(260px, 320px) 1fr;
        gap: 0;
        flex: 1;
        overflow: hidden;
    }

    /* Desktop: animate grid columns on collapse */
    @media (min-width: 901px) {
        .layout {
            transition: grid-template-columns 0.3s ease;
        }

        .layout:has(.sidebar--collapsed) {
            grid-template-columns: min-content 1fr;
        }
    }

    .sidebar {
        background: var(--md-sys-color-surface-variant);
        border-right: 1px solid var(--md-sys-color-outline-variant);
        padding: 1.25rem;
        overflow-y: auto;
    }

    .sidebar-header {
        position: sticky;
        top: -1.25rem; /* Negative top to align with sidebar padding */
        background: var(--md-sys-color-surface-variant);
        padding-top: 1.25rem; /* Match sidebar padding */
        padding-bottom: 1rem;
        margin-top: -1.25rem; /* Pull up to offset padding */
        margin-bottom: 1rem;
        margin-left: -1.25rem; /* Extend to sidebar edges */
        margin-right: -1.25rem;
        padding-left: 1.25rem; /* Add back padding for content */
        padding-right: 1.25rem;
        z-index: 10;
    }

    /* Desktop horizontal collapse (default) */
    @media (min-width: 901px) {
        .sidebar {
            padding: 1.25rem;
            transition: padding 0.3s ease;
        }

        /* Adjust header spacing on desktop for consistent gaps */
        .sidebar-header {
            padding-bottom: 0;
            margin-bottom: 0.5rem; /* 8px gap after view-toggle to match heading-to-search spacing */
        }

        .sidebar--collapsed {
            padding: 1.25rem 0.5rem;
        }

        .sidebar--collapsed .sidebar-header > *:not(.sidebar-header-top) {
            display: none;
        }

        .sidebar--collapsed .tree {
            display: none;
        }

        .sidebar--collapsed h2 {
            display: none;
        }
    }

    .sidebar-header-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: 0.75rem;
    }

    .sidebar h2 {
        margin: 0;
        font-size: var(--md-sys-typescale-title-medium-size);
        line-height: var(--md-sys-typescale-title-medium-line-height);
        font-weight: var(--md-sys-typescale-title-medium-weight);
    }

    .sidebar-collapse-btn,
    .sidebar-collapse-btn-mobile {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 32px;
        height: 32px;
        padding: 0;
        background: transparent;
        border: none;
        border-radius: 6px;
        color: var(--md-sys-color-on-surface-variant);
        cursor: pointer;
        transition: all 0.2s ease;
        flex-shrink: 0;
    }

    .sidebar-collapse-btn:hover,
    .sidebar-collapse-btn-mobile:hover {
        background: var(--md-sys-color-surface);
    }

    .sidebar-collapse-btn svg,
    .sidebar-collapse-btn-mobile svg {
        transition: transform 0.3s ease;
    }

    .sidebar--collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }

    /* Hide mobile collapse button on desktop, show desktop one */
    .sidebar-collapse-btn-mobile {
        display: none;
    }

    .sidebar-header-row {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .search-btn {
        width: 100%;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        margin-bottom: 0.5rem;
        background: var(--md-sys-color-surface);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: 8px;
        color: var(--md-sys-color-on-surface-variant);
        font-size: var(--md-sys-typescale-body-medium-size);
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .search-btn:hover {
        background: var(--md-sys-color-surface-container);
        border-color: var(--md-sys-color-outline);
    }

    .search-btn:active {
        transform: scale(0.98);
    }

    .search-btn-icon {
        flex-shrink: 0;
    }

    .search-btn-label {
        flex: 1;
        text-align: left;
    }

    .search-btn-shortcut {
        flex-shrink: 0;
        font-size: var(--md-sys-typescale-label-small-size);
    }

    .hint {
        margin: 0;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        color: var(--md-sys-color-on-surface-variant);
    }

    .search-box {
        position: relative;
        margin-top: 0.75rem;
    }

    .search-icon {
        position: absolute;
        left: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
        color: var(--md-sys-color-outline-strong);
        pointer-events: none;
        z-index: 1;
    }

    .search-input {
        width: 100%;
        padding: 0.6rem 2.5rem 0.6rem 2.5rem;
        border: 1px solid var(--md-sys-color-outline);
        border-radius: 8px;
        background: var(--md-sys-color-surface);
        color: var(--md-sys-color-on-surface);
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        transition: all 0.2s ease;
    }

    .search-input::placeholder {
        color: var(--md-sys-color-outline);
    }

    .search-input:focus {
        outline: none;
        border-color: var(--md-sys-color-primary);
        box-shadow: 0 0 0 2px rgba(var(--md-sys-color-primary-rgb), 0.15);
    }

    .clear-search-btn {
        position: absolute;
        right: 0.5rem;
        top: 50%;
        transform: translateY(-50%);
        background: transparent;
        border: none;
        padding: 0.25rem;
        cursor: pointer;
        color: var(--md-sys-color-outline-strong);
        border-radius: 4px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
    }

    .clear-search-btn:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        color: var(--md-sys-color-primary);
    }

    .view-toggle {
        margin-top: 0.5rem;
    }

    .toggle-btn {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        padding: 0.4rem 0.75rem;
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        border: 1px solid rgba(var(--md-sys-color-primary-rgb), 0.2);
        border-radius: 6px;
        color: var(--md-sys-color-primary);
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .toggle-btn:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.18);
        border-color: rgba(var(--md-sys-color-primary-rgb), 0.3);
    }

    .toggle-btn svg {
        opacity: 0.7;
    }

    .tree {
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
    }

    .tree ul {
        list-style: none;
        padding-left: 0;
        margin: 0;
    }

    .tree li {
        margin: 0;
    }

    .tree-button {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 0.4rem 0.6rem;
        border: none;
        background: transparent;
        text-align: left;
        cursor: pointer;
        border-radius: 6px;
        transition:
            background 0.15s ease,
            color 0.15s ease;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        color: var(--md-sys-color-on-surface);
        text-decoration: none;
    }

    .tree-button:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
    }

    .tree-button--active {
        background: rgba(var(--md-sys-color-primary-rgb), 0.22);
        color: var(--md-sys-color-primary);
        font-weight: 600;
    }

    .tree-label {
        display: flex;
        align-items: center;
        gap: 0.4rem;
    }

    .tree-chevron {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 16px;
        height: 16px;
        cursor: pointer;
        transition: transform 0.2s ease;
        color: var(--md-sys-color-outline-strong);
    }

    .tree-chevron:hover {
        color: var(--md-sys-color-primary);
    }

    .tree-button--expanded .tree-chevron {
        transform: rotate(90deg);
    }

    .tree-button--collapsed .tree-chevron {
        transform: rotate(0deg);
    }

    .tree-count {
        font-size: var(--md-sys-typescale-label-small-size);
        font-weight: 600;
        color: var(--md-sys-color-outline-strong);
    }

    .tree-children {
        padding-left: 1rem;
    }

    .content {
        padding: 1.5rem clamp(1rem, 4vw, 3rem);
        position: relative;
        display: flex;
        flex-direction: column;
        gap: 1rem;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .status {
        min-height: 1.2rem;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        color: var(--md-sys-color-on-surface-variant);
    }

    .status.error {
        color: var(--md-sys-color-error);
    }

    .content-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin: 1.25rem 0 0.75rem;
        gap: 1rem;
        flex-wrap: wrap;
    }

    .selection-header {
        font-size: var(--md-sys-typescale-title-medium-size);
        line-height: var(--md-sys-typescale-title-medium-line-height);
        font-weight: var(--md-sys-typescale-title-medium-weight);
        margin: 0;
    }

    .breadcrumb-link {
        color: var(--md-sys-color-primary);
        text-decoration: none;
        transition: opacity 0.2s ease;
    }

    .breadcrumb-link:hover {
        opacity: 0.7;
        text-decoration: underline;
    }

    .breadcrumb-separator {
        color: var(--md-sys-color-on-surface-variant);
    }

    .breadcrumb-current {
        color: var(--md-sys-color-on-surface);
    }

    .sort-controls {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .sort-label {
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        color: var(--md-sys-color-on-surface-variant);
    }

    .sort-select {
        padding: 0.375rem 0.625rem;
        border: 1px solid var(--md-sys-color-outline);
        border-radius: 0.375rem;
        background: var(--md-sys-color-surface);
        color: var(--md-sys-color-on-surface);
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        cursor: pointer;
        transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
    }

    .sort-select:hover {
        border-color: var(--md-sys-color-primary);
    }

    .sort-select:focus {
        outline: 2px solid var(--md-sys-color-primary);
        outline-offset: 2px;
    }

    .pr-list {
        display: grid;
        gap: 1rem;
    }

    .pagination-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-top: 1.5rem;
        padding: 1rem;
        background: var(--md-sys-color-surface);
        border-radius: 8px;
        box-shadow: var(--md-sys-elevation-level2);
        gap: 1rem;
        flex-wrap: wrap;
    }

    .pagination-info {
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        color: var(--md-sys-color-on-surface-variant);
    }

    .pagination-buttons {
        display: flex;
        align-items: center;
        gap: 1rem;
    }

    .pagination-btn {
        padding: 0.5rem 1rem;
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        border: 1px solid rgba(var(--md-sys-color-primary-rgb), 0.2);
        border-radius: 6px;
        color: var(--md-sys-color-primary);
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
    }

    .pagination-btn:hover:not(:disabled) {
        background: rgba(var(--md-sys-color-primary-rgb), 0.18);
        border-color: rgba(var(--md-sys-color-primary-rgb), 0.3);
    }

    .pagination-btn:disabled {
        opacity: 0.45;
        cursor: not-allowed;
    }

    .page-info {
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        font-weight: 500;
        color: var(--md-sys-color-primary);
    }

    .pagination-size {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
    }

    .pagination-size label {
        color: var(--md-sys-color-on-surface-variant);
    }

    .page-size-select {
        padding: 0.375rem 0.625rem;
        border: 1px solid var(--md-sys-color-outline);
        border-radius: 0.375rem;
        background: var(--md-sys-color-surface);
        color: var(--md-sys-color-on-surface);
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        cursor: pointer;
        transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
    }

    .page-size-select:hover {
        border-color: var(--md-sys-color-primary);
    }

    .page-size-select:focus {
        outline: 2px solid var(--md-sys-color-primary);
        outline-offset: 2px;
    }

    /* Loading states for pagination */
    .pr-list.loading {
        opacity: 0.6;
        pointer-events: none;
        position: relative;
    }

    .pagination-btn.loading {
        opacity: 0.6;
        pointer-events: none;
    }

    .pr-card {
        display: block;
        background: var(--md-sys-color-surface);
        border-radius: 12px;
        padding: 1rem 1.2rem;
        box-shadow: var(--md-sys-elevation-level2);
        border: 1px solid rgba(var(--md-sys-color-primary-container-rgb), 0.12);
        text-decoration: none;
        color: inherit;
        cursor: pointer;
        transition:
            box-shadow 0.2s ease,
            border-color 0.2s ease;
    }

    .pr-card:hover {
        box-shadow: var(--md-sys-elevation-level2-hover);
        border-color: rgba(var(--md-sys-color-primary-container-rgb), 0.24);
    }

    .pr-summary {
        cursor: pointer;
    }

    .pr-title-row {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.8rem;
        margin-bottom: 0.4rem;
    }

    .pr-card h3 {
        margin: 0;
        font-size: var(--md-sys-typescale-title-small-size);
        line-height: var(--md-sys-typescale-title-small-line-height);
        font-weight: var(--md-sys-typescale-title-small-weight);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.6rem;
        flex: 1;
    }

    .pr-title-text {
        flex: 1;
    }

    .pr-id {
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        font-weight: 500;
        color: var(--md-sys-color-outline-strong);
    }

    .expand-btn {
        background: transparent;
        border: none;
        padding: 0.25rem;
        cursor: pointer;
        color: var(--md-sys-color-outline-strong);
        transition: all 0.2s ease;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        flex-shrink: 0;
    }

    .expand-btn:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        color: var(--md-sys-color-primary);
    }

    .expand-btn svg {
        transition: transform 0.2s ease;
    }

    .pr-card--expanded .expand-btn svg {
        transform: rotate(180deg);
    }

    .pr-meta {
        margin: 0.4rem 0 0.6rem;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        color: var(--md-sys-color-on-surface-variant);
    }

    .pill-group {
        display: flex;
        gap: 0.4rem;
        flex-wrap: wrap;
        margin: 0.6rem 0;
    }

    .pill {
        border-radius: 999px;
        background: rgba(var(--md-sys-color-primary-rgb), 0.14);
        color: var(--md-sys-color-primary);
        padding: 0.2rem 0.6rem;
        font-size: var(--md-sys-typescale-label-medium-size);
        line-height: var(--md-sys-typescale-label-medium-line-height);
        font-weight: var(--md-sys-typescale-label-medium-weight);
        transition: background 0.2s ease;
        text-decoration: none;
        display: inline-block;
    }

    a.pill:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.24);
        color: var(--md-sys-color-primary);
    }

    .pill.active {
        background: var(--md-sys-color-primary-container);
        color: var(--md-sys-color-on-primary-container);
    }

    .pill.more-indicator {
        background: rgba(
            var(--md-sys-color-on-surface-variant-rgb, 75, 85, 99),
            0.1
        );
        color: var(--md-sys-color-on-surface-variant);
        font-style: italic;
    }

    .pr-details {
        margin-top: 1rem;
        padding-top: 1rem;
        border-top: 1px solid
            rgba(var(--md-sys-color-primary-container-rgb), 0.12);
    }

    .pr-link-section {
        margin-bottom: 0.75rem;
    }

    .pr-link {
        display: inline-flex;
        align-items: center;
        gap: 0.3rem;
        color: var(--md-sys-color-primary);
        font-weight: 500;
        text-decoration: none;
        padding: 0.4rem 0.75rem;
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        border-radius: 6px;
        transition: all 0.2s ease;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
    }

    .pr-link:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.18);
        text-decoration: none;
    }

    .pr-timestamp {
        margin: 0 0 0.75rem;
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        color: var(--md-sys-color-outline-strong);
    }

    .file-list-title {
        margin: 0.75rem 0 0.5rem;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        font-weight: 600;
        color: var(--md-sys-color-on-surface-variant);
    }

    .file-list {
        margin: 0;
    }

    .file-item {
        display: flex;
        justify-content: space-between;
        gap: 0.6rem;
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        padding: 0.35rem 0;
        border-bottom: 1px solid
            rgba(var(--md-sys-color-primary-container-rgb), 0.08);
    }

    .file-item:last-child {
        border-bottom: none;
    }

    .file-path {
        font-family: var(--md-ref-typeface-mono);
        font-size: var(--md-sys-typescale-label-medium-size);
        line-height: var(--md-sys-typescale-label-medium-line-height);
        color: var(--md-sys-color-on-surface);
        overflow-wrap: anywhere;
    }

    .file-stats {
        display: flex;
        gap: 0.5rem;
        font-family: var(--md-ref-typeface-mono);
    }

    .stat-add {
        color: var(--md-sys-color-success);
    }

    .stat-del {
        color: var(--md-sys-color-error);
    }

    .more-files {
        margin: 0.5rem 0 0;
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        color: var(--md-sys-color-outline-strong);
        font-style: italic;
    }

    .more-files-link {
        transition: color 0.2s ease;
    }

    .more-files-link:hover {
        color: var(--md-sys-color-primary);
        text-decoration: underline;
    }

    .empty-state {
        font-size: var(--md-sys-typescale-body-large-size);
        line-height: var(--md-sys-typescale-body-large-line-height);
        color: var(--md-sys-color-outline-strong);
        padding: 2rem 0;
        text-align: center;
    }

    .pr-detail-view {
        background: var(--md-sys-color-surface);
        border-radius: 12px;
        box-shadow: var(--md-sys-elevation-level2);
        padding: 1.5rem;
        border: 1px solid rgba(var(--md-sys-color-primary-container-rgb), 0.12);
    }

    .back-btn {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        background: rgba(var(--md-sys-color-primary-rgb), 0.1);
        border: 1px solid rgba(var(--md-sys-color-primary-rgb), 0.2);
        border-radius: 6px;
        color: var(--md-sys-color-primary);
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        margin-bottom: 1.5rem;
    }

    .back-btn:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.18);
        border-color: rgba(var(--md-sys-color-primary-rgb), 0.3);
    }

    .detail-title {
        margin: 0 0 0.5rem;
        font-size: var(--md-sys-typescale-headline-small-size);
        line-height: var(--md-sys-typescale-headline-small-line-height);
        font-weight: var(--md-sys-typescale-headline-small-weight);
        color: var(--md-sys-color-primary);
    }

    .detail-pr-number {
        font-size: var(--md-sys-typescale-title-medium-size);
        line-height: var(--md-sys-typescale-title-medium-line-height);
        font-weight: var(--md-sys-typescale-title-medium-weight);
        color: var(--md-sys-color-outline-strong);
        margin-bottom: 1rem;
    }

    .detail-meta {
        background: rgba(var(--md-sys-color-primary-rgb), 0.05);
        border-radius: 8px;
        padding: 1rem;
        margin-bottom: 1rem;
        display: grid;
        gap: 0.5rem;
        font-size: var(--md-sys-typescale-body-medium-size);
        line-height: var(--md-sys-typescale-body-medium-line-height);
    }

    .detail-meta strong {
        color: var(--md-sys-color-primary);
        margin-right: 0.5rem;
    }

    .detail-metrics {
        display: flex;
        gap: 0.6rem;
        flex-wrap: wrap;
        margin-bottom: 1rem;
    }

    .detail-link-section {
        margin-bottom: 1.5rem;
    }

    .detail-link {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.6rem 1.2rem;
        background: var(--md-sys-color-primary-container);
        color: var(--md-sys-color-on-primary-container);
        border-radius: 8px;
        text-decoration: none;
        font-weight: 500;
        transition: all 0.2s ease;
        font-size: var(--md-sys-typescale-body-large-size);
        line-height: var(--md-sys-typescale-body-large-line-height);
    }

    .detail-link:hover {
        background: var(--md-sys-color-primary);
        transform: translateY(-1px);
        box-shadow: var(--md-sys-elevation-level2-hover);
    }

    .detail-section {
        margin-bottom: 2rem;
    }

    .detail-section h3 {
        margin: 0 0 0.75rem;
        font-size: var(--md-sys-typescale-title-large-size);
        line-height: var(--md-sys-typescale-title-large-line-height);
        font-weight: var(--md-sys-typescale-title-large-weight);
        color: var(--md-sys-color-primary);
    }

    .detail-file-list {
        background: var(--md-sys-color-surface);
        border-radius: 8px;
        border: 1px solid rgba(var(--md-sys-color-primary-container-rgb), 0.1);
        overflow: hidden;
    }

    .detail-file-item {
        padding: 0.75rem 1rem;
        border-bottom: 1px solid
            rgba(var(--md-sys-color-primary-container-rgb), 0.08);
        transition: background 0.15s ease;
    }

    .detail-file-item:last-child {
        border-bottom: none;
    }

    .detail-file-item:hover {
        background: rgba(var(--md-sys-color-primary-rgb), 0.06);
    }

    .detail-file-path {
        font-family: var(--md-ref-typeface-mono);
        font-size: var(--md-sys-typescale-body-small-size);
        line-height: var(--md-sys-typescale-body-small-line-height);
        color: var(--md-sys-color-on-surface);
        overflow-wrap: anywhere;
    }

    @media (max-width: 900px) {
        .layout {
            grid-template-columns: 1fr;
            grid-template-rows: auto 1fr;
            transition: grid-template-rows 0.3s ease;
        }

        .sidebar {
            border-right: none;
            border-bottom: 1px solid var(--md-sys-color-outline-variant);
            padding: 1.25rem 1rem 0.5rem 1rem;
            transition: max-height 0.3s ease;
        }

        .sidebar--collapsed {
            max-height: 95px;
            overflow: hidden;
        }

        /* Fix sticky header margins on mobile */
        .sidebar-header {
            position: static;
            margin: 0;
            padding: 0;
        }

        /* Adjust header row layout on mobile */
        .sidebar-header-row {
            margin: 0;
            padding: 0;
        }

        /* Show mobile collapse button, hide desktop one */
        .sidebar-collapse-btn {
            display: none;
        }

        .sidebar-collapse-btn-mobile {
            display: flex;
            margin-left: 0.5rem;
        }

        /* Hide header top (Packages heading + desktop button) on mobile when expanded */
        .sidebar-header-top {
            display: none;
        }

        /* Adjust search button on mobile */
        .search-btn {
            margin-bottom: 0;
            flex: 1;
        }

        /* Animate content fade when collapsed on mobile */
        .sidebar .view-toggle,
        .sidebar .tree {
            transition:
                opacity 0.2s ease,
                visibility 0.2s ease;
        }

        .sidebar--collapsed .view-toggle,
        .sidebar--collapsed .tree {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
        }

        /* Rotate collapse icon for vertical collapse */
        .sidebar-collapse-btn-mobile svg {
            transform: rotate(90deg);
        }

        .sidebar--collapsed .sidebar-collapse-btn-mobile svg {
            transform: rotate(-90deg);
        }

        .header-bar {
            flex-direction: column;
            align-items: flex-start;
        }

        .header-actions {
            align-self: stretch;
            justify-content: flex-end;
        }
    }

    /* ============================================
   Search Modal (Cmd+K)
   ============================================ */

    .search-modal {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        display: flex;
        align-items: flex-start;
        justify-content: center;
        padding-top: 15vh;
    }

    .search-modal-backdrop {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
    }

    .search-modal-content {
        position: relative;
        width: 90%;
        max-width: 640px;
        background: var(--md-sys-color-surface);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: 12px;
        box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
        overflow: hidden;
        animation: modal-slide-in 0.2s ease-out;
    }

    @keyframes modal-slide-in {
        from {
            opacity: 0;
            transform: translateY(-20px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .search-modal-input-wrapper {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem 1.25rem;
        border-bottom: 1px solid var(--md-sys-color-outline-variant);
    }

    .search-modal-icon {
        color: var(--md-sys-color-on-surface-variant);
        flex-shrink: 0;
    }

    .search-modal-input {
        flex: 1;
        border: none;
        background: transparent;
        font-size: var(--md-sys-typescale-body-large-size);
        color: var(--md-sys-color-on-surface);
        outline: none;
    }

    .search-modal-input::placeholder {
        color: var(--md-sys-color-on-surface-variant);
    }

    .search-modal-hint {
        font-family: var(--md-ref-typeface-mono);
        font-size: var(--md-sys-typescale-label-small-size);
        padding: 0.25rem 0.5rem;
        background: var(--md-sys-color-surface-variant);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: 4px;
        color: var(--md-sys-color-on-surface-variant);
    }

    .search-modal-results {
        max-height: 400px;
        overflow-y: auto;
    }

    .search-modal-result-item {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1.25rem;
        cursor: pointer;
        border-left: 3px solid transparent;
        transition: all 0.15s ease;
    }

    .search-modal-result-item:hover {
        background: var(--md-sys-color-surface-variant);
    }

    .search-modal-result-item.selected {
        background: var(--md-sys-color-surface-variant);
        border-left-color: var(--md-sys-color-primary);
    }

    .search-modal-result-icon {
        color: var(--md-sys-color-on-surface-variant);
        flex-shrink: 0;
    }

    .search-modal-result-content {
        flex: 1;
        min-width: 0;
    }

    .search-modal-result-name {
        font-size: var(--md-sys-typescale-body-medium-size);
        font-weight: 500;
        color: var(--md-sys-color-on-surface);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .search-modal-result-path {
        font-size: var(--md-sys-typescale-body-small-size);
        font-family: var(--md-ref-typeface-mono);
        color: var(--md-sys-color-on-surface-variant);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .search-modal-result-count {
        font-size: var(--md-sys-typescale-label-small-size);
        font-weight: 600;
        color: var(--md-sys-color-on-surface-variant);
        padding: 0.25rem 0.5rem;
        background: var(--md-sys-color-surface-variant);
        border-radius: 4px;
        flex-shrink: 0;
    }

    .search-modal-no-results {
        padding: 2rem 1.25rem;
        text-align: center;
        color: var(--md-sys-color-on-surface-variant);
        font-size: var(--md-sys-typescale-body-medium-size);
    }

    .search-modal-footer {
        padding: 0.75rem 1.25rem;
        background: var(--md-sys-color-surface-variant);
        border-top: 1px solid var(--md-sys-color-outline-variant);
    }

    .search-modal-shortcuts {
        display: flex;
        gap: 1.5rem;
        font-size: var(--md-sys-typescale-label-small-size);
        color: var(--md-sys-color-on-surface-variant);
    }

    .search-modal-shortcuts kbd {
        font-family: var(--md-ref-typeface-mono);
        font-size: var(--md-sys-typescale-label-small-size);
        padding: 0.15rem 0.4rem;
        background: var(--md-sys-color-surface);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: 3px;
        margin: 0 0.2rem;
    }

    kbd {
        font-family: var(--md-ref-typeface-mono);
        font-size: 0.9em;
        padding: 0.15rem 0.4rem;
        background: var(--md-sys-color-surface-variant);
        border: 1px solid var(--md-sys-color-outline-variant);
        border-radius: 3px;
    }
} /* End @layer components */

@layer states {
    /* Loading state */
    .loading-screen--fade-out {
        opacity: 0;
        pointer-events: none;
    }

    /* Sidebar collapsed states */
    .sidebar--collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }

    .sidebar--collapsed .sidebar-collapse-btn-mobile svg {
        transform: rotate(-90deg);
    }

    /* Tree button states */
    .tree-button--active {
        background: rgba(var(--md-sys-color-primary-rgb), 0.22);
        color: var(--md-sys-color-primary);
        font-weight: 600;
    }

    li.expanded > .tree-button .tree-chevron {
        transform: rotate(90deg);
    }

    li.collapsed > .tree-button .tree-chevron {
        transform: rotate(0deg);
    }

    /* PR card states */
    .pr-card--expanded .expand-btn svg {
        transform: rotate(180deg);
    }

    /* Theme toggle states */
    .theme-toggle-icon--dark svg.icon-sun {
        display: none;
    }

    .theme-toggle-icon--dark svg.icon-moon {
        display: block;
    }

    /* Layout state changes */
    @media (min-width: 901px) {
        .layout:has(.sidebar--collapsed) {
            grid-template-columns: min-content 1fr;
        }

        .sidebar--collapsed {
            padding: 1.25rem 0.5rem;
        }

        /* Hide sidebar content when collapsed on desktop */
        .sidebar--collapsed .sidebar-header > *:not(.sidebar-header-top) {
            display: none;
        }

        .sidebar--collapsed .tree {
            display: none;
        }

        .sidebar--collapsed h2 {
            display: none;
        }
    }

    @media (max-width: 900px) {
        .sidebar--collapsed {
            max-height: 95px;
            overflow: hidden;
        }

        /* Hide tree and view toggle when collapsed on mobile */
        .sidebar--collapsed .view-toggle,
        .sidebar--collapsed .tree {
            opacity: 0;
            visibility: hidden;
            pointer-events: none;
        }
    }
}
