/* ═══════════════════════════════════════════════
   FieldSync Invoice — Editor + Print Styles
   ═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  line-height: 1.5;
}

/* ── Editor panel (no-print) ── */
.editor {
  max-width: 900px;
  margin: 32px auto;
  padding: 28px 32px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}
.editorTitle {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 20px;
  color: #7c3aed;
}
.editorGroup {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px 18px;
  margin-bottom: 16px;
}
.editorGroup legend {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  padding: 0 6px;
}
.editorRow {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.editorRow label {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
}
.editorRow input,
.editorRow select,
.editor textarea {
  display: block;
  width: 100%;
  margin-top: 3px;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: #1a1a2e;
  background: #fafafa;
}
.editorRow input:focus,
.editorRow select:focus,
.editor textarea:focus {
  outline: none;
  border-color: #7c3aed;
  box-shadow: 0 0 0 2px rgba(124,58,237,0.15);
}
.editor textarea {
  resize: vertical;
}

/* Line items table */
.editorLineItems {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 10px;
}
.editorLineItems th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 6px 4px;
  border-bottom: 2px solid #e5e7eb;
}
.editorLineItems td { padding: 4px; }
.editorLineItems input,
.editorLineItems select {
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  background: #fafafa;
}
.liAmount {
  font-weight: 600;
  font-size: 14px;
  text-align: right;
  padding-right: 8px !important;
  white-space: nowrap;
}
.liRemove {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.liRemove:hover { color: #b91c1c; }
.liItem {
  padding: 6px 8px;
  border: 1px solid #d1d5db;
  border-radius: 5px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
  background: #fafafa;
}

/* Buttons */
.editorBtn {
  padding: 8px 18px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  color: #374151;
}
.editorBtn:hover { background: #f3f4f6; }
.editorBtnPrimary {
  background: #7c3aed;
  color: #fff;
  border-color: #7c3aed;
}
.editorBtnPrimary:hover { background: #6d28d9; }
.editorBtnDanger { color: #ef4444; border-color: #fca5a5; }
.editorBtnDanger:hover { background: #fef2f2; }

.editorActions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.editorPresets {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}
.editorPresetsLabel {
  font-size: 12px;
  color: #9ca3af;
  font-weight: 600;
}
.editorPresetBtn {
  padding: 4px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  background: #f9fafb;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: #6b7280;
  font-family: inherit;
}
.editorPresetBtn:hover { background: #ede9fe; color: #7c3aed; border-color: #c4b5fd; }

/* ═══════════════════════════════════════════════
   INVOICE PREVIEW (rendered + printed)
   ═══════════════════════════════════════════════ */
.invoice {
  max-width: 850px;
  margin: 40px auto;
  padding: 48px 52px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  font-size: 13px;
  color: #1a1a2e;
  line-height: 1.55;
}

.inv-preview-hint {
  text-align: center;
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 16px;
}

/* Header */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  padding-bottom: 20px;
  border-bottom: 3px solid #7c3aed;
}
.inv-brand { display: flex; align-items: center; gap: 14px; }
.inv-logo {
  width: 56px;
  height: 56px;
  border-radius: 8px;
  object-fit: contain;
}
.inv-companyName {
  font-size: 20px;
  font-weight: 800;
  color: #7c3aed;
}
.inv-companyDetail {
  font-size: 12px;
  color: #6b7280;
}
.inv-headerRight { text-align: right; }
.inv-invoiceLabel {
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 2px;
  color: #1a1a2e;
  margin-bottom: 8px;
}
.inv-meta { border-collapse: collapse; margin-left: auto; }
.inv-metaKey {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: #9ca3af;
  padding: 2px 12px 2px 0;
  text-align: right;
}
.inv-metaVal {
  font-size: 13px;
  font-weight: 600;
  color: #1a1a2e;
  padding: 2px 0;
}

/* Bill-to / Meet */
.inv-parties {
  display: flex;
  gap: 40px;
  margin-bottom: 28px;
}
.inv-billTo, .inv-meetInfo { flex: 1; }
.inv-partyLabel {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #7c3aed;
  margin-bottom: 6px;
}
.inv-partyName { font-size: 15px; font-weight: 700; margin-bottom: 2px; }
.inv-partyDetail { font-size: 12px; color: #6b7280; }

/* Line items table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}
.inv-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  background: #7c3aed;
  padding: 8px 10px;
}
.inv-table th:first-child { border-radius: 4px 0 0 0; }
.inv-table th:last-child { border-radius: 0 4px 0 0; }
.inv-table td {
  padding: 10px;
  border-bottom: 1px solid #f3f4f6;
  font-size: 13px;
}
.inv-table tr:last-child td { border-bottom: 2px solid #e5e7eb; }
.inv-tItem { width: 18%; font-weight: 600; }
.inv-tDesc { width: 29%; }
.inv-table td.inv-tDesc { font-size: 11px; line-height: 1.35; }
.inv-tQty { width: 8%; text-align: center; }
.inv-tUnit { width: 8%; text-align: center; }
.inv-tRate { width: 17%; text-align: right; }
.inv-tAmt { width: 18%; text-align: right; font-weight: 600; }
.inv-table th.inv-tItem { text-align: left; }
.inv-table th.inv-tQty,
.inv-table th.inv-tUnit { text-align: center; }
.inv-table th.inv-tRate,
.inv-table th.inv-tAmt { text-align: right; }

/* Totals */
.inv-totals {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 28px;
}
.inv-totalsRight { width: 280px; }
.inv-totalRow {
  display: flex;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 14px;
}
.inv-totalBold {
  font-weight: 800;
  font-size: 18px;
  background: #f5f3ff;
  border-radius: 6px;
  margin-top: 4px;
  color: #7c3aed;
}

/* Notes */
.inv-notes {
  background: #f9fafb;
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 24px;
}
.inv-notesLabel {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9ca3af;
  margin-bottom: 4px;
}
.inv-notesText { font-size: 13px; color: #374151; white-space: pre-wrap; }

/* Payment */
.inv-payment {
  background: #f5f3ff;
  border: 1px solid #ede9fe;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
}
.inv-paymentTitle {
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #7c3aed;
  margin-bottom: 8px;
}
.inv-paymentBody { font-size: 13px; color: #374151; }
.inv-paymentBody p { margin-bottom: 4px; }

/* Terms & Conditions */
.inv-terms {
  border-top: 1px solid #e5e7eb;
  padding-top: 20px;
  margin-bottom: 24px;
}
.inv-termsTitle {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #9ca3af;
  margin-bottom: 10px;
}
.inv-termsList {
  padding-left: 18px;
  font-size: 10.5px;
  color: #6b7280;
  line-height: 1.6;
}
.inv-termsList li { margin-bottom: 4px; }
.inv-termsList strong { color: #374151; }

/* Footer */
.inv-footer {
  text-align: center;
  border-top: 1px solid #e5e7eb;
  padding-top: 14px;
}
.inv-footerLine { font-size: 11px; color: #9ca3af; }
.inv-footerTagline { font-size: 10px; color: #c4b5fd; margin-top: 2px; }


/* ═══════════════════════════════════════════════
   PRINT STYLES
   ═══════════════════════════════════════════════ */
@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .invoice {
    max-width: none;
    margin: 0;
    padding: 32px 40px;
    box-shadow: none;
    border-radius: 0;
    font-size: 12px;
  }
  .inv-header { border-bottom-width: 2px; margin-bottom: 24px; padding-bottom: 14px; }
  .inv-invoiceLabel { font-size: 28px; }
  .inv-logo { width: 48px; height: 48px; }
  .inv-companyName { font-size: 18px; }
  .inv-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-totalBold { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-payment { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .inv-totals {
    page-break-after: always;
    break-after: page;
  }
  .inv-page2 {
    page-break-before: always;
    break-before: page;
  }
  .inv-notes, .inv-payment, .inv-terms {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .inv-footer { position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 40px; }
  @page { margin: 0.5in; size: letter; }
}

/* ── Responsive for small screens ── */
@media (max-width: 700px) {
  .editor { margin: 12px; padding: 16px; }
  .editorRow { flex-direction: column; gap: 6px; }
  .invoice { margin: 12px; padding: 24px 20px; }
  .inv-header { flex-direction: column; gap: 16px; }
  .inv-headerRight { text-align: left; }
  .inv-parties { flex-direction: column; gap: 16px; }
}
