/* css/components/viewer/side-panel.css */
.side-panel-container { flex-basis: 400px; flex-shrink: 0; min-width: 250px; max-width: 60%; border-right: 1px solid var(--border-color); background-color: var(--surface-color); display: flex; flex-direction: column; }
.side-panel-container.wide { flex-basis: 50%; }
.side-panel-container.is-transitioning { transition: flex-basis 0.4s ease-in-out; }

.side-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-color); flex-shrink: 0; position: relative; }
.side-panel-tabs { display: flex; gap: 8px; flex-grow: 1; }
.side-panel-tab { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 16px; border-radius: 99px; background-color: var(--surface-color); border: 1px solid var(--border-color); cursor: pointer; font-weight: 600; font-size: 14px; color: var(--secondary-text); transition: all 0.2s ease; }
.side-panel-tab svg { fill: var(--secondary-text); width: 19px; transition: fill 0.2s ease; }
.side-panel-tab:hover { border-color: #CBD5E0; }
body.dark-mode .side-panel-tab:hover { border-color: #718096; }
.side-panel-tab.active { color: var(--accent-blue); background-color: var(--accent-blue-light); border-color: var(--accent-blue); }
.side-panel-tab.active svg { fill: var(--accent-blue); }

.side-panel-actions { position: relative; }
.side-panel-actions .icon-button {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    color: var(--secondary-text);
    padding: 8px;
    border-radius: 99px;
    display: grid;
    place-items: center;
    transition: all 0.2s ease;
}
.side-panel-actions .icon-button:hover {
    background-color: var(--border-color);
    color: var(--primary-text);
}

.side-panel-content { flex-grow: 1; position: relative; overflow-y: auto; scroll-behavior: smooth; }
.side-panel-pane { display: none; }
.side-panel-pane.active { display: block; }
#footnotes-pane, .study-guide-content { padding: 24px; }

/* css/components/viewer/side-panel.css */

/* ... (keep all the existing styles at the top of the file) ... */

@media (max-width: 800px) {
    /* --- THIS IS THE FIX (PART 1) --- */
    /* Apply touch-action to the main container to tell the browser JS is in control. */
    .mobile-side-panel-container {
        touch-action: none;
    }

    .mobile-side-panel-container .side-panel-header {
        cursor: grab;
        -webkit-tap-highlight-color: transparent;
        /* `touch-action: none` is REMOVED from here, it's now on the parent */
        border-top: 1px solid var(--border-color);
        padding-top: 20px;
    }
    
    /* --- THIS IS THE FIX (PART 2) --- */
    /* Explicitly re-enable scrolling on the specific child elements that need it. */
    .mobile-side-panel-container .side-panel-content {
        flex-grow: 1;
        overflow-y: auto;
        touch-action: pan-y; /* Allow vertical panning (scrolling) */
    }

    .mobile-side-panel-container .side-panel-tabs {
        display: flex;
        justify-content: flex-start;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-x; /* Allow horizontal panning (scrolling) */
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none;  /* IE 10+ */
        scroll-snap-type: x mandatory;
        padding: 0 40%;
    }
    /* --- END OF FIX --- */

    .mobile-side-panel-container .side-panel-actions {
        position: absolute;
        top: 20px;
        right: 16px;
        z-index: 2;
    }

    .mobile-side-panel-container .side-panel-header:active {
        cursor: grabbing;
    }

    .mobile-side-panel-container .side-panel-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background-color: var(--border-color);
        border-radius: 99px;
    }

    .side-panel-tabs {
        justify-content: center;
    }

    .mobile-side-panel-container .side-panel-tabs-wrapper {
        width: 100%;
        -webkit-mask-image: linear-gradient(to right,
            transparent 0%,
            black 20%,
            black 80%,
            transparent 100%
        );
        mask-image: linear-gradient(to right,
            transparent 0%,
            black 40%,
            black 60%,
            transparent 100%
        );
    }

    .mobile-side-panel-container .side-panel-tabs::-webkit-scrollbar {
        display: none; /* Safari and Chrome */
    }

    .mobile-side-panel-container .side-panel-tab {
        scroll-snap-align: center;
        flex-shrink: 0;
    }
}

@media (min-width: 801px) {
    .side-panel-tabs { justify-content: flex-start; }
}