/* ====================================================
   RESET & BASE
   ==================================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f1f5f9;
    color: #1e293b;
}

/* ====================================================
   TOOL WRAPPER
   ==================================================== */
.tool-wrapper {
    max-width: 1440px;
    margin: 20px auto;
    padding: 0 16px;
}

/* ====================================================
   APP CONTAINER (أصبح شفافاً تماماً)
   ==================================================== */
.app-container {
    background: transparent;  /* تم إزالة الخلفية البيضاء */
    border-radius: 0;          /* تم إزالة التدوير */
    box-shadow: none;          /* تم إزالة الظل */
    overflow: hidden;
}


/* ====================================================
   EDITOR PANEL (المحرر - يحتفظ بالخلفية البيضاء والظل)
   ==================================================== */
.editor-panel {
    display: none;  /* يظهر بعد رفع الملف */
    flex-direction: column;
    height: 90vh;
    min-height: 600px;

    /* تم نقل الخلفية البيضاء والظل والحدود الدائرية إلى هنا */
    background: #ffffff;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.08);
    overflow: hidden;
}

/* ====================================================
   TOP TOOLBAR
   ==================================================== */
.top-toolbar {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.toolbar-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}
.tool-group {
    display: flex;
    align-items: center;
    gap: 2px;
}
.tool-divider {
    width: 1px;
    height: 28px;
    background: #d1d5db;
    margin: 0 6px;
}
.tool-btn {
    background: transparent;
    border: none;
    padding: 6px 10px;
    border-radius: 8px;
    color: #475569;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}
.tool-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}
.tool-btn.active {
    background: #dbeafe;
    color: #1d4ed8;
}
.tool-btn.primary {
    background: #3b82f6;
    color: #fff;
}
.tool-btn.primary:hover {
    background: #2563eb;
}
.tool-btn.delete {
    color: #ef4444;
}
.tool-btn.delete:hover {
    background: #fee2e2;
}
.zoom-value-display {
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    min-width: 48px;
    text-align: center;
}

/* ====================================================
   PROPERTY PANEL
   ==================================================== */
.property-panel {
    background: #ffffff;
    border-radius: 8px;
    padding: 6px 12px;
    min-height: 44px;
    border: 1px solid #e2e8f0;
    flex-wrap: wrap;
}
.property-placeholder {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}
.prop-group {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #334155;
}
.prop-group label {
    font-weight: 500;
    font-size: 12px;
    color: #64748b;
}
.prop-group input[type="color"] {
    width: 28px;
    height: 28px;
    border: none;
    padding: 0;
    cursor: pointer;
    border-radius: 4px;
}
.prop-group input[type="number"],
.prop-group input[type="text"],
.prop-group select {
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    background: #fff;
}
.prop-group input[type="range"] {
    width: 80px;
    height: 4px;
    accent-color: #3b82f6;
}
.prop-btn {
    background: #f1f5f9;
    border: none;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.prop-btn:hover {
    background: #e2e8f0;
}
.prop-btn.active {
    background: #dbeafe;
    color: #1d4ed8;
}
.prop-btn.primary {
    background: #3b82f6;
    color: #fff;
}
.prop-btn.primary:hover {
    background: #2563eb;
}
.prop-btn.delete {
    color: #ef4444;
}

/* ====================================================
   EDITOR BODY (Thumbnails + Canvas)
   ==================================================== */
.editor-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: #f1f5f9;
}

/* ========== THUMBNAILS SIDEBAR ========== */
.thumbs {
    width: 140px;
    min-width: 140px;
    background: #ffffff;
    border-left: 1px solid #e2e8f0;
    overflow-y: auto;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.thumb {
    background: #f8fafc;
    border: 2px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
    padding: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}
.thumb:hover {
    border-color: #94a3b8;
}
.thumb.active {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.3);
}
.thumb canvas {
    width: 100%;
    height: auto;
    border-radius: 6px;
}
.thumb .page-num {
    font-size: 11px;
    color: #475569;
    margin-top: 4px;
}

/* ========== CANVAS AREA ========== */
.canvas-area {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    position: relative;
}
.pdf-container {
    position: relative;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    transform-origin: top center;
    transition: transform 0.05s;
}
.pdf-container {
    position: relative;
    overflow: hidden;
}

.pdf-container canvas {
    display: block;
    max-width: none;
    max-height: none;
}

.pdf-container canvas[data-role="pdf-canvas"] {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    pointer-events: none;
}

.pdf-container canvas[data-role="fabric-canvas"] {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    pointer-events: auto;
}

/* ====================================================
   DROPDOWN MENUS (Shapes & Pages)
   ==================================================== */
.shape-dropdown-panel,
.pages-dropdown-panel {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0,0,0,0.12);
    padding: 12px;
    z-index: 50;
    width: 280px;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}
.shape-dropdown-panel.open,
.pages-dropdown-panel.open {
    display: flex;
}
.shape-group,
.pages-group {
    position: relative;
}
.shape-option {
    background: transparent;
    border: none;
    padding: 6px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
}
.shape-option:hover {
    background: #f1f5f9;
}
.shape-option svg {
    width: 24px;
    height: 24px;
    color: #1e293b;
}
.page-option {
    background: transparent;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    transition: background 0.15s;
}
.page-option:hover {
    background: #f1f5f9;
}
.page-option i {
    width: 20px;
}

/* ====================================================
   MODALS (Signature & Image)
   ==================================================== */
.signatureModal,
.imageModal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.6);
    backdrop-filter: blur(4px);
    justify-content: center;
    align-items: center;
    z-index: 999;
}
.signatureBox,
.imageModalBox {
    background: #ffffff;
    border-radius: 24px;
    max-width: 800px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    padding: 32px;
    box-shadow: 0 40px 80px rgba(0,0,0,0.25);
    position: relative;
}
.closeSignatureBtn,
.closeImageBtn {
    position: absolute;
    top: 16px;
    left: 20px;
    background: #f1f5f9;
    border: none;
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.closeSignatureBtn:hover,
.closeImageBtn:hover {
    background: #e2e8f0;
}
.signatureBox h3,
.imageModalBox h3 {
    font-size: 22px;
    margin-bottom: 20px;
    color: #0f172a;
}
.signatureTabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 12px;
}
.sigTab {
    background: transparent;
    border: none;
    padding: 8px 20px;
    border-radius: 40px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    color: #64748b;
}
.sigTab.active {
    background: #dbeafe;
    color: #1d4ed8;
}
.signatureTabContent {
    display: none;
}
.signatureTabContent.active {
    display: block;
}
.signatureCanvasWrapper {
    background: #f8fafc;
    border-radius: 12px;
    padding: 8px;
    margin: 16px 0;
}
#signatureCanvasDraw {
    width: 100%;
    height: auto;
    border-radius: 8px;
    cursor: crosshair;
    touch-action: none;
}
.signatureOptions {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 12px;
}
.signatureOptions label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}
.signatureActions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}
.signatureActions button {
    padding: 10px 24px;
    border-radius: 40px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
#clearSigBtn {
    background: #f1f5f9;
    color: #475569;
}
#clearSigBtn:hover {
    background: #e2e8f0;
}
#useSigBtn {
    background: #3b82f6;
    color: #fff;
}
#useSigBtn:hover {
    background: #2563eb;
}
#typePreviewCanvas {
    width: 100%;
    height: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-top: 10px;
}
#uploadSigFile {
    margin: 16px 0;
}

/* ===== Image Upload Modal ===== */
.imageUploadArea {
    border: 3px dashed #d1d5db;
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    margin: 16px 0;
    transition: border-color 0.3s;
}
.imageUploadArea:hover {
    border-color: #3b82f6;
}
.imageUploadIcon {
    font-size: 48px;
    color: #94a3b8;
}
.imagePreviewArea {
    text-align: center;
}
#imagePreview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 12px;
    margin: 16px 0;
}
.imageActions {
    display: flex;
    justify-content: center;
    gap: 16px;
}
.btn-secondary {
    background: #f1f5f9;
    border: none;
    padding: 10px 24px;
    border-radius: 40px;
    cursor: pointer;
}
.btn-primary {
    background: #3b82f6;
    color: #fff;
    border: none;
    padding: 10px 24px;
    border-radius: 40px;
    cursor: pointer;
}
.btn-primary:hover {
    background: #2563eb;
}

/* ====================================================
   SMART FUNNEL (المزيد من الأدوات)
   ==================================================== */
.smart-funnel {
    background: #f8fafc;
    padding: 32px 24px;
    border-top: 1px solid #e2e8f0;
}
.funnel-header h3 {
    font-size: 20px;
    color: #0f172a;
}
.funnel-subtitle {
    color: #64748b;
    font-size: 14px;
    margin-bottom: 16px;
}
.funnel-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}
.funnel-card {
    background: #ffffff;
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: #1e293b;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    transition: all 0.2s;
    border: 1px solid #e2e8f0;
}
.funnel-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.06);
}
.funnel-icon {
    font-size: 24px;
}
.funnel-title {
    font-weight: 500;
}

/* ====================================================
   RESPONSIVE
   ==================================================== */
@media (max-width: 768px) {
    .thumbs {
        width: 80px;
        min-width: 80px;
        padding: 8px 4px;
    }
    .thumb canvas {
        width: 60px;
    }
    .tool-btn {
        font-size: 13px;
        padding: 4px 8px;
    }
    .tool-divider {
        margin: 0 2px;
    }
    .property-panel {
        padding: 4px 8px;
    }
    .prop-group {
        font-size: 12px;
    }
    .signatureBox {
        padding: 20px;
    }
}

/* ============================================================
   DONEPDF FABRIC INTERACTION LAYER
   IMPORTANT: Fabric creates its own .canvas-container
   and .upper-canvas layers.
   ============================================================ */

/* PDF page wrapper */
.pdf-container {
    position: relative !important;
    overflow: hidden !important;
    transform-origin: top center !important;
}

/* Fabric generated wrapper */
.pdf-container .canvas-container {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 20 !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    pointer-events: auto !important;
    touch-action: none !important;
}

/* Fabric rendering canvas */
.pdf-container .canvas-container .lower-canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 1 !important;
    pointer-events: none !important;
    display: block !important;
    max-width: none !important;
    max-height: none !important;
}

/* Fabric interactive canvas */
.pdf-container .canvas-container .upper-canvas {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 2 !important;
    pointer-events: auto !important;
    cursor: default;
    display: block !important;
    max-width: none !important;
    max-height: none !important;
    touch-action: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

/* Select mode cursor */
.pdf-container .canvas-container .upper-canvas:hover {
    cursor: default;
}

/* Do NOT let generic canvas rules resize Fabric canvases */
.pdf-container .canvas-container canvas {
    width: auto !important;
    height: auto !important;
}

/* PDF rendering layer must NEVER steal mouse events */
.pdf-container > canvas[data-role="pdf-canvas"] {
    pointer-events: none !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    z-index: 1 !important;
    display: block !important;
    max-width: none !important;
    max-height: none !important;
}

/* Fabric must always be above PDF */
.pdf-container .canvas-container {
    z-index: 20 !important;
}