body {
    font-family: 'Segoe UI', Arial, sans-serif;
    margin: 0;
    padding: 20px;
    background: #eef2f3;
    color: #333;
    touch-action: manipulation;
}

.invoice-box {
    max-width: 850px;
    margin: auto;
    padding: 40px;
    background: white;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-radius: 8px;
}

header { display: flex; justify-content: space-between; align-items: center; }
.logo img { max-width: 140px; height: auto; }
.company-details { text-align: right; }
.company-details h2 { margin: 0 0 6px 0; font-size: 18px; color: #111; }
.company-details p { margin: 0; font-size: 12px; line-height: 1.5; color: #555; }
.divider { border: 0; border-top: 2px solid #333; margin: 20px 0; }

.info-section { display: flex; justify-content: space-between; margin-bottom: 25px; }
.client-info { width: 55%; }
.client-info h3 { margin: 0 0 8px 0; font-size: 14px; color: #555; }
.display-text p { margin: 3px 0; font-size: 14px; color: #111; }
.quote-info { width: 35%; text-align: right; }
.quote-info h2 { margin: 0 0 10px 0; color: #0056b3; font-size: 22px; }
.quote-info p { margin: 5px 0; font-size: 14px; }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; margin: 25px 0; min-width: 600px; }
table, th, td { border: 1px solid #b2bec3; }
th { background-color: #f1f2f6; color: #2f3640; font-weight: 600; font-size: 13px; padding: 10px; }
td { padding: 8px; text-align: center; font-size: 14px; }
.item-text-left { text-align: left; }
.total-label { text-align: right; font-weight: bold; background-color: #f1f2f6; }

.terms-section { margin: 20px 0; font-size: 12px; color: #444; }
.terms-section h4 { margin: 0 0 10px 0; font-size: 14px; color: #2f3640; }
.terms-section ul { margin: 0; padding-left: 20px; }
.terms-section li { margin-bottom: 5px; line-height: 1.4; }

.bottom-section { display: flex; justify-content: space-between; margin-top: 30px; }
.bank-details { width: 48%; font-size: 12px; line-height: 1.6; background: #f8f9fa; padding: 15px; border-radius: 6px; border-left: 4px solid #0056b3; }
.bank-details h4 { margin: 0 0 8px 0; font-size: 14px; }
.bank-details p { margin: 2px 0; }
.closing-text { width: 48%; text-align: right; font-size: 13px; }
.closing-text p { margin: 5px 0; }
.signature { margin-top: 25px; text-align: right; }
.seal-img { max-width: 110px; margin-top: 8px; display: inline-block; }

.actions { text-align: center; margin: 30px 0 50px 0; display: flex; justify-content: center; gap: 15px; flex-wrap: wrap; }
.btn-submit, .btn-primary { padding: 14px 20px; font-weight: bold; background-color: #007bff; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
.btn-secondary { padding: 14px 20px; font-weight: bold; background-color: #6c757d; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; }
.btn-remove { background: #e74c3c; color: white; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-weight: bold; }
.btn-add { background: #2ecc71; color: white; border: none; padding: 8px 16px; border-radius: 4px; cursor: pointer; font-weight: bold; font-size: 14px; }

/* MODAL */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    z-index: 1000;
    padding: 12px;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-box {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 100%;
    max-width: 450px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    margin: 10px auto 30px auto;
    box-sizing: border-box;
}

.modal-box h2 { margin-top: 0; font-size: 20px; color: #333; margin-bottom: 15px; }
.modal-box label { display: block; margin-top: 12px; font-weight: bold; font-size: 13px; color: #555; }

.modal-box input,
.modal-box textarea {
    width: 100%;
    padding: 12px;
    margin-top: 5px;
    border: 1px solid #ccc;
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
}

.split-inputs { display: flex; gap: 10px; }
.split-inputs > div { flex: 1; min-width: 0; }

.modal-actions { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }
.modal-actions button { flex: 1; }

/* Stepper */
.quote-stepper {
    display: flex;
    align-items: center;
    margin-top: 5px;
    background: #f8f9fa;
    border: 1px solid #ccc;
    border-radius: 6px;
    overflow: hidden;
}
#quotePrefix {
    padding: 12px 8px;
    background: #e9ecef;
    font-weight: bold;
    color: #495057;
    border-right: 1px solid #ccc;
    font-size: 15px;
    white-space: nowrap;
}
.stepper-btn {
    background: #007bff;
    color: white;
    border: none;
    padding: 12px 18px;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stepper-btn:active { background: #0056b3; }
#quoteSeq {
    border: none;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    margin: 0;
    border-radius: 0;
    flex: 1;
    min-width: 40px;
    pointer-events: none;
    background: white;
}

/* Preview Mode */
body.preview-mode { background: white; padding: 0; }
body.preview-mode .invoice-box { box-shadow: none; border: none; padding: 20px; }
body.preview-mode .no-print { display: none !important; }
body.preview-mode #itemsTable th:last-child,
body.preview-mode #itemsTable td:last-child { display: none !important; }

@media print {
    body { background: white; padding: 0; }
    .invoice-box { box-shadow: none; max-width: 100%; padding: 0; border: none; }
    .no-print { display: none !important; }
}

.invoice-box { page-break-inside: avoid; }
table, tr, td, th, thead, tfoot { page-break-inside: avoid; }
.bottom-section, .terms-section { page-break-inside: avoid; }

/* MOBILE */
@media (max-width: 768px) {
    body { padding: 0; background: #eef2f3; }

    .invoice-box {
        padding: 15px;
        border-radius: 0;
        overflow-x: hidden;
    }

    header { flex-direction: column; text-align: center; }
    .company-details { text-align: center; margin-top: 12px; }
    .company-details h2 { font-size: 15px; }

    .info-section { flex-direction: column; }
    .client-info, .quote-info { width: 100%; margin-bottom: 12px; }
    .quote-info { text-align: left; border-top: 1px solid #eee; padding-top: 12px; }

    .bottom-section { flex-direction: column; }
    .bank-details, .closing-text { width: 100%; box-sizing: border-box; margin-bottom: 15px; }
    .closing-text { text-align: left; }
    .signature { text-align: left; margin-top: 12px; }

    .split-inputs { flex-direction: row; }
    .split-inputs > div { flex: 1; min-width: 0; }
    .split-inputs input { font-size: 16px; }

    .actions { flex-direction: column; gap: 10px; padding: 0 15px; margin-bottom: 30px; }
    .actions button { width: 100%; }

    #quotePrefix { font-size: 13px; padding: 10px 6px; }
}

@media (max-width: 380px) {
    #quotePrefix { font-size: 12px; padding: 8px 4px; }
    .stepper-btn { padding: 10px 14px; }
}

/* New action buttons */
.btn-edit      { padding: 12px 16px; font-weight: bold; background: #6f42c1; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 15px; }
.btn-add-item  { padding: 12px 16px; font-weight: bold; background: #28a745; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 15px; }
.btn-whatsapp  { padding: 12px 16px; font-weight: bold; background: #25D366; color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 15px; }

@media (max-width: 768px) {
    .btn-edit, .btn-add-item, .btn-whatsapp { width: 100%; }
}

/* TC Card */
.tc-card {
    max-width: 850px;
    margin: 16px auto;
    background: #fff8e1;
    border-left: 4px solid #f59f00;
    border-radius: 8px;
    padding: 18px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.tc-card h3 { margin: 0 0 10px 0; font-size: 15px; color: #333; }
.tc-card textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 15px;
    box-sizing: border-box;
    resize: vertical;
    font-family: inherit;
}
.btn-tc-save {
    margin-top: 10px;
    padding: 10px 20px;
    background: #f59f00;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
}

/* Finalise button */
.btn-finalise {
    padding: 14px 20px;
    font-weight: bold;
    background: #e63946;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
}

@media (max-width: 768px) {
    .tc-card { margin: 12px 0; border-radius: 0; }
    .btn-finalise { width: 100%; }
}