:root {
    --primary-color: #000000;
    --secondary-color: #333333;
    --accent-color: #000000;
    --light-bg: #f8f9fa;
    --border-color: #dee2e6;
    --sidebar-width: 340px;
    --viewer-surface: #ebebeb;
}

html {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background-color: var(--light-bg);
    max-width: 100%;
    width: 100%;
}

html:not(.itqan-editor-active) {
    overflow-x: visible;
}

body,
body.bg-light-subtle {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg) !important;
}

html:not(.itqan-editor-active) body.bg-light-subtle {
    overflow-x: visible;
    overflow-y: auto;
}

html.itqan-editor-active {
    height: 100%;
    overflow: hidden;
}
html.itqan-editor-active body.bg-light-subtle {
    overflow: hidden !important;
    height: 100%;
    max-height: 100dvh;
}
html.itqan-editor-active nav.navbar.navbar-expand-xl.navbar-dark.bg-dark {
    position: sticky;
    top: 0;
    z-index: 1040;
}
html.itqan-editor-active .navbar .dropdown-menu {
    z-index: 1060 !important;
}
html.itqan-editor-active .nav-dropdown-wrapper {
    z-index: 1045;
}
html.itqan-editor-active .nav-dropdown-menu {
    z-index: 1050;
}
@media (min-width: 1200px) {
    html.itqan-editor-active .navbar.navbar-expand-xl #navbarNav.collapse.navbar-collapse {
        max-height: none !important;
        overflow: visible !important;
    }
}

.upload-area {
    position: relative;
    cursor: pointer;
    transition: all 0.3s;
    border: 2px dashed #dee2e6;
    border-radius: 10px;
    background: white;
    min-height: auto;
}
.upload-area:hover,
.upload-area.dragover {
    background-color: #f8f9fa;
    border-color: var(--primary-color);
}

#dropArea,
.upload-area.card {
    overflow-x: visible;
    max-width: 100%;
}
.container.my-5 > .row.justify-content-center > .col-lg-8 {
    min-width: 0;
}

#pdfUploadInput {
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 10;
}

.cloud-upload-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #dee2e6;
    background: white;
    transition: all 0.3s;
    cursor: pointer;
    padding: 0;
    position: relative;
    z-index: 100;
}

.cloud-upload-btn:hover {
    border-color: #000;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.cloud-icon {
    position: relative;
    display: inline-block;
    transition: transform 0.3s ease;
    z-index: 101;
}
.cloud-tooltip {
    visibility: hidden;
    width: 140px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px 5px;
    position: absolute;
    z-index: 1000;
    bottom: 125%;
    left: 50%;
    margin-left: -70px;
    opacity: 0;
    transition: opacity 0.3s;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
}
.cloud-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}
.cloud-icon:hover .cloud-tooltip {
    visibility: visible;
    opacity: 1;
}

#adContainer {
    margin: 20px 0;
    text-align: center;
    overflow: hidden;
    max-width: 100%;
    box-sizing: border-box;
}
#adContainer ins.adsbygoogle {
    display: block !important;
    width: min(100%, 728px) !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
}
#adContainer iframe {
    max-width: 100% !important;
    width: 100% !important;
    display: block !important;
    margin-left: auto !important;
    margin-right: auto !important;
    box-sizing: border-box !important;
}

.sidebar-ads {
    display: none !important;
    visibility: hidden !important;
}
.sidebar-ads.visible {
    display: block !important;
    visibility: visible !important;
    background: #007bff !important;
    padding: 10px !important;
    border-radius: 8px !important;
}
.sidebar-left {
    position: fixed;
    left: 20px;
    top: 150px;
    width: auto;
    max-width: 300px;
    z-index: 100;
}
.sidebar-right {
    position: fixed;
    right: 20px;
    top: 150px;
    width: auto;
    max-width: 300px;
    z-index: 100;
}
@media (max-width: 768px) {
    .sidebar-left,
    .sidebar-right {
        display: none !important;
    }
}

.main-editor {
    display: none;
    height: calc(100vh - 60px);
    flex-direction: row;
    min-width: 0;
    min-height: 0;
}
html.itqan-editor-active #editor-section.main-editor {
    display: flex !important;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: var(--itqan-editor-top, 72px);
    height: auto !important;
    min-height: 0 !important;
    box-sizing: border-box;
    z-index: 1;
}
#editor-section .sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    flex: 0 0 var(--sidebar-width);
    background: #fff;
    border-left: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
    overflow: hidden;
    min-height: 0;
    height: 100%;
}
#editor-section .sidebar .merge-sidebar-body {
    padding-top: 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
}
.merge-sidebar-header {
    flex-shrink: 0;
    padding: 16px 18px;
    border-bottom: 1px solid #eee;
    font-weight: 700;
    font-size: 17px;
    line-height: 1.35;
    background: #fff;
    position: relative;
    z-index: 2;
    text-align: center;
    color: #222;
}
.merge-sidebar-body {
    padding: 16px 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
#editor-section .sidebar > .merge-sidebar-footer {
    flex-shrink: 0;
    margin-top: auto;
    padding: 14px 18px 18px;
    border-top: 1px solid #eee;
    background: #fff;
    z-index: 2;
}
.merge-sidebar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}
.merge-sidebar-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: #666;
    text-align: center;
    margin: 0;
}
#editor-section .merge-cloud-stack {
    display: flex;
    flex-direction: row;
    gap: 12px;
    align-items: center;
    justify-content: center;
    padding: 12px 14px;
    background: #f8f9fa;
    border: 1px dashed #dee2e6;
    border-radius: 10px;
    width: 100%;
    box-sizing: border-box;
}
.reset-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    color: #333;
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.2s;
    margin-bottom: 8px;
}
.reset-btn:hover {
    background: #e0e0e0;
    border-color: #000;
}
.merge-sidebar-btn-clear {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid #ddd;
    background: #f5f5f5;
    color: #444;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.merge-sidebar-btn-clear:hover {
    background: #eee;
    border-color: #bbb;
    color: #222;
}
.btn-finish {
    background: #000;
    color: #fff;
    width: 100%;
    border: none;
    padding: 15px;
    font-size: 18px;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-finish:hover:not(:disabled) {
    background: #222;
    color: #fff;
}
.btn-finish:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.viewer-container {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    background: var(--viewer-surface);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0 120px 0;
    scroll-behavior: smooth;
}
.viewer-container #adContainerViewer {
    margin-top: 16px;
    flex-shrink: 0;
    text-align: center;
}
.viewer-container #adContainerViewer ins.adsbygoogle {
    display: inline-block !important;
    width: min(100%, 728px) !important;
    max-width: 100% !important;
    margin-left: auto !important;
    margin-right: auto !important;
}
.viewer-column {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #f3f3f3;
    position: relative;
}
.pages-stack { display: flex; flex-direction: column; gap: 30px; }
.page-box {
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    position: relative;
    line-height: 0;
}
.page-box.mode-redact { cursor: crosshair; touch-action: none; }
.page-box.mode-pan { cursor: grab; }
.redact-box { position: absolute; border: 2px dashed #e5322d; box-sizing: border-box; z-index: 8; pointer-events: auto; touch-action: none; }
.redact-box.is-adjusting { opacity: 0.82; }
.redact-box .redact-remove { position: absolute; top: -10px; left: -10px; width: 22px; height: 22px; border-radius: 50%; border: none; background: #fff; color: #333; font-size: 14px; line-height: 1; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.25); z-index: 20; touch-action: manipulation; }
.redact-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 2px solid #111;
    box-sizing: border-box;
    border-radius: 1px;
    z-index: 18;
    touch-action: none;
    pointer-events: auto;
}
.redact-resize-handle--nw { top: -6px; left: -6px; cursor: nwse-resize; }
.redact-resize-handle--n  { top: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.redact-resize-handle--ne { top: -6px; right: -6px; cursor: nesw-resize; }
.redact-resize-handle--e  { top: 50%; right: -6px; transform: translateY(-50%); cursor: ew-resize; }
.redact-resize-handle--se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.redact-resize-handle--s  { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.redact-resize-handle--sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.redact-resize-handle--w  { top: 50%; left: -6px; transform: translateY(-50%); cursor: ew-resize; }
@media (max-width: 991.98px) {
    .redact-box .redact-remove { width: 30px; height: 30px; font-size: 18px; top: -14px; left: -14px; }
    .redact-resize-handle {
        width: 18px;
        height: 18px;
        border-width: 2px;
    }
    .redact-resize-handle--nw { top: -10px; left: -10px; }
    .redact-resize-handle--n  { top: -10px; }
    .redact-resize-handle--ne { top: -10px; right: -10px; }
    .redact-resize-handle--e  { right: -10px; }
    .redact-resize-handle--se { bottom: -10px; right: -10px; }
    .redact-resize-handle--s  { bottom: -10px; }
    .redact-resize-handle--sw { bottom: -10px; left: -10px; }
    .redact-resize-handle--w  { left: -10px; }
}
.redact-draft { position: absolute; border: 2px solid #111; pointer-events: none; z-index: 9; }
.redact-color-row { margin-bottom: 16px; }
.redact-color-swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.redact-color-swatch { width: 32px; height: 32px; border-radius: 8px; border: 2px solid #ddd; cursor: pointer; padding: 0; transition: transform .15s, border-color .15s; }
.redact-color-swatch:hover { transform: scale(1.08); border-color: #999; }
.redact-color-swatch.active { border-color: #111; box-shadow: 0 0 0 2px #fff, 0 0 0 4px #111; }
.redact-color-picker-wrap { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.redact-color-picker-wrap input[type="color"] { width: 48px; height: 36px; border: 1px solid #ccc; border-radius: 6px; padding: 2px; cursor: pointer; background: #fff; }
.redact-color-preview { flex: 1; height: 36px; border-radius: 6px; border: 1px solid #ddd; min-width: 0; }
.editor-toolbar { display: flex; gap: 6px; padding: 10px 14px; background: #fff; border-bottom: 1px solid #e5e5e5; flex-wrap: wrap; }
.tool-btn { border: 1px solid #ddd; background: #fafafa; border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; transition: .2s; }
.tool-btn.active { background: #111; color: #fff; border-color: #111; }
.tool-btn:hover:not(.active) { border-color: #999; }
.marks-list { margin-top: 12px; max-height: 220px; overflow-y: auto; }
.mark-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid #eee; border-radius: 8px; margin-bottom: 8px; font-size: 13px; background: #fafafa; }
.mark-item button { border: none; background: transparent; color: #999; cursor: pointer; }
.alert-warn-side { background: #fff8e6; border: 1px solid #f0d78c; border-radius: 8px; padding: 10px 12px; font-size: 12px; color: #6b5a00; margin-top: 12px; }
.pattern-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pattern-chip { border: 1px solid #ddd; background: #fff; border-radius: 20px; padding: 6px 12px; font-size: 12px; cursor: pointer; }
.pattern-chip:hover { border-color: #111; }

.viewbar {
    position: absolute;
    bottom: 18px;
    left: 50%;
    right: auto;
    width: max-content;
    max-width: calc(100% - 24px);
    margin: 0;
    transform: translateX(-50%);
    background: #1e1e1e;
    border-radius: 8px;
    padding: 6px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    z-index: 2000;
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    will-change: left;
}
.viewbar-btn {
    background: transparent;
    border: none;
    color: white;
    padding: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: 0.2s;
}
.viewbar-btn:hover { background: rgba(255,255,255,0.1); border-radius: 4px; }
.viewbar-input {
    width: 45px;
    background: #000;
    border: 1px solid #444;
    color: white;
    text-align: center;
    border-radius: 4px;
    padding: 3px;
    font-size: 14px;
}
.viewbar-divisor { width: 1px; height: 22px; background: #444; }

.upload-pick-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transform: translateX(18px);
    position: relative;
    z-index: 20;
}
.upload-cloud-stack {
    display: flex;
    flex-direction: column;
    gap: 1px;
    position: relative;
    z-index: 220;
    pointer-events: auto;
}
.upload-cloud-stack .cloud-icon,
.upload-cloud-stack .cloud-upload-btn {
    pointer-events: auto;
}

.container.my-5 {
    margin-top: 1rem !important;
    margin-bottom: 2rem !important;
}
/* واجهة اختيار الملف — مطابقة الدمج فقط */
#mergePageHeader { margin-bottom: 0 !important; }
#mergePageHeader .display-5 { font-size: clamp(1.75rem, 3.5vw, 2.15rem); margin-bottom: 0.55rem !important; line-height: 1.25; font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; }
#mergePageHeader .lead { margin-bottom: 1.15rem !important; font-size: 0.98rem; line-height: 1.45; }
#selectFilesBtn { font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif; white-space: nowrap; display: inline-flex; align-items: center; flex-shrink: 0; }
:root { --itqan-tool-panel-w: 46.5rem; }
.upload-cloud-spacer { width: 44px; flex: 0 0 44px; visibility: hidden; pointer-events: none; }
#upload-section #dropArea.upload-area { width: min(100%, var(--itqan-tool-panel-w)); max-width: min(100%, var(--itqan-tool-panel-w)); margin-left: auto; margin-right: auto; padding: 0.65rem 1.55rem 0.45rem !important; box-shadow: none !important; overflow: visible !important; background: var(--light-bg, #f8f9fa) !important; }
#upload-section #dropArea .card-body, #upload-section #dropArea .upload-row-wrap, #upload-section #dropArea .d-flex.justify-content-center, #upload-section #dropArea .upload-pick-wrap, #upload-section #dropArea .upload-cloud-stack, #upload-section #dropArea .cloud-icon { overflow: visible !important; }
#upload-section .cloud-tooltip { display: none !important; }
@media (min-width: 576px) { #upload-section .upload-cloud-stack { flex-direction: column !important; gap: 8px !important; width: auto !important; flex: 0 0 auto !important; } #upload-section .upload-pick-wrap { flex-wrap: nowrap !important; flex-direction: row !important; } #upload-section .upload-cloud-spacer { display: block; } }
@media (max-width: 1199.98px) { #upload-section .upload-cloud-stack { flex-direction: row !important; justify-content: center !important; gap: 12px !important; width: auto !important; flex: 0 0 auto !important; } }
@media (min-width: 992px) { #upload-section, #upload-section .container.my-5, #upload-section .row, #upload-section .col-lg-8 { max-width: 100%; min-width: 0; overflow: visible !important; } #upload-section #dropArea.upload-area { padding-block: 0.75rem 0.5rem !important; padding-inline: 1.55rem !important; overflow: visible !important; } }
@media (max-width: 575.98px) { #upload-section #dropArea.upload-area { width: 100%; padding: 1rem !important; overflow: visible !important; } #upload-section #dropArea .card-body, #upload-section #dropArea .upload-row-wrap { overflow: visible !important; } .upload-cloud-spacer { display: none !important; } #upload-section .upload-pick-wrap { flex-direction: column !important; width: 100% !important; gap: 12px !important; } #upload-section #dropArea .upload-row-wrap { flex-wrap: nowrap !important; } #selectFilesBtn { width: 100%; max-width: 100%; } }
#upload-section #dropArea .card-body { padding: 0.3rem 0.85rem 0.2rem; overflow: visible !important; width: 100%; background: transparent !important; }
#upload-section #dropArea .upload-row-wrap { overflow: visible !important; width: 100%; display: flex; justify-content: center; align-items: center; flex-wrap: nowrap !important; }
@media (max-width: 768px) { .upload-pick-wrap { transform: none; } }

.merge-sidebar-help-btn {
    width: 100%;
    margin: 0 0 0.85rem;
    padding: 0.55rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    background: #fff;
    color: #333;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.merge-sidebar-help-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
    color: #111;
}
.merge-seo-content {
    margin-top: 2.5rem;
    padding-top: 1.75rem;
    border-top: 1px solid var(--border-color);
    max-width: 42rem;
    margin-left: auto;
    margin-right: auto;
}
.merge-seo-content--modal {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    max-width: none;
}
.merge-seo-steps {
    list-style: none;
    padding: 0;
    margin: 0;
    counter-reset: merge-howto-step;
}
.merge-seo-steps li {
    counter-increment: merge-howto-step;
    display: flex;
    gap: 0.85rem;
    align-items: flex-start;
    padding: 0.55rem 0;
    color: #495057;
    font-size: 0.95rem;
    line-height: 1.55;
}
.merge-seo-steps li::before {
    content: counter(merge-howto-step);
    flex-shrink: 0;
    width: 1.65rem;
    height: 1.65rem;
    border-radius: 50%;
    background: #111;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.1rem;
}
.merge-seo-faq .accordion-button {
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.85rem 1rem;
}
.merge-seo-faq .accordion-button:not(.collapsed) {
    background: #f8f9fa;
    color: #111;
    box-shadow: none;
}
.merge-seo-faq .accordion-item {
    border-color: var(--border-color);
}

@media (max-width: 991.98px) {
    html.itqan-editor-active {
        overflow: auto !important;
        height: auto !important;
    }
    html.itqan-editor-active body.bg-light-subtle {
        overflow: auto !important;
        height: auto !important;
        max-height: none !important;
    }
    .main-editor {
        flex-direction: column;
        height: auto;
    }
    html.itqan-editor-active #editor-section.main-editor {
        position: relative !important;
        flex-direction: column !important;
        height: auto !important;
        top: auto !important;
        left: auto !important;
        right: auto !important;
        bottom: auto !important;
    }
    #editor-section .sidebar {
        order: 1;
        position: relative !important;
        width: 100% !important;
        min-width: 0;
        max-height: none !important;
        height: auto !important;
        flex: none !important;
        border-top: 1px solid #ddd;
        border-left: none !important;
    }
    #editor-section .sidebar .merge-sidebar-body {
        padding: 12px 16px !important;
        overflow: visible !important;
        max-height: none !important;
        height: auto !important;
        padding-bottom: 80px !important;
    }
    .viewer-column {
        order: 2;
        width: 100% !important;
        height: auto !important;
    }
    .viewer-container {
        flex: 1 1 auto;
        min-height: 60vh;
        width: 100% !important;
        overflow: visible !important;
        padding: 15px 8px 20px 8px !important;
    }
    #editor-section .sidebar > .merge-sidebar-footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1050;
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        background: #fff;
        border-top: 1px solid #e8e8e8;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
    }
    #editor-section .sidebar .btn-finish {
        padding: 14px;
        font-size: 16px;
        border-radius: 10px;
    }
    /* شريط التنقل (viewbar) بعرض الصفحة */
    .viewbar {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
        bottom: calc(66px + env(safe-area-inset-bottom, 0px)) !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
        flex-wrap: nowrap !important;
        justify-content: center;
        gap: 10px;
        padding: 6px 12px !important;
        z-index: 1049;
    }
    /* إخفاء الأسئلة الشائعة عند تفعيل المحرر */
    html.itqan-editor-active .tool-seo-visible-wrap,
    html.itqan-editor-active .merge-seo-content {
        display: none !important;
    }
}
