/* ================================================
   Analysis page — photo comparison for orthodontists
   ================================================ */

/* === Patient selector === */
.patient-selector {
    position: relative;
    margin-top: 8px;
}

.patient-selector__field {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 10px;
    padding: 8px 12px;
    transition: border-color .2s;
}

.patient-selector__field:focus-within {
    border-color: #4fc3f7;
}

.patient-selector__icon {
    color: #888;
    flex-shrink: 0;
}

.patient-selector__input {
    flex: 1;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 15px;
    outline: none;
    min-width: 0;
}

.patient-selector__input::placeholder {
    color: #777;
}

.patient-selector__clear {
    background: none;
    border: none;
    color: #888;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}

/* Autocomplete dropdown */
.patient-selector .autocomplete-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #2a2a2a;
    border: 1px solid #444;
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 240px;
    overflow-y: auto;
    z-index: 50;
    list-style: none;
}

.autocomplete-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 15px;
    transition: background .15s;
}

.autocomplete-item:hover,
.autocomplete-item--active {
    background: #333;
}

.autocomplete-item__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #4fc3f7;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

/* Selected patient chip */
.selected-patient {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding: 6px 0;
}

.selected-patient__avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #4fc3f7;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.selected-patient__name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
}

/* === Toolbar === */
.toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: #1a1a1a;
    border-bottom: 1px solid #333;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: wrap;
}

.toolbar__group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.toolbar__separator {
    width: 1px;
    height: 24px;
    background: #444;
    margin: 0 6px;
    flex-shrink: 0;
}

.toolbar__btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #aaa;
    cursor: pointer;
    font-size: 12px;
    transition: all .15s;
    white-space: nowrap;
}

.toolbar__btn:hover {
    background: #2a2a2a;
    color: #e0e0e0;
}

.toolbar__btn--active {
    background: #4fc3f7;
    color: #000;
    border-color: #4fc3f7;
}

.toolbar__badge {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    line-height: 1;
    letter-spacing: 0.5px;
}

.toolbar__label {
    font-size: 11px;
}

.toolbar__group--sliders {
    gap: 8px;
}

.toolbar__slider-label {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #aaa;
    cursor: pointer;
}

.toolbar__slider {
    width: 70px;
    height: 4px;
    accent-color: #4fc3f7;
    cursor: pointer;
}

/* === Comparison area === */
.analysis-main {
    flex: 1;
    padding: 0;
    gap: 0;
    overflow: hidden;
}

/* Wrapper: selectors + toolbar + panels */
.comparison-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Fullscreen mode */
.comparison-wrap--fullscreen {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: #121212;
}

.body--fullscreen {
    overflow: hidden;
}

/* === Selectors row (side by side) === */
.comparison-selectors {
    display: flex;
    align-items: stretch;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

.comparison-selectors__panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    min-width: 0;
}

.comparison-selectors__divider {
    width: 1px;
    background: #333;
}

/* Toolbar spacer pushes fullscreen btn to right */
.toolbar__spacer {
    flex: 1;
}

.toolbar__btn--fullscreen {
    margin-left: auto;
}

.comparison {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: hidden;
}

/* Overlay mode: panels stack */
.comparison--overlay .comparison__panel:nth-child(2) {
    position: absolute;
    inset: 0;
    z-index: 2;
    pointer-events: none;
}

.comparison--overlay .comparison__panel:nth-child(2) .comparison__panel-header,
.comparison--overlay .comparison__panel:nth-child(2) .comparison__date {
    pointer-events: auto;
}

/* Swipe mode */
.comparison--swipe {
    position: relative;
}

.comparison--swipe .comparison__panel:nth-child(1) {
    position: absolute;
    inset: 0;
    z-index: 1;
    clip-path: inset(0 var(--swipe-right, 50%) 0 0);
}

.comparison--swipe .comparison__panel:nth-child(2) {
    position: absolute;
    inset: 0;
    z-index: 0;
}

/* === Panel === */
.comparison__panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid #333;
    position: relative;
}

.comparison__panel:last-of-type {
    border-right: none;
}

.comparison__select {
    width: 100%;
    padding: 10px 12px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 14px;
    outline: none;
    min-width: 0;
    cursor: pointer;
}

.comparison__select:focus {
    border-color: #4fc3f7;
}

/* === Thumbnail strip === */
.thumb-strip {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: #555 transparent;
    padding: 2px 0;
    min-height: 56px;
    align-items: center;
}

.thumb-strip::-webkit-scrollbar {
    height: 4px;
}

.thumb-strip::-webkit-scrollbar-track {
    background: transparent;
}

.thumb-strip::-webkit-scrollbar-thumb {
    background: #555;
    border-radius: 2px;
}

.thumb-strip__empty {
    color: #666;
    font-size: 12px;
    white-space: nowrap;
    padding: 0 4px;
}

.thumb-card {
    position: relative;
    flex-shrink: 0;
    width: 64px;
    height: 48px;
    border-radius: 6px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color .15s, box-shadow .15s;
    background: #222;
}

.thumb-card:hover {
    border-color: #666;
}

.thumb-card--active {
    border-color: #4fc3f7;
    box-shadow: 0 0 0 1px #4fc3f7, 0 0 8px rgba(79, 195, 247, 0.35);
}

.thumb-card__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.thumb-card__name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1px 3px;
    background: rgba(0,0,0,.7);
    color: #ccc;
    font-size: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: center;
    line-height: 1.3;
}

.thumb-card__spinner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #222;
}

.thumb-card__spinner::after {
    content: '';
    width: 16px;
    height: 16px;
    border: 2px solid #444;
    border-top-color: #4fc3f7;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

/* Info bar above each photo: date + filename */
.comparison__info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: #1a1a1a;
    flex-shrink: 0;
    min-height: 24px;
    border-bottom: 1px solid #282828;
}

.comparison__date {
    font-size: 12px;
    color: #4fc3f7;
    white-space: nowrap;
}

.comparison__filename {
    font-size: 11px;
    color: #888;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

/* === Viewport (zoomable/pannable area) === */
.comparison__viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    background: #111;
    display: flex;
    align-items: center;
    justify-content: center;
}

.comparison__img-wrap {
    position: relative;
    transform-origin: 0 0;
    will-change: transform;
    display: none; /* shown when image loaded */
}

.comparison__img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

/* B&W filter */
.comparison__img--bw {
    filter: grayscale(1);
}

/* Mirror */
.comparison__img--mirror {
    transform: scaleX(-1);
}

/* Placeholder */
.comparison__placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #555;
    font-size: 13px;
}

/* === Grid overlay === */
.comparison__grid {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: none;
}

/* Attached grid lives inside img-wrap, moves with image */
.comparison__grid--attached {
    z-index: 5;
}

/* Fixed grid lives inside viewport, stays in place */
.comparison__grid--fixed {
    z-index: 6;
}

.comparison__grid--visible {
    display: block;
}

.comparison__grid::before,
.comparison__grid::after {
    content: '';
    position: absolute;
}

/* 3x3 rule-of-thirds grid using repeating gradient */
.comparison__grid--visible {
    background:
        repeating-linear-gradient(
            to right,
            transparent,
            transparent calc(33.333% - 0.5px),
            rgba(79, 195, 247, 0.35) calc(33.333% - 0.5px),
            rgba(79, 195, 247, 0.35) calc(33.333% + 0.5px),
            transparent calc(33.333% + 0.5px)
        ),
        repeating-linear-gradient(
            to bottom,
            transparent,
            transparent calc(33.333% - 0.5px),
            rgba(79, 195, 247, 0.35) calc(33.333% - 0.5px),
            rgba(79, 195, 247, 0.35) calc(33.333% + 0.5px),
            transparent calc(33.333% + 0.5px)
        );
}

/* Also add crosshair center lines */
.comparison__grid--visible::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 152, 0, 0.4);
}

.comparison__grid--visible::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(255, 152, 0, 0.4);
}

/* === Swipe handle === */
.comparison__swipe-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 40px;
    margin-left: -20px;
    z-index: 10;
    cursor: ew-resize;
    touch-action: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.comparison__swipe-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    background: #4fc3f7;
    box-shadow: 0 0 6px rgba(79, 195, 247, 0.5);
}

.comparison__swipe-grip {
    position: relative;
    z-index: 1;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #4fc3f7;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

/* === Responsive: stack on mobile === */
@media (max-width: 640px) {
    .comparison-selectors {
        flex-direction: column;
    }

    .comparison-selectors__divider {
        width: auto;
        height: 1px;
    }

    .comparison {
        flex-direction: column;
    }

    .comparison__panel {
        border-right: none;
        border-bottom: 1px solid #333;
        min-height: 0;
        flex: 1;
    }

    .comparison__panel:last-of-type {
        border-bottom: none;
    }

    .toolbar {
        flex-wrap: wrap;
        gap: 4px;
    }

    .toolbar__label {
        display: none;
    }

    .toolbar__slider {
        width: 50px;
    }

    .thumb-card {
        width: 56px;
        height: 42px;
    }

    .thumb-strip {
        min-height: 48px;
    }

    /* In swipe mode on mobile, keep side-by-side look */
    .comparison--swipe {
        flex-direction: row;
    }

    .comparison--overlay {
        flex-direction: row;
    }

    .comparison__swipe-handle {
        display: flex;
    }
}

/* === Fullscreen image states === */
.comparison__img-wrap--loaded {
    display: block;
}

.comparison__img-wrap--loaded + .comparison__placeholder {
    display: none;
}

/* Smooth zoom/pan transitions */
.comparison__img-wrap--animated {
    transition: transform 0.2s ease-out;
}

/* === Zoom badge (shows current scale) === */
.comparison__zoom-badge {
    position: absolute;
    bottom: 10px;
    left: 10px;
    z-index: 12;
    padding: 2px 8px;
    background: rgba(0,0,0,.65);
    color: #999;
    font-size: 11px;
    font-family: monospace;
    border-radius: 4px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .2s;
}

.comparison__zoom-badge--active {
    opacity: 1;
    color: #4fc3f7;
}

/* === Per-panel reset zoom button === */
.comparison__reset-btn {
    position: absolute;
    bottom: 10px;
    right: 10px;
    z-index: 12;
    padding: 3px 10px;
    background: rgba(0,0,0,.7);
    color: #4fc3f7;
    border: 1px solid rgba(79, 195, 247, 0.4);
    border-radius: 5px;
    font-size: 11px;
    cursor: pointer;
    display: none;
}

.comparison__reset-btn--visible {
    display: block;
}

.comparison__reset-btn:hover {
    background: rgba(79, 195, 247, 0.15);
}

/* Loading spinner inside viewport */
.comparison__loading {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(17,17,17,.8);
    z-index: 5;
    align-items: center;
    justify-content: center;
}

.comparison__loading--visible {
    display: flex;
}
