/* ==========================================================================
   EgyZone Official Merchant Partnership Agreement - Document Viewer & Print Styles
   Executive Legal Document Layout for Screen & Pixel-Perfect 13 A4 Pages Print
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Amiri:ital,wght@0,400;0,700;1,400&family=Aref+Ruqaa:wght@700&family=Cairo:wght@400;500;600;700;800&family=Tajawal:wght@400;500;700&display=swap');

:root {
    --doc-bg: #0f172a;
    --doc-sheet-bg: #ffffff;
    --doc-text-main: #1e293b;
    --doc-text-muted: #475569;
    --doc-heading: #0f172a;
    --doc-border: #94a3b8;
    --doc-border-light: #e2e8f0;
    --doc-table-header: #1e293b;
    --doc-accent-gold: #d97706;
    --doc-accent-blue: #2563eb;
    --doc-font-body: 'Cairo', 'Amiri', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --doc-font-legal: 'Amiri', 'Cairo', serif;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background-color: var(--doc-bg);
    color: var(--doc-text-main);
    font-family: var(--doc-font-body);
    font-size: 13px;
    line-height: 1.75;
    direction: rtl;
    text-align: right;
    -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Executive Top Action Bar (Screen Only)
   ========================================================================== */
.contract-topbar {
    position: sticky;
    top: 0;
    z-index: 1050;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    color: #ffffff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-badge {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #000;
    font-weight: 900;
    font-size: 16px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.topbar-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-subtitle {
    font-size: 11px;
    color: #94a3b8;
    margin: 0;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-contract-action {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
    font-family: var(--doc-font-body);
}

.btn-contract-primary {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.btn-contract-primary:hover {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.45);
    color: #ffffff;
}

.btn-contract-gold {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #0f172a;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}

.btn-contract-gold:hover {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    transform: translateY(-1px);
    color: #000000;
}

.btn-contract-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-contract-secondary:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #ffffff;
}

/* Document Viewer Container */
.contract-viewer-body {
    padding: 30px 15px 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ==========================================================================
   A4 Sheet Layout (Screen Representation)
   ========================================================================== */
.a4-page {
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto 35px;
    background: var(--doc-sheet-bg);
    padding: 20mm 20mm 18mm 20mm;
    position: relative;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35), 0 4px 10px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.a4-page-content {
    flex-grow: 1;
}

/* Page Header (Subtle Brand Mark) */
.page-header-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 6px;
    margin-bottom: 16px;
    font-size: 10px;
    color: #64748b;
}

.page-header-title {
    font-weight: 700;
    color: #0f172a;
}

/* Page Footer with Page Number */
.page-footer {
    border-top: 1px solid #cbd5e1;
    padding-top: 8px;
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: #64748b;
}

.page-number {
    font-weight: 600;
    color: #334155;
}

/* ==========================================================================
   Legal Typography & Elements
   ========================================================================== */
.contract-main-title {
    font-size: 22px;
    font-weight: 800;
    text-align: center;
    color: var(--doc-heading);
    margin: 0 0 6px 0;
    line-height: 1.4;
}

.contract-sub-title {
    font-size: 20px;
    font-weight: 800;
    text-align: center;
    color: var(--doc-heading);
    margin: 0 0 16px 0;
}

.contract-doc-type {
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    color: #475569;
    margin: 0 0 20px 0;
    padding-bottom: 12px;
    border-bottom: 1.5px solid #0f172a;
}

/* Article & Section Titles */
.article-title {
    font-size: 14.5px;
    font-weight: 800;
    color: var(--doc-heading);
    margin: 18px 0 8px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.article-title::before {
    content: "";
    display: inline-block;
    width: 6px;
    height: 14px;
    background: #0f172a;
    border-radius: 2px;
}

.section-heading {
    font-size: 15px;
    font-weight: 800;
    color: var(--doc-heading);
    margin: 16px 0 10px 0;
    border-bottom: 1.5px solid #0f172a;
    padding-bottom: 4px;
}

.appendix-title {
    font-size: 17px;
    font-weight: 800;
    color: var(--doc-heading);
    text-align: center;
    margin: 0 0 8px 0;
}

.appendix-subtitle {
    font-size: 12.5px;
    text-align: center;
    color: #475569;
    margin-bottom: 16px;
}

/* Legal Paragraphs & Lists */
.legal-p {
    font-size: 12px;
    line-height: 1.85;
    color: var(--doc-text-main);
    margin: 0 0 8px 0;
    text-align: justify;
    text-justify: inter-word;
}

.legal-clause {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 7px;
    font-size: 12px;
    line-height: 1.8;
    text-align: justify;
    text-justify: inter-word;
}

.clause-num {
    font-weight: 700;
    color: var(--doc-heading);
    min-width: 18px;
    flex-shrink: 0;
}

.clause-text {
    flex-grow: 1;
}

/* Dynamic Data Styling (Bold with NO dotted underline) */
.dynamic-val {
    font-weight: 700;
    color: #0f172a;
    border-bottom: none !important;
    text-decoration: none !important;
    display: inline;
}

.dots-text {
    color: #64748b;
    letter-spacing: 1px;
    font-family: inherit;
    font-weight: normal;
}

/* ==========================================================================
   Contract Tables
   ========================================================================== */
.contract-meta-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    border: 1px solid #0f172a;
}

.contract-meta-table td {
    padding: 7px 12px;
    font-size: 12.5px;
    border: 1px solid #0f172a;
}

.contract-meta-table td.label-cell {
    width: 24%;
    font-weight: 700;
    background: #f8fafc;
    color: #0f172a;
    text-align: center;
}

.contract-data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 14px 0 16px 0;
    font-size: 11.5px;
    border: 1.5px solid #0f172a;
}

.contract-data-table th {
    background: #1e293b;
    color: #ffffff;
    font-weight: 700;
    text-align: center;
    padding: 9px 8px;
    border: 1px solid #334155;
    font-size: 12px;
}

.contract-data-table td {
    padding: 8px 10px;
    border: 1px solid #94a3b8;
    line-height: 1.6;
    vertical-align: top;
}

.contract-data-table td.table-label {
    background: #f8fafc;
    font-weight: 700;
    width: 28%;
    color: #0f172a;
}

.contract-data-table tr:nth-child(even) td:not(.table-label) {
    background: #fafafa;
}

/* Matrix Table Specifics (Appendix 2) */
.matrix-table th:nth-child(1) { width: 22%; }
.matrix-table th:nth-child(2) { width: 26%; }
.matrix-table th:nth-child(3) { width: 26%; }
.matrix-table th:nth-child(4) { width: 26%; }

/* Signatures Box */
.signatures-container {
    display: flex;
    justify-content: space-between;
    gap: 30px;
    margin: 20px 0;
}

.sig-box {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 14px;
    background: #f8fafc;
}

.sig-box-header {
    font-size: 14px;
    font-weight: 800;
    color: #0f172a;
    border-bottom: 2px solid #0f172a;
    padding-bottom: 6px;
    margin-bottom: 10px;
    text-align: center;
}

.sig-line {
    display: flex;
    margin-bottom: 8px;
    font-size: 12px;
}

.sig-label {
    width: 60px;
    font-weight: 700;
    color: #334155;
    flex-shrink: 0;
}

.sig-val {
    flex-grow: 1;
    color: #0f172a;
    font-weight: 600;
}

.sig-stamp-space {
    height: 48px;
    margin-top: 4px;
}

/* Authentic Clean Handwritten Owner Signature */
.owner-signature-container {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    margin: 2px 0 0 0;
    position: relative;
}

.handwritten-signature-text {
    font-family: 'Aref Ruqaa', 'Amiri', cursive, serif;
    font-size: 26px;
    font-weight: 700;
    color: #0d47a1;
    line-height: 1.1;
    letter-spacing: -0.3px;
    transform: rotate(-3deg);
    display: inline-block;
    user-select: none;
    text-shadow: 0 0.5px 1px rgba(13, 71, 161, 0.2);
}

.handwritten-flourish {
    margin-top: -4px;
    transform: rotate(-1.5deg);
}

/* Final Declaration Box */
.final-declaration-box {
    background: #f1f5f9;
    border-right: 4px solid #0f172a;
    padding: 10px 14px;
    font-size: 11.5px;
    line-height: 1.7;
    margin-top: 15px;
    border-radius: 0 4px 4px 0;
}

/* ==========================================================================
   Quick Fill Drawer (Live Customizer)
   ========================================================================== */
.quick-fill-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 360px;
    max-width: 90vw;
    background: #1e293b;
    color: #f8fafc;
    z-index: 1060;
    box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    display: flex;
    flex-direction: column;
}

.quick-fill-drawer.active {
    transform: translateX(0);
}

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

.drawer-header h5 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
}

.btn-drawer-close {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
}

.btn-drawer-close:hover {
    color: #ffffff;
}

.drawer-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
}

.drawer-input-group {
    margin-bottom: 14px;
}

.drawer-input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #cbd5e1;
    margin-bottom: 6px;
}

.drawer-input-group input,
.drawer-input-group select {
    width: 100%;
    padding: 8px 12px;
    background: #0f172a;
    border: 1px solid #334155;
    border-radius: 6px;
    color: #ffffff;
    font-family: var(--doc-font-body);
    font-size: 12.5px;
}

.drawer-input-group input:focus,
.drawer-input-group select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.25);
}

.drawer-footer {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    gap: 10px;
}

.drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1055;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.drawer-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ==========================================================================
   Print Optimization (@media print) - Exactly 13 Pages
   ========================================================================== */
@media print {
    @page {
        size: A4 portrait;
        margin: 12mm 14mm 12mm 14mm;
    }

    html, body {
        background: #ffffff !important;
        color: #000000 !important;
        font-size: 11.5px !important;
        line-height: 1.65 !important;
        width: 100% !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .contract-topbar,
    .quick-fill-drawer,
    .drawer-overlay,
    .no-print {
        display: none !important;
    }

    .contract-viewer-body {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .a4-page {
        width: 100% !important;
        min-height: 0 !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 0 8mm 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        page-break-after: always !important;
        break-after: page !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }

    /* Last page should not force a trailing blank page */
    .a4-page:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    .page-header-brand {
        margin-bottom: 12px !important;
        border-bottom: 1px solid #94a3b8 !important;
    }

    .page-footer {
        margin-top: 12px !important;
        border-top: 1px solid #94a3b8 !important;
    }

    /* Retain table borders & contrast */
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;

    .contract-data-table th {
        background-color: #1e293b !important;
        color: #ffffff !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .contract-meta-table td.label-cell,
    .contract-data-table td.table-label {
        background-color: #f1f5f9 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .sig-box {
        background-color: #f8fafc !important;
        border: 1px solid #94a3b8 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .final-declaration-box {
        background-color: #f1f5f9 !important;
        border-right: 4px solid #000000 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .handwritten-signature-text {
        color: #0d47a1 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .handwritten-flourish path {
        stroke: #0d47a1 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}
