/* Comparison history and document reader. Plain CSS, no framework. */
[hidden] {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
}

.history-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid #eaf0f7;
}

.history-toolbar > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

.history-toolbar h2 {
    margin: 0;
    font-size: 16px;
    color: #182f4c;
}

.history-toolbar > div > span,
.history-pagination > span {
    color: #71839c;
    font-size: 12px;
}

#history-search {
    display: flex;
    width: 280px;
    border: 1px solid #dce5f1;
    border-radius: 7px;
    background: #fff;
}

#history-search input {
    flex: 1;
    width: 0;
    min-width: 0;
    padding: 8px 12px;
    border: 0;
    background: transparent;
    outline-offset: -3px;
    font: inherit;
    font-size: 13px;
}

#history-search button {
    border: 0;
    background: transparent;
    color: #3866d5;
    padding: 0 14px;
    font-weight: 600;
}

.history-table-wrap {
    overflow-x: auto;
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    color: #344b68;
    font-size: 13px;
    text-align: left;
}

.history-table th {
    background: #f8faff;
    font-weight: 500;
    color: #6c809c;
    white-space: nowrap;
    padding: 12px 18px;
    font-size: 12px;
    border-bottom: 1px solid #edf1f7;
}

.history-table td {
    padding: 12px 18px;
    border-bottom: 1px solid #edf1f7;
    vertical-align: middle;
}

.history-table tr:last-child td {
    border-bottom: 0;
}

.history-table tbody tr:hover {
    background: #fafcff;
}

.history-file {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 150px;
    max-width: 260px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.history-file svg {
    box-sizing: content-box;
    width: 16px;
    height: 16px;
    padding: 6px;
    border-radius: 5px;
    background: #eaf2ff;
    color: #3974ea;
    flex-shrink: 0;
}

.history-similarity {
    font-weight: 600;
    white-space: nowrap;
    color: #119971;
}

.history-similarity.low {
    color: #dd4c59;
}

.history-updated {
    color: #73839a;
    min-width: 130px;
    font-size: 13px;
}

.history-state {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    color: #c47c15;
}

.phase-ring,
.pending-progress-ring,
.similarity-ring {
    --progress: 0;
    --ring-color: #e8ad4d;
    display: inline-grid;
    place-items: center;
    position: relative;
    width: 37px;
    height: 37px;
    flex-shrink: 0;
    border-radius: 50%;
    background: conic-gradient(var(--ring-color) calc(var(--progress) * 1%), #e7ecf2 0);
}

.phase-ring::before,
.pending-progress-ring::before,
.similarity-ring::before {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: #fff;
}

.phase-ring > span,
.pending-progress-ring > span {
    position: relative;
    font-size: 10px;
    font-weight: 600;
}

.history-state.done {
    color: #0b9b72;
}

.history-state.done .phase-ring {
    display: none;
}

.history-complete-icon {
    display: block;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
}

.history-state .phase-ring {
    width: 32px;
    height: 32px;
}

.history-state.failed,
.history-state.review {
    color: #d55858;
}

.history-menu,
.compare-export {
    position: relative;
    width: max-content;
}

.history-menu summary {
    color: #6d82a1;
    cursor: pointer;
    white-space: nowrap;
    padding: 6px;
}

.history-menu summary,
.compare-export summary {
    list-style: none;
}

.history-menu summary::-webkit-details-marker,
.compare-export summary::-webkit-details-marker {
    display: none;
}

.comparison-menu {
    position: fixed;
    z-index: 100;
    min-width: 185px;
    padding: 7px 0;
    border: 1px solid #dce5f1;
    border-radius: 9px;
    background: #fff;
    box-shadow: 0 8px 24px #2436531c;
}

.comparison-menu a,
.comparison-menu button,
.comparison-menu > span {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 12px 18px;
    color: #344967;
    font: inherit;
    font-size: 13px;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}

.comparison-menu a:hover,
.comparison-menu button:hover {
    background: #f4f7fc;
}

.comparison-menu .history-remove {
    border-top: 1px solid #edf1f7;
    color: #d94e59;
}

.comparison-menu button:disabled,
.comparison-menu a[aria-disabled="true"] {
    color: #b4c0d0;
    pointer-events: none;
}

.history-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid #edf1f7;
}

.history-pagination button,
#compare-retry {
    border: 1px solid #dce4ef;
    border-radius: 5px;
    padding: 7px 12px;
    background: #fff;
    color: #3d5574;
}

.history-pagination button:disabled {
    color: #bac4d1;
    cursor: default;
}

.history-message {
    padding: 16px 24px;
    color: #b95a26;
    margin: 0;
}

.history-empty {
    text-align: center;
    padding: 55px 20px !important;
    color: #74859c;
}

.comparison-page {
    margin: 0;
    background: #f1f5fa;
    color: #203450;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
}

.comparison-page #main {
    padding: 0;
    margin: 0;
}

.comparison-app {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.compare-topbar {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 20px;
    min-height: 78px;
    padding: 12px 24px;
    border-bottom: 1px solid #dfe7f1;
    background: #fff;
}

.compare-heading {
    display: flex;
    align-items: center;
    gap: 22px;
    margin-right: auto;
}

.compare-heading h1 {
    font-size: 19px;
    margin: 0;
    padding-left: 22px;
    border-left: 1px solid #dfe7f1;
}

.compare-back {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 28px;
    color: #536780;
}

.compare-back span {
    font-size: 14px;
}

.compare-stats {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 8px 18px;
    border: 1px solid #edf1f7;
    border-radius: 9px;
    background: #f8faff;
}

.similarity-ring {
    --ring-color: #11b88d;
    width: 31px;
    height: 31px;
}

.similarity-value {
    padding-right: 20px;
    border-right: 1px solid #dfe7f1;
}

.compare-stats small {
    display: block;
    font-size: 11px;
    color: #7b8ba3;
}

.similarity-value strong {
    font-size: 21px;
    line-height: 1.4;
    color: #1a304f;
}

.change-total {
    text-align: center;
}

.change-total strong {
    display: block;
    border-radius: 20px;
    padding: 0 8px;
    font-size: 13px;
    line-height: 1.6;
}

.count-delete {
    color: #d75461;
    background: #fff0f1;
}

.count-insert {
    color: #0ba476;
    background: #eafaef;
}

.count-replace {
    color: #bf801d;
    background: #fff5de;
}

.compare-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.compare-view-switch {
    display: flex;
    padding: 4px;
    border: 1px solid #e1e7f0;
    border-radius: 7px;
    background: #f2f5fa;
}

.compare-view-switch button {
    border: 0;
    border-radius: 5px;
    padding: 7px 12px;
    background: transparent;
    color: #7789a1;
    font: inherit;
    font-size: 13px;
}

.compare-view-switch button.active {
    color: #365fe4;
    background: #fff;
    box-shadow: 0 1px 4px #21364c0d;
}

.compare-export summary {
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 6px;
    padding: 10px 18px;
    background: #4262dc;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.comparison-notice {
    flex-shrink: 0;
    padding: 9px 24px;
    background: #fff8e9;
    color: #95641b;
    border-bottom: 1px solid #f1dfbb;
    font-size: 12px;
}

.compare-workbench {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    flex: 1;
    min-height: 0;
}

.document-workspace {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.document-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 12px;
    min-height: 43px;
    padding: 6px 18px;
    background: #fff;
    border-bottom: 1px solid #e0e7f1;
    font-size: 12px;
}

.reader-zoom,
.sync-scroll {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    color: #677b96;
}

.reader-zoom button,
.document-pane footer button,
.difference-navigation button {
    min-width: 29px;
    border: 1px solid #e1e8f2;
    border-radius: 4px;
    background: #fff;
    color: #506785;
    font: inherit;
    cursor: pointer;
    padding: 3px 7px;
}

.reader-zoom #zoom-fit {
    font-size: 11px;
}

.document-deck {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    flex: 1;
    min-height: 0;
}

.document-deck.merged-document {
    grid-template-columns: minmax(0, 1fr);
}

.document-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    border-right: 1px solid #dfe7f1;
}

.document-pane > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 8px 16px;
    line-height: 1.4;
    gap: 12px;
    background: #f8faff;
    border-bottom: 1px solid #dfe7f1;
    font-size: 14px;
}

.document-caption {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 8px;
    color: #2b466a;
    font-weight: 600;
}

.document-caption > span {
    min-width: 0;
}

.document-caption small {
    display: block;
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 3px;
    font-size: 11px;
    color: #7d8ba0;
    font-weight: 400;
}

.document-dot {
    width: 8px;
    height: 8px;
    flex-shrink: 0;
    border-radius: 50%;
}

.document-dot.old {
    background: #e6606a;
}

.document-dot.new {
    background: #19b988;
}

.document-pane > header a {
    white-space: nowrap;
    color: #4264d5;
    font-size: 11px;
}

.pdf-scroll {
    position: relative;
    min-height: 0;
    flex: 1;
    overflow: auto;
    overscroll-behavior: contain;
    padding: 16px;
    scrollbar-color: #c8d3e2 #edf2f8;
    scrollbar-width: thin;
    background: #edf2f8;
}

.pdf-sheet {
    position: relative;
    margin: 0 auto 16px;
    background: #fff;
    box-shadow: 0 1px 5px #29456314;
    border-radius: 3px;
    overflow: hidden;
}

.pdf-sheet canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.pdf-page-loading {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: #90a0b5;
    font-size: 12px;
}

.pdf-highlights {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.pdf-highlight {
    position: absolute;
    padding: 0;
    border: 1px solid #ed6873;
    border-radius: 1px;
    background: #ff526b29;
    pointer-events: auto;
    cursor: pointer;
    min-width: 3px;
    min-height: 3px;
}

.pdf-highlight.is-new {
    background: #10c58c29;
    border-color: #19b989;
}

.pdf-highlight.selected {
    outline: 2px solid #4168e4;
    outline-offset: 2px;
    z-index: 2;
}

.pdf-sheet-number {
    position: absolute;
    bottom: 4px;
    right: 8px;
    color: #9aa8bb;
    font-size: 9px;
}

.document-pane footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 6px;
    background: #fff;
    border-top: 1px solid #dfe7f1;
    color: #75859b;
    font-size: 11px;
}

.difference-sidebar {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #f7f9fc;
    border-left: 1px solid #dfe7f1;
}

.difference-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    padding: 17px 18px;
    border-bottom: 1px solid #e7edf5;
    background: #fff;
}

.difference-heading h2 {
    margin: 0;
    font-size: 16px;
}

.difference-heading > span {
    padding: 1px 8px;
    border-radius: 20px;
    background: #f0f4f9;
    color: #7a8ba2;
    font-size: 11px;
}

.difference-navigation {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 10px 16px 0;
    flex-shrink: 0;
    font-size: 11px;
    color: #77879e;
}

.difference-navigation > span {
    margin-right: auto;
}

.difference-filters {
    display: flex;
    gap: 4px;
    padding: 10px 16px;
    flex-shrink: 0;
}

.difference-filters button {
    padding: 5px 11px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: #70819a;
    font: inherit;
    font-size: 11px;
}

.difference-filters button.active {
    color: #3c61d4;
    background: #eaf0ff;
    font-weight: 600;
}

.difference-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0 14px 14px;
    scrollbar-width: thin;
}

.diff-item {
    display: block;
    width: 100%;
    padding: 13px;
    margin-bottom: 10px;
    border: 1px solid #edf1f7;
    border-left: 3px solid #e6bc67;
    border-radius: 6px;
    background: #fff;
    color: #415a78;
    text-align: left;
    font: inherit;
    font-size: 14px;
    line-height: 1.65;
    cursor: pointer;
    box-shadow: 0 1px 2px #27405f05;
}

.diff-item:hover {
    border-color: #b4c6ef;
}

.diff-item.selected {
    border-color: #5b7be1;
    box-shadow: 0 0 0 1px #5b7be126;
}

.diff-item.type-insert {
    border-left-color: #36bf90;
}

.diff-item.type-delete {
    border-left-color: #ef8490;
}

.diff-item-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.diff-type {
    font-size: 12px;
    padding: 0 6px;
    border-radius: 3px;
    color: #a37214;
    background: #fff1cd;
}

.type-insert .diff-type {
    color: #0d9d71;
    background: #ddfaeb;
}

.type-delete .diff-type {
    color: #dc4b5b;
    background: #ffeaee;
}

.diff-page-label {
    font-size: 11px;
    color: #9aa6b8;
}

.diff-old,
.diff-new {
    display: block;
    padding: 5px 8px;
    margin-top: 5px;
    border-radius: 3px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.diff-old {
    color: #cb4756;
    background: #fff0f2;
    text-decoration: line-through;
}

.diff-new {
    color: #0b9873;
    background: #eefaF4;
}

#difference-more {
    flex-shrink: 0;
    padding: 10px;
    background: #fff;
    color: #5576cf;
    border: 0;
    border-top: 1px solid #e7edf5;
    font: inherit;
    font-size: 12px;
}

.compare-pending {
    margin: auto;
    width: min(720px, calc(100% - 40px));
    padding: 50px 30px;
    text-align: center;
    box-sizing: border-box;
    border: 1px solid #e1e8f2;
    border-radius: 10px;
    background: #fff;
}

.pending-progress-ring {
    --ring-color: #4d75df;
    width: 88px;
    height: 88px;
    color: #4566bf;
}

.pending-progress-ring::before {
    inset: 6px;
}

.pending-progress-ring > span {
    font-size: 21px;
}

.compare-pending h2 {
    margin: 20px 0 10px;
    font-size: 21px;
}

.compare-pending > p {
    color: #7b8aa1;
    font-size: 13px;
}

.pending-documents {
    display: grid;
    gap: 5px;
    margin-top: 22px;
    color: #586d8b;
    overflow-wrap: anywhere;
    font-size: 12px;
}

.comparison-steps {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 30px 0;
    justify-content: center;
    gap: 18px;
    color: #a3afbf;
    font-size: 12px;
}

.comparison-steps li::before {
    content: '';
    display: block;
    height: 3px;
    background: #e6ecf5;
    border-radius: 4px;
    margin-bottom: 12px;
}

.comparison-steps li.active {
    color: #3866d8;
    font-weight: 600;
}

.comparison-steps li.complete::before,
.comparison-steps li.active::before {
    background: #5279df;
}

.pending-history-link {
    font-size: 12px;
    color: #5877c3;
}

.mobile-document-switch {
    display: none;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 2px solid #3866df;
    outline-offset: 3px;
}

@media (min-width: 1600px) {
    .compare-workbench {
        grid-template-columns: minmax(0, 1fr) 370px;
    }
}

@media (max-width: 1100px) {
    .compare-topbar {
        gap: 10px;
        padding: 10px 16px;
    }

    .compare-stats {
        gap: 10px;
        padding: 7px 10px;
    }

    .compare-workbench {
        grid-template-columns: minmax(0, 1fr) 280px;
    }

    .compare-heading {
        gap: 12px;
    }

    .compare-heading h1 {
        padding-left: 12px;
    }

    .history-table {
        min-width: 980px;
    }
}

@media (max-width: 760px) {
    .history-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 14px;
        padding: 18px;
    }

    #history-search {
        width: 100%;
    }

    .history-table {
        min-width: 0;
    }

    .history-table thead {
        display: none;
    }

    .history-table,
    .history-table tbody,
    .history-table tr {
        display: block;
    }

    .history-table tr {
        padding: 15px 18px;
        border-bottom: 1px solid #e5ecf5;
    }

    .history-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        padding: 7px 0;
        border: 0;
        min-width: 0;
    }

    .history-table td::before {
        content: attr(data-label);
        color: #8b9ab0;
        font-size: 11px;
        white-space: nowrap;
    }

    .history-table td.history-empty::before {
        content: none;
    }

    .history-file {
        min-width: 0;
        max-width: 75%;
        font-size: 12px;
        justify-content: flex-end;
    }

    .history-file svg {
        width: 16px;
        height: 16px;
        padding: 5px;
    }

    .history-pagination {
        padding: 14px 18px;
        gap: 8px;
    }

    .compare-topbar {
        padding: 10px 12px;
        min-height: 0;
    }

    .compare-heading h1 {
        font-size: 16px;
    }

    .compare-back span {
        display: none;
    }

    .compare-stats {
        order: 3;
        width: 100%;
        justify-content: center;
        padding: 6px 10px;
        box-sizing: border-box;
    }

    .compare-actions {
        gap: 8px;
    }

    .compare-view-switch button {
        padding: 5px 8px;
        font-size: 11px;
    }

    .compare-export summary {
        padding: 8px 11px;
        font-size: 12px;
    }

    .compare-export summary svg {
        display: none;
    }

    .compare-workbench {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(200px, 58%) minmax(130px, 42%);
    }

    .document-toolbar {
        gap: 6px;
        flex-wrap: wrap;
        padding: 5px 10px;
        min-height: 35px;
    }

    .reader-zoom {
        gap: 6px;
    }

    .reader-zoom #zoom-fit,
    .sync-scroll {
        display: none;
    }

    .mobile-document-switch {
        display: flex;
        gap: 2px;
        padding: 2px;
        border-radius: 5px;
        background: #edf2fa;
    }

    .mobile-document-switch button {
        border: 0;
        border-radius: 4px;
        background: transparent;
        padding: 5px 8px;
        font: inherit;
        font-size: 11px;
        color: #7186a1;
    }

    .mobile-document-switch button.active {
        background: #fff;
        color: #3e64ce;
    }

    .document-deck {
        grid-template-columns: minmax(0, 1fr);
    }

    .document-deck[data-mobile-side="base"] [data-side="compare"],
    .document-deck[data-mobile-side="compare"] [data-side="base"] {
        display: none;
    }

    .document-pane > header {
        padding: 7px 12px;
        font-size: 11px;
    }

    .document-caption small {
        max-width: 200px;
        font-size: 9px;
    }

    .pdf-scroll {
        padding: 10px;
    }

    .document-pane footer {
        padding: 3px;
    }

    .difference-heading {
        padding: 8px 12px;
    }

    .difference-heading h2 {
        font-size: 14px;
    }

    .difference-navigation {
        padding: 7px 12px 0;
    }

    .difference-filters {
        padding: 5px 12px;
    }

    .difference-list {
        padding: 0 10px 10px;
    }

    .diff-item {
        padding: 10px;
    }

    .compare-pending {
        padding: 30px 16px;
    }

    .comparison-steps {
        gap: 10px;
        font-size: 10px;
    }
}
