/* The comparison viewer (js/compare-viewer.js, includes/CompareViewer.php):
   one shared component, 2026-11-04. Tokens only; light and dark come from
   app.css. Breakpoints: 1100 px (Side by side offered), 760 px (compact
   header, previous / next at the bottom). */

html.cv-open {
    overflow: hidden;
}

.cv {
    /* No cap: side by side, the pages are limited by width, so every
       pixel of width is page height. */
    width: 98vw;
    max-width: none;
    height: 96vh;
    height: 96dvh;
    max-height: none;
    margin: auto;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.cv[open] {
    display: flex;
    flex-direction: column;
}

.cv::backdrop {
    background-color: var(--backdrop);
}

.cv-icon {
    flex-shrink: 0;
}

/* ---- Header: one row, wrapping when narrow ---- */
.cv-head {
    position: relative;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-3) var(--space-4) var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.cv-titles {
    flex: 1 1 11rem;
    min-width: 9rem;
}

/* The view switch and the tools: they wrap among themselves before the
   title, previous / next or Close move. */
.cv-controls {
    display: flex;
    flex: 0 1 auto;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    min-width: 0;
}

.cv-count {
    margin: 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.cv-title {
    margin: 0;
    font-size: var(--text-lg);
    font-weight: 700;
    line-height: 1.3;
    /* Up to two lines, then an ellipsis. */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.cv-title:focus {
    outline: none;
}

.cv-title:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* Segmented switches: the view, and the panel in One at a time. */
.cv-seg {
    display: flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-card-subtle);
}

.cv-seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 2.25rem;
    padding: 0 var(--space-3);
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.cv-seg-btn:hover {
    color: var(--text-primary);
}

.cv-seg-btn[aria-pressed="true"] {
    background: var(--bg-card);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

/* Side by side needs the room of three columns. */
.cv-views [data-view="side"] {
    display: none;
}

@media (min-width: 1100px) {
    .cv-views [data-view="side"] {
        display: inline-flex;
    }
}

.cv-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.cv-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 2.5rem;
    padding: 0 var(--space-3);
    border: 1px solid var(--border-strong, var(--border-color));
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
}

.cv-btn:hover {
    background: var(--bg-card-subtle);
}

.cv-toggle[aria-pressed="true"] {
    border-color: var(--brand-tint-border);
    background: var(--brand-tint-subtle);
    color: var(--brand-text);
}

.cv-marks-symbol {
    font-size: 1.125em;
    font-weight: 700;
    line-height: 1;
}

.cv-hw-symbol {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border-radius: 2px;
    background: #ffeb3b;
    border: 1px solid #b59f00;
}

.cv-zoom {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border-strong, var(--border-color));
    border-radius: var(--radius-md);
    background: var(--bg-card);
}

.cv-zoom-btn,
.cv-zoom-level,
.cv-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    height: 2.375rem;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
}

.cv-zoom-btn {
    width: 2.375rem;
}

.cv-zoom-level {
    min-width: 3.25rem;
    padding: 0 var(--space-1);
    font-variant-numeric: tabular-nums;
}

.cv-zoom-sep {
    width: 1px;
    height: 1.375rem;
    background: var(--border-color);
}

.cv-link {
    padding: 0 var(--space-3);
    color: var(--text-secondary);
}

.cv-link[aria-pressed="true"] {
    color: var(--brand-text);
}

.cv-zoom-btn:hover,
.cv-zoom-level:hover,
.cv-link:hover {
    background: var(--bg-card-subtle);
}

.cv-steps {
    display: flex;
    gap: var(--space-1);
}

.cv-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.cv-icon-btn:hover {
    background: var(--bg-card-subtle);
    color: var(--text-primary);
}

.cv-bordered {
    border-color: var(--border-strong, var(--border-color));
    background: var(--bg-card);
    color: var(--text-primary);
}

.cv-icon-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* "More options" is for the compact header only. */
.cv-more {
    display: none;
}

.cv button:focus-visible,
.cv a:focus-visible,
.cv-viewport:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

/* ---- Panels ---- */
.cv-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-card-subtle);
}

.cv-tabs {
    align-self: center;
}

/* At Fit the panels hug their pages; the findings follow right below and
   the group sits in the middle of the room. */
/* Big screens: less room between the panels, more for the pages. */
@media (min-width: 1100px) {
    .cv .cv-body {
        padding: var(--space-3) var(--space-4);
    }

    .cv .cv-panels {
        gap: var(--space-3);
    }
}

.cv-body.is-fit {
    justify-content: center;
}

.cv-body.is-fit .cv-panels {
    flex: 0 1 auto;
    justify-content: center;
}

/* At Fit the page fits exactly: never a scroll bar. */
.cv-body.is-fit .cv-viewport {
    align-self: center;
    overflow: hidden;
}

/* One at a time: the switch replaces the panel's name in its head. */
.cv[data-view="one"] .cv-panel-head {
    flex-wrap: wrap;
}

.cv[data-view="one"] .cv-panel-head .cv-tabs {
    align-self: auto;
}

.cv[data-view="one"] .cv-panel-names {
    margin-left: auto;
    text-align: right;
}

.cv[data-view="one"] .cv-panel-name {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.cv-tabs[hidden] {
    display: none;
}

.cv-panels {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(var(--cv-cols, 3), minmax(0, 1fr));
    gap: var(--space-5);
}

.cv[data-view="one"] .cv-panels {
    width: min(100%, 64rem);
    margin: 0 auto;
}

.cv-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    min-width: 0;
    min-height: 0;
}

.cv-panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
}

.cv-panel-names {
    min-width: 0;
}

.cv-panel-name {
    margin: 0;
    font-size: var(--text-md);
    font-weight: 700;
    line-height: 1.3;
}

.cv-panel-unfold .cv-panel-name {
    color: var(--brand-text);
}

.cv-panel-status {
    display: flex;
    align-items: center;
    gap: 0.35em;
    margin: 0;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.cv-tone-ok {
    color: var(--success-text);
}

.cv-tone-warn {
    color: var(--warning-text);
}

.cv-dl {
    min-height: 2.25rem;
    padding: 0 var(--space-3);
    flex-shrink: 0;
}

.cv-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-card);
    box-shadow: var(--shadow-card);
}

/* The panel handles pinch and double-tap itself (js); one finger scrolls. */
.cv-viewport {
    touch-action: pan-x pan-y;
}

.cv-viewport.is-zoomed {
    cursor: grab;
}

.cv-viewport.is-dragging {
    cursor: grabbing;
}

.cv-stage img {
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
}

.cv-stage {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    box-sizing: border-box;
    padding: 12px; /* PAD in the script */
}

.cv-stage img {
    display: block;
    box-sizing: border-box; /* the border stays inside the sized box: no scroll bars at Fit */
    max-width: none;
    border: 1px solid var(--border-color);
    background: var(--surface-paper);
    box-shadow: var(--shadow-sm);
}

.cv-pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.cv-pager {
    min-height: 2.25rem;
}

.cv-pager[hidden] {
    display: none;
}

.cv-panels.has-pager .cv-pager[hidden] {
    display: flex;
    visibility: hidden;
}

.cv-page-btn {
    width: 2.25rem;
    height: 2.25rem;
}

.cv-page-label {
    font-variant-numeric: tabular-nums;
}

/* ---- Findings: markers on the pages ---- */
.cv-page {
    position: relative;
    flex-shrink: 0;
}

.cv-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.cv-marker {
    position: absolute;
    left: max(2px, calc(var(--fx) * 100% - 1.85rem));
    top: calc(var(--fy) * 100%);
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    border: 2px solid var(--brand-primary);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--brand-text);
    font: inherit;
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 1;
    opacity: 0.85;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    pointer-events: auto;
}

.cv-marker.at-right {
    left: min(calc(var(--fr) * 100% + 0.35rem), calc(100% - 1.6rem));
}

.cv-marker:hover {
    opacity: 1;
}

.cv-marker.is-selected {
    z-index: 1;
    background: var(--brand-primary);
    color: var(--on-brand);
    opacity: 1;
    box-shadow: 0 0 0 4px var(--brand-tint-border);
}

.cv-marker.is-miss {
    border-color: var(--warning-text);
    color: var(--warning-text);
}

.cv-marker.is-miss.is-selected {
    background: var(--warning-text);
    color: var(--bg-card);
}

.cv-region {
    position: absolute;
    border: 2px solid var(--brand-primary);
    border-radius: 4px;
    background: var(--brand-tint-faint);
    opacity: 0.8;
}

.cv-region.is-miss {
    border-color: var(--warning-text);
}

.cv-elsewhere {
    min-height: 2.25rem;
    margin-left: var(--space-2);
    border-color: var(--brand-tint-border);
    color: var(--brand-text);
}

/* ---- Findings: the strip of cards ---- */
.cv-findings {
    display: flex;
    gap: var(--space-3);
    flex-shrink: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    padding: 2px 2px var(--space-1);
}

.cv-findings[hidden] {
    display: none;
}

.cv-finding {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    flex: 1 1 0;
    min-width: 15rem;
    max-width: 30rem;
    padding: var(--space-3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font: inherit;
    font-size: var(--text-sm);
    line-height: 1.4;
    text-align: left;
    scroll-snap-align: start;
    cursor: pointer;
}

/* Centred when they fit; auto margins (not justify-content) keep the
   first card reachable when the strip scrolls sideways. */
.cv-finding:first-child {
    margin-left: auto;
}

.cv-finding:last-child {
    margin-right: auto;
}

.cv-finding:hover {
    border-color: var(--brand-tint-border);
}

.cv-finding[aria-pressed="true"] {
    border-color: var(--brand-primary);
    background: var(--brand-tint-subtle);
    box-shadow: 0 0 0 1px var(--brand-primary);
}

.cv-finding-n {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    background: var(--brand-primary);
    color: var(--on-brand);
    font-size: var(--text-xs);
    font-weight: 700;
}

.cv-finding.is-miss .cv-finding-n {
    background: var(--warning-text);
    color: var(--bg-card);
}

.cv-finding-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.cv-finding-title {
    font-weight: 700;
}

.cv-finding-lines {
    display: flex;
    flex-direction: column;
    gap: 1px;
    color: var(--text-secondary);
}

.cv-finding-who {
    font-weight: 600;
    color: var(--text-primary);
}

.cv-finding-tag {
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--warning-text);
}

/* Previous / next with names: the compact layout's bottom bar. */
.cv-foot {
    display: none;
}

/* ---- Compact (phones) ---- */
@media (max-width: 760px) {
    .cv {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border: 0;
        border-radius: 0;
    }

    .cv-head {
        flex-wrap: wrap;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-2) var(--space-3) var(--space-4);
    }

    .cv-title {
        font-size: var(--text-md);
    }

    .cv-steps {
        display: none;
    }

    .cv-more {
        display: inline-flex;
    }

    .cv-controls {
        display: contents;
    }

    .cv-views {
        order: 5;
        flex-basis: 100%;
    }

    .cv-views .cv-seg-btn {
        flex: 1;
    }

    .cv-tools {
        display: none;
        position: absolute;
        z-index: 2;
        top: calc(100% - var(--space-2));
        right: var(--space-2);
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-2);
        min-width: 15rem;
        padding: var(--space-3);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        background: var(--bg-card);
        box-shadow: var(--shadow-lg);
    }

    .cv-tools.is-open {
        display: flex;
    }

    .cv-tools .cv-zoom {
        justify-content: space-between;
    }

    .cv-body {
        padding: var(--space-3);
    }

    .cv-tabs {
        align-self: stretch;
    }

    .cv-tabs .cv-seg-btn {
        flex: 1;
        padding: 0 var(--space-2);
    }

    .cv-panels {
        gap: var(--space-3);
    }

    .cv-foot {
        display: flex;
        justify-content: space-between;
        gap: var(--space-2);
        padding: var(--space-2) var(--space-3);
        border-top: 1px solid var(--border-color);
        flex-shrink: 0;
    }

    .cv-foot-btn {
        min-width: 0;
        max-width: calc(50% - var(--space-1));
    }

    .cv-foot-name {
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .cv-findings {
        gap: var(--space-2);
        scroll-snap-type: x mandatory;
    }

    .cv-finding {
        flex: 0 0 82%;
        min-width: 0;
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-xs);
    }
}

/* Scan vs OrigaDoc on a phone: the two panels one above the other. */
@media (max-width: 760px) {
    .cv[data-view="pair"] .cv-panels {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: repeat(2, minmax(0, 1fr));
    }
}

.cv[data-view="one"] .cv-panel-status {
    justify-content: flex-end;
}

/* One at a time on a phone: the switch on its own row, the status and the
   download below it. */
@media (max-width: 760px) {
    .cv[data-view="one"] .cv-panel-head {
        flex-wrap: wrap;
    }

    .cv[data-view="one"] .cv-panel-head .cv-tabs {
        flex-basis: 100%;
    }

    .cv[data-view="one"] .cv-panel-names {
        margin-left: 0;
        text-align: left;
    }

    .cv[data-view="one"] .cv-panel-status {
        justify-content: flex-start;
    }
}
