* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', 'Helvetica', sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    background: white;
    padding: 20px 30px;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 1.8rem;
    color: #333;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
}

.invoice-type-toggle {
    display: flex;
    gap: 0;
    margin-right: 12px;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid #d1d5db;
}

.toggle-btn {
    padding: 10px 20px;
    border: none;
    background: white;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border-right: 1px solid #d1d5db;
}

.toggle-btn:last-child {
    border-right: none;
}

.toggle-btn:hover {
    background: #f3f4f6;
}

.toggle-btn.active {
    background: #3b82f6;
    color: white;
}

.invoice-type-select {
    padding: 8px 12px;
    border: 2px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    background: white;
}

.invoice-type-select:focus {
    outline: none;
    border-color: #3b82f6;
}

.btn-primary {
    background: #10b981;
    color: white;
}

.btn-primary:hover {
    background: #059669;
}

.btn-success {
    background: #3b82f6;
    color: white;
}

.btn-success:hover {
    background: #2563eb;
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.invoice-wrapper {
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

.invoice {
    padding: 25px 35px 100px 35px;
    background: white;
    min-height: 297mm;
    position: relative;
    overflow: visible;
}

/* Decorative Corners */
.corner-decoration {
    position: absolute;
    width: 180px;
    height: 180px;
    z-index: 1;
}

.corner-decoration.top-right {
    top: -5px;
    right: -5px;
    background: linear-gradient(225deg, #ff5e7a 0%, #ff8fa3 50%, transparent 50%);
    clip-path: polygon(100% 0, 100% 100%, 0 0);
}

.corner-decoration.bottom-left {
    bottom: -5px;
    left: -5px;
    background: linear-gradient(45deg, #4a5073 0%, #5d6891 50%, transparent 50%);
    clip-path: polygon(0 100%, 100% 100%, 0 0);
}

/* Invoice Top Header - Simple Layout */
.invoice-top-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

.logo-container {
    flex: 0 0 auto;
}

.company-logo {
    width: 140px;
    height: auto;
    border: 1px solid #e5e7eb;
    padding: 5px;
    background: white;
}

.invoice-date-right {
    text-align: right;
}

.date-input {
    padding: 6px 10px;
    border: 2px solid #e5e7eb;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
}

/* Company Details */
.company-details {
    margin-bottom: 20px;
    position: relative;
    z-index: 2;
}

.company-name {
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 6px;
}

.company-address,
.company-contact,
.company-email {
    font-size: 12px;
    color: #4b5563;
    line-height: 1.5;
    margin-bottom: 2px;
}

.company-email a {
    color: #3b82f6;
    text-decoration: none;
}

/* FACTURE Title */
.facture-title {
    text-align: center;
    margin: 15px 0;
    padding: 10px 0;
    border-top: 2px solid #1f2937;
    border-bottom: 2px solid #1f2937;
}

.facture-title h1 {
    font-size: 24px;
    font-weight: 900;
    color: #1f2937;
    letter-spacing: 2px;
    margin: 0;
}

/* Invoice Number and Client Section */
.ref-client-section {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 15px;
    margin: 15px 0 20px 0;
}

.ref-box {
    padding: 10px;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 4px;
}

.ref-box label {
    font-weight: 700;
    font-size: 13px;
    color: #1f2937;
    display: block;
    margin-bottom: 6px;
}

.ref-box input {
    width: 100%;
    border: none;
    background: transparent;
    font-weight: 700;
    font-size: 14px;
    color: #1f2937;
    padding: 3px 0;
}

.client-box {
    padding: 12px;
    background: white;
    border: 2px solid #1f2937;
    border-radius: 4px;
}

.client-field {
    display: flex;
    align-items: baseline;
    margin-bottom: 6px;
    line-height: 1.4;
}

.client-field:last-child {
    margin-bottom: 0;
}

.client-field label {
    font-weight: 700;
    color: #1f2937;
    font-size: 12px;
    white-space: nowrap;
}

.client-field .input-inline {
    border: none;
    padding: 0 0 0 5px;
    font-size: 12px;
    font-weight: 400;
    color: #1f2937;
    background: transparent;
    flex: 1;
}

.client-field .input-inline:focus {
    outline: none;
}

/* Object Section */
.objet-section {
    margin: 15px 0;
}

.objet-line {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 8px;
}

.objet-label {
    font-weight: 700;
    color: #1f2937;
    font-size: 13px;
}

.objet-value {
    font-weight: 400;
    color: #1f2937;
    font-size: 13px;
}

.objet-options {
    display: flex;
    gap: 25px;
    margin-top: 5px;
    padding: 8px;
    background: #f5f5f5;
    border-radius: 4px;
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
}

.checkbox-option input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.checkbox-option span {
    user-select: none;
}

.objet-section label {
    font-weight: 700;
    color: #1f2937;
    font-size: 14px;
}

.input-field-inline {
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    padding: 4px 8px;
    width: 70%;
}

.input-field-inline:focus {
    outline: none;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}

.objet-print {
    font-weight: 600;
    color: #1f2937;
    font-size: 14px;
    padding: 4px 8px;
}

/* Client Section */
.client-section {
    margin: 30px 0;
    padding: 20px;
    background: #f9fafb;
    border-radius: 8px;
    border: 2px solid #e5e7eb;
}

.client-section h3 {
    font-size: 16px;
    color: #1f2937;
    margin-bottom: 12px;
    font-weight: 700;
}

.input-field {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
}

.input-field:focus {
    outline: none;
    border-color: #fc466b;
}

/* Items Table */
.items-section {
    margin: 15px 0;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 15px;
    border: 1px solid #e74c3c;
}

.invoice-table thead {
    background: #e74c3c;
}

.invoice-table th {
    padding: 12px 10px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
    color: white;
    text-transform: none;
    letter-spacing: 0.3px;
    border-right: 1px solid #c0392b;
}

.invoice-table th:last-child {
    border-right: none;
}

.invoice-table th:first-child {
    text-align: left;
}

.invoice-table td {
    padding: 10px;
    border-bottom: 1px solid #bdc3c7;
    border-right: 1px solid #bdc3c7;
    font-size: 12px;
    background: #e8f4fc;
    vertical-align: middle;
}

.invoice-table td:last-child {
    border-right: none;
}

.invoice-table td:first-child {
    width: 45%;
}

.invoice-table tbody tr:hover {
    background: #d4edfc;
}

.invoice-table input,
.invoice-table textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid #bdc3c7;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    font-family: inherit;
}

.invoice-table textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.6;
    overflow: visible;
}

.item-amount {
    font-weight: 600;
    color: #1f2937;
    text-align: right;
}

.remove-item {
    background: #ef4444;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.3s ease;
}

.remove-item:hover {
    background: #dc2626;
}

/* Totals Section - Right aligned small box */
.totals-wrapper-right {
    display: flex;
    justify-content: flex-end;
    margin: 20px 0 25px 0;
    width: 100%;
}

.totals-table {
    border-collapse: collapse;
    border: 1px solid #000;
    width: auto !important;
    max-width: 280px;
}

.totals-table tr {
    border-bottom: 1px solid #000;
}

.totals-table tr:last-child {
    border-bottom: none;
}

.totals-table tr.grand-total-row {
    background: none;
}

.totals-table td {
    padding: 5px 10px;
    font-size: 11px;
    border-right: 1px solid #000;
    white-space: nowrap;
    background: white;
}

.totals-table td:last-child {
    border-right: none;
}

.totals-table .total-label {
    text-align: left;
    font-weight: 600;
    color: #000;
}

.totals-table .total-value {
    text-align: right;
    font-weight: 700;
    color: #000;
}

.totals-table .grand-total-row td {
    font-weight: 700;
    color: #000;
}

/* Stamp Section - Centered on page */
.stamp-wrapper-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 25px 0;
}

.stamp-toggle-container {
    margin-bottom: 5px;
    text-align: center;
}

.stamp-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: #4b5563;
}

.stamp-toggle-label input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.cachet-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
}

.cachet-image-large {
    max-width: 280px;
    height: auto;
}

/* Payment Information - Fixed to bottom */
.payment-info {
    position: absolute;
    bottom: 20px;
    left: 35px;
    right: 35px;
    padding: 12px;
    background: #f9fafb;
    border-top: 2px solid #1f2937;
    z-index: 2;
}

.bank-details {
    font-size: 10px;
    color: #1f2937;
    margin-bottom: 3px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.3px;
}

/* Stamp Section Bottom (Hidden - old) */
.stamp-section-bottom {
    margin: 40px 0 20px 0;
    display: flex;
    justify-content: flex-end;
}

.signature-box {
    width: 300px;
    text-align: center;
}

/* Footer */
.invoice-footer {
    margin-top: 20px;
    height: 20px;
}

.print-only {
    display: none;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 1000px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 30px;
    border-bottom: 2px solid #e5e7eb;
    background: #1f2937;
    color: white;
}

.modal-header h2 {
    margin: 0;
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.close-modal:hover {
    transform: scale(1.2);
}

.modal-body {
    padding: 30px;
    overflow-y: auto;
}

.invoice-list-table {
    width: 100%;
    border-collapse: collapse;
}

.invoice-list-table th {
    background: #f3f4f6;
    padding: 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid #e5e7eb;
}

.invoice-list-table td {
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.invoice-list-table tbody tr:hover {
    background: #f9fafb;
}

.invoice-actions {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 14px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-view {
    background: #3b82f6;
    color: white;
}

.btn-view:hover {
    background: #2563eb;
}

.btn-delete {
    background: #ef4444;
    color: white;
}

.btn-delete:hover {
    background: #dc2626;
}

/* Invoice Tabs */
.invoice-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
    padding-bottom: 10px;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.tab-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.tab-btn.active {
    background: #3b82f6;
    color: white;
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
        margin: 0;
    }

    .container {
        max-width: 100%;
    }

    header {
        display: none;
    }

    .invoice-wrapper {
        box-shadow: none;
    }

    .invoice {
        padding: 12mm 15mm;
        max-height: 100vh;
        page-break-after: avoid;
        page-break-inside: avoid;
    }

    @page {
        size: A4;
        margin: 5mm;
    }

    .corner-decoration {
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .no-print,
    .no-print-edit {
        display: none !important;
    }

    .print-only {
        display: block !important;
    }

    .input-field,
    .date-input,
    #invoiceNumber {
        border: none !important;
        background: transparent !important;
        padding: 2px !important;
    }

    .client-section {
        border: 1px solid #e5e7eb;
    }
    
    .client-field .input-inline {
        border: none !important;
        border-bottom: none !important;
    }

    .invoice-table input,
    .invoice-table textarea {
        border: none !important;
        background: transparent !important;
        resize: none !important;
        padding: 5px !important;
        font-size: 12px !important;
        line-height: 1.5 !important;
    }
    
    .invoice-table textarea {
        display: block !important;
        overflow: visible !important;
        height: auto !important;
        min-height: auto !important;
        white-space: pre-wrap !important;
    }
    
    .invoice-table td:first-child {
        width: 50% !important;
    }
    
    .invoice-table thead {
        background: #e74c3c !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    
    .invoice-table th {
        color: white !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }
    
    .invoice-table td {
        background: #e8f4fc !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .cachet-image-large {
        display: block !important;
        max-width: 250px !important;
    }

    .notes-display {
        display: block !important;
    }
    
    /* Compact spacing for print */
    .company-details {
        margin-bottom: 12px;
    }
    
    .facture-title {
        margin: 10px 0;
        padding: 8px 0;
    }
    
    .ref-client-section {
        margin: 10px 0 12px 0;
    }
    
    .objet-section {
        margin: 10px 0;
        padding: 8px;
    }
    
    .items-section {
        margin: 10px 0;
    }
    
    .totals-stamp-wrapper {
        margin: 10px 0;
    }
    
    /* Force totals table to be small and right-aligned in print */
    .totals-wrapper-right {
        display: flex !important;
        justify-content: flex-end !important;
        width: 100% !important;
    }
    
    .totals-wrapper-right .totals-table {
        width: auto !important;
        min-width: 0 !important;
        max-width: 280px !important;
    }
    
    .stamp-wrapper-center {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        width: 100% !important;
    }
    
    .invoice {
        min-height: 277mm !important;
        padding-bottom: 80px !important;
    }
    
    .payment-info {
        position: absolute !important;
        bottom: 15px !important;
        left: 15mm !important;
        right: 15mm !important;
        padding: 8px;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .invoice {
        padding: 20px;
    }

    .invoice-top-header {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .header-design {
        width: 100%;
        height: 150px;
    }

    .totals-stamp-wrapper {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .totals-grid {
        width: 100%;
    }
}

/* Invoice Tabs */
.invoice-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #e5e7eb;
}

.tab-btn {
    padding: 12px 24px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}

.tab-btn:hover {
    color: #1f2937;
    background: #f3f4f6;
}

.tab-btn.active {
    color: #3b82f6;
    border-bottom-color: #3b82f6;
}

.tab-content {
    min-height: 200px;
}
