body {
    margin: 0;
    font-family: sans-serif;
    overflow: hidden;
}

#container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow-x: auto;
    overflow-y: hidden;
}

#image-wrapper {
    position: relative;
    flex-shrink: 0;
    height: 100vh;
    overflow: visible;
}

#main-image {
    height: 100vh;
    width: auto;
    min-width: auto;
    display: block;
    object-fit: contain;
    transform-origin: top left;
    cursor: grab;
    background-color: transparent;
}

#main-image:active {
    cursor: grabbing;
}

body.annotations-active #image-wrapper {
}

#tooltip-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    pointer-events: none;
}

.marker {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: pointer;
    opacity: 0.8;
    z-index: 1;
    transform: translate(-50%, -50%);
    border: 2px solid;
    transition: all 0.2s ease;
    pointer-events: auto;
}

.tooltip-box {
    position: absolute;
    background: rgba(30, 30, 30, 0.95);
    color: white;
    padding: 10px;
    border-radius: 6px;
    font-size: clamp(11px, 2vw, 14px);
    min-width: 320px;
    max-width: 500px;
    white-space: pre-wrap;
    text-align: left;
    pointer-events: auto;
    transform: translate(-50%, 0);
    display: none;
}

.tooltip-box a {
    color: #4fc3f7;
    text-decoration: underline;
}

#annotation-list {
    width: 500px;
    height: 100vh;
    overflow-x: scroll;
    overflow-y: hidden;
    padding: 20px;
    column-width: 260px;
    column-gap: 32px;
    column-fill: auto;
    flex-shrink: 0;
}

.annotation-item {
    margin-bottom: 12px;
    font-size: 14px;
    padding: 8px;
    border-radius: 6px;
    break-inside: avoid;
}

.annotation-item:nth-child(even) {
    background: #f9f9f9;
}

.annotation-item:nth-child(odd) {
    background: #fff;
}

.annotation-separator {
    display: flex;
    align-items: center;
    margin: 24px 0 12px;
    font-weight: bold;
    color: #555;
    white-space: nowrap;
    break-inside: avoid;
}

.annotation-separator::before,
.annotation-separator::after {
    content: "";
    flex: 1;
    border-top: 1px solid #ccc;
    margin: 0 8px;
}

.annotation-separator span {
    white-space: nowrap;
}

.hidden-markers .marker {
    display: none !important;
}

.numbered .marker::before {
    content: attr(data-index);
    position: relative;
    z-index: 1;
}

.footer-link {
    position: fixed;
    bottom: 10px;
    left: 10px;
    font-size: 12px;
    color: #888;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
    z-index: 10000;
    pointer-events: auto;
}

.footer-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.user-annotations-row {
    display: flex;
    align-items: center;
    gap: 0;
}

.footer-control {
    font-size: 12px;
    color: #4fc3f7;
    cursor: pointer;
    padding: 4px 0 4px 24px;
    position: relative;
    display: inline-block;
    user-select: none;
    transition: color 0.2s;
}

.footer-control::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border: 1px solid #4fc3f7;
    border-radius: 2px;
    background: transparent;
    transition: all 0.2s;
    box-sizing: border-box;
}

.footer-control.active::before {
    background: #0af;
    border-color: #0af;
}

.footer-control.active::after {
    content: "✔";
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: #000;
    pointer-events: none;
}

.footer-control:hover {
    color: #0af;
}

.user-annotations-btn {
    font-size: 12px;
    background: #4fc3f7;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 12px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    transition: background-color 0.2s;
}

.user-annotations-btn:hover {
    background: #29b6f6;
}

.exit-edit-mode-btn {
    font-size: 10px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 3px;
    padding: 3px 6px;
    cursor: pointer;
    font-family: inherit;
    font-weight: normal;
    transition: background-color 0.2s;
    margin-left: 4px;
    white-space: nowrap;
    vertical-align: middle;
}

.exit-edit-mode-btn:hover {
    background: #d32f2f;
}

.footer-link a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: #4fc3f7;
}

.footer-link a:hover {
    text-decoration: underline;
}

.footer-link svg {
    vertical-align: middle;
}

.footer-meta {
    color: #999;
}

.footer-meta .version {
    font-weight: bold;
    color: #ccc;
}

.footer-github {
    font-size: 12px;
    color: #4fc3f7;
    display: flex;
    gap: 4px;
    align-items: center;
}

.footer-github a {
    color: #4fc3f7;
    text-decoration: none;
}

.footer-github a:hover {
    text-decoration: underline;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .footer-buttons {
        display: none;
    }

    #container {
        display: block;
        height: 100vh;
        width: 100vw;
        overflow: hidden;
    }

    #image-wrapper {
        width: 100vw;
        height: 100vh;
        overflow-x: auto;
        overflow-y: hidden;
        touch-action: pan-x pan-y;
        flex-shrink: 0;
    }

    #main-image {
        height: 100vh;
        width: auto;
        min-width: auto;
        display: block;
        object-fit: contain;
        transform-origin: top left;
        cursor: grab;
        background-color: transparent;
    }

    #main-image:active {
        cursor: grabbing;
    }

    .tooltip-box {
        font-size: 11px;
        min-width: 240px;
        max-width: 85vw;
        padding: 8px;
        width: auto;
    }
}

/* User Annotations Styles */
.user-annotation-marker {
    transform: scale(2) translate(-25%, -25%); /* 2x larger and adjusted centering */
    font-size: 12px !important;
    min-width: 20px;
    min-height: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.user-annotation-ghost {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.user-annotation-tooltip {
    font-size: 14px;
    background: rgba(20, 20, 20, 0.95) !important;
    border: 1px solid #444;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.modal-content {
    background: white;
    border-radius: 8px;
    max-width: min(800px, 90vw);
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    position: relative;
    width: 100%;
    left: 50%;
    transform: translateX(-50%);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 10px;
    border-bottom: 1px solid #eee;
}

.modal-header h3 {
    margin: 0;
    color: #333;
}

.close-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s;
}

.close-button:hover {
    background-color: #f0f0f0;
}

.modal-body {
    padding: 20px;
    min-width: 400px;
}

/* Responsive visibility */
.desktop-only {
    display: block;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none !important;
    }
}

/* Add Annotation Form */
.add-annotation-form {
    margin-bottom: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.add-annotation-form h4 {
    margin: 0 0 15px 0;
    color: #333;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
}

.form-row .form-group {
    flex: 1;
}

.selector-row {
    align-items: flex-end;
    gap: 15px;
}

.type-selector-group {
    max-width: 300px;
}

.type-selector {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 5px;
}

.type-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    background: white;
}

.type-btn:hover {
    border-color: #333;
    transform: scale(1.1);
}

.type-btn.active {
    border-color: #333;
    border-width: 3px;
    transform: scale(1.1);
}

.type-btn.active::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 14px;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

.type-selection {
    display: flex;
    align-items: center;
    gap: 10px;
}

.type-selection select {
    flex: 1;
}

.type-preview-marker {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #ddd;
    background: #f5f5f5;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

/* Mode selector styles */
.mode-selector-group {
    max-width: 180px;
}

.mode-selector {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.mode-btn {
    width: 80px;
    height: 60px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 8px 4px;
    font-size: 11px;
    color: #666;
}

.mode-btn:hover {
    border-color: #4fc3f7;
    background: #f8fffe;
    color: #4fc3f7;
}

.mode-btn.active {
    border-color: #4fc3f7;
    background: #e3f2fd;
    color: #4fc3f7;
}

.mode-icon {
    width: 20px;
    height: 20px;
    margin-bottom: 4px;
    border: 2px solid #666;
    transition: border-color 0.2s ease;
}

.point-icon {
    border-radius: 50%;
    background: #666;
}

.area-icon {
    border-radius: 2px;
}

.mode-btn.active .mode-icon {
    border-color: #4fc3f7;
}

.mode-btn.active .point-icon {
    background: #4fc3f7;
}

.mode-btn:hover .mode-icon {
    border-color: #4fc3f7;
}

.mode-btn:hover .point-icon {
    background: #4fc3f7;
}

/* Shape selector styles */
.shape-selector-group {
    max-width: 120px;
}

.shape-selector {
    display: flex;
    gap: 8px;
    margin-top: 5px;
}

.shape-btn {
    width: 50px;
    height: 50px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0;
}

.shape-btn:hover {
    border-color: #4fc3f7;
    background: #f8fffe;
}

.shape-btn.active {
    border-color: #4fc3f7;
    background: #e3f2fd;
}

.shape-icon {
    width: 24px;
    height: 24px;
    border: 2px solid #666;
    transition: border-color 0.2s ease;
}

.rectangle-icon {
    border-radius: 2px;
}

.circle-icon {
    border-radius: 50%;
}

.shape-btn.active .shape-icon {
    border-color: #4fc3f7;
}

.shape-btn:hover .shape-icon {
    border-color: #4fc3f7;
}

#place-annotation-btn {
    padding: 12px 24px;
    background: #4fc3f7;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

#place-annotation-btn:hover:not(:disabled) {
    background: #29b6f6;
}

#place-annotation-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.annotation-help {
    color: #666;
    font-size: 11px;
    margin-top: 3px;
}


/* User Annotations List */
.user-annotations-list {
    margin-bottom: 20px;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap;
    gap: 10px;
}

.list-header h4 {
    margin: 0;
    color: #333;
}

.edit-mode-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    user-select: none;
}

.edit-mode-toggle input[type="checkbox"] {
    display: none;
}

.edit-mode-toggle .checkmark {
    position: relative;
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-radius: 3px;
    background: white;
    transition: all 0.2s;
}

.edit-mode-toggle input[type="checkbox"]:checked + .checkmark {
    background: #4fc3f7;
    border-color: #4fc3f7;
}

.edit-mode-toggle input[type="checkbox"]:checked + .checkmark::after {
    content: '✓';
    position: absolute;
    top: -1px;
    left: 2px;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

.user-annotation-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    margin-bottom: 8px;
    overflow: hidden;
}

.annotation-item-row {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 12px;
}

.type-indicator {
    width: 16px;
    height: 16px;
    border: 2px solid;
    flex-shrink: 0;
}

.annotation-info {
    flex: 1;
    min-width: 0;
}

.annotation-title {
    display: block;
    font-weight: bold;
    color: #333;
    font-size: 14px;
    line-height: 1.2;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.annotation-meta {
    display: block;
    font-size: 11px;
    color: #666;
    line-height: 1;
}

.annotation-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.action-btn {
    width: 28px;
    height: 28px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.2s;
    padding: 0;
}

.action-btn:hover {
    background: #f5f5f5;
    border-color: #999;
}

.type-badge {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.annotation-item-title {
    color: #333;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 8px;
    flex: 1;
}

.annotation-item-actions {
    display: flex;
    gap: 8px;
}

.edit-btn, .delete-btn {
    padding: 4px 8px;
    font-size: 12px;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.edit-btn {
    background: #e3f2fd;
    color: #1976d2;
}

.edit-btn:hover {
    background: #bbdefb;
}

.delete-btn {
    background: #ffebee;
    color: #d32f2f;
}

.delete-btn:hover {
    background: #ffcdd2;
}

/* Modal Actions */
.modal-actions {
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-actions button {
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

#share-url-btn {
    background: #4caf50;
    color: white;
}

#share-url-btn:hover {
    background: #45a049;
}

.danger-btn {
    background: #f44336;
    color: white;
}

.danger-btn:hover {
    background: #da190b;
}

/* Form Styles */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    color: #333;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}

.form-group textarea {
    resize: vertical;
    font-family: 'Courier New', monospace;
    line-height: 1.4;
}

.char-count {
    display: block;
    text-align: right;
    color: #666;
    font-size: 12px;
    margin-top: 3px;
}

.description-preview {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f9f9f9;
    min-height: 40px;
    font-size: 14px;
    line-height: 1.4;
    white-space: pre-wrap;
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

.form-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s;
}

.form-actions button[type="submit"] {
    background: #4fc3f7;
    color: white;
}

.form-actions button[type="submit"]:hover {
    background: #29b6f6;
}

.form-actions button[type="button"] {
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

.form-actions button[type="button"]:hover {
    background: #e0e0e0;
}

/* Area annotation styles */
.area-annotation {
    position: absolute;
    background: transparent;
    box-sizing: border-box;
    cursor: pointer;
    transition: border-width 0.2s ease;
    pointer-events: auto;
}

.area-annotation.rectangle {
    border-radius: 4px;
}

.area-annotation.circle {
    border-radius: 50%;
}

.area-annotation:hover {
    filter: brightness(1.1);
}

.area-annotation.edit-mode {
    cursor: move;
}

.area-annotation.edit-mode .resize-handle {
    display: block;
}

.resize-handle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fff;
    border: 2px solid;
    border-radius: 50%;
    display: none;
    cursor: nw-resize;
}

.resize-handle.se {
    bottom: -4px;
    right: -4px;
}

.resize-handle.sw {
    bottom: -4px;
    left: -4px;
    cursor: sw-resize;
}

.resize-handle.ne {
    top: -4px;
    right: -4px;
    cursor: ne-resize;
}

.resize-handle.nw {
    top: -4px;
    left: -4px;
}

/* Mobile optimizations for modals */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: calc(100vh - 20px);
    }
    
    .modal-body {
        min-width: auto;
        padding: 15px;
    }
    
    .form-row {
        flex-direction: column;
        gap: 15px;
    }
    
    .type-preview-group {
        max-width: none;
    }
    
    .size-controls {
        flex-direction: column;
        gap: 10px;
        align-items: flex-start;
    }
    
    .modal-actions {
        flex-direction: column;
    }
    
    .modal-actions button {
        width: 100%;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .form-actions button {
        width: 100%;
    }
    
    .annotation-item-actions {
        flex-direction: column;
        gap: 5px;
    }
    
    .edit-btn, .delete-btn {
        width: 100%;
        padding: 8px;
    }
}