/* ============================================================
   RESET AND BASE STYLES
   ============================================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', sans-serif;
    background-color: #f5f5f5;
    padding: 20px;
    line-height: 1.4;
}

.container {
    max-width: 800px;
    margin: 0 auto;
}


/* ============================================================
   INVOICE TEMPLATE
   ============================================================ */
.invoice-template {
    background: white;
    padding: 40px;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    border: 1px solid #ddd;
    min-height: 1056px; /* 11in at 96dpi */
    width: 816px;       /* 8.5in at 96dpi - avoids html2canvas inch-unit issues */
    margin: 0 auto 20px auto;
	position: relative;
}

/* ============================================================
   PAID STAMP STYLES
   ============================================================ */
   
/* PAID Control Checkbox */
.paid-control {
    text-align: center;
    margin: 20px 0;
    padding: 15px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.paid-checkbox-label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 500;
    color: #333;
    user-select: none;
}

/* Custom Checkbox Styling */
.paid-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: #28a745;
}

.paid-checkbox:checked + .checkmark::after {
    content: "✓";
    color: #28a745;
    font-weight: bold;
    margin-left: 5px;
}

/* PAID Stamp Overlay */
.paid-stamp {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-25deg);
    z-index: 100;
    pointer-events: none; /* Allows clicking through the stamp */
    user-select: none;
}

.stamp-text {
    /* Garish styling */
    font-size: 120px;
    font-weight: 900;
    font-family: 'Arial Black', Arial, sans-serif;
    color: #dc3545;
    text-shadow: 
        3px 3px 0px #fff,
        -3px -3px 0px #fff,
        3px -3px 0px #fff,
        -3px 3px 0px #fff,
        4px 4px 8px rgba(0,0,0,0.3);
    
    /* Semi-transparent background */
    background: rgba(220, 53, 69, 0.15);
    border: 8px solid #dc3545;
    border-radius: 20px;
    padding: 20px 40px;
    
    /* Additional garish effects */
    box-shadow: 
        0 0 20px rgba(220, 53, 69, 0.4),
        inset 0 0 20px rgba(255, 255, 255, 0.3);
    
    /* Animation for extra attention */
    animation: stampPulse 2s ease-in-out infinite alternate;
}

/* Stamp animation */
@keyframes stampPulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.02);
        opacity: 1;
    }
}


/* ============================================================
   INVOICE HEADER
   ============================================================ */
.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #333;
}

/* Left side: logo + company details side by side */
.company-info {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 15px;
    flex: 1;
}

/* Logo container sizes itself to its content - no fixed width */
.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex-shrink: 0; /* don't compress logo when space is tight */
}

/* Company name and address stack vertically */
.company-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1;
}

/* Right side: invoice number/dates */
.invoice-info {
    text-align: right;
    flex-shrink: 0;
}

.invoice-info h1 {
    font-size: 36px;
    color: #333;
    margin-bottom: 15px;
}

.invoice-number,
.invoice-date,
.due-date {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
    justify-content: flex-end;
}

.invoice-info label {
    font-weight: bold;
    min-width: 100px;
}


/* ============================================================
   LOGO UPLOAD AREA
   ============================================================ */
.logo-upload-area {
    width: 120px;
    height: 120px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background-color: #fafafa;
    position: relative;
    overflow: hidden;
}

.logo-upload-area:hover {
    border-color: #007bff;
    background-color: #f0f8ff;
}

.logo-upload-area.dragover {
    border-color: #007bff;
    background-color: #e3f2fd;
    transform: scale(1.02);
}

.logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.logo-placeholder {
    text-align: center;
    padding: 10px;
    color: #666;
}

.upload-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.upload-text {
    font-size: 12px;
    line-height: 1.3;
    margin-bottom: 5px;
}

.upload-formats {
    font-size: 10px;
    color: #999;
}

.logo-controls {
    display: flex;
    gap: 5px;
}


/* ============================================================
   COMPANY NAME AND ADDRESS INPUTS
   ============================================================ */
.company-name {
    font-size: 18px;
    font-weight: bold;
    border: none;
    background: transparent;
    border-bottom: 1px solid #ccc;
    padding: 5px 0;
}

.company-address {
    border: none;
    background: transparent;
    border-bottom: 1px solid #ccc;
    padding: 5px 0;
    resize: none;
    height: 60px;
}


/* ============================================================
   BILL TO + NOTES (side by side)
   ============================================================ */
.bill-to-section {
    display: flex;
    gap: 20px;
    width: 100%;
    margin-bottom: 30px;
}

.bill-to {
    flex: 0 0 50%;
}

.bill-to h3 {
    margin-bottom: 10px;
}

.notes-section {
    flex: 0 0 50%;
}

.notes-section h4 {
    margin-bottom: 10px;
    color: #333;
}

.notes-field {
    width: 100%;
    height: 80px;
    resize: vertical;
}


/* ============================================================
   ITEMS TABLE
   ============================================================ */
.items-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.items-table th {
    background-color: #f8f9fa;
    padding: 12px;
    text-align: left;
    border: 1px solid #ddd;
    font-weight: bold;
}

.items-table td {
    padding: 10px 12px;
    border: 1px solid #ddd;
    vertical-align: middle;
}

.item-amount {
    text-align: right;
    font-weight: bold;
}

/* Last column (remove button) */
.items-table th:last-child,
.items-table td:last-child {
    width: 50px;
    text-align: center;
}

/* Table controls (add row button, row count) */
.table-controls {
    margin: 10px 0 20px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.row-info {
    color: #666;
    font-size: 14px;
}

.remove-row-btn {
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.remove-row-btn:hover {
    background: #c82333;
}


/* ============================================================
   TOTALS SECTION
   ============================================================ */
.totals-section {
    width: 100%;
    margin-bottom: 30px;
    overflow: hidden; /* float clearfix */
}

.totals {
    float: right;
    min-width: 300px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
}

.total-final {
    border-top: 2px solid #333;
    border-bottom: 2px solid #333;
    font-size: 18px;
    margin-top: 10px;
    padding-top: 15px;
}

.tax-input {
    width: 60px;
    text-align: center;
}


/* ============================================================
   INPUT FIELDS
   ============================================================ */
.input-field {
    border: none;
    border-bottom: 1px solid #ccc;
    background: transparent;
    padding: 5px 0;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.3s;
}

.input-field:focus {
    outline: none;
    border-bottom-color: #007bff;
    background-color: #f8f9ff;
}

.input-field::placeholder {
    color: #999;
    font-style: italic;
}


/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    padding: 12px 24px;
    margin: 0 10px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #545b62;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-small {
    padding: 4px 8px;
    font-size: 11px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
}

.action-buttons {
    text-align: center;
    margin-top: 20px;
}


/* ============================================================
   EMAIL MODAL
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: white;
    margin: 10% auto;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    position: relative;
}

.close {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 24px;
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-actions {
    text-align: right;
    margin-top: 20px;
}


/* ============================================================
   PRINT / HTML2CANVAS STYLES
   
   Strategy: replace all flexbox with floats + explicit widths
   so html2canvas can resolve layout without miscomputing
   container widths. The logo-container sizes itself to its
   content, so when it's hidden via .logo-not-uploaded, no
   space is left behind and company-details fills naturally.
   ============================================================ */
@media print {

    /* --- Page chrome --- */
    body {
        background: white;
        padding: 0;
    }

    .container {
        max-width: none;
        margin: 0;
    }

    .invoice-template {
        box-shadow: none;
        border: none;
        margin: 0;
        padding: 20px;
    }
	
    .paid-stamp {
        position: absolute !important;
        display: block !important;
        z-index: 100 !important;
    }
    
    .stamp-text {
        /* Ensure stamp is visible in print */
        -webkit-print-color-adjust: exact;
        color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .paid-control {
        display: none !important;
    }

    .no-print {
        display: none !important;
    }

    /* --- Input fields --- */
    .input-field {
        border: none;
        background: transparent;
        color: black;
    }

    .input-field:focus {
        background: transparent;
    }

    /* --- Invoice header: float-based layout for html2canvas --- */
    .invoice-header {
        display: block;
        overflow: hidden; /* clearfix for floated children */
        width: 100%;
    }

    /* Left column: logo + company details together */
    .company-info {
        display: block;
        overflow: hidden; /* clearfix for logo-container float */
        float: left;
        width: 50%;
    }

    /*
     * logo-container floats left inside company-info and sizes
     * itself to its content (no fixed width). When logo-not-uploaded
     * hides it entirely, it vanishes from the flow completely and
     * company-details fills from the left edge with no gap.
     */
    .logo-container {
        float: left;
        margin-right: 12px;
    }

    .company-details {
        display: block;
        overflow: hidden; /* sits beside the floated logo-container */
    }

    /* Right column: invoice info */
    .invoice-info {
        float: right;
        width: 45%;
        text-align: right;
    }

    /* --- Logo: hide upload chrome, keep image only --- */
    .logo-upload-area {
        border: none;
        background: transparent;
        width: auto;
        height: auto;
    }

    .logo-placeholder {
        display: none !important;
    }

    .logo-controls {
        display: none !important;
    }

    /*
     * When no logo is uploaded, collapse the entire logo-container
     * (not just the upload area inside it). Because logo-container
     * has no fixed width and is float:left, setting it to
     * display:none removes it from flow entirely — company-details
     * then starts at the left edge automatically, no gap.
     */
    .logo-not-uploaded {
        display: none !important;
    }

    .company-info:has(.logo-not-uploaded) .logo-container {
        display: none !important;
    }

    /* --- Table: hide interactive controls --- */
    .remove-row-btn,
    .table-controls {
        display: none !important;
    }

    .items-table th:last-child,
    .items-table td:last-child {
        display: none;
    }
}


/* ============================================================
   RESPONSIVE (MOBILE)
   ============================================================ */
@media (max-width: 768px) {
    .invoice-template {
        width: 100%;
        padding: 20px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }
	
    .stamp-text {
        font-size: 80px;
        padding: 15px 30px;
        border-width: 6px;
    }

    .company-info {
        flex-direction: column;
        align-items: center;
        gap: 15px;
    }

    .logo-upload-area {
        width: 100px;
        height: 100px;
    }

    .invoice-info {
        text-align: left;
    }

    .items-table {
        font-size: 12px;
    }

    .totals-section {
        justify-content: center;
    }
}