/**
 * PDF Monster - Sign PDF Tool (Client-Side)
 * Standard 2-Spalten-Layout (tool-main + tool-sidebar)
 * Alle Klassen mit sign- Prefix um Konflikte zu vermeiden
 */

/* ===== PDF Viewer (in tool-main) ===== */
.sign-pdf-viewer {
    position: relative;
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: var(--gray-100, #f3f4f6);
    border-radius: 12px;
    border: 1px solid var(--gray-200, #e5e7eb);
}

.sign-pdf-page {
    position: relative;
    margin: 0 auto 16px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
    max-width: 100%;
    overflow: hidden;
}

.sign-pdf-page:last-child {
    margin-bottom: 0;
}

.sign-pdf-page canvas {
    display: block;
    max-width: 100%;
    height: auto !important;
}

.sign-page-label {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 5;
}

/* ===== Placed Signatures ===== */
.sign-placed {
    position: absolute;
    z-index: 10;
    cursor: move;
    border: 2px dashed transparent;
    transition: border-color 0.2s;
    touch-action: none;
}

.sign-placed:hover,
.sign-placed:active,
.sign-placed.sign-dragging {
    border-color: var(--primary-color, #e85d04);
}

.sign-placed img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
}

.sign-placed .sign-resize-handle {
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 24px;
    height: 24px;
    background: var(--primary-color, #e85d04);
    border: 2px solid #fff;
    border-radius: 4px;
    cursor: se-resize;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 11;
}

.sign-placed .sign-remove-btn {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 32px;
    height: 32px;
    background: #ef4444;
    color: #fff;
    border: 2px solid #fff;
    border-radius: 50%;
    font-size: 16px;
    line-height: 28px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 12;
}

.sign-placed:hover .sign-resize-handle,
.sign-placed:hover .sign-remove-btn,
.sign-placed.sign-dragging .sign-resize-handle {
    opacity: 1;
}

/* Touch devices: Always show controls */
@media (hover: none) and (pointer: coarse) {
    .sign-placed .sign-remove-btn,
    .sign-placed .sign-resize-handle {
        opacity: 1;
    }

    .sign-placed .sign-resize-handle {
        width: 28px;
        height: 28px;
        bottom: -8px;
        right: -8px;
    }

    .sign-placed .sign-remove-btn {
        width: 36px;
        height: 36px;
        top: -16px;
        right: -16px;
        font-size: 18px;
        line-height: 32px;
    }
}

/* ===== Sidebar: Current Signature Preview ===== */
.sign-current-preview {
    margin-top: 12px;
    padding: 12px;
    background: var(--gray-50, #f9fafb);
    border: 1px solid var(--gray-200, #e5e7eb);
    border-radius: 8px;
}

.sign-current-preview-label {
    font-size: 12px;
    color: var(--gray-500, #6b7280);
    margin-bottom: 8px;
}

.sign-current-preview-img {
    background: #fff;
    border: 1px dashed var(--gray-300, #d1d5db);
    border-radius: 6px;
    padding: 8px;
    text-align: center;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sign-current-preview-img img {
    max-width: 100%;
    max-height: 60px;
}

.sign-current-preview-hint {
    font-size: 12px;
    color: var(--primary-color, #e85d04);
    margin-top: 8px;
    text-align: center;
    font-weight: 600;
}

/* ===== Sidebar: Placed Signatures Info ===== */
.sign-placed-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sign-placed-count {
    font-size: 14px;
    color: var(--gray-600, #4b5563);
}

/* ===== Signature Modal ===== */
.sign-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.sign-modal-backdrop.sign-modal-open {
    display: flex;
}

.sign-modal {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: sign-modal-in 0.25s ease-out;
}

@keyframes sign-modal-in {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.sign-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--gray-200, #e5e7eb);
}

.sign-modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
}

.sign-modal-close {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--gray-100, #f3f4f6);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--gray-600, #4b5563);
    transition: background 0.2s;
    flex-shrink: 0;
}

.sign-modal-close:hover {
    background: var(--gray-200, #e5e7eb);
}

.sign-modal-body {
    padding: 20px 24px;
}

.sign-modal-footer {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--gray-200, #e5e7eb);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.sign-modal-footer .btn {
    min-height: 44px;
}

/* ===== Tabs ===== */
.sign-tabs {
    display: flex;
    gap: 4px;
    background: var(--gray-100, #f3f4f6);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
}

.sign-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600, #4b5563);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    min-height: 44px;
}

.sign-tab.active {
    background: #fff;
    color: var(--gray-900, #111827);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.sign-tab:hover:not(.active) {
    color: var(--gray-900, #111827);
}

.sign-panel {
    display: none;
}

.sign-panel.active {
    display: block;
}

/* ===== Draw Panel ===== */
.sign-canvas-wrapper {
    border: 2px dashed var(--gray-300, #d1d5db);
    border-radius: 12px;
    background: #fff;
    overflow: hidden;
    margin-bottom: 12px;
}

.sign-canvas-wrapper canvas {
    display: block;
    width: 100%;
    height: 180px;
    touch-action: none;
}

.sign-canvas-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
}

.sign-canvas-actions .btn {
    min-height: 44px;
}

.sign-color-picker {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}

.sign-color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
}

.sign-color-swatch:hover {
    transform: scale(1.1);
}

.sign-color-swatch.active {
    border-color: var(--gray-400, #9ca3af);
    box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--gray-400, #9ca3af);
}

/* ===== Type Panel ===== */
.sign-type-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--gray-200, #e5e7eb);
    border-radius: 10px;
    font-size: 16px;
    outline: none;
    transition: border-color 0.2s;
    margin-bottom: 16px;
    box-sizing: border-box;
    min-height: 44px;
}

.sign-type-input:focus {
    border-color: var(--primary-color, #e85d04);
}

.sign-type-preview {
    padding: 20px;
    border: 2px dashed var(--gray-300, #d1d5db);
    border-radius: 12px;
    text-align: center;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    background: #fff;
    overflow: hidden;
    word-break: break-word;
}

.sign-type-preview span {
    font-size: 36px;
    color: #000;
}

.sign-font-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.sign-font-option {
    padding: 12px;
    border: 2px solid var(--gray-200, #e5e7eb);
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-size: 18px;
    transition: all 0.2s;
    background: #fff;
    min-height: 44px;
}

.sign-font-option:hover {
    border-color: var(--gray-400, #9ca3af);
}

.sign-font-option.active {
    border-color: var(--primary-color, #e85d04);
    background: rgba(232, 93, 4, 0.05);
}

.sign-font-option .sign-font-name {
    font-size: 11px;
    color: var(--gray-500, #6b7280);
    margin-top: 4px;
    font-family: system-ui, sans-serif;
}

/* ===== Upload Panel ===== */
.sign-upload-zone {
    border: 2px dashed var(--gray-300, #d1d5db);
    border-radius: 12px;
    padding: 32px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--gray-50, #f9fafb);
    min-height: 100px;
}

.sign-upload-zone:hover {
    border-color: var(--primary-color, #e85d04);
    background: rgba(232, 93, 4, 0.03);
}

.sign-upload-zone p {
    margin: 0;
    color: var(--gray-600, #4b5563);
    font-size: 14px;
}

.sign-upload-zone p:first-child {
    font-weight: 600;
    margin-bottom: 4px;
}

.sign-upload-zone .sign-upload-preview {
    max-width: 100%;
    max-height: 100px;
    margin-top: 12px;
}

/* ===== Loading State ===== */
.sign-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 16px;
    color: var(--gray-500, #6b7280);
    gap: 12px;
}

.sign-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--gray-200, #e5e7eb);
    border-top-color: var(--primary-color, #e85d04);
    border-radius: 50%;
    animation: sign-spin 0.8s linear infinite;
}

@keyframes sign-spin {
    to { transform: rotate(360deg); }
}

/* ===== Keyboard Shortcut Hints (in sidebar) ===== */
.sign-shortcut-hints {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding-top: 4px;
}

.sign-shortcut-hint {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--gray-500, #6b7280);
    white-space: nowrap;
}

.sign-shortcut-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 11px;
    font-family: system-ui, -apple-system, sans-serif;
    font-weight: 600;
    line-height: 14px;
    color: var(--gray-700, #374151);
    background: #fff;
    border: 1px solid var(--gray-300, #d1d5db);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--gray-200, #e5e7eb);
}

/* ===== Responsive: Tablet ===== */
@media (max-width: 768px) {
    .sign-pdf-viewer {
        max-height: 55vh;
        border-radius: 8px;
        padding: 8px;
    }

    .sign-pdf-page {
        margin-bottom: 8px;
    }

    .sign-shortcut-hints {
        display: none !important;
    }

    .sign-modal {
        max-width: 100%;
        border-radius: 16px 16px 0 0;
        max-height: 92vh;
        margin: 0;
    }

    .sign-modal-backdrop {
        align-items: flex-end;
        padding: 0;
    }

    .sign-modal-body {
        padding: 16px;
    }

    .sign-modal-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 1;
    }

    .sign-modal-footer {
        padding: 12px 16px 16px;
        position: sticky;
        bottom: 0;
        background: #fff;
        z-index: 1;
    }

    .sign-modal-footer .btn {
        flex: 1;
        min-height: 48px;
    }

    .sign-font-options {
        grid-template-columns: 1fr;
    }

    .sign-canvas-wrapper canvas {
        height: 160px;
    }

    .sign-type-preview span {
        font-size: 28px;
    }
}

/* ===== Responsive: Small Phone ===== */
@media (max-width: 380px) {
    .sign-pdf-viewer {
        max-height: 50vh;
    }

    .sign-tabs {
        gap: 2px;
    }

    .sign-tab {
        padding: 10px 8px;
        font-size: 13px;
    }

    .sign-color-swatch {
        width: 32px;
        height: 32px;
    }
}

/* ===== Touch-friendly: Larger targets ===== */
@media (hover: none) and (pointer: coarse) {
    .sign-color-swatch {
        width: 44px;
        height: 44px;
    }

    .sign-color-picker {
        gap: 16px;
    }

    .sign-font-option {
        min-height: 56px;
        padding: 14px 12px;
    }

    .sign-upload-zone {
        padding: 40px 16px;
        min-height: 120px;
    }
}
