.kdpm-pdf-card,
.kdpm-pdf-card * {
    box-sizing: border-box;
}

.kdpm-pdf-card {
    display: block;
    width: min(var(--kdpm-thumb-width, 300px), 100%);
    max-width: 100%;
    margin-top: 1.2em;
    margin-bottom: 1.2em;
}

.kdpm-pdf-card.kdpm-align-left {
    margin-left: 0;
    margin-right: auto;
}

.kdpm-pdf-card.kdpm-align-center {
    margin-left: auto;
    margin-right: auto;
}

.kdpm-pdf-card.kdpm-align-right {
    margin-left: auto;
    margin-right: 0;
}

.kdpm-card-trigger {
    display: block;
    width: 100%;
    max-width: 100%;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: inherit;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
}

.kdpm-card-trigger:hover,
.kdpm-card-trigger:focus {
    color: inherit;
    text-decoration: none;
    outline: none;
}

.kdpm-card-trigger:focus-visible .kdpm-card-image-wrap {
    box-shadow: 0 0 0 4px rgba(19, 94, 150, 0.34);
}

.kdpm-card-image-wrap {
    display: block;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 6px;
    background: #fff;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.12);
    transition: transform 160ms ease, box-shadow 160ms ease;
}

.kdpm-card-trigger:hover .kdpm-card-image-wrap,
.kdpm-card-trigger:focus .kdpm-card-image-wrap {
    transform: translateY(-2px);
    box-shadow: 0 9px 24px rgba(0, 0, 0, 0.16);
}

.kdpm-card-image {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

.kdpm-card-title,
.kdpm-card-info {
    display: block;
}

.kdpm-card-title {
    margin-top: 0.65em;
    font-weight: 700;
    line-height: 1.35;
}

.kdpm-card-info {
    margin-top: 0.25em;
    color: #5d6268;
    font-size: 0.88em;
}

.kdpm-frontend-warning {
    margin: 1em 0;
    padding: 0.8em 1em;
    border-left: 4px solid #b32d2e;
    background: #fcf0f1;
    color: #1d2327;
}

html.kdpm-modal-open,
body.kdpm-modal-open {
    overflow: hidden !important;
    overscroll-behavior: none;
}

.kdpm-modal,
.kdpm-modal * {
    box-sizing: border-box;
}

.kdpm-modal[hidden],
.kdpm-standard-scroll[hidden],
.kdpm-flipbook[hidden],
.kdpm-viewer-fallback[hidden],
.kdpm-modal-notice[hidden],
.kdpm-modal-action[hidden],
.kdpm-zoom-controls[hidden],
.kdpm-flip-page[hidden] {
    display: none !important;
}

.kdpm-modal {
    position: fixed;
    inset: 0;
    z-index: 2147483000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    background: rgba(5, 8, 12, 0.88);
    color: #1d2327;
}

.kdpm-modal-dialog {
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    width: min(1600px, calc(100vw - 24px));
    height: min(1100px, calc(100vh - 24px));
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    background: #fff;
    color: #1d2327;
    box-shadow: 0 28px 100px rgba(0, 0, 0, 0.62);
}

@supports (height: 100dvh) {
    .kdpm-modal-dialog {
        height: min(1100px, calc(100dvh - 24px));
        max-height: calc(100dvh - 24px);
    }
}

.kdpm-modal-topbar,
.kdpm-modal-bottombar {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    padding: 10px 16px;
    background: #f6f7f7;
}

.kdpm-modal-topbar {
    grid-row: 1;
    justify-content: space-between;
    border-bottom: 1px solid #dcdcde;
}

.kdpm-modal-title {
    min-width: 0;
    margin: 0;
    overflow: hidden;
    color: #1d2327;
    font-size: clamp(1rem, 1.5vw, 1.25rem);
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kdpm-modal-close {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    min-width: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid #8c8f94;
    border-radius: 50%;
    background: #fff;
    color: #1d2327;
    font-family: Arial, sans-serif;
    font-size: 30px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
}

.kdpm-modal-close:hover,
.kdpm-modal-close:focus-visible {
    border-color: #135e96;
    box-shadow: 0 0 0 3px rgba(19, 94, 150, 0.25);
    outline: none;
}

.kdpm-modal-notice {
    grid-row: 2;
    padding: 9px 16px;
    border-bottom: 1px solid #dcdcde;
    background: #fff8e5;
    color: #5b4100;
    font-size: 0.95rem;
    line-height: 1.45;
}

.kdpm-viewer {
    grid-row: 3;
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background:
        radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.08), transparent 48%),
        #24282d;
}

/* Vanlig PDF-visning: alla sidor efter varandra med lodrät rullning. */
.kdpm-standard-scroll {
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow-x: auto;
    overflow-y: auto;
    padding: clamp(10px, 2vw, 24px);
    scroll-behavior: smooth;
    scrollbar-gutter: stable;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #30343a;
}

.kdpm-standard-scroll:focus-visible,
.kdpm-flipbook:focus-visible {
    outline: 3px solid #72aee6;
    outline-offset: -3px;
}

.kdpm-reader-page {
    position: relative;
    width: min(96%, 1400px);
    max-width: none;
    margin: 0 auto clamp(16px, 2.5vw, 30px);
    padding: 0;
    min-height: 180px;
    overflow: hidden;
    border-radius: 3px;
    background: #fff;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.42);
}

.kdpm-reader-page[data-orientation="portrait"] {
    width: min(92%, 920px);
}

.kdpm-reader-page[data-orientation="landscape"] {
    width: min(98%, 1450px);
}

.kdpm-reader-page-image {
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    margin: 0;
    background: #fff;
    object-fit: contain;
}

.kdpm-reader-page-loading,
.kdpm-reader-page-error {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    padding: 30px;
    background: #fff;
    color: #50575e;
    text-align: center;
}

.kdpm-reader-page-loading[hidden],
.kdpm-reader-page-error[hidden] {
    display: none !important;
}

.kdpm-page-caption {
    position: absolute;
    right: 10px;
    bottom: 10px;
    z-index: 2;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.64);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    pointer-events: none;
}

/* Bläddringsläge: ingen dokumentrullning, endast sidbyte. */
.kdpm-flipbook {
    position: relative;
    display: grid;
    grid-template-columns: clamp(52px, 5vw, 78px) minmax(0, 1fr) clamp(52px, 5vw, 78px);
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    touch-action: pan-y pinch-zoom;
    user-select: none;
}

.kdpm-flipbook.is-zoomed {
    touch-action: none;
}

.kdpm-flip-stage {
    grid-column: 2;
    position: relative;
    display: block;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    padding: 0;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    perspective: 1800px;
}

.kdpm-flip-stage::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.kdpm-flip-pan-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
}

.kdpm-flip-zoom-layer {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: clamp(8px, 1.5vw, 20px) 0;
    transform-origin: center center;
    transition: transform 140ms ease-out;
    will-change: transform;
}

.kdpm-flipbook.is-zoomed .kdpm-flip-stage {
    cursor: grab;
    touch-action: none;
}

.kdpm-flipbook.is-zoomed .kdpm-flip-stage.is-panning {
    cursor: grabbing;
}

.kdpm-flip-spread {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: min(100%, 1420px);
    height: 100%;
    min-width: 0;
    min-height: 0;
    transform-origin: center center;
}

.kdpm-flip-spread.is-single,
.kdpm-flip-spread.is-cover {
    grid-template-columns: minmax(0, 1fr);
    width: min(100%, 1120px);
}

.kdpm-flip-page {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    margin: 0;
    overflow: visible;
}

.kdpm-flip-page-status {
    position: absolute;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.94);
    color: #3c434a;
    text-align: center;
    line-height: 1.45;
}

.kdpm-flip-page-status[hidden] {
    display: none !important;
}

.kdpm-flip-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 2px;
    background: #fff;
    object-fit: contain;
    box-shadow: 0 16px 44px rgba(0, 0, 0, 0.52);
}

.kdpm-flip-page-a .kdpm-flip-image {
    justify-self: end;
}

.kdpm-flip-page-b .kdpm-flip-image {
    justify-self: start;
}

.kdpm-flip-spread.is-single .kdpm-flip-image,
.kdpm-flip-spread.is-cover .kdpm-flip-image {
    justify-self: center;
}

.kdpm-flip-spread.is-turning-forward {
    animation: kdpm-turn-forward 190ms ease-out;
}

.kdpm-flip-spread.is-turning-backward {
    animation: kdpm-turn-backward 190ms ease-out;
}

@keyframes kdpm-turn-forward {
    from { opacity: 0.5; transform: translateX(12px) rotateY(-2deg); }
    to { opacity: 1; transform: translateX(0) rotateY(0); }
}

@keyframes kdpm-turn-backward {
    from { opacity: 0.5; transform: translateX(-12px) rotateY(2deg); }
    to { opacity: 1; transform: translateX(0) rotateY(0); }
}

.kdpm-edge-arrow {
    position: relative;
    z-index: 6;
    align-self: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: clamp(46px, 4.4vw, 62px);
    height: clamp(58px, 7vw, 84px);
    min-width: 46px;
    min-height: 58px;
    margin: 0 auto;
    padding: 0;
    border: 2px solid rgba(255, 255, 255, 0.84);
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.48);
    color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36);
    cursor: pointer;
    transition: background 140ms ease, transform 140ms ease, opacity 140ms ease;
}

.kdpm-edge-previous {
    grid-column: 1;
}

.kdpm-edge-next {
    grid-column: 3;
}

.kdpm-edge-arrow-symbol {
    display: block;
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: clamp(44px, 5vw, 68px);
    font-weight: 300;
    line-height: 0.8;
    transform: translateY(-2px);
}

.kdpm-edge-arrow:hover,
.kdpm-edge-arrow:focus-visible {
    background: rgba(0, 0, 0, 0.78);
    transform: scale(1.05);
    outline: 3px solid rgba(255, 255, 255, 0.48);
    outline-offset: 2px;
}

.kdpm-edge-arrow:disabled {
    opacity: 0.18;
    cursor: default;
    transform: none;
}

.kdpm-viewer-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    min-height: 220px;
    padding: 30px;
    color: #fff;
    text-align: center;
}

.kdpm-viewer-fallback-text {
    max-width: 640px;
    margin: 0;
    padding: 18px 22px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.32);
    font-size: 1rem;
    line-height: 1.55;
}

.kdpm-modal-bottombar {
    grid-row: 4;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 12px;
    border-top: 1px solid #dcdcde;
}

.kdpm-page-status {
    min-width: 120px;
    justify-self: start;
    color: #1d2327;
    font-weight: 700;
    line-height: 1.35;
}

.kdpm-zoom-controls {
    display: inline-flex;
    align-items: stretch;
    justify-content: center;
    justify-self: center;
    overflow: hidden;
    border: 1px solid #8c8f94;
    border-radius: 7px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.kdpm-zoom-button,
.kdpm-zoom-value {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    margin: 0;
    padding: 6px 11px;
    border: 0;
    border-radius: 0;
    -webkit-appearance: none;
    appearance: none;
    background: #fff;
    box-shadow: none;
    text-transform: none;
    touch-action: manipulation;
    color: #1d2327;
    font-family: Arial, sans-serif;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.kdpm-zoom-button {
    min-width: 42px;
    font-size: 24px;
}

.kdpm-zoom-value {
    min-width: 74px;
    border-right: 1px solid #c3c4c7;
    border-left: 1px solid #c3c4c7;
    font-size: 13px;
    white-space: nowrap;
}

.kdpm-zoom-button:hover:not(:disabled),
.kdpm-zoom-button:focus-visible,
.kdpm-zoom-value:hover,
.kdpm-zoom-value:focus-visible {
    position: relative;
    z-index: 1;
    background: #f0f6fc;
    color: #0a4b78;
    outline: 3px solid rgba(19, 94, 150, 0.22);
    outline-offset: -3px;
}

.kdpm-zoom-button:disabled {
    background: #f6f7f7;
    color: #a7aaad;
    cursor: default;
}

.kdpm-modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    justify-self: end;
    flex-wrap: wrap;
    gap: 8px;
}

.kdpm-modal-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 7px 12px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    background: #fff;
    color: #1d2327;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
}

.kdpm-modal-action:hover,
.kdpm-modal-action:focus-visible {
    border-color: #135e96;
    color: #0a4b78;
    text-decoration: none;
    outline: 3px solid rgba(19, 94, 150, 0.2);
    outline-offset: 1px;
}

/* Besökarens mobilvisning: helskärm, enkelsida och stora tryckytor. */
@media (max-width: 900px) {
    .kdpm-modal {
        align-items: stretch;
        padding: 0;
    }

    .kdpm-modal-dialog {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border: 0;
        border-radius: 0;
    }

    @supports (height: 100dvh) {
        .kdpm-modal-dialog {
            height: 100dvh;
            max-height: 100dvh;
        }
    }

    .kdpm-modal-topbar {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-right: max(10px, env(safe-area-inset-right));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .kdpm-modal-close {
        width: 46px;
        height: 46px;
        min-width: 46px;
        min-height: 46px;
    }

    .kdpm-modal-notice {
        padding-right: max(12px, env(safe-area-inset-right));
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .kdpm-standard-scroll {
        padding: 8px;
        scrollbar-gutter: auto;
    }

    .kdpm-reader-page,
    .kdpm-reader-page[data-orientation="portrait"],
    .kdpm-reader-page[data-orientation="landscape"] {
        width: 100%;
        max-width: none;
        margin-bottom: 12px;
        border-radius: 2px;
    }

    .kdpm-flipbook {
        grid-template-columns: 46px minmax(0, 1fr) 46px;
    }

    .kdpm-flip-stage {
        padding: 0;
    }

    .kdpm-flip-zoom-layer {
        padding: 5px 0;
    }

    .kdpm-flip-spread,
    .kdpm-flip-spread.is-single,
    .kdpm-flip-spread.is-cover {
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
        height: 100%;
        gap: 0;
    }

    .kdpm-flip-image {
        max-width: 100%;
        max-height: 100%;
    }

    .kdpm-edge-arrow {
        width: 42px;
        height: 66px;
        min-width: 42px;
        min-height: 56px;
        border-width: 1px;
    }

    .kdpm-edge-arrow-symbol {
        font-size: 50px;
    }

    .kdpm-modal-bottombar {
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
        padding-right: max(10px, env(safe-area-inset-right));
        padding-bottom: max(8px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
    }

    .kdpm-page-status {
        width: auto;
        min-width: 0;
        text-align: left;
    }

    .kdpm-zoom-controls {
        grid-column: 2;
        justify-self: end;
    }

    .kdpm-zoom-button,
    .kdpm-zoom-value {
        min-height: 44px;
    }

    .kdpm-modal-actions {
        grid-column: 1 / -1;
        width: 100%;
        justify-content: center;
        justify-self: stretch;
    }

    .kdpm-modal-action {
        flex: 1 1 130px;
        min-height: 44px;
        white-space: normal;
        text-align: center;
    }
}

@media (max-width: 480px) {
    .kdpm-modal-title {
        font-size: 1rem;
    }

    .kdpm-modal-actions {
        gap: 6px;
    }

    .kdpm-modal-action {
        flex-basis: 46%;
        padding: 6px 8px;
        font-size: 13px;
    }

    .kdpm-flipbook {
        grid-template-columns: 42px minmax(0, 1fr) 42px;
    }

    .kdpm-edge-arrow {
        width: 38px;
        min-width: 38px;
    }
}

@media (max-height: 560px) and (orientation: landscape) {
    .kdpm-modal-topbar,
    .kdpm-modal-bottombar {
        padding-top: 5px;
        padding-bottom: 5px;
    }

    .kdpm-modal-close {
        width: 38px;
        height: 38px;
        min-width: 38px;
        min-height: 38px;
    }

    .kdpm-modal-bottombar {
        grid-template-columns: auto auto minmax(0, 1fr);
    }

    .kdpm-page-status {
        width: auto;
    }

    .kdpm-zoom-controls {
        grid-column: 2;
    }

    .kdpm-modal-actions {
        grid-column: 3;
        width: auto;
        justify-self: end;
    }

    .kdpm-modal-action {
        min-height: 36px;
        padding-top: 4px;
        padding-bottom: 4px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kdpm-card-image-wrap,
    .kdpm-edge-arrow,
    .kdpm-flip-spread,
    .kdpm-flip-zoom-layer {
        transition: none;
        animation: none;
        scroll-behavior: auto;
    }
}

/* På bred skärm möts två PDF-sidor tydligt vid uppslagets mitt. */
.kdpm-flip-page-a {
    justify-content: flex-end;
}

.kdpm-flip-page-b {
    justify-content: flex-start;
}

.kdpm-flip-spread.is-single .kdpm-flip-page,
.kdpm-flip-spread.is-cover .kdpm-flip-page {
    justify-content: center;
}
