* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--vscode-font-family, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    background: var(--vscode-editor-background);
    color: var(--vscode-editor-foreground);
    overflow: hidden;
}

.container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--vscode-editorWidget-background);
    border-bottom: 1px solid var(--vscode-widget-border);
    flex-shrink: 0;
}

.title {
    font-weight: 600;
    font-size: 14px;
}

.toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
}

.tool-btn {
    padding: 6px 12px;
    font-size: 12px;
    border: 1px solid var(--vscode-button-border, transparent);
    background: var(--vscode-button-secondaryBackground);
    color: var(--vscode-button-secondaryForeground);
    border-radius: 4px;
    cursor: pointer;
}

.tool-btn:hover {
    background: var(--vscode-button-secondaryHoverBackground);
}

.tool-btn.active {
    background: var(--vscode-button-background);
    color: var(--vscode-button-foreground);
}

.tool-btn.save-btn {
    background: var(--vscode-button-background);
    color: var(--vscode-button-foreground);
}

.tool-btn.save-btn:hover {
    background: var(--vscode-button-hoverBackground);
}

.page-info {
    font-size: 12px;
    color: var(--vscode-descriptionForeground);
    margin-left: 12px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px;
    background: var(--vscode-editorWidget-background);
    border-bottom: 1px solid var(--vscode-widget-border);
    flex-shrink: 0;
}

.icon-btn {
    width: 28px;
    height: 28px;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    border: 1px solid var(--vscode-button-border, transparent);
    background: var(--vscode-button-secondaryBackground);
    color: var(--vscode-button-secondaryForeground);
    border-radius: 4px;
    cursor: pointer;
}

.icon-btn:hover {
    background: var(--vscode-button-secondaryHoverBackground);
}

#zoomLevel {
    min-width: 48px;
    text-align: center;
    font-size: 12px;
}

.loading, .error {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    text-align: center;
}

.error {
    color: var(--vscode-errorForeground);
}

.pdf-body {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.thumbnail-sidebar {
    width: 100px;
    flex-shrink: 0;
    overflow-y: auto;
    border-right: 1px solid var(--vscode-widget-border);
    background: var(--vscode-editorWidget-background);
}

.thumbnail-list {
    padding: 8px;
}

.thumbnail-help {
    font-size: 10px;
    line-height: 1.35;
    color: var(--vscode-descriptionForeground);
    padding: 8px;
    border-bottom: 1px solid var(--vscode-widget-border);
}

.thumbnail-item {
    position: relative;
    margin-bottom: 8px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 2px;
    overflow: hidden;
    background: #fff;
}

.thumbnail-item:hover {
    border-color: var(--vscode-focusBorder);
}

.thumbnail-item.active {
    border-color: var(--vscode-focusBorder);
}

.thumbnail-item.dragging {
    opacity: 0.45;
}

.thumbnail-item.drop-target {
    border-color: var(--vscode-button-background);
    box-shadow: 0 0 0 1px var(--vscode-button-background) inset;
}

.thumbnail-item canvas {
    display: block;
    width: 100%;
    height: auto;
}

.thumbnail-delete-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 16px;
    height: 16px;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    line-height: 16px;
    cursor: pointer;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    padding: 0;
}

.thumbnail-delete-btn:hover {
    background: rgba(204, 0, 0, 0.85);
}

.thumbnail-item .page-num {
    font-size: 10px;
    text-align: center;
    padding: 2px 0;
    color: var(--vscode-descriptionForeground);
}

.pdf-container {
    flex: 1;
    overflow: auto;
    position: relative;
    padding: 20px;
    min-width: 0;
}

.pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.page-wrapper {
    position: relative;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    background: #fff;
}

.page-wrapper canvas {
    display: block;
    vertical-align: top;
}

.overlay-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.overlay-layer.editing {
    pointer-events: auto;
}

.annotation-text {
    position: absolute;
    padding: 0;
    font-size: 12px;
    color: #000;
    background: transparent;
    border: none;
    white-space: pre;
    cursor: move;
    pointer-events: auto;
}

.annotation-delete-btn {
    position: absolute;
    top: -9px;
    right: -9px;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 9px;
    background: rgba(170, 0, 0, 0.9);
    color: #fff;
    font-size: 12px;
    line-height: 18px;
    text-align: center;
    cursor: pointer;
    padding: 0;
    display: none;
}

.annotation-text.selected > .annotation-delete-btn,
.annotation-signature.selected > .annotation-delete-btn {
    display: block;
}

.annotation-signature {
    position: absolute;
    pointer-events: auto;
    cursor: move;
    border-radius: 4px;
}

.annotation-text.selected,
.annotation-signature.selected {
    outline: 2px dashed #2f80ed;
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.12);
}

.annotation-signature img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--vscode-editorWidget-background);
    border: 1px solid var(--vscode-widget-border);
    border-radius: 8px;
    padding: 20px;
    min-width: 280px;
}

.modal-content label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
}

.modal-content input {
    width: 100%;
    padding: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    background: var(--vscode-input-background);
    color: var(--vscode-input-foreground);
    border: 1px solid var(--vscode-input-border);
    border-radius: 4px;
}

.modal-inline-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.modal-inline-label input[type="color"] {
    width: 40px;
    height: 24px;
    border: 1px solid var(--vscode-widget-border);
    border-radius: 4px;
    background: transparent;
    padding: 0;
    cursor: pointer;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-hint {
    margin: -4px 0 12px;
    font-size: 12px;
    color: var(--vscode-descriptionForeground);
}

.modal-hint.error {
    color: var(--vscode-errorForeground);
}

.btn {
    padding: 6px 14px;
    font-size: 12px;
    border: 1px solid var(--vscode-button-border, transparent);
    background: var(--vscode-button-secondaryBackground);
    color: var(--vscode-button-secondaryForeground);
    border-radius: 4px;
    cursor: pointer;
}

.btn.primary {
    background: var(--vscode-button-background);
    color: var(--vscode-button-foreground);
}

.btn.primary:hover {
    background: var(--vscode-button-hoverBackground);
}

/* Signature modal – same layer as text modal, flat panel */
.signature-modal-content {
    border: 2px solid #333;
    background: #fff;
}

.signature-modal-label {
    display: block;
    margin-bottom: 8px;
    font-size: 12px;
    color: #000;
}

.signature-modal .modal-inline-label {
    color: #000;
}

.signature-canvas-modal {
    width: 320px;
    height: 140px;
    margin-bottom: 12px;
    border: 2px solid #333;
    background: #fff;
    cursor: crosshair;
}

.signature-canvas-modal .signature-canvas-el {
    display: block;
    width: 100%;
    height: 100%;
}
