/* Injected from client print flow: hide agreement + invoice signature blocks */
body.agreement-no-signatures .signature-section,
body.agreement-no-signatures .service-signature-section {
    display: none !important;
}

@media print {
    body {
        margin: 0;
        padding: 0;
        background: white;
    }

    .no-print,
    .sa-floating-toolbar,
    .rich-text-toolbar {
        display: none !important;
    }

    .page-break {
        page-break-before: always;
    }

    .section {
        page-break-inside: avoid;
    }

    .container {
        box-shadow: none;
        border-radius: 0;
        max-width: 100%;
    }

    .content {
        padding: 30px;
    }

    .header {
        padding: 30px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .parties,
    .critical-box,
    .signature-section {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .section-number {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Ensure inputs print their values cleanly */
    .invoice-input-desc,
    .invoice-input-amount,
    input[type="text"],
    input[type="number"] {
        border: none !important;
        background: transparent !important;
        padding: 0;
        margin: 0;
    }

    /* Tech notes: ruled lines at print (toggle off with body.sa-notes-no-ruled-lines) */
    .tech-notes-area {
        overflow: visible !important;
        height: auto !important;
        color: #000 !important;
        background-image: repeating-linear-gradient(to bottom,
                transparent,
                transparent 29px,
                #bbb 29px,
                #bbb 30px) !important;
        background-attachment: local !important;
        line-height: 30px !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body.sa-notes-no-ruled-lines .tech-notes-area {
        background-image: none !important;
    }

    /* Enforce space for blank lines when printed empty */
    .tech-notes-area.compact {
        min-height: 500px !important;
    }

    .tech-notes-area.full-page {
        min-height: 800px !important;
    }

    .rich-text-editor {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
    }

    .rich-text-toolbar {
        display: none !important;
    }

    .invoice-input-desc::placeholder,
    .invoice-input-amount::placeholder {
        color: transparent;
    }
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #2c3e50;
    background: #f5f7fa;
    padding: 20px;
}

.container {
    max-width: 850px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    text-align: center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #f093fb 0%, #f5576c 100%);
}

.logo-text {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    color: white;
}

.header-content h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 1px;
    margin-bottom: 5px;
    text-align: right;
}

.header-content p {
    font-size: 12px;
    opacity: 0.9;
    text-align: right;
}

.content {
    padding: 20px;
}

.parties {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.party {
    display: flex;
    flex-direction: column;
}

.party-label {
    font-weight: 600;
    color: #667eea;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.party-name {
    font-size: 16px;
    font-weight: 500;
    color: #2c3e50;
}

.input-line {
    border: none;
    border-bottom: 2px solid #667eea;
    padding: 5px 0;
    font-size: 14px;
    background: transparent;
    width: 100%;
    margin-top: 5px;
}

.section {
    margin-bottom: 20px;
}

.section-title {
    font-size: 14px;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 8px;
    padding-bottom: 5px;
    border-bottom: 2px solid #e8eaf6;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Specific spacing for Travel Fee Section */
.travel-fee-section {
    margin-bottom: 60px;
}

.section-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 700;
}

.critical-box {
    background: linear-gradient(135deg, #fff5f5 0%, #fed7d7 100%);
    border-left: 4px solid #e53e3e;
    padding: 10px;
    margin: 10px 0;
    border-radius: 4px;
    font-size: 13px;
}

p {
    font-size: 13px;
    margin-bottom: 8px;
}

ul {
    margin: 8px 0 8px 20px;
    font-size: 13px;
}

.critical-box strong {
    color: #c53030;
}

.initials-box {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    padding: 15px 20px;
    background: white;
    border: 2px solid #e53e3e;
    border-radius: 6px;
    font-weight: 600;
}

.initials-box input {
    width: 80px;
    border: none;
    border-bottom: 2px solid #e53e3e;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #c53030;
}

ul {
    margin: 15px 0 15px 25px;
}

li {
    margin-bottom: 10px;
    padding-left: 10px;
}

li strong {
    color: #667eea;
}

.signature-section {
    margin-top: 50px;
    padding: 30px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 8px;
    border-top: 4px solid #667eea;
}

.signature-section h3 {
    color: #667eea;
    font-size: 20px;
    margin-bottom: 25px;
    text-align: center;
}

.signature-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.signature-field {
    display: flex;
    flex-direction: column;
}

.signature-field label {
    font-weight: 600;
    color: #667eea;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.signature-field input {
    border: none;
    border-bottom: 2px solid #667eea;
    padding: 10px 0;
    font-size: 14px;
    background: transparent;
}

.acknowledgment {
    text-align: center;
    font-style: italic;
    color: #666;
    margin-bottom: 20px;
}

.print-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transition: transform 0.2s;
}

.print-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 5px;
}

/* Technician Notes & Invoice Section */
.tech-invoice-container {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.tech-notes-box {
    flex: 1;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 4px;
    background: #fff;
    margin-bottom: 4px;
}

.tech-notes-title {
    color: #667eea;
    font-size: 10px;
    margin-bottom: 1px;
    font-weight: bold;
    text-transform: uppercase;
    border-bottom: 0px solid #e2e8f0;
    padding-bottom: 1px;
}

/* Invoice table (screen + print) */
.sa-invoice-title {
    color: #d69e2e;
    font-size: 16px;
    margin: 0;
    padding: 5px 10px;
    font-weight: bold;
    text-transform: uppercase;
}

.sa-invoice-table {
    width: 100%;
    border-collapse: collapse;
    border-top: 1px solid #cbd5e0;
}

.sa-invoice-th {
    padding: 5px 10px;
    border-bottom: 1px solid #e2e8f0;
    font-size: 13px;
    color: #744210;
    background: #fffff0;
}

.sa-invoice-th--service {
    text-align: left;
    border-right: 1px solid #cbd5e0;
}

.sa-invoice-th--amount {
    text-align: right;
    padding: 10px;
    width: 120px;
}

.sa-travel-fee-chip {
    float: left;
    display: flex;
    align-items: center;
    border: 1px solid #cbd5e0;
    border-radius: 4px;
    background: white;
    padding: 2px 5px;
    margin-right: 8px;
}

.sa-travel-fee-chip span {
    font-size: 11px;
    color: #718096;
    margin-right: 5px;
    font-weight: normal;
}

.sa-travel-fee-chip input {
    width: 70px;
    text-align: right;
    border: none;
    font-size: 12px;
    font-weight: 600;
    color: #2d3748;
    padding: 0;
    background: transparent;
}

.payment-methods {
    padding: 8px 10px;
    margin-bottom: 5px;
    border-top: 2px solid #ecc94b;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.payment-methods h4 {
    margin: 0;
    font-size: 14px;
    color: #4a5568;
    text-transform: uppercase;
    white-space: nowrap;
}

.payment-methods label {
    display: flex;
    align-items: center;
    font-size: 13px;
    cursor: pointer;
}

.payment-methods input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-right: 5px;
}

/* Invoice Table Styles */
.invoice-container {
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
    /* Ensures table corners respect radius */
    margin-top: 5px;
    /* Increase spacing from tech notes */
}

.invoice-item-row td {
    padding: 4px 10px;
    /* Reduced padding for shorter rows */
    border-bottom: 1px solid #cbd5e0;
    font-size: 13px;
    color: #2d3748;
    height: 25px;
    /* Reduced height */
}

/* Add vertical borders to invoice cells */
.invoice-td {
    border-right: 1px solid #cbd5e0;
}

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

.invoice-td.amount {
    text-align: right;
    font-weight: 600;
}

/* Summary Rows (Travel Fee, Totals) */
.invoice-total-label {
    text-align: right;
    padding: 5px 15px 5px 10px;
    font-weight: 700;
    color: #4a5568;
    border-top: 1px solid #cbd5e0;
    /* Matches other borders */
    border-right: 1px solid #cbd5e0;
    /* Vertical border for label */
}

.invoice-total-amount {
    text-align: right !important;
    padding: 10px;
    font-weight: 700;
    color: #2d3748;
    border-top: 1px solid #cbd5e0;
    background: #f7fafc;
}

/* Specific override for Grand Total */
tr:last-child .invoice-total-label,
tr:last-child .invoice-total-amount {
    border-top: 2px solid #ecc94b;
    /* Lighter Gold/Orange */
    font-size: 15px;
    color: #744210;
    background: #fffff0;
    padding: 5px 10px;
    /* Reduced padding for shorter height */
}

/* Note Bubble (GitHub Style) */
.note-bubble {
    background-color: #e6fffa;
    /* Light Teal */
    border-left: 4px solid #38b2ac;
    /* Teal Accent */
    padding: 15px;
    margin: 15px 0;
    border-radius: 4px;
    color: #234e52;
    /* Dark Teal Text */
    font-size: 13px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.note-bubble strong {
    color: #2c7a7b;
    display: block;
    margin-bottom: 5px;
}

/* =========================================
   Notes Area — Single Contenteditable Editor
   =========================================
   No ruled lines on screen: clean, distraction-free editing.
   Paste works. Bold / italic / font-size all work normally.
   Ruled lines are injected only at @media print (see above).
*/

.tech-notes-area {
    width: 100%;
    border: none;
    resize: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 14px;
    line-height: 30px;
    /* matches print gradient period for best-effort alignment */
    color: #2c3e50;
    outline: none;
    display: block;
    background: white;
    padding: 5px 10px;
}

.tech-notes-area.full-page {
    height: calc(100% - 90px);
    overflow-y: auto;
}

.tech-notes-area.compact {
    height: 480px;
    overflow-y: auto;
}

/* Preserve line breaks and allow wrapping within the contenteditable */
.tech-notes-area[contenteditable] {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Keep child elements (bold, font spans) in the same rhythm */
.tech-notes-area * {
    line-height: 30px;
    margin-top: 0;
    margin-bottom: 0;
}

/* Restore proper margins/padding for lists and indents */
.tech-notes-area ul,
.tech-notes-area ol {
    margin-left: 20px;
    padding-left: 15px;
}

.tech-notes-area li {
    line-height: 30px;
}

/* =========================================
   Invoice Input Styles
   ========================================= */

.invoice-input-desc,
.invoice-input-amount {
    width: 100%;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 13px;
    color: #2c3e50;
    outline: none;
}

.invoice-input-amount {
    text-align: right;
}

/* Placeholder Styling */
.invoice-input-desc::placeholder,
.invoice-input-amount::placeholder {
    color: #cbd5e0;
    opacity: 1;
}

/* Hide Spinners for Number Inputs */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Interactive Hover States (Screen Only) */
@media screen {

    .invoice-input-desc:hover,
    .invoice-input-amount:hover {
        background-color: rgba(247, 250, 252, 0.5);
    }

    .invoice-input-desc:focus,
    .invoice-input-amount:focus {
        background-color: #fff;
    }
}

/* Extra full-page technician notes only (cloned above invoice) */
.sa-extra-notes-page {
    page-break-before: always;
    margin-top: 1.5rem;
    padding-top: 0.35rem;
}

#sa-extra-pages-anchor {
    display: none;
}

/* ==============================================
   Embed / dark-mode (sa-embed-mode)
   Screen-only: print still uses white paper.
   ============================================== */
@media screen {
    /* Embed in app modal: no inner scroll — parent modal scrolls */
    html.sa-embed-root,
    body.sa-embed-mode {
        overflow: visible !important;
        height: auto !important;
    }
    body.sa-embed-mode {
        background: #111827;
        color: #d1d5db;
        padding: 12px;
    }
    body.sa-embed-mode .container {
        background: #1f2937;
        border: 1px solid #374151;
        box-shadow: none;
    }
    body.sa-embed-mode .content {
        background: #1f2937;
    }
    body.sa-embed-mode h2,
    body.sa-embed-mode h3 {
        color: #e5e7eb;
    }
    body.sa-embed-mode p,
    body.sa-embed-mode li,
    body.sa-embed-mode td,
    body.sa-embed-mode th {
        color: #d1d5db;
    }
    body.sa-embed-mode .section-title {
        color: #e5e7eb;
    }
    body.sa-embed-mode .parties {
        background: #374151;
        border-color: #4b5563;
    }
    body.sa-embed-mode .party-label {
        color: #9ca3af;
    }
    body.sa-embed-mode .party-name {
        color: #f9fafb;
    }
    body.sa-embed-mode .input-line {
        background: transparent;
        border-bottom-color: #6b7280;
        color: #f9fafb;
    }
    body.sa-embed-mode .input-line:focus {
        border-bottom-color: #818cf8;
        outline: none;
    }
    body.sa-embed-mode .note-bubble {
        background: #1e3a5f;
        border-left-color: #3b82f6;
        color: #bfdbfe;
    }
    body.sa-embed-mode .critical-box {
        background: #450a0a;
        border-color: #dc2626;
        color: #fca5a5;
    }
    body.sa-embed-mode .section {
        border-color: #374151;
    }
    /* Notes / rich-text areas go dark */
    body.sa-embed-mode .tech-notes-area,
    body.sa-embed-mode .rich-text-editor {
        background: #111827 !important;
        color: #e2e8f0 !important;
        border-color: #374151 !important;
        caret-color: #a5b4fc;
    }
    body.sa-embed-mode [contenteditable]:focus {
        outline: 2px solid #6366f1 !important;
        outline-offset: 2px;
    }
    body.sa-embed-mode .rich-text-toolbar button {
        background: #374151 !important;
        border-color: #4b5563 !important;
        color: #d1d5db !important;
    }
    body.sa-embed-mode .rich-text-toolbar button:hover {
        background: #4b5563 !important;
        color: #f9fafb !important;
    }
    /* Invoice table */
    body.sa-embed-mode .invoice-container {
        border-color: #374151;
        background: #1f2937;
    }
    body.sa-embed-mode table {
        border-color: #374151;
    }
    body.sa-embed-mode thead tr {
        background: #111827 !important;
    }
    body.sa-embed-mode .invoice-input-desc,
    body.sa-embed-mode .invoice-input-amount {
        background: transparent;
        color: #f9fafb;
        border-color: #374151;
    }
    body.sa-embed-mode .invoice-input-desc:hover,
    body.sa-embed-mode .invoice-input-amount:hover {
        background: #1e293b;
    }
    body.sa-embed-mode .invoice-input-desc:focus,
    body.sa-embed-mode .invoice-input-amount:focus {
        background: #1e293b;
        border-color: #6366f1;
    }
    body.sa-embed-mode .invoice-td {
        border-color: #374151;
    }
    body.sa-embed-mode .invoice-total-display {
        color: #bfdbfe !important;
        background: #1e3a5f !important;
        border: 1px solid #3b82f6 !important;
    }
    body.sa-embed-mode .sa-invoice-title {
        color: #93c5fd !important;
        background: #111827 !important;
    }
    body.sa-embed-mode .invoice-container thead tr,
    body.sa-embed-mode .invoice-container thead th {
        background: #111827 !important;
        color: #9ca3af !important;
        border-color: #374151 !important;
    }
    body.sa-embed-mode tr.sa-invoice-total-row .invoice-total-label,
    body.sa-embed-mode tr.sa-invoice-total-row .invoice-total-amount,
    body.sa-embed-mode tr:last-child .invoice-total-label,
    body.sa-embed-mode tr:last-child .invoice-total-amount {
        background: #1f2937 !important;
        border-color: #374151 !important;
        border-top-color: #4b5563 !important;
        color: #e5e7eb !important;
    }
    body.sa-embed-mode .sa-travel-fee-chip {
        background: #111827 !important;
        border-color: #4b5563 !important;
    }
    body.sa-embed-mode .sa-travel-fee-chip span {
        color: #9ca3af !important;
    }
    body.sa-embed-mode .sa-travel-fee-chip input {
        color: #f9fafb !important;
        background: transparent !important;
    }
    body.sa-embed-mode .sa-floating-toolbar {
        display: none !important;
    }
    body.sa-embed-mode .tech-notes-box {
        border-color: #374151;
        background: #1f2937;
    }
    body.sa-embed-mode .tech-notes-title {
        color: #e5e7eb;
    }
    /* Full-page notes wrapper — inline styles omitted bg so embed can theme it */
    body.sa-embed-mode .sa-tech-notes-full-page,
    body.sa-embed-mode .tech-notes-full-page {
        background: #1f2937 !important;
        border-color: #374151 !important;
    }
    body.sa-embed-mode .sa-tech-notes-full-page .tech-notes-title,
    body.sa-embed-mode .tech-notes-full-page .tech-notes-title,
    body.sa-embed-mode .tech-notes-full-page h3 {
        color: #e5e7eb !important;
        border-bottom-color: #374151 !important;
    }
    /* Signatures */
    body.sa-embed-mode .signature-section,
    body.sa-embed-mode .service-signature-section {
        background: #1f2937;
        border-color: #374151;
        color: #d1d5db;
    }
    body.sa-embed-mode .signature-field label {
        color: #9ca3af;
    }
    body.sa-embed-mode .signature-grid input {
        border-bottom-color: #6b7280;
        color: #f9fafb;
        background: transparent;
    }
    /* Payment section */
    body.sa-embed-mode .payment-methods {
        border-top: 1px solid #374151 !important;
        background: #111827 !important;
        color: #d1d5db;
    }
    body.sa-embed-mode .payment-methods h4,
    body.sa-embed-mode .payment-methods label {
        color: #d1d5db;
    }
    body.sa-embed-mode input[type="checkbox"] {
        accent-color: #6366f1;
    }
    /* Travel fee box */
    body.sa-embed-mode .invoice-total-label > div,
    body.sa-embed-mode .sa-travel-fee-chip {
        background: #111827 !important;
        border-color: #4b5563 !important;
    }
    body.sa-embed-mode .invoice-total-label {
        color: #d1d5db;
    }
    /* Acknowledgment text */
    body.sa-embed-mode .acknowledgment {
        color: #9ca3af;
    }
}

/* Full-page notes: light paper by default; embed overrides above */
.sa-tech-notes-full-page,
.tech-notes-full-page {
    background: white;
}

/* Floating action toolbar — row, flush right (hidden when printing) */
.sa-floating-toolbar {
    position: fixed;
    bottom: 28px;
    right: 28px;
    display: flex;
    flex-flow: row wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    z-index: 999;
    max-width: calc(100vw - 56px);
}
.sa-floating-toolbar button {
    white-space: nowrap;
}