* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Raleway", sans-serif;
    overflow: hidden;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 1000;
    flex-shrink: 0;
}

.header-logo {
    height: 40px;
    width: auto;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
}

.header-right a {
    color: #002347;
    text-decoration: none;
}

.header-right a:hover {
    color: #F8991D;
}

/* Main Content Area */
.main-container {
    flex: 1;
    display: flex;
    overflow: hidden;
    position: relative;
}

/* Sidebar */
.sidebar {
    width: 250px;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s ease;
    border-right: 1px solid #ddd;
    flex-shrink: 0;
}

.sidebar.collapsed {
    margin-left: -250px;
}

.sidebar-header {
    padding: 0.75rem;
    background: #e9e9e9;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-title {
    font-weight: 600;
    font-size: 0.9rem;
    flex: 1;
}

.file-count {
    color: #666;
    font-size: 0.85rem;
}

/* Toggle button inside sidebar */
.toggle-sidebar-inner {
    background: transparent;
    border: 1px solid #ccc;
    width: 32px;
    height: 32px;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    color: #666;
}

.toggle-sidebar-inner:hover {
    background-color: rgba(0, 0, 0, 0.1);
    border-color: #999;
    color: #333;
}

/* Search Box */
.search-box {
    padding: 0.5rem;
    border-bottom: 1px solid #ddd;
}

.search-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* File List */
.file-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.file-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.file-item:hover {
    background-color: #e9e9e9;
}

.file-item.active {
    background-color: #002347;
    color: white;
}

.file-item i {
    flex-shrink: 0;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Viewer Container */
.viewer-container {
    flex: 1;
    position: relative;
    background: #fafafa;
}

#openseadragon {
    width: 100%;
    height: 100%;
}

/* Floating Controls */
.toggle-sidebar {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 100;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    display: none; /* Hidden by default, shown when sidebar collapsed */
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.sidebar.collapsed ~ .viewer-container .toggle-sidebar {
    display: flex;
}

.sidebar.collapsed ~ .viewer-container .viewer-controls {
    margin-left: 60px; /* Push toolbar to the right when toggle button is shown */
}

.toggle-sidebar:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
}

.label-overlay {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 100;
    opacity: 0.3;
    transition: opacity 0.2s;
    max-width: 120px;
    max-height: 120px;
}

.label-overlay:hover {
    opacity: 0.9;
}

.label-overlay img {
    width: 100%;
    height: auto;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.viewer-controls {
    position: absolute;
    top: 1rem;
    left: 1rem;
    z-index: 100;
    display: flex;
    gap: 0.5rem;
    flex-direction: row;
    align-items: center;
    transition: margin-left 0.3s ease;
}

.control-btn {
    background: rgba(255, 255, 255, 0.9);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    transition: all 0.2s;
    position: relative;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 1);
    transform: scale(1.05);
}

.control-btn.active {
    background: #002347;
    color: white;
}

.control-btn i {
    font-size: 1.1rem;
}

/* Separator between control groups */
.control-separator {
    width: 1px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.2);
    margin: 0 0.25rem;
    align-self: center;
}

/* Custom scalebar positioning */
.openseadragon-container .scalebar {
    top: 65px !important;
    left: 16px !important;
    bottom: auto !important;
    right: auto !important;
}

/* When sidebar is collapsed, adjust scalebar to match toolbar offset */
.sidebar.collapsed ~ .viewer-container .openseadragon-container .scalebar {
    left: 76px !important; /* 16px base + 60px offset to match toolbar */
}

/* Loading Indicator */
.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 1.2rem;
    z-index: 50;
}

/* Tablet Responsive (iPad and similar) */
@media (min-width: 769px) and (max-width: 1024px) {
    .label-overlay {
        max-width: 80px !important;
        max-height: 80px !important;
        top: auto !important;
        bottom: 1rem !important;
        right: 1rem !important;
        z-index: 100 !important;
    }
    
    .viewer-controls {
        flex-wrap: wrap;
        max-width: calc(100vw - 2rem);
    }
    
    .control-btn {
        width: 36px;
        height: 36px;
    }
    
    .copyright-footer p {
        font-size: 0.55rem !important;
    }
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .header {
        padding: 0.5rem;
    }

    .header-logo {
        height: 30px;
    }

    .header-right {
        font-size: 0.8rem;
        gap: 0.5rem;
    }

    .sidebar {
        position: fixed;
        height: calc(100vh - 60px); /* Account for header height */
        top: 60px; /* Position below header */
        left: 0;
        z-index: 200;
        box-shadow: 2px 0 8px rgba(0,0,0,0.2);
    }

    .sidebar.collapsed {
        margin-left: -100%;
    }

    .sidebar.collapsed ~ .viewer-container .toggle-sidebar {
        display: flex;
    }

    .toggle-sidebar {
        background: #002347;
        color: white;
        top: 0.5rem;
        opacity: 0.9;
    }
    
    .toggle-sidebar:hover {
        opacity: 1;
    }

    .sidebar.collapsed ~ .viewer-container .viewer-controls {
        margin-left: 56px; /* Adjust for mobile */
    }

    .label-overlay {
        position: absolute !important;
        max-width: 60px !important;
        max-height: 60px !important;
        bottom: 1rem !important;
        right: 0.5rem !important;
        top: auto !important; /* Override the top positioning */
        z-index: 100 !important;
    }

    .viewer-controls {
        top: 0.5rem;
        left: 0.5rem;
        max-width: calc(100vw - 1rem);
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
        scrollbar-color: rgba(0, 35, 71, 0.3) transparent;
        padding-bottom: 0.25rem;
        padding-right: 2rem; /* Add padding to ensure last button is accessible */
    }
    
    /* Show scrollbar on mobile for better UX */
    .viewer-controls::-webkit-scrollbar {
        height: 4px;
    }
    
    .viewer-controls::-webkit-scrollbar-track {
        background: rgba(0, 0, 0, 0.1);
        border-radius: 2px;
    }
    
    .viewer-controls::-webkit-scrollbar-thumb {
        background: rgba(0, 35, 71, 0.5);
        border-radius: 2px;
    }
    
    /* Add fade indicators for scrollable content */
    .viewer-controls::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 20px;
        background: linear-gradient(to right, transparent, rgba(250, 250, 250, 0.8));
        pointer-events: none;
        display: none; /* Hide when scrolled to end */
    }
    
    /* Show fade when not scrolled to end */
    .viewer-controls:not(:hover) {
        scrollbar-width: none;
    }
    
    .viewer-controls:not(:hover)::-webkit-scrollbar {
        display: none;
    }

    .control-btn {
        width: 36px;
        height: 36px;
        flex-shrink: 0;
    }

    .control-btn i {
        font-size: 1rem;
    }

    /* Ensure proper spacing after last button */
    .control-btn:last-child {
        margin-right: 1rem;
    }
    .openseadragon-container .scalebar {
        top: 100px !important;
        left: 8px !important;
    }
    
    .copyright-footer {
        bottom: 0.25rem !important;
        left: 0.25rem !important;
    }
    
    .copyright-footer p {
        font-size: 0.5rem !important; /* Smaller font on mobile */
        line-height: 1.2 !important; /* Tighter line height */
    }
}

/* Fullscreen Mode */
.fullscreen .header {
    display: none;
}

.fullscreen .sidebar {
    display: none;
}

.fullscreen .toggle-sidebar {
    display: none !important;
}

.fullscreen .viewer-controls {
    margin-left: 0 !important;
    left: 16px !important;
}

/* Ensure scalebar aligns with toolbar in fullscreen */
.fullscreen .openseadragon-container .scalebar {
    left: 16px !important;
}

/* Ensure label overlay maintains proper z-index */
.label-overlay {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 150; /* Increased to be above all controls */
    opacity: 0.3;
    transition: opacity 0.2s;
    max-width: 120px;
    max-height: 120px;
    pointer-events: auto;
}

/* Ensure annotation canvas doesn't block label */
#annotationOverlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

#annotationOverlay.drawing {
    pointer-events: auto;
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 512 512"><path fill="black" d="M362.7 19.3L314.3 67.7 444.3 197.7l48.4-48.4c25-25 25-65.5 0-90.5L453.3 19.3c-25-25-65.5-25-90.5 0zM292 90L120.1 261.9c-4.1 4.1-7 9.2-8.4 14.9L64 427.7c-3.7 15.2 9.5 28.4 24.7 24.7l150.9-47.7c5.7-1.4 10.8-4.3 14.9-8.4L426.4 224.6 292 90z"/></svg>') 0 16, crosshair;
}

#annotationOverlay.erasing {
    pointer-events: auto;
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="white" stroke="black" stroke-width="2"><path d="M20 20H7L2 15l5-5 7 7-2 3z"/><path d="M13 13l7-7"/></svg>') 10 10, crosshair;
}

#annotationOverlay.pinning {
    pointer-events: auto;
    cursor: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="%23F8991D" stroke="white" stroke-width="1"><path d="M12 2C8 2 5 5 5 9c0 5.5 7 13 7 13s7-7.5 7-13c0-4-3-7-7-7z"/><circle cx="12" cy="9" r="3" fill="white"/></svg>') 10 20, pointer;
}

#annotationOverlay.texting {
    pointer-events: auto;
    cursor: text;
}

#annotationOverlay.measuring {
    pointer-events: auto;
    cursor: crosshair;
}

#annotationOverlay.rectangling {
    pointer-events: auto;
    cursor: crosshair;
}

/* Measurement styles */
.measurement-line {
    position: absolute;
    background: #F8991D;
    height: 2px;
    transform-origin: left center;
    pointer-events: none;
    z-index: 55;
}

.measurement-label {
    position: absolute;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid #F8991D;
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
    border-radius: 4px;
    z-index: 60;
    pointer-events: auto;
    cursor: pointer;
    user-select: none;
}

.measurement-label .delete-btn {
    margin-left: 0.5rem;
    color: #F8991D;
    cursor: pointer;
}

.measurement-label .delete-btn:hover {
    color: #002347;
}

/* Rectangle annotation styles */
.annotation-rectangle {
    position: absolute;
    border: 2px solid;
    pointer-events: auto;
    cursor: move;
    z-index: 55;
}

.annotation-rectangle.other-user {
    border-color: #616161 !important;
    background: rgba(97, 97, 97, 0.1) !important;
}

.annotation-rectangle .resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    border: 1px solid white;
    background: inherit;
    border-color: inherit;
}

.annotation-rectangle.other-user .resize-handle {
    background: #616161 !important;
}

.annotation-rectangle .resize-handle.nw { top: -4px; left: -4px; cursor: nw-resize; }
.annotation-rectangle .resize-handle.ne { top: -4px; right: -4px; cursor: ne-resize; }
.annotation-rectangle .resize-handle.sw { bottom: -4px; left: -4px; cursor: sw-resize; }
.annotation-rectangle .resize-handle.se { bottom: -4px; right: -4px; cursor: se-resize; }

.annotation-rectangle .delete-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    width: 20px;
    height: 20px;
    background: #F8991D;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    z-index: 61;
}

.annotation-rectangle.other-user .delete-btn {
    background: #616161 !important;
}

.annotation-rectangle:hover .delete-btn {
    display: flex;
}

/* Notification styles */
.notification {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 1000;
    max-width: 400px;
    text-align: center;
}

.notification h3 {
    margin: 0 0 1rem 0;
    color: #d32f2f;
}

.notification p {
    margin: 0 0 1.5rem 0;
    color: #666;
}

.notification button {
    background: #002347;
    color: white;
    border: none;
    padding: 0.5rem 2rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
}

.notification button:hover {
    background: #F8991D;
}

.overlay-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* File list scrollbar */
.file-list::-webkit-scrollbar {
    width: 6px;
}

.file-list::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.file-list::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.file-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Annotation pins and text */
.annotation-pin {
    position: absolute;
    width: 24px;
    height: 24px;
    background: #F8991D;
    border: 2px solid white;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    cursor: pointer;
    z-index: 60;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    margin-left: -12px;
    margin-top: -24px;
}

.annotation-pin:hover {
    transform: rotate(-45deg) scale(1.1);
}

.annotation-text {
    position: absolute;
    background: rgba(255, 255, 255, 0.75);
    border: 2px solid #002347;
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 0.9rem;
    z-index: 60;
    max-width: 200px;
    word-wrap: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    cursor: move;
    transition: background-color 0.2s ease;
    user-select: none;
}

.annotation-text:hover {
    background: rgba(255, 255, 255, 1);
}

.annotation-text.dragging {
    opacity: 0.8;
    cursor: grabbing;
}

.annotation-text .username-label {
    font-size: 0.75rem;
    color: #616161;
    font-style: italic;
    margin-bottom: 0.25rem;
    display: block;
}

.annotation-text.other-user {
    border-color: #616161;
}

.annotation-pin.other-user {
    background: #616161;
}

.annotation-text .delete-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 20px;
    height: 20px;
    background: #F8991D;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.annotation-text:hover .delete-btn {
    display: flex;
}

/* Text input modal */
.text-input-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 1001;
    min-width: 300px;
}

.text-input-modal h3 {
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
}

.text-input-modal textarea {
    width: 100%;
    min-height: 80px;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.9rem;
    resize: vertical;
}

.text-input-modal .modal-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.text-input-modal button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.text-input-modal .cancel-btn {
    background: #f5f5f5;
    color: #333;
}

.text-input-modal .save-btn {
    background: #002347;
    color: white;
}

.text-input-modal button:hover {
    opacity: 0.9;
}

/* Save status indicator */
.save-status {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 100;
}

.save-status.show {
    opacity: 1;
}

.save-status.success {
    background: rgba(0, 35, 71, 0.9);
}

.save-status.error {
    background: rgba(248, 153, 29, 0.9);
}

/* Color picker for annotations */
.annotation-colors {
    position: absolute;
    top: 60px;
    left: 1rem;
    background: rgba(255, 255, 255, 0.95);
    padding: 0.5rem;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    display: none;
    flex-direction: row;
    gap: 0.5rem;
    z-index: 101;
    align-items: center;
}

.annotation-colors.show {
    display: flex;
}

.color-option {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: #333;
    transform: scale(1.2);
}

.fill-toggle-btn {
    width: 32px;
    height: 32px;
    background: white;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 16px;
    color: #666;
    flex-shrink: 0;
}

.fill-toggle-btn:hover {
    background: #f5f5f5;
    border-color: #999;
    transform: scale(1.05);
}

.fill-toggle-btn.active {
    background: #002347;
    color: white;
    border-color: #002347;
}

/* Custom confirm modal */
.confirm-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    z-index: 1001;
    min-width: 300px;
    text-align: center;
}

.confirm-modal h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: #333;
}

.confirm-modal .modal-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.confirm-modal button {
    padding: 0.5rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 80px;
}

.confirm-modal .cancel-btn {
    background: #f5f5f5;
    color: #333;
}

.confirm-modal .confirm-btn {
    background: #F8991D;
    color: white;
}

.confirm-modal button:hover {
    opacity: 0.9;
}

.about_orange {
    color: #F8991D;
}

/* Copyright Footer */
.copyright-footer {
    position: absolute;
    bottom: 0.5rem;
    left: 0.5rem;
    z-index: 90;
    opacity: 0.4;
    transition: opacity 0.2s;
    pointer-events: auto;
}

.copyright-footer:hover {
    opacity: 0.8;
}

.copyright-footer p {
    margin: 0;
    font-size: 0.65rem;
    color: #616161;
}

.copyright-footer a {
    color: #616161;
    text-decoration: none;
}

.copyright-footer a:hover {
    color: #002347;
    text-decoration: underline;
}

/* Hide copyright in fullscreen */
.fullscreen .copyright-footer {
    display: none;
}