:root {
    --primary-color: #4361ee;
    --secondary-color: #3f37c9;
    --accent-color: #4895ef;
    --danger-color: #f72585;
    --success-color: #4cc9f0;
    --dark-color: #2b2d42;
    --light-color: #f8f9fa;
    --gray-color: #6c757d;
    --border-radius: 8px;
    --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

body.no-scroll {
    overflow: hidden;
}

/* Firebase sign-in button is handled by navbar.js site auth — always hidden */
#signInBtn,
.user-profile {
    display: none !important;
}

.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.user-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-signin {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-signin:hover {
    background-color: var(--secondary-color);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.user-name {
    font-weight: 500;
}

/* Main Content Styles */
.main-content {
    flex: 1;
    padding: 2rem;
    padding-top: 4rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.card {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    padding: 1.5rem;
}

/* Company Section */
.company-section {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.logo-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.logo-preview {
    width: 100px;
    height: 100px;
    border: 2px dashed var(--gray-color);
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden; /* Ensure image doesn't spill out */
}

.logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain; /* This is key for maintaining aspect ratio and fitting */
}

.logo-preview:hover {
    border-color: var(--primary-color);
    background-color: rgba(67, 97, 238, 0.05);
}

.logo-preview i {
    font-size: 1.5rem;
    color: var(--gray-color);
}

.logo-controls {
    display: flex;
    gap: 0.5rem;
    width: 100%;
}

#logoUrl {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    width: 100%; /* Ensure it takes full width when not in flex with button */
}

.company-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Document Type & Currency */
.controls-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 1rem; /* Space between elements when wrapped */
}

.document-type {
    display: flex;
    gap: 0.5rem;
}

.btn-type {
    padding: 0.75rem 1.5rem;
    border: 1px solid var(--primary-color);
    background: none;
    color: var(--primary-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-type.active {
    background: var(--primary-color);
    color: white;
}

.btn-type:hover:not(.active) {
    background: rgba(67, 97, 238, 0.1);
}

/* Currency Selector */
.currency-selector-group {
    min-width: 150px; /* Ensure it has some minimum width */
}

.currency-selector-group label {
    margin-bottom: 0.5rem;
}

#currencySelect {
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-family: inherit;
    transition: var(--transition);
    background-color: white; /* Ensure consistent background */
    -webkit-appearance: none; /* Remove default select arrow on WebKit browsers */
    -moz-appearance: none; /* Remove default select arrow on Firefox */
    appearance: none; /* Remove default select arrow */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 1em;
    padding-right: 2.5rem; /* Make space for custom arrow */
}

/* Customer & Document Details */
.details-section {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.customer-details,
.document-meta {
    flex: 1;
    min-width: 300px; /* Ensure they don't get too small */
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(67, 97, 238, 0.2);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* New: Two-column layout for due date and payment terms */
.two-column-form-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap; /* Allow wrapping for responsiveness */
}

.two-column-form-group .form-group {
    flex: 1; /* Each child form-group takes equal width */
    min-width: 150px; /* Prevent them from becoming too narrow */
}

/* Items & Summary Section */
.items-summary-section {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
}

.items-section {
    flex: 2;
    min-width: 300px; /* Minimum width for items table */
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#itemsTable {
    width: 100%;
    border-collapse: collapse;
}

#itemsTable th,
#itemsTable td {
    padding: 0.8rem;
    border: 1px solid #ddd;
    text-align: left;
}

#itemsTable th {
    background: var(--primary-color);
    color: white;
    font-weight: 500;
}

#itemsTable input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #eee;
    background: #f9f9f9;
}

#itemsTable input:focus {
    background: white;
}

.item-total {
    font-weight: 600;
}

.btn-remove-item {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem;
}

.btn-add-item {
    align-self: flex-start;
    padding: 0.75rem 1.5rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.summary-section {
    flex: 1;
    min-width: 280px; /* Minimum width for summary */
    position: sticky;
    top: 6rem;
    align-self: flex-start;
}

.summary-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid #eee;
    align-items: center; /* Align items vertically */
}

/* Improved styling for Tax Rate and Discount inputs */
.summary-row.form-inline {
    display: grid;
    grid-template-columns: auto minmax(50px, 0.5fr) 1fr; /* Label, Input (flexible but smaller), Span (more flexible) */
    gap: 0.5rem;
    align-items: center;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid #eee;
}

.summary-row.form-inline label {
    font-weight: 500;
    font-size: 0.9rem;
    justify-self: start; /* Align label to start of grid cell */
}

.summary-row.form-inline input {
    width: 100%; /* Take full width of its grid column */
    max-width: 70px; /* Slightly reduced max-width for input */
    padding: 0.4rem 0.6rem;
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    font-family: inherit;
    text-align: right;
}

.summary-row.form-inline span {
    text-align: right; /* Align amounts to the right */
    font-weight: 500;
}

.summary-row.total {
    border-bottom: none;
    padding-top: 0.8rem;
    border-top: 1px solid #eee;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--primary-color);
}

.summary-row.due-amount {
    color: var(--danger-color);
    font-weight: 600;
}

/* Checkbox row (Mark as Paid) */
.form-group.checkbox-only {
    flex-direction: row;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0;
}

.form-group.checkbox-only input[type="checkbox"] {
    width: 18px;
    height: 18px;
    min-width: 18px;
    padding: 0;
    border: 2px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.form-group.checkbox-only label {
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    margin: 0;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.btn-preview,
.btn-generate-document, /* Changed from btn-save-pdf/btn-print */
.btn-reset {
    padding: 0.8rem 1.5rem;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 150px;
    justify-content: center;
}

.btn-preview {
    background: var(--accent-color);
    color: white;
    border: none;
}

.btn-generate-document { /* Styling for the new combined button */
    background: var(--success-color); /* Green for generation */
    color: white;
    border: none;
}

.btn-reset {
    background: white;
    color: var(--danger-color);
    border: 1px solid var(--danger-color);
}

/* Stats Section */
.stats-section {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    margin: 0 2rem 1.5rem;
    flex-wrap: wrap; /* Allow wrapping */
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1; /* Allow cards to grow */
    min-width: 180px; /* Minimum width for stats card */
}

.stat-card i {
    font-size: 1.8rem;
    color: var(--primary-color);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-label {
    font-size: 0.9rem;
    color: var(--gray-color);
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: 0;
    background: white;
    z-index: 1;
}

.modal-header h3 {
    margin: 0;
}

.btn-close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-color);
}

.modal-body {
    padding: 1.5rem;
}

/* === PREVIEW MODAL SPECIFIC STYLES (for professional print/PDF look) === */
.preview-modal .modal-body {
    padding: 2rem; /* More padding for document feel */
    font-size: 0.9rem;
    line-height: 1.5;
    color: #333;
    background-color: white;
    min-height: 400px; /* Give it a default height to look like a document */
    box-sizing: border-box; /* Include padding in height */
    position: relative; /* For absolute positioning of footer */
}

/* IMPORTANT: This is the .document-container that html2canvas sees. */
/* It must be robust and self-contained for PDF generation. */
.document-container {
    background-color: white;
    box-sizing: border-box;
    width: 100%; /* Take full width of its parent (.modal-body) */
    min-height: 297mm; /* Minimum A4 height for consistent page look */
    padding: 2cm; /* Standard A4-like margins */
    color: #000; /* Ensure black text */
    position: relative; /* For watermark positioning */
    display: flex;
    flex-direction: column;
    justify-content: space-between; /* Pushes footer to bottom */
}

.document-header {
    text-align: center;
    margin-bottom: 2rem;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 1rem;
}

.document-header .logo-container {
    max-width: 150px; /* Slightly larger logo in preview */
    margin: 0 auto 1rem;
    border: none;
    display: flex; /* To center the image within the container */
    justify-content: center;
    align-items: center;
    height: 100px; /* Fix height for consistency */
}

.document-header .logo-container img {
    max-width: 100%;
    max-height: 100%; /* Ensure it fits the container height */
    object-fit: contain;
}

.document-header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    line-height: 1.1;
    text-transform: uppercase;
}

.document-header h2 {
    font-size: 1.8rem;
    color: var(--secondary-color);
    margin-top: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.document-header p {
    margin: 0.2rem 0;
    color: var(--gray-color);
}

.document-details {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 2rem;
    flex-wrap: nowrap; /* Prevent wrapping in document details section */
}

.document-meta,
.customer-details {
    flex: 1;
    min-width: 250px; /* Ensure they don't get too small */
}

.document-details h3 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 0.8rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.document-details p {
    margin-bottom: 0.5rem;
}

.document-details strong {
    color: var(--dark-color);
}

.document-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
}

.document-items th,
.document-items td {
    border: 1px solid #ddd;
    padding: 0.8rem 1rem;
    text-align: left;
}

.document-items th {
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
}

.document-items tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.document-items td:nth-child(2), /* Qty */
.document-items td:nth-child(3), /* Price */
.document-items td:nth-child(4) { /* Amount */
    text-align: right;
}

/* Notes and Summary container in preview */
.notes-and-summary-container {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
    flex-grow: 1; /* Allows it to expand and push footer down */
    align-items: flex-start; /* Align content to the top */
    gap: 2rem; /* Space between notes and summary columns */
}

.document-notes {
    flex: 1; /* Allow notes to take up available space */
    min-width: 45%; /* Ensure notes take at least 45% */
}
.document-notes h3 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 0.8rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 0.5rem;
}

.document-notes-placeholder {
    flex: 1;
    min-width: 45%;
    visibility: hidden; /* It exists for layout but is unseen */
    height: 1px; /* Minimal height so it doesn't take up too much space */
}

.document-notes p {
    color: #555;
}

.document-summary {
    width: 300px; /* Fixed width for summary in preview */
    margin-left: auto; /* Align to the right */
    border: 1px solid #ddd;
    border-radius: var(--border-radius);
    padding: 1rem;
    background-color: #fcfcfc;
    flex-shrink: 0; /* Prevent summary from shrinking */
}

.document-summary .summary-row {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px dashed #eee;
}

.document-summary .summary-row:last-of-type {
    border-bottom: none;
}

.document-summary .summary-row span:first-child {
    font-weight: 500;
    color: var(--gray-color);
}

.document-summary .summary-row span:last-child {
    font-weight: 600;
    color: var(--dark-color);
}

.document-summary .summary-row.total,
.document-summary .summary-row.due-amount {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid var(--primary-color);
    margin-top: 1rem;
    padding-top: 1rem;
}

.document-summary .summary-row.due-amount {
    color: var(--danger-color);
}

/* System Generated Footer Message in Preview */
.system-message-footer {
    text-align: center;
    margin-top: auto; /* Push to the bottom using flexbox */
    padding-top: 1rem;
    border-top: 1px solid #eee;
    color: #777;
    font-size: 0.8rem;
    /* Removed absolute positioning for consistency in flex context */
}

.paid-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-45deg);
    font-size: 100px;
    color: rgba(0, 0, 0, 0.1);
    font-weight: bold;
    text-transform: uppercase;
    z-index: 10;
    pointer-events: none; /* Allows interaction with elements behind it */
    white-space: nowrap;
    opacity: 0.7;
}

/* Responsive Styles */
@media (max-width: 1024px) {
    .details-section,
    .items-summary-section {
        flex-direction: column;
    }
    
    .summary-section {
        position: static;
        width: 100%; /* Take full width when stacked */
    }
    .items-section {
        width: 100%;
    }
    /* Adjusted for preview modal on smaller screens - will apply to live preview but not PDF */
    .preview-modal .document-summary {
        width: 100%; /* Full width for summary in preview on smaller screens */
        margin-left: 0;
    }
    .notes-and-summary-container {
        flex-direction: column; /* Stack notes and summary on smaller screens */
        gap: 1rem;
    }
    .document-notes, .document-notes-placeholder, .document-summary {
        width: 100%;
        min-width: unset;
    }
}

@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        gap: 1rem;
        padding: 1rem;
    }
    
    .company-section {
        flex-direction: column;
        gap: 1rem;
    }
    .logo-container {
        width: 100%;
    }
    .logo-controls {
        flex-direction: column;
    }
    #logoUrl {
        width: 100%;
    }
    
    .controls-section {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start; /* Align items to start when stacked */
    }
    
    .document-type {
        width: 100%;
        justify-content: center;
    }
    .currency-selector-group {
        width: 100%;
    }
    #currencySelect {
        width: 100%;
    }
    
    .details-section {
        flex-direction: column;
    }
    .two-column-form-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    .two-column-form-group .form-group {
        width: 100%;
    }
    
    .stats-section {
        flex-direction: column;
        gap: 0.8rem;
        margin: 0 1rem 1rem; /* Adjust margins for smaller screens */
    }
    .stat-card {
        justify-content: center; /* Center content in stat cards */
    }

    /* Preview Modal for smaller screens */
    .preview-modal .modal-body {
        padding: 1rem;
    }
    .preview-modal .document-details {
        flex-direction: column;
        gap: 1.5rem;
    }
    .preview-modal .document-meta,
    .preview-modal .customer-details {
        min-width: unset; /* Remove min-width to allow shrinking */
        width: 100%;
    }
    .preview-modal .document-summary {
        margin-left: 0; /* Remove auto margin */
        width: 100%;
    }
    .system-message-footer { /* In this case it's .system-message-footer within .preview-modal .modal-body */
        position: static; /* Remove absolute positioning for small screens */
        width: auto;
        margin-left: 0;
        margin-right: 0;
        padding: 1rem; /* Adjust padding for static position */
    }
}


/* --- CRITICAL: MEDIA QUERY FOR HTML2CANVAS/PDF GENERATION --- */
/* This specifically targets the styles that html2canvas should see for the PDF. */
@media screen { /* Apply these styles to the "screen" version that html2canvas captures */
    /* Ensure the document-container is treated like a printable page */
    .document-container {
        width: 210mm !important; /* A4 width */
        min-height: 297mm !important; /* A4 height */
        padding: 2cm !important; /* Consistent padding for A4-like page */
        margin: 0 auto !important; /* Center on screen for html2canvas to capture */
        box-shadow: none !important; /* No shadow in "print" version */
        border: none !important; /* No border in "print" version */
        background-color: white !important; /* Ensure white background */
        color: black !important; /* Ensure black text */
        font-size: 10pt !important; /* Smaller font for print-like output */
        line-height: 1.4 !important; /* Adjust line height for print */
        overflow: hidden !important; /* Prevents scrollbars from appearing in capture */
    }

    /* Adjust font sizing and colors for better print readability */
    .document-header h1,
    .document-header h2,
    .document-details h3,
    .document-summary .summary-row.total,
    .document-summary .summary-row.due-amount {
        color: #000 !important; /* Force black for headings and totals */
        -webkit-print-color-adjust: exact; /* Ensure color prints correctly */
        print-color-adjust: exact;
    }
    
    .document-header p,
    .document-details p,
    .document-notes p,
    .system-message-footer {
        color: #333 !important; /* Darker gray for readability */
    }

    /* Table styling for print */
    .document-items th {
        background-color: #f0f0f0 !important; /* Lighter background for table headers */
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-items tbody tr:nth-child(even) {
        background-color: #f8f8f8 !important; /* Subtle row striping for print */
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-items th, .document-items td {
        border-color: #ccc !important; /* Lighter borders */
    }
    .document-items td:nth-child(2),
    .document-items td:nth-child(3),
    .document-items td:nth-child(4) {
        text-align: right !important; /* Ensure numerical columns are right-aligned */
    }

    /* Summary section alignment for print */
    .document-summary {
        width: 300px !important; /* Maintain fixed width for summary */
        margin-left: auto !important; /* Keep it right-aligned */
        padding: 1rem !important;
        border-color: #ccc !important;
        background-color: #fdfdfd !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .document-summary .summary-row {
        border-bottom-color: #eee !important;
    }
    .document-summary .summary-row.total,
    .document-summary .summary-row.due-amount {
        border-top-color: #aaa !important; /* Darker border for totals */
    }
    .document-summary .summary-row span:last-child {
        text-align: right !important; /* Ensure values are right-aligned */
        min-width: 80px !important; /* Ensure enough space */
    }

    /* Notes and Summary flex behavior for print */
    .notes-and-summary-container {
        display: flex !important; /* Ensure side-by-side */
        flex-direction: row !important; /* Explicitly row direction */
        justify-content: space-between !important;
        align-items: flex-start !important;
        gap: 2rem !important;
        margin-top: 2rem !important;
        flex-grow: 1 !important; /* Allows vertical expansion */
    }

    .document-notes, .document-notes-placeholder {
        flex: 1 !important;
        min-width: 45% !important; /* Ensure reasonable width */
        max-width: 50% !important; /* Limit max width */
        box-sizing: border-box !important;
    }
    .document-notes-placeholder {
        visibility: hidden !important;
        height: 1px !important; /* Minimal height */
    }

    /* Footer adjustments for print */
    .system-message-footer {
        margin-top: auto !important; /* Push to bottom of flex container */
        padding-top: 1rem !important;
        border-top-color: #eee !important;
    }

    /* Watermark for print */
    .paid-watermark {
        font-size: 80pt !important; /* Adjust size for print */
        color: rgba(0, 0, 0, 0.1) !important;
        transform: translate(-50%, -50%) rotate(-45deg) !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    /* Logo in print */
    .document-header .logo-container img {
        max-width: 150px !important; /* Control logo size */
        height: auto !important;
        display: block !important;
        margin: 0 auto 1rem !important;
    }

    /* Hide any interactive elements that might get captured */
    .preview-modal input,
    .preview-modal textarea,
    .preview-modal button,
    .preview-modal .close-modal-btn,
    .preview-modal .modal-header {
        display: none !important;
        visibility: hidden !important;
    }
}


.hidden {
    display: none !important;
}

/* ═══════════════════════════════════════════════════
   Dark Mode Overrides — Form UI only
   (document-container stays white — it's paper)
═══════════════════════════════════════════════════ */
[data-theme="dark"] .card {
    background: var(--card);
    color: var(--text);
}

[data-theme="dark"] .card h2 {
    color: var(--text-heading);
}

[data-theme="dark"] .form-group label {
    color: var(--text);
}

[data-theme="dark"] .form-group input,
[data-theme="dark"] .form-group textarea,
[data-theme="dark"] .form-group select {
    background: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text);
}

[data-theme="dark"] #logoUrl {
    background: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text);
}

[data-theme="dark"] #currencySelect {
    background-color: var(--input-bg);
    border-color: var(--input-border);
    color: var(--text);
}

[data-theme="dark"] #itemsTable th,
[data-theme="dark"] #itemsTable td {
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] #itemsTable th {
    background: #1e3a8a;
    color: #e2e8f0;
}

[data-theme="dark"] #itemsTable input {
    background: var(--input-bg);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] #itemsTable input:focus {
    background: var(--card);
}

[data-theme="dark"] .summary-row {
    border-bottom-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .summary-row.form-inline {
    border-bottom-color: var(--border);
}

[data-theme="dark"] .summary-row.form-inline input {
    background: var(--input-bg);
    border-color: var(--border);
    color: var(--text);
}

[data-theme="dark"] .summary-row.total {
    border-top-color: var(--border);
    color: #93c5fd;
}

[data-theme="dark"] .summary-row.due-amount {
    color: #f87171;
}

[data-theme="dark"] .btn-reset {
    background: transparent;
}

[data-theme="dark"] .modal-content {
    background: var(--card);
    color: var(--text);
}

[data-theme="dark"] .modal-header {
    background: var(--card);
    border-bottom-color: var(--border);
    color: var(--text-heading);
}

[data-theme="dark"] .btn-close-modal {
    color: var(--text-muted);
}

[data-theme="dark"] .form-group.checkbox-only input[type="checkbox"] {
    border-color: var(--border);
}

[data-theme="dark"] .form-group.checkbox-only label {
    color: var(--text);
}

[data-theme="dark"] .logo-preview {
    border-color: var(--border);
    background: var(--input-bg);
}

[data-theme="dark"] .logo-preview i {
    color: var(--text-muted);
}