/*
 * Annotate page: lock to viewport — no document/body scroll; .checklist-scroll holds #checklist + annotator note.
 */
html:has(body.page-annotate) {
    height: 100%;
}

body.page-annotate {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.page-annotate .site-header {
    flex-shrink: 0;
}

/* Full-width annotate workspace (container max-width removed for this page only). */
.page-annotate .container {
    max-width: none;
    width: 100%;
    padding: clamp(12px, 2vw, 28px);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* 12-column grid: image 9 cols, checklist 3 cols; one row fills remaining height. */
.page-annotate .annotate-layout {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    gap: clamp(16px, 2.2vw, 28px);
    align-items: stretch;
}

.page-annotate .image-panel {
    grid-column: span 9;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border-radius: 16px;
    padding: clamp(14px, 2vw, 22px);
    border: 1px solid #e2e8f0;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 10px 32px rgba(20, 34, 90, 0.09);
    max-width: none;
    justify-self: stretch;
}

.page-annotate .checklist-panel {
    grid-column: span 3;
    min-height: 0;
}

/* Wide desktop: search + category filters on one row (60% / 40%); summary full width below when shown. */
@media (min-width: 1025px) {
    .page-annotate .search-bar-main {
        display: grid;
        grid-template-columns: 60% 40%;
        gap: 8px;
        align-items: stretch;
    }

    .page-annotate .search-bar-main > input {
        grid-column: 1;
        grid-row: 1;
        width: 100%;
    }

    .page-annotate .search-bar-main > select {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        min-width: 0;
    }

    .page-annotate .search-bar-main > .checked-summary:not(.checked-summary-hidden) {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
    }
}

@media (max-width: 1024px) {
    .page-annotate .annotate-layout {
        display: flex;
        flex-direction: column;
        grid-template-columns: unset;
        grid-template-rows: unset;
        gap: 16px;
    }

    .page-annotate .image-panel {
        flex: 0 0 auto;
        max-height: min(42vh, 520px);
        padding: 14px;
        width: 100%;
        margin-bottom: 0;
        position: static;
        box-shadow:
            0 4px 20px rgba(15, 23, 42, 0.1),
            0 1px 3px rgba(15, 23, 42, 0.06);
    }

    .page-annotate .image-carousel {
        max-height: min(34vh, 440px);
    }

    .page-annotate .image-carousel > img {
        margin: 0 auto;
    }

    .page-annotate .search-bar {
        position: static;
        top: auto;
    }

    .page-annotate .checklist-panel {
        flex: 1 1 auto;
        min-height: 0;
        margin-top: 0;
        height: auto;
    }
}

/* Image + carousel bar: grid so the image is capped to remaining space (no page scroll). */
.page-annotate .image-carousel {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 12px;
    overflow: hidden;
    align-items: stretch;
}

.page-annotate .image-carousel-bar {
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.page-annotate .image-carousel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 14px;
    border-radius: 10px;
    border: 1px solid #d2e3fc;
    background: #e8f0fe;
    color: #1967d2;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, transform .15s;
    white-space: nowrap;
}

.page-annotate .image-carousel-btn:hover {
    background: #d2e3fc;
    border-color: #c3d8fd;
    transform: translateY(-1px);
}

.page-annotate .image-carousel-btn:focus {
    outline: 2px solid #1967d2;
    outline-offset: 2px;
}

.page-annotate .image-carousel-counter {
    font-size: 13px;
    font-weight: 600;
    color: #3f4f74;
    min-width: 7.5rem;
    text-align: center;
}

.page-annotate .image-carousel > img {
    grid-row: 1;
    display: block;
    width: 100%;
    min-height: 0;
    max-height: 100%;
    height: 100%;
    align-self: center;
    object-fit: contain;
    object-position: top center;
    border-radius: 8px;
}

.page-annotate .form-image-clickable {
    cursor: zoom-in;
}

.page-annotate .form-image-clickable:focus {
    outline: 2px solid #1967d2;
    outline-offset: 2px;
}

.page-annotate .image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: max(56px, calc(env(safe-area-inset-top, 0px) + 48px)) 16px 24px;
    background: rgba(15, 15, 25, 0.92);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    cursor: zoom-out;
}

.page-annotate .image-lightbox.image-lightbox--open { display: flex; }

.page-annotate .image-lightbox-close {
    position: fixed;
    top: max(12px, env(safe-area-inset-top, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    z-index: 5001;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.15s ease;
}

.page-annotate .image-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.05);
}

.page-annotate .image-lightbox-close:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.page-annotate .image-lightbox-content {
    position: relative;
    z-index: 1;
    max-width: min(100%, 96vw);
    max-height: calc(100vh - max(56px, env(safe-area-inset-top, 0px)) - 32px);
    cursor: default;
}

.page-annotate .image-lightbox-content img {
    display: block;
    max-width: 100%;
    max-height: calc(100vh - max(56px, env(safe-area-inset-top, 0px)) - 48px);
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.page-annotate .checklist-panel {
    --annotate-pad: clamp(18px, 2vw, 26px);
    background: #fff;
    border-radius: 16px;
    padding: var(--annotate-pad);
    border: 1px solid #e2e8f0;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, 0.04),
        0 10px 32px rgba(20, 34, 90, 0.09);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: none;
}

/* Scroll checklist + annotator note together (note sits after labels at end of scroll area). */
.page-annotate .checklist-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    scrollbar-gutter: stable;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.page-annotate .checklist-scroll::-webkit-scrollbar {
    width: 8px;
}

.page-annotate .checklist-scroll::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.page-annotate .checklist-scroll::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 999px;
}

.page-annotate #checklist {
    flex: 0 0 auto;
    min-height: 0;
}

.page-annotate .search-bar {
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, #fff 70%, rgba(255, 255, 255, 0.92) 100%);
    z-index: 2;
    padding: 0 0 8px;
    margin-bottom: 8px;
    border-bottom: 1px solid #edf1f7;
}

.page-annotate .search-bar-main {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.page-annotate .search-bar-main > input {
    width: 100%;
    min-width: 0;
    padding: 11px 14px;
    border: 1px solid #cfd8e8;
    border-radius: 11px;
    font-size: 14px;
    outline: none;
    background: #fafbfd;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.page-annotate .search-bar-main > input:hover:not(:focus) {
    border-color: #b8c5db;
    background: #fff;
}

.page-annotate .search-bar-main > input:focus {
    border-color: #1967d2;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25, 103, 210, 0.14);
}

.page-annotate .search-bar-main > select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cfd8e8;
    border-radius: 11px;
    font-size: 13px;
    font-weight: 500;
    background: #fafbfd;
    color: #334155;
    outline: none;
    cursor: pointer;
    min-width: 160px;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.page-annotate .search-bar-main > select:hover:not(:focus) {
    border-color: #b8c5db;
    background: #fff;
}

.page-annotate .search-bar-main > select:focus {
    border-color: #1967d2;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(25, 103, 210, 0.14);
}

.page-annotate .search-bar-main > .checked-summary:not(.checked-summary-hidden) {
    width: 100%;
}

.page-annotate .search-stats {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
    min-height: 14px;
    font-weight: 500;
}

/* No reserved space while filter summary is blank (see filterTests() clearing textContent). */
.page-annotate .search-stats:empty {
    margin-top: 0;
    min-height: 0;
    height: 0;
    line-height: 0;
    overflow: hidden;
    padding: 0;
}

.page-annotate .checked-summary {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 7px 10px;
    font-size: 12px;
    color: #333;
    margin-bottom: 7px;
    line-height: 1.4;
    border: 1px solid #eef0f3;
}

.page-annotate .checked-summary-head {
    font-weight: 600;
    color: #4a4a4a;
}

.page-annotate .checked-summary-toggle {
    width: 100%;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0;
    margin: 0;
    cursor: pointer;
}

.page-annotate .checked-summary-chevron {
    font-size: 12px;
    color: #667085;
}

.page-annotate .checked-summary-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px;
    margin-top: 8px;
    padding-right: 2px;
}

.page-annotate .checked-summary-tags-hidden {
    display: none;
}

.page-annotate .selected-tag {
    display: inline-flex;
    align-items: center;
    background: #e8f0fe;
    color: #1967d2;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    transition: background .15s;
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
}

.page-annotate .selected-tag:hover {
    background: #fdecea;
    color: #d32f2f;
}

.page-annotate .category-group { margin-bottom: 12px; }

.page-annotate .category-group h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #1557b0;
    background: linear-gradient(90deg, #e8f0fe 0%, #f0f4ff 100%);
    margin: 0 calc(-1 * var(--annotate-pad, 24px));
    padding: 9px var(--annotate-pad, 24px);
    font-weight: 700;
    border-top: 1px solid #dbeafe;
    border-bottom: 1px solid #dbeafe;
}


.page-annotate .check-item {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background .12s;
    cursor: pointer;
    border-bottom: 1px solid #eef2f8;
}

.page-annotate .annot-table-head {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 7px 10px;
    margin: 8px 0 4px;
    border: 1px solid #dce4f3;
    border-radius: 8px;
    background: #f6f8fe;
    font-size: 12px;
    font-weight: 700;
    color: #3f4f74;
}

.page-annotate .check-label-cell {
    display: flex;
    align-items: center;
    min-height: 38px;
}

.page-annotate .check-item:last-child { border-bottom: none; }
.page-annotate .check-item:hover { background: #f5f7fa; }

.page-annotate .check-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 10px;
    accent-color: #1967d2;
    cursor: pointer;
    flex-shrink: 0;
}

.page-annotate .check-item label {
    font-size: 13px;
    cursor: pointer;
    user-select: none;
    overflow-wrap: break-word;
    word-break: break-word;
    color: #1e293b;
    line-height: 1.35;
}

.page-annotate .check-extra-input,
.page-annotate .check-extra-select {
    width: 100%;
    border: 1px solid #d4daea;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    outline: none;
    background: #fff;
}

.page-annotate .check-extra-input:focus,
.page-annotate .check-extra-select:focus {
    border-color: #1967d2;
    box-shadow: 0 0 0 3px rgba(25, 103, 210, 0.12);
}

.page-annotate .annotator-note-block {
    flex-shrink: 0;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #edf1f7;
}

.page-annotate .annotator-note-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 6px;
}

.page-annotate .annotator-note-hint {
    font-weight: 400;
    color: #64748b;
}

.page-annotate .annotator-note-input {
    width: 100%;
    min-height: 88px;
    max-height: min(220px, 28vh);
    resize: none;
    overflow-y: auto;
    box-sizing: border-box;
    border: 1px solid #d4daea;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    line-height: 1.45;
    font-family: inherit;
    background: #fff;
    outline: none;
}

.page-annotate .annotator-note-input:focus {
    border-color: #1967d2;
    box-shadow: 0 0 0 3px rgba(25, 103, 210, 0.12);
}

.page-annotate .save-bar {
    position: sticky;
    bottom: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #fff 8px);
    padding: 10px 0 4px;
    border-top: 1px solid #edf1f7;
    margin-top: 8px;
}

.page-annotate .save-bar .save-btn {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 4px 16px rgba(25, 103, 210, 0.3);
}

.page-annotate .save-bar .save-btn:hover:not(:disabled) {
    box-shadow: 0 6px 22px rgba(25, 103, 210, 0.38);
}

.page-annotate .save-bar .status {
    text-align: center;
    font-size: 13px;
    color: #34a853;
    margin-top: 4px;
    min-height: 16px;
}

.page-annotate .save-bar .status:empty {
    margin-top: 0;
    min-height: 0;
    height: 0;
    line-height: 0;
    overflow: hidden;
    padding: 0;
}

.page-annotate .checked-summary.checked-summary-hidden {
    display: none !important;
}

.page-annotate .annotate-back-link {
    display: inline-block;
    margin-bottom: 8px;
    font-weight: 500;
}

/* Annotate on small screens: hide back link, filters + selection count in one row. (Header uses global mobile layout.) */
@media (max-width: 768px) {
    .page-annotate .annotate-back-link {
        display: none;
    }

    .page-annotate .search-bar-main {
        display: grid;
        gap: 6px;
        align-items: stretch;
    }

    .page-annotate .search-bar-main:has(.checked-summary:not(.checked-summary-hidden)) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    }

    .page-annotate .search-bar-main:not(:has(.checked-summary:not(.checked-summary-hidden))) {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .page-annotate .search-bar-main > input {
        grid-column: 1;
        grid-row: 1;
        width: 100%;
    }

    .page-annotate .search-bar-main > select {
        grid-column: 2;
        grid-row: 1;
        width: 100%;
        min-width: 0;
    }

    .page-annotate .search-bar-main > .checked-summary:not(.checked-summary-hidden) {
        display: contents;
        margin: 0;
        padding: 0;
        border: none;
        background: transparent;
    }

    .page-annotate .search-bar-main .checked-summary-toggle {
        grid-column: 3;
        grid-row: 1;
        width: auto;
        min-width: 0;
        max-width: 4.75rem;
        justify-content: center;
        gap: 4px;
        padding: 8px 8px;
        margin: 0;
        border: 1px solid #cfd8e8;
        border-radius: 9px;
        background: #fafbfd;
        box-sizing: border-box;
    }

    .page-annotate .search-bar-main .checked-summary-count {
        font-size: 11px;
        font-weight: 700;
        color: #1557b0;
        white-space: nowrap;
    }

    .page-annotate .search-bar-main .checked-summary-tags {
        grid-column: 1 / -1;
        grid-row: 2;
        margin-top: 0;
        padding: 8px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 9px;
    }

    .page-annotate .search-bar-main .checked-summary-chevron {
        font-size: 0 !important;
        line-height: 0;
        width: 1rem;
        height: 1rem;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        color: transparent;
    }

    .page-annotate .search-bar-main .checked-summary-chevron::after {
        content: '\2713';
        font-size: 12px;
        font-weight: 700;
        color: #1967d2;
        line-height: 1;
    }
}

@media (max-width: 1100px) {
    .page-annotate .annot-table-head {
        display: none;
    }

    /* Denser rows so more labels fit when the checklist column is narrow. */
    .page-annotate .category-group {
        margin-bottom: 8px;
    }

    .page-annotate .category-group h4 {
        padding: 7px var(--annotate-pad, 24px);
        font-size: 10.5px;
        letter-spacing: 0.05em;
    }

    .page-annotate .check-item {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 5px 8px;
        border-radius: 6px;
    }

    .page-annotate .check-label-cell {
        min-height: 32px;
    }

    .page-annotate .check-item input[type="checkbox"] {
        width: 15px;
        height: 15px;
        margin-right: 8px;
    }

    .page-annotate .check-item label {
        font-size: 12.5px;
        line-height: 1.28;
    }

    /* Compact panel chrome: back link, search, save — more room for checklist. */
    .page-annotate .annotate-back-link {
        margin-bottom: 6px;
        font-size: 14px;
    }

    .page-annotate .search-bar {
        padding: 0 0 6px;
        margin-bottom: 6px;
    }

    .page-annotate .search-bar-main {
        gap: 5px;
    }

    .page-annotate .search-bar-main > input {
        padding: 9px 12px;
        font-size: 13px;
        border-radius: 10px;
    }

    .page-annotate .search-bar-main > select {
        padding: 9px 10px;
        font-size: 12px;
        border-radius: 10px;
        min-width: 140px;
    }

    .page-annotate .search-stats {
        margin-top: 3px;
        min-height: 12px;
        font-size: 11px;
    }

    .page-annotate .checked-summary {
        padding: 6px 9px;
        margin-bottom: 6px;
        font-size: 11px;
    }

    .page-annotate .save-bar {
        padding: 8px 0 3px;
        margin-top: 6px;
    }

    .page-annotate .save-bar .save-btn {
        min-height: 42px;
        font-size: 14px;
        border-radius: 11px;
    }

    .page-annotate .save-bar .status {
        margin-top: 3px;
        min-height: 14px;
        font-size: 12px;
    }
}

@media (max-width: 640px) {
    .page-annotate .checklist-panel {
        --annotate-pad: 14px;
        padding: 14px;
    }

    .page-annotate .category-group {
        margin-bottom: 5px;
    }

    .page-annotate .category-group h4 {
        margin: 0 calc(-1 * var(--annotate-pad));
        padding: 6px var(--annotate-pad);
        font-size: 10px;
    }

    .page-annotate .check-item {
        gap: 2px;
        padding: 3px 6px;
        border-radius: 5px;
    }

    .page-annotate .check-label-cell {
        min-height: 26px;
    }

    .page-annotate .check-item input[type="checkbox"] {
        width: 14px;
        height: 14px;
        margin-right: 6px;
    }

    .page-annotate .check-item label {
        font-size: 12px;
        line-height: 1.22;
    }

    .page-annotate .check-extra-input,
    .page-annotate .check-extra-select {
        padding: 6px 8px;
        font-size: 12px;
    }

    .page-annotate .search-bar-main > input,
    .page-annotate .search-bar-main > select {
        width: 100%;
    }

    .page-annotate .search-bar-main > select {
        min-width: 0;
    }

    .page-annotate .annotate-back-link {
        margin-bottom: 4px;
        font-size: 13px;
    }

    .page-annotate .search-bar {
        padding: 0 0 5px;
        margin-bottom: 5px;
    }

    .page-annotate .search-bar-main {
        gap: 4px;
    }

    .page-annotate .search-bar-main > input {
        padding: 8px 11px;
        font-size: 13px;
        border-radius: 9px;
    }

    .page-annotate .search-bar-main > select {
        padding: 8px 10px;
        font-size: 12px;
        border-radius: 9px;
    }

    .page-annotate .search-stats {
        margin-top: 2px;
        min-height: 12px;
        font-size: 10px;
    }

    .page-annotate .checked-summary {
        padding: 4px 7px;
        margin-bottom: 5px;
        font-size: 10px;
        line-height: 1.35;
    }

    .page-annotate .save-bar {
        padding: 6px 0 2px;
        margin-top: 4px;
    }

    .page-annotate .save-bar .save-btn {
        min-height: 40px;
        font-size: 13px;
        border-radius: 10px;
    }

    .page-annotate .save-bar .status {
        margin-top: 2px;
        min-height: 13px;
        font-size: 11px;
    }
}
