.document-viewer {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: grid;
    place-items: center;
    padding: clamp(.5rem, 2vw, 1.5rem);
    background: rgba(15, 23, 42, .72);
    backdrop-filter: blur(5px);
}

.document-viewer__dialog {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1440px, 100%);
    height: min(920px, 100%);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 1rem;
    background: #f8fafc;
    box-shadow: 0 28px 80px rgba(2, 6, 23, .45);
}

.document-viewer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .8rem 1rem;
    border-bottom: 1px solid var(--cri-brand-red-strong, #812229);
    background: linear-gradient(135deg, var(--cri-brand-red-gradient-start, #bd4650), var(--cri-brand-red-gradient-end, #992d36));
    box-shadow: 0 8px 24px rgba(var(--cri-brand-red-rgb, 181, 56, 66), .22);
}

.document-viewer__identity,
.document-viewer__actions,
.document-viewer__meta {
    display: flex;
    align-items: center;
}

.document-viewer__identity {
    min-width: 0;
    gap: .75rem;
}

.document-viewer__file-icon {
    display: grid;
    flex: 0 0 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
    place-items: center;
    border-radius: .7rem;
    color: #fff;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .3);
    font-size: 1.2rem;
}

.document-viewer__identity h2 {
    max-width: min(65vw, 780px);
    margin: 0;
    overflow: hidden;
    color: #fff;
    font-size: 1rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-viewer__meta {
    flex-wrap: wrap;
    gap: .2rem .6rem;
    margin-top: .15rem;
    color: rgba(255, 255, 255, .82);
    font-size: .76rem;
}

.document-viewer__meta span + span::before {
    content: "·";
    margin-right: .6rem;
}

.document-viewer__actions {
    flex: 0 0 auto;
    gap: .45rem;
}

.document-viewer__actions .btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    color: #fff;
    border-color: rgba(255, 255, 255, .6);
    background: rgba(255, 255, 255, .1);
}

.document-viewer__actions .btn:hover,
.document-viewer__actions .btn:focus-visible {
    color: var(--cri-brand-red-strong, #812229);
    border-color: #fff;
    background: #fff;
}

.document-viewer__actions .btn:disabled {
    color: rgba(255, 255, 255, .58);
    border-color: rgba(255, 255, 255, .28);
    background: rgba(255, 255, 255, .06);
}

.document-viewer__close {
    width: 2.15rem;
    justify-content: center;
    color: #fff !important;
    border-color: rgba(255, 255, 255, .72) !important;
    background: rgba(30, 12, 14, .34) !important;
}

.document-viewer__close:hover,
.document-viewer__close:focus-visible {
    color: var(--cri-brand-red-strong, #812229) !important;
    background: #fff !important;
}

.document-viewer__content {
    min-height: 0;
    overflow: hidden;
    background: #e2e8f0;
}

.document-viewer__content iframe {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
}

.document-viewer__pdf-stage {
    width: 100%;
    height: 100%;
    min-height: 32rem;
}

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

.document-viewer__image-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: .45rem .65rem;
    min-height: 3rem;
    padding: .45rem .75rem;
    border-bottom: 1px solid #cbd5e1;
    background: rgba(248, 250, 252, .96);
    box-shadow: 0 4px 14px rgba(15, 23, 42, .08);
    z-index: 1;
}

.document-viewer__image-toolbar-label {
    color: #64748b;
    font-size: .76rem;
    font-weight: 700;
    letter-spacing: .02em;
    text-transform: uppercase;
}

.document-viewer__image-toolbar .btn {
    min-width: 2.25rem;
}

.document-viewer__image-toolbar .btn:focus-visible {
    box-shadow: 0 0 0 .2rem rgba(var(--cri-brand-red-rgb, 181, 56, 66), .22);
}

.document-viewer__zoom-value {
    min-width: 4rem !important;
    font-variant-numeric: tabular-nums;
}

.document-viewer__apply-image {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin-left: .25rem;
}

.document-viewer__crop-toggle {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
}

.document-viewer__image-edit-message {
    flex: 1 0 100%;
    color: #475569;
    font-size: .8rem;
    font-weight: 600;
    text-align: center;
}

.document-viewer__image-stage {
    display: block;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: auto;
    padding: 1.5rem;
    background-color: #cbd5e1;
    background-image: linear-gradient(45deg, #dbe3ec 25%, transparent 25%), linear-gradient(-45deg, #dbe3ec 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #dbe3ec 75%), linear-gradient(-45deg, transparent 75%, #dbe3ec 75%);
    background-position: 0 0, 0 10px, 10px -10px, -10px 0;
    background-size: 20px 20px;
}

.document-viewer__image-canvas {
    position: relative;
    min-width: 1px;
    min-height: 1px;
    margin: auto;
}

.document-viewer__image-stage img {
    position: absolute;
    left: 50%;
    top: 50%;
    display: block;
    max-width: none;
    max-height: none;
    object-fit: contain;
    border-radius: .35rem;
    background: #fff;
    box-shadow: 0 12px 35px rgba(15, 23, 42, .25);
    opacity: 0;
    transform-origin: center center;
    transition: opacity .12s ease;
    will-change: transform, width, height;
}

.document-viewer__image-stage img.document-viewer__image--ready {
    opacity: 1;
}

.document-viewer__image-crop {
    position: absolute;
    z-index: 2;
    box-sizing: border-box;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, .55);
    cursor: move;
    touch-action: none;
}

.document-viewer__image-crop[hidden] {
    display: none !important;
}

.document-viewer__image-crop::before,
.document-viewer__image-crop::after {
    content: "";
    position: absolute;
    pointer-events: none;
}

.document-viewer__image-crop::before {
    top: 0;
    left: 33.333%;
    width: 33.333%;
    height: 100%;
    border-left: 1px solid rgba(255, 255, 255, .65);
    border-right: 1px solid rgba(255, 255, 255, .65);
}

.document-viewer__image-crop::after {
    top: 33.333%;
    left: 0;
    width: 100%;
    height: 33.333%;
    border-top: 1px solid rgba(255, 255, 255, .65);
    border-bottom: 1px solid rgba(255, 255, 255, .65);
}

.document-viewer__image-crop-handle {
    position: absolute;
    z-index: 3;
    width: 30px;
    height: 30px;
}

.document-viewer__image-crop-handle::after {
    content: "";
    position: absolute;
    top: 9px;
    left: 9px;
    width: 11px;
    height: 11px;
    border: 1px solid rgba(0, 0, 0, .45);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(15, 23, 42, .35);
}

.document-viewer__image-crop-handle[data-handle="nw"] { top: -1px; left: -1px; cursor: nwse-resize; }
.document-viewer__image-crop-handle[data-handle="ne"] { top: -1px; right: -1px; cursor: nesw-resize; }
.document-viewer__image-crop-handle[data-handle="sw"] { bottom: -1px; left: -1px; cursor: nesw-resize; }
.document-viewer__image-crop-handle[data-handle="se"] { right: -1px; bottom: -1px; cursor: nwse-resize; }

.document-viewer__state {
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: .75rem;
    padding: 2rem;
    color: #475569;
    text-align: center;
}

.document-viewer__state > i {
    color: #2563eb;
    font-size: 2.5rem;
}

.document-viewer__state--error > i {
    color: #dc2626;
}

@media (max-width: 720px) {
    .document-viewer {
        padding: 0;
    }

    .document-viewer__dialog {
        width: 100%;
        height: 100%;
        border: 0;
        border-radius: 0;
    }

    .document-viewer__header {
        align-items: flex-start;
        padding: .65rem;
    }

    .document-viewer__file-icon,
    .document-viewer__actions .btn span {
        display: none;
    }

    .document-viewer__identity h2 {
        max-width: 48vw;
    }

    .document-viewer__image-stage {
        padding: .5rem;
    }

    .document-viewer__image-toolbar {
        gap: .35rem .5rem;
        padding: .4rem .5rem;
    }

    .document-viewer__image-toolbar-label {
        display: none;
    }
}
