:root {
    --blue-950: #053b65;
    --blue-900: #064f82;
    --blue-800: #075f95;
    --blue-700: #0874ad;
    --blue-100: #e8f4fb;
    --ink: #102131;
    --muted: #667687;
    --line: #dfe7ee;
    --surface: #ffffff;
    --background: #f2f6f9;
    --danger: #d83a48;
    --shadow: 0 18px 54px rgba(18, 53, 77, 0.12);
    --header-height: 76px;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    background: var(--background);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    color: #fff;
    background: linear-gradient(135deg, var(--blue-900), var(--blue-700));
    box-shadow: 0 8px 30px rgba(4, 61, 99, .2);
}
.header-inner {
    width: min(1180px, calc(100% - 32px));
    height: 72px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    font-size: 18px;
    font-weight: 800;
    text-decoration: none;
}
.brand-mark {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.18);
}
.brand-mark svg { width: 22px; fill: currentColor; }
.header-badge {
    padding: 7px 11px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 999px;
    color: rgba(255,255,255,.9);
    background: rgba(255,255,255,.1);
    font-size: 12px;
    font-weight: 700;
}

.library-shell {
    width: min(1180px, calc(100% - 32px));
    margin: 32px auto 72px;
}
.hero-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.04fr) minmax(360px, .96fr);
    gap: 32px;
    align-items: center;
    padding: clamp(28px, 5vw, 60px);
    border-radius: 30px;
    background:
        radial-gradient(circle at 12% 15%, rgba(21, 141, 203, .15), transparent 32%),
        linear-gradient(135deg, #ffffff, #edf7fc);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.hero-copy h1 {
    max-width: 650px;
    margin: 10px 0 16px;
    font-size: clamp(34px, 5vw, 58px);
    line-height: 1.05;
    letter-spacing: -0.045em;
}
.hero-copy p {
    max-width: 590px;
    margin: 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.7;
}
.eyebrow {
    color: var(--blue-700);
    font-size: 12px;
    font-weight: 900;
    letter-spacing: .13em;
}
.upload-card {
    padding: 18px;
    border: 1px solid rgba(7, 95, 149, .14);
    border-radius: 24px;
    background: rgba(255,255,255,.9);
    box-shadow: 0 16px 40px rgba(16, 72, 107, .12);
    backdrop-filter: blur(12px);
}
.drop-zone {
    width: 100%;
    min-height: 216px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    border: 2px dashed #a9cadd;
    border-radius: 18px;
    color: var(--ink);
    background: #f7fbfe;
    cursor: pointer;
    transition: border-color .2s, background .2s, transform .2s;
}
.drop-zone:hover,
.drop-zone.is-dragging {
    border-color: var(--blue-700);
    background: var(--blue-100);
    transform: translateY(-2px);
}
.drop-zone strong { font-size: 17px; }
.drop-zone small { color: var(--muted); text-align: center; }
.upload-icon {
    width: 54px;
    height: 54px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    color: #fff;
    background: linear-gradient(135deg, var(--blue-800), #10a6d4);
    box-shadow: 0 12px 26px rgba(8, 116, 173, .25);
}
.upload-icon svg { width: 27px; fill: currentColor; }
.selected-files {
    max-height: 126px;
    margin-top: 12px;
    overflow: auto;
    border-radius: 12px;
    background: #f6f9fb;
}
.selected-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}
.selected-file:last-child { border-bottom: 0; }
.selected-file strong { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-file span { color: var(--muted); white-space: nowrap; }
.primary-button, .secondary-button {
    min-height: 48px;
    border-radius: 14px;
    border: 0;
    padding: 0 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: transform .18s, opacity .18s, box-shadow .18s;
}
.primary-button {
    width: 100%;
    margin-top: 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--blue-800), var(--blue-700));
    box-shadow: 0 12px 22px rgba(7, 95, 149, .2);
}
.primary-button.inline { width: auto; margin-top: 0; }
.primary-button:hover:not(:disabled), .secondary-button:hover { transform: translateY(-1px); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.button-arrow { margin-left: auto; font-size: 19px; }
.secondary-button {
    color: var(--blue-800);
    background: var(--blue-100);
}
.upload-progress { margin-top: 16px; }
.progress-track {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #dfeaf0;
}
.progress-track span {
    width: 0;
    height: 100%;
    display: block;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--blue-700), #12add3);
    transition: width .15s;
}
.progress-copy { margin-top: 8px; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.form-message { min-height: 20px; margin: 12px 2px 0; color: var(--muted); font-size: 13px; }
.form-message.is-error { color: var(--danger); }
.form-message.is-success { color: #087f56; }

.documents-section { margin-top: 44px; }
.section-head {
    margin-bottom: 20px;
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
}
.section-head h2 { margin: 6px 0 0; font-size: clamp(25px, 3vw, 36px); letter-spacing: -.035em; }
.search-box {
    width: min(330px, 100%);
    min-height: 46px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(23, 62, 87, .05);
}
.search-box span { width: 20px; height: 20px; color: var(--muted); }
.search-box svg { width: 100%; fill: currentColor; }
.search-box input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.document-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.document-card {
    position: relative;
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 10px 30px rgba(30, 66, 91, .06);
    transition: transform .2s, box-shadow .2s, border-color .2s;
}
.document-card:hover { transform: translateY(-3px); border-color: #b8d7e7; box-shadow: 0 16px 34px rgba(30, 66, 91, .11); }
.document-link {
    min-width: 0;
    padding: 15px 52px 15px 15px;
    display: flex;
    align-items: center;
    gap: 14px;
    text-decoration: none;
}
.pdf-thumbnail {
    position: relative;
    flex: 0 0 54px;
    height: 68px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    overflow: hidden;
    color: #fff;
    background: linear-gradient(155deg, #f0545f, #c82437);
    box-shadow: 0 9px 20px rgba(205, 37, 53, .2);
}
.pdf-thumbnail::after { content: ''; position: absolute; top: 0; right: 0; border-top: 14px solid rgba(255,255,255,.82); border-left: 14px solid transparent; }
.pdf-thumbnail span { position: relative; z-index: 1; font-size: 12px; font-weight: 900; letter-spacing: .06em; }
.pdf-thumbnail svg { position: absolute; width: 66px; fill: rgba(255,255,255,.08); transform: rotate(-8deg); }
.document-info { min-width: 0; flex: 1; }
.document-info h3 { margin: 0 0 7px; overflow: hidden; color: #15293a; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.document-info p { margin: 0; color: var(--muted); font-size: 12px; }
.open-button { width: 34px; height: 34px; display: grid; place-items: center; color: var(--blue-800); border-radius: 11px; background: var(--blue-100); }
.open-button svg { width: 18px; fill: currentColor; }
.delete-button {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 34px;
    height: 34px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 10px;
    color: #b52938;
    background: #fff0f2;
    cursor: pointer;
}
.delete-button svg { width: 17px; fill: currentColor; }
.empty-state {
    padding: 56px 20px;
    border: 1px dashed #bfd2de;
    border-radius: 24px;
    text-align: center;
    background: rgba(255,255,255,.62);
}
.empty-state.compact { padding: 34px 20px; }
.empty-state h3 { margin: 16px 0 7px; }
.empty-state p { margin: 0; color: var(--muted); }
.empty-icon { width: 66px; height: 66px; margin: 0 auto; display: grid; place-items: center; border-radius: 22px; color: var(--blue-700); background: var(--blue-100); }
.empty-icon svg { width: 34px; fill: currentColor; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + env(safe-area-inset-bottom));
    z-index: 100;
    max-width: min(92vw, 440px);
    padding: 12px 16px;
    border-radius: 13px;
    color: #fff;
    background: rgba(15, 34, 49, .94);
    box-shadow: 0 12px 30px rgba(0,0,0,.25);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 15px);
    transition: opacity .22s, transform .22s;
    font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Viewer */
.viewer-page {
    min-height: 100%;
    overflow-x: hidden;
    background: #fff;
}
.viewer-header {
    position: fixed !important;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    isolation: isolate;
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    color: #fff;
    background:
        linear-gradient(120deg, rgba(255,255,255,.06), transparent 42%),
        linear-gradient(135deg, var(--blue-900), #076da2);
    box-shadow: 0 6px 18px rgba(1, 45, 73, .18);
    padding-top: env(safe-area-inset-top);
}
.viewer-toolbar {
    width: min(100%, 1260px);
    height: var(--header-height);
    margin: 0 auto;
    padding: 0 max(12px, env(safe-area-inset-left)) 0 max(8px, env(safe-area-inset-right));
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr) 48px 48px;
    align-items: center;
    gap: 2px;
}
.viewer-toolbar h1 {
    min-width: 0;
    margin: 0;
    padding: 0 8px;
    overflow: hidden;
    font-size: clamp(17px, 4.3vw, 24px);
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.toolbar-button {
    width: 46px;
    height: 46px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: transparent;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.toolbar-button:active { background: rgba(255,255,255,.14); }
.toolbar-button svg { width: 29px; fill: currentColor; }
.viewer-load-track { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; overflow: hidden; background: rgba(255,255,255,.11); }
.viewer-load-track span { width: 0; height: 100%; display: block; background: rgba(255,255,255,.88); transition: width .2s; }
.viewer-main { padding-top: calc(var(--header-height) + env(safe-area-inset-top)); min-height: 100vh; }
.pdf-surface {
    position: relative;
    width: min(100%, 1260px);
    min-height: calc(100vh - var(--header-height));
    margin: 0 auto;
    overflow: hidden;
    border-radius: 24px 24px 0 0;
    background: #fff;
    box-shadow: 0 -8px 24px rgba(3, 48, 77, .18);
}
.pages-container {
    width: 100%;
    margin: 0;
    padding: 0;
    background: #fff;
    line-height: 0;
}
.pdf-page {
    position: relative;
    width: 100%;
    min-height: 120px;
    overflow: hidden;
    border: 0;
    outline: 0;
    background: #fff;
    font-size: 0;
    line-height: 0;
}
/* Halaman menyatu tanpa garis atau celah antarpages. Overlap 1px menutup hairline akibat pembulatan canvas di layar HP. */
.pdf-page + .pdf-page {
    margin-top: -1px;
    border-top: 0;
}
.pdf-page canvas {
    width: 100%;
    height: auto;
    display: block;
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    background: #fff;
}
.page-placeholder {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #7b8d9a;
    background: linear-gradient(110deg, #fff 25%, #f1f5f7 38%, #fff 52%);
    background-size: 260% 100%;
    animation: shimmer 1.5s linear infinite;
    font-size: 12px;
}
.pdf-page.is-rendered .page-placeholder { display: none; }
@keyframes shimmer { to { background-position: -180% 0; } }
.viewer-state {
    min-height: calc(100vh - var(--header-height));
    padding: 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 9px;
    color: #213746;
    text-align: center;
    background: #fff;
}
.viewer-state small { color: var(--muted); }
.spinner {
    width: 42px;
    height: 42px;
    margin-bottom: 8px;
    border: 4px solid #dceaf2;
    border-top-color: var(--blue-700);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error-symbol { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--danger); font-size: 25px; font-weight: 900; }
.viewer-state .secondary-button { margin-top: 10px; }
/* Nomor halaman pojok kanan dihapus pada V4. */
.page-indicator { display: none !important; }
.password-dialog {
    width: min(90vw, 390px);
    padding: 0;
    border: 0;
    border-radius: 22px;
    color: var(--ink);
    box-shadow: 0 30px 90px rgba(0,0,0,.35);
}
.password-dialog::backdrop { background: rgba(4, 23, 36, .66); backdrop-filter: blur(4px); }
.password-dialog form { padding: 26px; }
.password-dialog h2 { margin: 14px 0 7px; }
.password-dialog p { margin: 0 0 17px; color: var(--muted); line-height: 1.5; }
.password-dialog input { width: 100%; height: 48px; padding: 0 13px; border: 1px solid #cddae2; border-radius: 12px; outline: 0; }
.password-dialog input:focus { border-color: var(--blue-700); box-shadow: 0 0 0 3px rgba(8,116,173,.12); }
.dialog-icon { width: 50px; height: 50px; display: grid; place-items: center; border-radius: 16px; color: var(--blue-700); background: var(--blue-100); }
.dialog-icon svg { width: 27px; fill: currentColor; }
.dialog-actions { margin-top: 17px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dialog-actions .primary-button, .dialog-actions .secondary-button { min-height: 46px; }
.error-page { display: grid; place-items: center; padding: 24px; }
.error-page main { max-width: 520px; padding: 34px; border-radius: 24px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.error-page p { color: var(--muted); }

@media (max-width: 860px) {
    .hero-panel { grid-template-columns: 1fr; }
    .document-grid { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
    :root { --header-height: 72px; }
    .library-shell { width: min(100% - 20px, 1180px); margin-top: 16px; }
    .header-inner { width: calc(100% - 24px); height: 64px; }
    .header-badge { display: none; }
    .hero-panel { padding: 24px 15px 16px; border-radius: 24px; gap: 24px; }
    .hero-copy { padding: 4px 6px; }
    .hero-copy h1 { font-size: 36px; }
    .hero-copy p { font-size: 15px; }
    .upload-card { padding: 12px; border-radius: 20px; }
    .drop-zone { min-height: 190px; }
    .section-head { align-items: stretch; flex-direction: column; gap: 15px; }
    .search-box { width: 100%; }
    .document-link { padding-left: 12px; }
    .pdf-thumbnail { flex-basis: 48px; height: 62px; }
    .viewer-toolbar { grid-template-columns: 46px minmax(0, 1fr) 46px 46px; padding-left: 4px; padding-right: 4px; }
    .toolbar-button { width: 44px; height: 44px; }
    .toolbar-button svg { width: 27px; }
    .pdf-surface { width: 100%; border-radius: 22px 22px 0 0; box-shadow: none; }
}
@media (min-width: 1261px) {
    .viewer-page { background: #fff; }
    .pdf-surface { margin-top: 0; border-radius: 0; box-shadow: none; }
    .viewer-main { padding-bottom: 0; }
    .pdf-page { width: min(100%, 980px); margin-right: auto; margin-left: auto; }
    .pdf-page + .pdf-page { margin-top: -1px; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* V2 mobile reliability states */
.viewer-error-actions {
    width: min(100%, 360px);
    margin-top: 10px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 9px;
}
.viewer-error-actions .primary-button,
.viewer-error-actions .secondary-button {
    width: 100%;
    min-height: 48px;
    margin: 0;
}

/* V4: toolbar judul selalu diam saat dokumen digeser. */
body.viewer-page .viewer-header {
    position: fixed !important;
    top: 0 !important;
    will-change: transform;
}

/* V5 FINAL: sembunyikan indikator scrollbar pada viewer tanpa mematikan gerakan scroll. */
html.viewer-document {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: none;
    scrollbar-gutter: auto;
    -ms-overflow-style: none;
}
html.viewer-document body.viewer-page {
    overflow-x: hidden;
    overflow-y: visible;
    scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
}
html.viewer-document .viewer-main,
html.viewer-document .pdf-surface,
html.viewer-document .pages-container {
    scrollbar-width: none;
    -ms-overflow-style: none;
}
html.viewer-document::-webkit-scrollbar,
html.viewer-document body.viewer-page::-webkit-scrollbar,
html.viewer-document .viewer-main::-webkit-scrollbar,
html.viewer-document .pdf-surface::-webkit-scrollbar,
html.viewer-document .pages-container::-webkit-scrollbar {
    width: 0 !important;
    height: 0 !important;
    display: none !important;
    background: transparent !important;
}
html.viewer-document::-webkit-scrollbar-track,
html.viewer-document::-webkit-scrollbar-thumb,
html.viewer-document body.viewer-page::-webkit-scrollbar-track,
html.viewer-document body.viewer-page::-webkit-scrollbar-thumb {
    background: transparent !important;
    border: 0 !important;
}

/* ========================================================================== 
   V6 REFERENCE MATCH — mobile viewer geometry tuned to the supplied video.
   Target logical viewport: 360px wide (Galaxy S8+ class).
   - toolbar: 64px
   - white PDF sheet begins flush under toolbar
   - top sheet corners: 18px
   - PDF pages remain 100% viewport width
   ========================================================================== */
@media (max-width: 620px) {
    :root {
        --header-height: 64px;
        --viewer-mobile-radius: 18px;
    }

    /* Compact toolbar proportions matching the reference recording. */
    .viewer-toolbar {
        height: var(--header-height);
        grid-template-columns: 44px minmax(0, 1fr) 44px 44px;
        gap: 0;
        padding-left: max(4px, env(safe-area-inset-left));
        padding-right: max(4px, env(safe-area-inset-right));
    }

    .viewer-toolbar h1 {
        padding: 0 4px;
        font-size: 18px;
        line-height: 1.15;
        font-weight: 700;
        letter-spacing: 0;
    }

    .toolbar-button {
        width: 44px;
        height: 44px;
    }

    .toolbar-button svg {
        width: 26px;
    }

    /* The blue continues behind the curved white sheet corners, exactly like
       the mobile reference. The PDF itself still fills the full screen width. */
    .viewer-main {
        padding-top: calc(var(--header-height) + env(safe-area-inset-top));
        padding-bottom: 0;
        background:
            linear-gradient(120deg, rgba(255,255,255,.06), transparent 42%),
            linear-gradient(135deg, var(--blue-900), #076da2);
    }

    .pdf-surface {
        width: 100%;
        margin: 0;
        border-radius: var(--viewer-mobile-radius) var(--viewer-mobile-radius) 0 0;
        box-shadow: none;
        overflow: hidden;
        background: #fff;
    }

    .pages-container,
    .pdf-page,
    .pdf-page canvas {
        width: 100%;
        max-width: none;
    }
}


/* ========================================================================== 
   V7 EXACT VIDEO MATCH
   Reference comparison on 717px capture:
   - target document toolbar ≈ 101px physical vs V6 ≈ 118px
   - equivalent CSS height ≈ 55px on the tested mobile viewport
   - PDF top corner ≈ 30-34px physical => 18px CSS remains correct
   Browser URL/address UI is outside the webpage. Exact reference requires
   launching the installed PWA (display-mode: standalone).
   ========================================================================== */
@media (max-width: 620px) {
    :root {
        --header-height: 55px;
        --viewer-mobile-radius: 18px;
    }

    .viewer-header {
        background:
            linear-gradient(118deg, rgba(255,255,255,.045), transparent 44%),
            linear-gradient(135deg, #0a568e, #0b649b);
        box-shadow: none;
    }

    .viewer-toolbar {
        height: var(--header-height);
        grid-template-columns: 50px minmax(0, 1fr) 45px 45px;
        gap: 0;
        padding-left: max(4px, env(safe-area-inset-left));
        padding-right: max(4px, env(safe-area-inset-right));
    }

    .viewer-toolbar h1 {
        padding: 0 4px;
        font-size: 18px;
        line-height: 1;
        font-weight: 700;
        letter-spacing: 0;
    }

    .toolbar-button {
        width: 44px;
        height: 44px;
    }

    .toolbar-button svg {
        width: 26px;
        height: 26px;
    }

    .viewer-main {
        padding-top: calc(var(--header-height) + env(safe-area-inset-top));
        background: #0b5c97;
    }

    .pdf-surface {
        width: 100%;
        margin: 0;
        border-radius: var(--viewer-mobile-radius) var(--viewer-mobile-radius) 0 0;
        box-shadow: none;
        overflow: hidden;
        background: #fff;
    }

    .pages-container,
    .pdf-page,
    .pdf-page canvas {
        width: 100%;
        max-width: none;
    }
}

/* In standalone PWA the browser address bar is absent; keep the viewer flush
   under the OS status bar, matching the supplied recording. */
@media (max-width: 620px) and (display-mode: standalone) {
    html.viewer-document,
    html.viewer-document body.viewer-page {
        background: #0b5c97;
    }
}
