/* Document Editor Styles */

:root {
    --doc-brand-color: #3b82f6;
    --doc-text-color: #0f172a;
    --doc-border-color: #e2e8f0;
    --doc-bg-light: #f8fafc;
}

/* Document Container */
.document-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Toolbar */
/* Toolbar */
.document-toolbar {
    background: white;
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    position: sticky;
    top: 80px;
    z-index: 50;
    width: 100%;
    box-sizing: border-box;
}

.document-toolbar button {
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid var(--doc-border-color);
    background: white;
    color: var(--doc-text-color);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.document-toolbar button:hover {
    background: var(--doc-brand-color);
    color: white;
    border-color: var(--doc-brand-color);
    transform: translateY(-2px);
}

.document-toolbar button i {
    font-size: 1rem;
}

#saveIndicator {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: #10b981;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

/* Customization Panel */
.customization-panel {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.customization-panel input,
.customization-panel select {
    padding: 10px 15px;
    border-radius: 8px;
    border: 1px solid var(--doc-border-color);
    font-size: 0.95rem;
    font-family: 'Outfit', sans-serif;
}

.customization-panel input[type="color"] {
    height: 45px;
    cursor: pointer;
}

.customization-panel input[type="file"] {
    padding: 8px;
}

/* Document Preview */
.document-preview {
    background: white;
    padding: 60px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    min-height: 1100px;
    /* A4 height approximation */
    font-size: 12pt;
    line-height: 1.6;
    color: var(--doc-text-color);
}

/* Document Header */
.doc-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 40px;
    padding-bottom: 20px;
    border-bottom: 3px solid var(--doc-brand-color);
}

.logo-area {
    width: 150px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--doc-border-color);
    border-radius: 8px;
    background: var(--doc-bg-light);
}

.logo-area img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.company-info {
    text-align: right;
    flex: 1;
    margin-left: 20px;
}

.company-info h2 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--doc-brand-color);
    margin-bottom: 8px;
}

.company-info p {
    margin: 4px 0;
    color: #64748b;
}

/* Document Title */
.doc-title {
    text-align: center;
    font-size: 2rem;
    font-weight: 800;
    color: var(--doc-text-color);
    margin: 30px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Document Body */
.doc-body {
    margin: 30px 0;
}

.doc-section {
    margin-bottom: 30px;
}

.doc-section h3 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--doc-brand-color);
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--doc-border-color);
}

/* Form Fields */
/* Compact Form Fields */
.doc-field {
    margin-bottom: 10px;
}

.doc-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    color: #475569;
    font-size: 0.85rem;
}

.doc-field input,
.doc-field textarea,
.doc-field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--doc-border-color);
    border-radius: 6px;
    font-size: 0.9rem;
    font-family: 'Outfit', sans-serif;
}

.doc-field textarea {
    min-height: 60px;
    resize: vertical;
}

.doc-field-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

/* Compact Tables */
.doc-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
}

.doc-table thead {
    background: var(--doc-brand-color);
    color: white;
}

.doc-table th {
    padding: 8px;
    text-align: left;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.doc-table td {
    padding: 6px 8px;
    border-bottom: 1px solid var(--doc-border-color);
}

.doc-table tbody tr:hover {
    background: var(--doc-bg-light);
}

.doc-table input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid var(--doc-border-color);
    border-radius: 4px;
    font-size: 0.9rem;
}

.doc-table .remove-row-btn {
    background: #ef4444;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}

.doc-table .remove-row-btn:hover {
    background: #dc2626;
}

.add-row-btn {
    background: var(--doc-brand-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 10px;
}

.add-row-btn:hover {
    background: #2563eb;
}

/* Totals Section */
.totals-section {
    margin-top: 30px;
    display: flex;
    justify-content: flex-end;
}

.totals-table {
    width: 400px;
}

.totals-table tr {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.totals-table tr:last-child {
    border-top: 2px solid var(--doc-brand-color);
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--doc-brand-color);
    padding-top: 12px;
}

/* Document Footer */
.doc-footer {
    margin-top: 50px;
    padding-top: 30px;
    border-top: 2px solid var(--doc-border-color);
}

.signature-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 40px;
    margin-bottom: 30px;
}

.signature-box {
    text-align: center;
}

.signature-line {
    border-top: 2px solid var(--doc-text-color);
    margin-top: 60px;
    padding-top: 10px;
    font-weight: 600;
}

.terms {
    background: var(--doc-bg-light);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--doc-brand-color);
    font-size: 0.9rem;
    color: #475569;
    line-height: 1.8;
}

/* WYSIWYG Toolbar */
.wysiwyg-toolbar {
    position: fixed;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 8px;
    display: none;
    gap: 5px;
    z-index: 1000;
}

.wysiwyg-toolbar button {
    width: 35px;
    height: 35px;
    border: none;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.wysiwyg-toolbar button:hover {
    background: var(--doc-brand-color);
    color: white;
}

/* Print Styles - COMPREHENSIVE: Only Document Content Prints */
@media print {

    /* Hide ALL UI controls, toolbars, navigation, and customization elements */
    .document-toolbar,
    .customization-panel,
    .customization-toolbar,
    .floating-toolbar,
    .logo-editor-modal,
    .signature-modal,
    .stamp-modal,
    .color-picker-panel,
    .units-selector,
    .currency-selector,
    header,
    footer,
    nav,
    .wysiwyg-toolbar,
    .formatting-toolbar,
    .add-row-btn,
    .remove-row-btn,
    .feedback-link-container,
    .complaint-trigger,
    .news-ticker-container,
    .no-print,
    [class*="toolbar"],
    #logoUpload,
    #brandColor,
    #fontSize,
    .upload-btn-wrapper,
    .add-row-btn,
    .remove-row-btn,
    .btn-premium,
    button:not(.signature-box button):not(.doc-footer button) {
        display: none !important;
        visibility: hidden !important;
    }

    /* Show ONLY the document preview/content */
    .document-preview {
        box-shadow: none !important;
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        border-radius: 0 !important;
        background: white !important;
        width: 100% !important;
        max-width: 100% !important;

        /* Avoid page breaks in critical sections */
        .doc-section,
        .signature-section,
        .totals-section {
            page-break-inside: avoid;
        }

        /* Force page break before footer if needed */
        .doc-footer {
            page-break-before: auto;
        }

        /* Ensure colors print correctly */
        * {
            -webkit-print-color-adjust: exact !important;
            print-color-adjust: exact !important;
        }

        /* Hide contenteditable indicators */
        [contenteditable="true"] {
            border: none !important;
            outline: none !important;
        }

        /* Optimize fonts for print */
        body,
        .document-preview {
            font-size: 11pt !important;
            line-height: 1.5 !important;
            color: #000 !important;
        }

        /* Ensure logos and images print */
        img {
            max-width: 100% !important;
            page-break-inside: avoid;
        }

        /* Hide any floating/absolute positioned UI elements */
        [style*="position: fixed"],
        [style*="position: sticky"] {
            position: static !important;
        }
    }

    /* Responsive */
    @media (max-width: 768px) {
        .document-preview {
            padding: 30px 20px;
        }

        .doc-header {
            flex-direction: column;
            gap: 20px;
        }

        .company-info {
            text-align: left;
            margin-left: 0;
        }

        .customization-panel {
            grid-template-columns: 1fr;
        }

        .totals-table {
            width: 100%;
        }
    }

    /* Toolbar Button Styles */
    .toolbar-left,
    .toolbar-right {
        display: flex;
        gap: 10px;
        flex-wrap: wrap;
        align-items: center;
    }

    .toolbar-btn {
        padding: 10px 20px;
        border-radius: 8px;
        border: 1px solid var(--doc-border-color);
        background: white;
        color: var(--doc-text-color);
        font-weight: 600;
        font-size: 0.9rem;
        cursor: pointer;
        transition: all 0.2s;
        display: flex;
        align-items: center;
        gap: 8px;
        font-family: 'Outfit', sans-serif;
    }

    .toolbar-btn:hover {
        background: var(--doc-brand-color);
        color: white;
        border-color: var(--doc-brand-color);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    }

    .toolbar-btn-primary {
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
        color: #ffffff !important;
        border-color: #667eea;
        -webkit-text-fill-color: #ffffff !important;
        text-shadow: none;
    }

    .toolbar-btn-primary:hover {
        background: linear-gradient(135deg, #5568d3 0%, #653a8b 100%) !important;
        transform: translateY(-2px);
        box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    }

    .toolbar-btn i {
        font-size: 1rem;
    }

    /* Header Navigation Fixes for Documents */
    @media screen and (min-width: 900px) {
        header nav ul {
            flex-wrap: nowrap !important;
            gap: 20px !important;
        }

        header nav ul a {
            white-space: nowrap;
            font-size: 0.9rem !important;
        }
    }

    /* Ensure link color handles dark/light modes globally */
    header nav ul a {
        color: var(--text-muted) !important;
    }

    header nav ul a:hover,
    header nav ul a.active {
        color: var(--primary-color) !important;
    }