[hidden] { display: none !important; }
* { box-sizing: border-box; }

:root {
    --bg1: #6177e5;
    --bg2: #7650ba;
    --header: #2d4356;
    --text: #2d4356;
    --muted: #71808c;
    --line: #dce4ea;
    --accent: #1598ea;
    --toolbar: #ffffff;
}

html, body { width: 100%; height: 100%; margin: 0; }

body {
    overflow: hidden;
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, var(--bg1), var(--bg2));
    padding: 14px;
}

button, input { font: inherit; }

.app-shell {
    width: min(1125px, 100%);
    height: calc(100dvh - 28px);
    margin: 0 auto;
    overflow: hidden;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 18px 60px rgba(19,30,48,.22);
}

.app-header {
    height: 136px;
    padding: 28px 30px 20px;
    text-align: center;
    color: #fff;
    background: var(--header);
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.title-icon { font-size: 33px; }

.app-header h1 {
    margin: 0;
    font-size: clamp(27px, 3vw, 41px);
    line-height: 1.12;
    font-weight: 800;
}

.app-header p {
    margin: 15px 0 0;
    color: rgba(255,255,255,.78);
}

.workspace {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    height: calc(100% - 136px);
    min-height: 0;
}

.sidebar {
    min-width: 0;
    overflow-y: auto;
    padding: 19px;
    border-right: 1px solid var(--line);
    background: #fafbfd;
    z-index: 30;
}

.sidebar-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 12px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--accent);
    font-size: 17px;
}

.count {
    display: inline-grid;
    place-items: center;
    min-width: 27px;
    height: 22px;
    padding: 0 7px;
    border-radius: 20px;
    color: #fff;
    background: #2e95d6;
    font-size: 12px;
    font-weight: 700;
}

.pdf-list { display: grid; gap: 8px; }

.pdf-item {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid #dce4e9;
    border-radius: 8px;
    text-align: left;
    background: #fff;
    cursor: pointer;
}

.pdf-item:hover { border-color: #a9d3ed; }

.pdf-item.is-active {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.pdf-name {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #253643;
    font-size: 14px;
    font-weight: 500;
}

.pdf-meta {
    display: block;
    margin-top: 5px;
    color: #8896a0;
    font-size: 11px;
}

.reader-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    background: #f3f5f7;
}

.reader-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 35px;
    text-align: center;
}

.placeholder-icon { font-size: 62px; opacity: .62; }
.reader-placeholder h2 { margin: 15px 0 8px; font-size: 24px; }
.reader-placeholder p { margin: 0; color: var(--muted); }
.reader-placeholder small { margin-top: 16px; color: #a5b0b8; }

.reader-wrap {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    width: 100%;
    height: 100%;
    min-height: 0;
}

.reader-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    gap: 12px;
    padding: 6px 12px 6px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--toolbar);
}

.reader-topbar > strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbar {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 5px;
}

.toolbar button,
.toolbar a {
    display: inline-grid;
    place-items: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid #d5dde3;
    border-radius: 6px;
    color: #2d4356;
    background: #fff;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
}

.page-control {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #5d6b75;
    font-size: 13px;
}

.page-control input {
    width: 52px;
    height: 32px;
    padding: 3px 4px;
    border: 1px solid #d5dde3;
    border-radius: 6px;
    text-align: center;
}

.zoom-value {
    width: 48px;
    text-align: center;
    color: #65747f;
    font-size: 12px;
}

.status-bar {
    padding: 8px 12px;
    color: #345064;
    background: #eaf5fc;
    border-bottom: 1px solid #cde7f6;
    font-size: 13px;
}

.status-bar.error {
    color: #8d2525;
    background: #fff1f1;
    border-color: #f2caca;
}

.pdf-viewer {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 18px;
    background: #3f4149;
    scroll-behavior: auto;
    outline: none;
}

.pdf-page-shell {
    position: relative;
    max-width: none;
    margin: 0 auto 18px;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0,0,0,.32);
    content-visibility: auto;
    contain-intrinsic-size: 800px 1131px;
}

.pdf-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #fff;
}

.page-badge {
    position: absolute;
    z-index: 2;
    left: 50%;
    bottom: 8px;
    transform: translateX(-50%);
    min-width: 30px;
    padding: 3px 8px;
    border-radius: 12px;
    color: #fff;
    background: rgba(38,43,51,.78);
    text-align: center;
    font-size: 11px;
    pointer-events: none;
}

.mobile-only { display: none !important; }

.empty-list {
    padding: 13px;
    border: 1px dashed #ccd6de;
    border-radius: 8px;
    color: var(--muted);
    background: #fff;
}

@media (max-width: 820px) {
    body { padding: 0; overflow: hidden; }

    .app-shell {
        width: 100%;
        height: 100dvh;
        border-radius: 0;
    }

    .app-header {
        height: 88px;
        padding: max(12px, env(safe-area-inset-top)) 12px 10px;
    }

    .title-icon { font-size: 23px; }

    .app-header h1 { font-size: clamp(20px, 5vw, 27px); }

    .app-header p {
        margin-top: 6px;
        font-size: 12px;
    }

    .workspace {
        position: relative;
        grid-template-columns: 1fr;
        height: calc(100% - 88px);
    }

    .sidebar {
        position: absolute;
        inset: 0 auto 0 0;
        width: min(82vw, 330px);
        transform: translateX(-105%);
        transition: transform .2s ease;
        box-shadow: 8px 0 30px rgba(0,0,0,.2);
    }

    .sidebar.is-open { transform: translateX(0); }

    .reader-panel { width: 100%; height: 100%; }

    .reader-topbar {
        padding: 5px 6px;
        gap: 5px;
    }

    .reader-topbar > strong { display: none; }

    .toolbar {
        width: 100%;
        justify-content: space-between;
        gap: 3px;
    }

    .toolbar button,
    .toolbar a {
        min-width: 34px;
        height: 34px;
        padding: 0 6px;
    }

    .mobile-only { display: inline-grid !important; }
    .zoom-value { display: none; }

    .page-control input { width: 44px; }

    .pdf-viewer { padding: 8px; }

    .pdf-page-shell { margin-bottom: 10px; }
}

@media (max-width: 460px) {
    #zoomOut, #zoomIn { display: none; }
}

/* === V4 — bibliothèque classée + introduction === */
.main-nav {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 14px;
}

.main-nav a {
    padding: 7px 13px;
    border: 1px solid rgba(255,255,255,.28);
    border-radius: 999px;
    color: rgba(255,255,255,.84);
    text-decoration: none;
    font-size: 13px;
    font-weight: 700;
}

.main-nav a:hover,
.main-nav a.is-current {
    color: #243747;
    background: #fff;
    border-color: #fff;
}

.library-controls {
    display: grid;
    gap: 7px;
    padding: 0 0 16px;
    margin-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.control-label {
    margin-top: 3px;
    color: #526674;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .04em;
    text-transform: uppercase;
}

.library-input,
.library-select {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #d4dfe6;
    border-radius: 8px;
    color: #273b4a;
    background: #fff;
    outline: none;
}

.library-input:focus,
.library-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(21,152,234,.12);
}

.clear-filters {
    justify-self: start;
    padding: 6px 0;
    border: 0;
    color: #3479a8;
    background: transparent;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

.pdf-item {
    display: block;
}

.pdf-category {
    display: inline-block;
    max-width: 100%;
    margin-bottom: 7px;
    padding: 3px 7px;
    overflow: hidden;
    border-radius: 999px;
    color: #2f678e;
    background: #eaf5fc;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .02em;
}

.pdf-name {
    white-space: normal;
    line-height: 1.28;
}

.pdf-byline,
.pdf-description {
    display: block;
    margin-top: 5px;
    line-height: 1.35;
}

.pdf-byline {
    color: #617481;
    font-size: 11px;
    font-weight: 700;
}

.pdf-description {
    color: #758690;
    font-size: 11px;
}

.reader-document-info {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.reader-document-info strong,
.reader-document-info span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader-document-info span {
    color: #73838e;
    font-size: 11px;
}

.intro-link {
    margin-top: 16px;
    color: #2685bd;
    text-decoration: none;
    font-weight: 800;
}

.intro-link:hover { text-decoration: underline; }

/* Page d'introduction */
.intro-body {
    overflow: auto;
    min-height: 100%;
    padding: 22px;
}

.intro-shell {
    width: min(1125px, 100%);
    margin: 0 auto;
    overflow: hidden;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 18px 60px rgba(19,30,48,.22);
}

.intro-header { height: auto; min-height: 164px; }

.intro-page {
    padding: clamp(28px, 5vw, 64px);
    background: #f7f9fb;
}

.intro-lead {
    max-width: 820px;
    margin: 0 auto 42px;
    text-align: center;
}

.eyebrow {
    margin: 0 0 9px;
    color: #2a85bd;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.intro-page h2 {
    margin: 0 0 14px;
    color: #243746;
    font-size: clamp(26px, 3.5vw, 42px);
    line-height: 1.08;
}

.intro-page h3 {
    margin: 8px 0 10px;
    color: #243746;
    font-size: 19px;
}

.intro-page p {
    color: #5d6f7b;
    line-height: 1.7;
}

.intro-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 16px;
    max-width: 960px;
    margin: 0 auto 48px;
}

.intro-card {
    padding: 24px;
    border: 1px solid #dfe7ec;
    border-radius: 12px;
    background: #fff;
}

.step {
    display: inline-grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: #fff;
    background: #2d4356;
    font-size: 11px;
    font-weight: 900;
}

.intro-section {
    max-width: 960px;
    margin: 0 auto;
    padding: 36px 0;
    border-top: 1px solid #dfe7ec;
}

.concept-flow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 9px;
    margin: 24px 0;
}

.concept-flow span {
    padding: 9px 13px;
    border-radius: 8px;
    color: #294457;
    background: #eaf5fc;
    font-weight: 800;
}

.concept-flow b { color: #7a8d99; }

.category-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    margin: 22px 0;
}

.category-summary a {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border: 1px solid #dce6ec;
    border-radius: 9px;
    color: #294457;
    background: #fff;
    text-decoration: none;
}

.category-summary a:hover { border-color: #9bcce9; }
.category-summary span { color: #7c8c96; font-size: 12px; }

.intro-actions { margin-top: 24px; }
.primary-action {
    display: inline-block;
    padding: 11px 17px;
    border-radius: 8px;
    color: #fff;
    background: #2d4356;
    text-decoration: none;
    font-weight: 800;
}

.maintenance-note code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #e9eef2;
}

@media (min-width: 821px) {
    .app-header { height: 164px; padding-top: 21px; }
    .workspace { height: calc(100% - 164px); }
}

@media (max-width: 820px) {
    .app-header { height: 112px; }
    .workspace { height: calc(100% - 112px); }
    .main-nav { margin-top: 7px; }
    .main-nav a { padding: 5px 10px; font-size: 11px; }
    .reader-document-info { display: none; }
    .intro-body { padding: 0; }
    .intro-shell { border-radius: 0; min-height: 100dvh; }
    .intro-header { height: auto; min-height: 112px; }
    .intro-page { padding: 28px 18px 42px; }
    .intro-grid { grid-template-columns: 1fr; }
}
