/**
 * Public iTwin Viewer Styles
 */

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    overflow: hidden;
    background: #1a1a1a;
}

/* Viewer container - full screen */
.viewer-container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Recenter button */
.recenter-btn {
    position: fixed;
    top: 9px;
    right: 52px;  /* Position next to base layer picker */
    z-index: 1000;
    background: rgba(50, 50, 50, 0.5);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    width: 32px;
    height: 32px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    padding: 0;
}

.recenter-btn:hover {
    background: rgba(70, 70, 70, 0.95);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.recenter-btn:active {
    transform: scale(0.95);
}

.recenter-btn svg {
    display: block;
}

/* Controls instruction panel */
.controls-panel {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 1000;
    background: rgba(50, 50, 50, 0.4);
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    width: 260px; /* Match collapsed comparison panel width */
}

.controls-panel h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: white;
}

.controls-panel ul {
    list-style: none;
    margin: 0 0 15px 0;
    padding: 0;
}

.controls-panel li {
    font-size: 12px;
    margin-bottom: 8px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.9);
}

.controls-panel li:last-child {
    margin-bottom: 0;
}

.controls-panel strong {
    color: white;
    font-weight: 600;
}

/* Rotation Slider Control */
.rotation-control {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.rotation-control label {
    display: block;
    font-size: 12px;
    margin-bottom: 8px;
    color: white;
}

.rotation-control input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.2);
    outline: none;
    -webkit-appearance: none;
    margin-bottom: 8px;
}

.rotation-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.rotation-control input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.rotation-control input[type="range"]::-webkit-slider-thumb:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

.rotation-control input[type="range"]::-moz-range-thumb:hover {
    background: #f0f0f0;
    transform: scale(1.1);
}

#rotation-value {
    display: inline-block;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
    min-width: 40px;
    text-align: center;
}

/* Comparison Slider Panel */
.comparison-panel {
    position: fixed;
    top: 230px; /* Below the controls panel with rotation slider */
    left: 20px;
    z-index: 1000;
    background: rgba(50, 50, 50, 0.4);
    color: white;
    padding: 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    width: 400px;
    transition: all 0.5s cubic-bezier(0.4, 0.0, 0.2, 1);
    will-change: transform, width, top, left;
}

.comparison-panel.collapsed {
    width: 260px;
}

.comparison-panel.collapsed .comparison-header {
    margin-bottom: 0;
}

.comparison-panel.collapsed .ba-container {
    height: 0;
    opacity: 0;
    margin-top: 0;
    overflow: hidden;
}

.comparison-panel.collapsed #enlarge-btn {
    display: none;
}

.comparison-panel.enlarged {
    /* Original: 55vw, but constrain based on available height to prevent overflow */
    width: min(55vw, calc((90vh - 80px) / 0.75));
    min-width: 700px;
    /* Center on screen regardless of normal panel position */
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%);
    max-height: 100vh;
    overflow-y: auto;
}

.comparison-panel.enlarged .ba-container {
    /* Original ratio: height = width * 0.75, calculated from actual width */
    height: calc(min(55vw, calc((90vh - 80px) / 0.75)) * 0.75);
    min-height: calc(700px * 0.75);
}

.comparison-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.comparison-header h4 {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: white;
    flex: 1;
}

.comparison-buttons {
    display: flex;
    gap: 8px;
}

.panel-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: all 0.2s ease;
    padding: 0;
}

.panel-btn img {
    width: 20px;
    height: 20px;
    filter: brightness(0) invert(1);
}

.panel-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

.panel-btn:active {
    transform: scale(0.95);
}

.panel-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* Comparison container */
.ba-container {
    position: relative;
    user-select: none;
    touch-action: none;
    background: #000;
    overflow: hidden;
    border-radius: 6px;
    width: 100%;
    height: 300px;
    transition: height 0.4s ease, opacity 0.3s ease;
    will-change: height, opacity;
}

.ba-container img {
    display: block;
    vertical-align: top;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Top image is clipped by adjusting its container height */
.img-top {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 50%;
    overflow: hidden;
}

.img-top img {
    display: block;
    width: 100%;
    height: 300px;
    object-fit: cover;
}

.comparison-panel.enlarged .img-top img {
    /* Match container height - same calculation as ba-container */
    height: calc(min(55vw, calc((90vh - 80px) / 0.75)) * 0.75);
    min-height: calc(700px * 0.75);
}

/* Comparison disclaimer */
.comparison-disclaimer {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.6);
    margin: 8px 0 0 0;
    font-style: italic;
    line-height: 1.3;
    text-align: left;
}

.comparison-panel.collapsed .comparison-disclaimer {
    display: none;
}

/* Handle: horizontal bar with a circular knob */
.handle {
    position: absolute;
    left: 0;
    right: 0;
    height: 28px;
    margin-top: -14px;
    background: linear-gradient(90deg, rgba(255,255,255,0.06), rgba(255,255,255,0.12));
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: ns-resize;
}

.handle .knob {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 3px solid rgba(0, 0, 0, 0.45);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.ba-container:active .handle {
    transform: scaleY(1.02);
}

/* Navigation buttons */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 32px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease, background 0.2s ease;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    pointer-events: auto;
}

.nav-btn-left {
    left: 10px;
}

.nav-btn-right {
    right: 10px;
}

/* Show left button only when hovering left half */
.ba-container:hover .nav-btn-left {
    opacity: 0;
}

.ba-container.hover-left .nav-btn-left {
    opacity: 1;
}

/* Show right button only when hovering right half */
.ba-container:hover .nav-btn-right {
    opacity: 0;
}

.ba-container.hover-right .nav-btn-right {
    opacity: 1;
}

.nav-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

.nav-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* Image counter */
.image-counter {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    backdrop-filter: blur(5px);
    z-index: 10;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.image-counter.visible {
    opacity: 1;
}

/* Loading screen */
.loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #FF6B35 0%, #FFC72C 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    transition: opacity 0.3s ease;
}

.loading-content {
    text-align: center;
    color: white;
}

.loading-content h2 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 15px;
}

.loading-content p {
    font-size: 14px;
    opacity: 0.9;
    margin-top: 10px;
}

/* Spinner animation */
.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error screen */
.error-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, #f56565 0%, #c53030 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10001;
}

.error-content {
    text-align: center;
    color: white;
    max-width: 500px;
    padding: 40px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
}

.error-icon {
    font-size: 64px;
    margin-bottom: 20px;
}

.error-content h2 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 15px;
}

.error-content p {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 25px;
    line-height: 1.5;
}

.retry-button {
    padding: 12px 30px;
    background: white;
    color: #c53030;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.retry-button:hover {
    background: #f7fafc;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* Info panel */
.info-panel {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    max-width: 350px;
}

.toggle-info-btn {
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.toggle-info-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    transform: scale(1.05);
}

.info-content {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
}

.info-content h3 {
    font-size: 18px;
    margin-bottom: 15px;
    color: #2d3748;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
}

.info-content p {
    font-size: 13px;
    margin-bottom: 10px;
    color: #4a5568;
    line-height: 1.5;
}

.info-content strong {
    color: #2d3748;
    font-weight: 600;
}

.info-content code {
    background: #f7fafc;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    color: #667eea;
    word-break: break-all;
    display: inline-block;
    max-width: 100%;
}

/* Responsive design */
@media (max-width: 768px) {
    .info-panel {
        top: 10px;
        right: 10px;
        max-width: calc(100vw - 20px);
    }

    .loading-content h2 {
        font-size: 22px;
    }

    .error-content {
        padding: 30px 20px;
        margin: 20px;
    }

    .error-content h2 {
        font-size: 22px;
    }

    /* Controls panel adjustments for mobile */
    .controls-panel {
        max-width: calc(100vw - 40px);
    }

    /* Comparison panel adjustments for mobile */
    .comparison-panel {
        width: calc(100vw - 40px); /* Full width minus margins */
        max-width: 350px; /* Cap maximum width */
        left: 20px;
        right: 20px;
    }

    .comparison-panel .ba-container {
        height: 250px; /* Smaller height for mobile */
    }

    .comparison-header h4 {
        font-size: 12px; /* Slightly smaller text */
    }

    /* Hide enlarge button on mobile */
    #enlarge-btn {
        display: none;
    }
}

/* Print styles */
@media print {
    .loading-screen,
    .error-screen,
    .info-panel {
        display: none !important;
    }

    .viewer-container {
        width: 100%;
        height: 100%;
    }
}

/* Accessibility */
.toggle-info-btn:focus,
.retry-button:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Smooth transitions */
* {
    transition: background-color 0.2s ease,
                color 0.2s ease,
                transform 0.2s ease;
}

/* Custom scrollbar for info panel */
.info-content::-webkit-scrollbar {
    width: 6px;
}

.info-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.info-content::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

.info-content::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}
