.color-select-mobile {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
}

.mobile-stroke-select {
    background: #202124;
    color: #e8eaed;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.mobile-stroke-select:focus {
    border-color: #1a73e8;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #525659;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Thumbnail Sidebar */
.thumbnail-sidebar {
    position: fixed;
    left: -250px;
    top: max(48px, calc(env(safe-area-inset-top) + 48px));
    bottom: max(24px, env(safe-area-inset-bottom));
    width: 250px;
    background: #323639;
    box-shadow: 2px 0 8px rgba(0,0,0,0.3);
    z-index: 100;
    transition: left 0.3s ease;
    display: flex;
    flex-direction: column;
}

.thumbnail-sidebar.open {
    left: 0;
}

.thumbnail-header {
    padding: 12px 16px;
    background: #202124;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.thumbnail-header span {
    color: #e8eaed;
    font-size: 14px;
    font-weight: 500;
}

.thumbnail-header button {
    background: transparent;
    border: none;
    color: #e8eaed;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.thumbnail-header button:hover {
    background: rgba(255,255,255,0.1);
}

.thumbnail-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.thumbnail-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    transition: all 0.2s;
    background: #202124;
    padding: 8px;
    position: relative;
}

.thumbnail-item:hover {
    border-color: rgba(138, 180, 248, 0.5);
}

.thumbnail-item.active {
    border-color: #8ab4f8;
    box-shadow: 0 0 0 2px rgba(138, 180, 248, 0.3);
}

.thumbnail-item canvas {
    width: 100%;
    display: block;
    border-radius: 2px;
}

.thumbnail-page-number {
    text-align: center;
    color: #e8eaed;
    font-size: 12px;
    margin-top: 4px;
}

.thumbnail-container::-webkit-scrollbar {
    width: 8px;
}

.thumbnail-container::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.05);
}

.thumbnail-container::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

.thumbnail-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}

.toolbar {
    background: #323639;
    padding: 8px 16px;
    padding-top: max(8px, env(safe-area-inset-top));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    position: sticky;
    top: 0;
    z-index: 10000;
    min-height: 48px;
}



.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-group-left {
    justify-content: flex-start;
}

.toolbar-group-center {
    justify-content: center;
    margin: 0 auto;
}

.toolbar-group-right {
    justify-content: flex-end;
    margin-left: auto;
}

.toolbar::-webkit-scrollbar {
    height: 4px;
}

.toolbar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
}

.toolbar button {
    background: transparent;
    border: none;
    color: #e8eaed;
    padding: 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    font-size: 20px;
    font-weight: 300;
    outline: none;
}

.toolbar button:focus {
    outline: none;
}

.toolbar button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
}

.toolbar button:active,
.toolbar button.active {
    background: rgba(255,255,255,0.2);
}

.toolbar button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,0.2);
    margin: 0 4px;
}

.page-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#pageInput {
    background: #202124;
    color: #e8eaed;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 4px 8px;
    width: 50px;
    text-align: center;
    font-size: 13px;
    outline: none;
}

#pageInput:focus {
    border-color: #8ab4f8;
    background: #292b2e;
}

#pageTotal {
    color: #e8eaed;
    font-size: 13px;
}

#pageInfo,
#zoomLevel {
    color: #e8eaed;
    font-size: 13px;
    min-width: 50px;
    text-align: center;
}

#viewer {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    padding: 20px;
    touch-action: pan-x pan-y pinch-zoom;
    transition: margin-left 0.3s ease;
}

#viewer.sidebar-open {
    margin-left: 250px;
}

#dropzone {
    position: fixed;
    inset: 48px 0 24px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
    pointer-events: none;
}

#dropzone.hidden {
    display: none;
}

.dropzone-content {
    text-align: center;
    color: #e8eaed;
    pointer-events: auto;
}

.dropzone-content svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.dropzone-content p {
    margin: 16px 0;
    font-size: 14px;
    opacity: 0.8;
}

.dropzone-content button {
    background: #8ab4f8;
    color: #202124;
    border: none;
    padding: 10px 24px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.dropzone-content button:hover {
    background: #aecbfa;
}

#canvasContainer {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: none;
}

#canvasContainer.has-pdf {
    display: flex;
}

.page-wrapper {
    position: relative;
    display: inline-block;
    box-shadow: 0 2px 8px rgba(0,0,0,0.5);
    line-height: 0;
    overflow: visible;
    background: white;
}

.page-canvas {
    display: block;
}

.page-form-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 10;
    pointer-events: auto;
}

.page-annotation-canvas {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 20;
    pointer-events: none;
}

.page-annotation-canvas.text-mode {
    pointer-events: auto;
    cursor: text;
}

.page-annotation-canvas.draw-mode {
    pointer-events: auto;
    cursor: crosshair;
}

.page-annotation-canvas.rectangle-mode {
    pointer-events: auto;
    cursor: crosshair;
}

.page-annotation-canvas.oval-mode {
    pointer-events: auto;
    cursor: crosshair;
}

.page-annotation-canvas.arrow-mode {
    pointer-events: auto;
    cursor: crosshair;
}

.page-annotation-canvas.has-selection {
    pointer-events: auto;
}

#formCanvas {
    z-index: 10;
    pointer-events: auto;
}

#annotationCanvas {
    z-index: 20;
    /* Standard: Events durchreichen an darunterliegende Layer */
    pointer-events: none;
}

/* Im aktiven Tool-Modus: Volle Interaktion nötig */
#annotationCanvas.text-mode,
#annotationCanvas.draw-mode,
#annotationCanvas.rectangle-mode,
#annotationCanvas.oval-mode,
#annotationCanvas.arrow-mode {
    pointer-events: auto;
}

/* Bei Selektion: Volle Interaktion zum Verschieben */
#annotationCanvas.has-selection {
    pointer-events: auto;
}

/* Wenn Annotationen existieren aber keine ausgewählt:
   pointer-events bleiben aus, damit Formularfelder klickbar sind.
   Annotationen werden über formCanvas-Handler angeklickt */

#annotationCanvas.text-mode {
    cursor: text;
}

#annotationCanvas.draw-mode,
#annotationCanvas.rectangle-mode,
#annotationCanvas.oval-mode,
#annotationCanvas.arrow-mode {
    cursor: crosshair;
}

#statusBar {
    background: #323639;
    padding: 4px 16px;
    color: #e8eaed;
    font-size: 12px;
    border-top: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

#statusText {
    opacity: 0.8;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background: #323639;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    min-width: 400px;
}

.modal-content h3 {
    color: #e8eaed;
    margin-bottom: 16px;
    font-size: 16px;
    font-weight: 500;
}

#signatureCanvas {
    background: white;
    border: 1px solid #5f6368;
    border-radius: 4px;
    cursor: crosshair;
    display: block;
    width: 100%;
}

.modal-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}

.modal-buttons button {
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

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

#clearSignature {
    background: transparent;
    color: #e8eaed;
}

#clearSignature:hover {
    background: rgba(255,255,255,0.1);
}

#cancelSignature {
    background: transparent;
    color: #e8eaed;
    margin-left: auto;
}

#cancelSignature:hover {
    background: rgba(255,255,255,0.1);
}

#saveSignature {
    background: #8ab4f8;
    color: #202124;
    font-weight: 500;
}

#saveSignature:hover {
    background: #aecbfa;
}

.signature-item {
    user-select: none;
}

.signature-item:hover {
    transform: translateY(-1px);
}

#signatureListContainer::-webkit-scrollbar {
    width: 8px;
}

#signatureListContainer::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#signatureListContainer::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#signatureListContainer::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Loader */
.pdf-loader {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.pdf-loader.show {
    opacity: 1;
    pointer-events: auto;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top-color: #8ab4f8;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loader-text {
    color: #e8eaed;
    margin-top: 16px;
    font-size: 14px;
}

/* Color Picker */
.color-picker {
    position: relative;
    display: inline-block;
}

.color-btn {
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.color-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #000000;
    border: 2px solid #e8eaed;
    pointer-events: none;
}

.color-dropdown {
    display: none;
    visibility: hidden;
    position: fixed;
    margin-top: 4px;
    background: #323639;
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    z-index: 99999999;
    width: 200px;
    -webkit-tap-highlight-color: transparent;
}

@media (max-width: 768px) {
    .color-dropdown {
        width: 200px;
        padding: 10px;
        left: 50% !important;
        right: auto !important;
        top: auto !important;
        bottom: 80px !important;
        transform: translateX(-50%) !important;
        position: fixed !important;
    }
    
    .color-grid {
        gap: 6px;
    }
    
    .color-option {
        width: 29px;
        height: 29px;
    }
    
    .stroke-width-section {
        display: block !important;
        margin-top: 0;
    }
    
    .stroke-width-grid {
        gap: 6;
    }
    
    .stroke-width-option {
        width: 30px;
        height: 30px;
    }
}

.color-dropdown.show {
    display: block !important;
    visibility: visible !important;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.color-option {
    width: 29px;
    height: 29px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.color-option:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.color-option.selected {
    border-color: #8ab4f8;
    box-shadow: 0 0 0 2px rgba(138, 180, 248, 0.3);
}

.color-custom {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
}

.color-custom label {
    color: #e8eaed;
    font-size: 12px;
    flex: 0 0 100%;
    margin-bottom: 4px;
}

.color-custom input[type="color"] {
    width: 40px;
    height: 32px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
    flex-shrink: 0;
}

.color-custom button {
    transition: background 0.2s;
    flex-shrink: 0;
}

.color-custom button:hover {
    background: #2b7de9 !important;
}

.color-history {
    display: flex;
    gap: 4px;
    flex: 0 0 100%;
    margin-top: 4px;
    overflow: hidden;
}

.color-history-item {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    border: 2px solid rgba(255,255,255,0.2);
    cursor: pointer;
    transition: all 0.2s;
}

.color-history-item:hover {
    transform: scale(1.1);
    border-color: rgba(255,255,255,0.4);
}

/* Stroke Width Section */
.stroke-width-section {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding-top: 12px;
    margin-top: 0px;
}

.stroke-width-section label {
    color: #e8eaed;
    font-size: 12px;
    display: block;
    margin-bottom: 8px;
}

.stroke-width-grid {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.stroke-width-option {
    width: 30px;
    height: 30px;
    border-radius: 4px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    background: #202124;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.stroke-width-option:hover {
    transform: scale(1.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.stroke-width-option.selected {
    border-color: #8ab4f8;
    box-shadow: 0 0 0 2px rgba(138, 180, 248, 0.3);
}

.stroke-width-option svg {
    pointer-events: none;
}

/* Text Format Panel */
.text-format-panel,
.rectangle-format-panel,
.arrow-format-panel {
    position: fixed;
    background: #323639;
    border-radius: 8px;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(255,255,255,0.1);
}

.text-format-panel select {
    background: #202124;
    color: #e8eaed;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 6px 8px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.text-format-panel select:hover {
    background: #292b2e;
}

.format-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: #e8eaed;
    padding: 6px;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    width: 32px;
    height: 32px;
}

.format-btn:hover {
    background: rgba(255,255,255,0.1);
}

.format-btn.active {
    background: #1a73e8;
    border-color: #1a73e8;
}

.format-btn svg {
    pointer-events: none;
}

.opacity-control {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 8px;
    border-left: 1px solid rgba(255,255,255,0.2);
}

.opacity-control label {
    display: flex;
    align-items: center;
    color: #e8eaed;
}

.opacity-control input[type="range"] {
    width: 80px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255,255,255,0.2);
    outline: none;
    -webkit-appearance: none;
}

.opacity-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #1a73e8;
    cursor: pointer;
}

.opacity-control input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #1a73e8;
    cursor: pointer;
    border: none;
}

.opacity-control span {
    color: #e8eaed;
    font-size: 12px;
    min-width: 38px;
    text-align: right;
}

/* Hide mobile select on all devices */
.mobile-stroke-select {
    display: none !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    
    /* Toolbar scrollbar auf Mobile ausblenden */
    .toolbar::-webkit-scrollbar {
        display: none;
    }
    
    .toolbar {
        -ms-overflow-style: none;
        scrollbar-width: none;
    }
    .modal-content {
        min-width: unset !important;
        width: calc(100vw - 32px) !important;
        max-width: 500px !important;
        max-height: calc(100vh - 100px) !important;
        overflow-y: auto;
        padding: 16px !important;
    }
    
    /* Grid Layout auf Mobile überschreiben */
    #signatureModal .modal-content > div[style] {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
    }
    
    #signatureCanvas {
        height: 180px !important;
        width: 100% !important;
    }
    
    #signatureListContainer {
        max-height: 120px !important;
        width: 100% !important;
    }
    
    .modal-content h4 {
        font-size: 13px !important;
    }
    
    .modal-buttons {
        flex-wrap: wrap;
    }
    
    .modal-buttons button {
        flex: 1;
        min-width: 100px;
    }
    
    /* Text-Format-Panel auf Mobile */
    .text-format-panel,
    .rectangle-format-panel,
    .arrow-format-panel {
        left: 50% !important;
        top: auto !important;
        bottom: 80px !important;
        transform: translateX(-50%);
        width: calc(100vw - 32px);
        max-width: 400px;
        padding: 12px;
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .rectangle-format-panel .opacity-control {
        flex: 1 0 100%;
        margin-top: 8px;
        padding-left: 0;
        border-left: none;
        border-top: 1px solid rgba(255,255,255,0.2);
        padding-top: 8px;
        justify-content: center;
    }
    
    .opacity-control input[type="range"] {
        width: 120px !important;
    }
    
    .text-format-panel select {
        flex: 1;
        min-width: 120px;
        font-size: 14px;
        padding: 8px;
    }
    
    .format-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    
    .format-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Arrow Format Panel Spezifisch */
.arrow-format-panel {
    gap: 12px;
}

.arrow-format-panel label {
    display: flex;
    align-items: center;
    color: #e8eaed;
}

.arrow-format-panel select {
    background: #202124;
    color: #e8eaed;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    outline: none;
    min-width: 110px;
}

.arrow-format-panel select:hover {
    background: #292b2e;
}

.arrow-format-panel select:focus {
    border-color: #1a73e8;
}

#annotationCanvas.arrow-mode {
    pointer-events: auto;
    cursor: crosshair;
}
