:root {
  --ink: #17212b;
  --muted: #697783;
  --line: #dfe6ea;
  --soft-line: #edf1f3;
  --canvas: #f3f7f8;
  --white: #ffffff;
  --teal: #087f80;
  --teal-dark: #056466;
  --teal-soft: #e8f5f3;
  --navy: #1e3545;
  --danger: #c84f55;
  --shadow: 0 18px 45px rgba(34, 61, 72, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.5;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.page-shell { max-width: 1120px; margin: 0 auto; padding: 30px 24px 46px; }

.app-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; border-radius: 12px; background: var(--navy); color: #d8f2ee; font-weight: 800; font-size: 17px; letter-spacing: -1px; }
.eyebrow { margin: 0 0 3px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.eyebrow.accent { color: var(--teal); }
.app-header h1 { margin: 0; color: var(--navy); font-size: 21px; letter-spacing: -.03em; }
.header-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #42b69a; box-shadow: 0 0 0 4px #e3f3ef; }

.invoice-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--white); box-shadow: var(--shadow); }
.invoice-heading { display: flex; align-items: flex-start; justify-content: space-between; padding: 32px 36px 27px; border-bottom: 1px solid var(--soft-line); }
.invoice-heading h2 { margin: 0 0 4px; color: var(--navy); font-size: 25px; letter-spacing: -.04em; }
.muted { margin: 0; color: var(--muted); font-size: 12px; }
.document-note { margin: 0; padding: 11px 36px; border-bottom: 1px solid #f0e4c7; background: #fffaf0; color: #7f6a3d; font-size: 11px; }
.document-note strong { color: #6b572d; }
.field em { color: #a0abb0; font-size: 10px; font-style: normal; font-weight: 500; }
.invoice-badge { min-width: 225px; padding: 12px 15px; border: 1px solid #cce7e2; border-radius: 9px; background: var(--teal-soft); text-align: right; }
.invoice-badge span { display: block; margin-bottom: 3px; color: var(--teal-dark); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.invoice-badge strong { color: var(--navy); font-size: 13px; }

.form-section { padding: 27px 36px 30px; border-bottom: 1px solid var(--soft-line); }
.section-title { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 21px; }
.section-title-with-action { align-items: center; justify-content: space-between; }
.section-title-main { display: flex; align-items: flex-start; gap: 12px; }
.section-number { display: grid; flex: 0 0 auto; width: 28px; height: 28px; margin-top: -2px; place-items: center; border-radius: 9px; background: var(--teal-soft); color: var(--teal-dark); font-size: 11px; font-weight: 800; }
.section-title h3 { margin: 0 0 2px; color: var(--navy); font-size: 15px; letter-spacing: -.01em; }
.section-title p { margin: 0; color: var(--muted); font-size: 11px; }
.compact-title { margin-bottom: 17px; }

.form-grid { display: grid; gap: 17px; }
.three-columns { grid-template-columns: 1.2fr 1fr .9fr; }
.field { display: block; }
.field > span, .field label { display: block; margin: 0 0 7px; color: #52616b; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; color: var(--ink); border: 1px solid #d5dfe3; border-radius: 7px; outline: none; background: var(--white); transition: border-color .15s ease, box-shadow .15s ease; }
input, select { height: 39px; padding: 0 11px; }
textarea { min-height: 78px; padding: 10px 11px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #a1adb3; }
input:focus, select:focus, textarea:focus { border-color: #54aaa4; box-shadow: 0 0 0 3px rgba(55, 166, 157, .12); }

.party-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.party-card { padding: 20px; border: 1px solid var(--line); border-radius: 10px; }
.seller-card { border-top: 3px solid var(--teal); }
.buyer-card { border-top: 3px solid #93a9b5; }
.party-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 17px; }
.party-icon { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 8px; background: var(--teal-soft); color: var(--teal-dark); font-size: 12px; font-weight: 800; }
.buyer-card .party-icon { background: #edf2f4; color: #57707f; }
.party-heading h4 { margin: 0; color: var(--navy); font-size: 13px; }
.party-heading p { margin: 1px 0 0; color: var(--muted); font-size: 10px; }
.party-card .field + .field { margin-top: 12px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 15px; border: 0; border-radius: 7px; font-size: 12px; font-weight: 750; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--teal); color: white; box-shadow: 0 5px 12px rgba(8, 127, 128, .17); }
.button-primary:hover { background: var(--teal-dark); }
.button-secondary { min-height: 34px; border: 1px solid #b9deda; background: white; color: var(--teal-dark); }
.button-secondary:hover { background: var(--teal-soft); }
.button-ghost { border: 1px solid var(--line); background: white; color: var(--muted); }
.button-ghost:hover { border-color: #b7c4ca; color: var(--ink); }
.button-plus { font-size: 18px; font-weight: 400; line-height: 0; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 9px; }
.items-table { width: 100%; min-width: 690px; border-collapse: collapse; }
.items-table th { padding: 12px 11px; background: #f8fafb; color: #71808a; font-size: 10px; font-weight: 800; text-align: left; text-transform: uppercase; letter-spacing: .06em; }
.items-table td { padding: 9px 8px; border-top: 1px solid var(--soft-line); vertical-align: middle; }
.items-table td:first-child, .items-table th:first-child { padding-left: 14px; }
.items-table input { height: 36px; border-color: #e0e7e9; }
.number-column { width: 40px; }
.quantity-column { width: 112px; }
.price-column { width: 155px; }
.amount-column { width: 140px; }
.action-column { width: 43px; text-align: center !important; }
.row-number { color: var(--muted); font-size: 12px; text-align: center; }
.item-amount { color: var(--navy); font-size: 12px; font-weight: 750; white-space: nowrap; }
.remove-item { width: 27px; height: 27px; border: 0; border-radius: 6px; background: transparent; color: #9ba8ae; font-size: 20px; line-height: 1; }
.remove-item:hover { background: #fff0f0; color: var(--danger); }
.table-helper { margin: 9px 0 0; color: #95a2a8; font-size: 11px; }

.totals-section { display: grid; grid-template-columns: 1fr 365px; gap: 55px; padding-bottom: 31px; }
.notes-area > textarea { min-height: 92px; margin-bottom: 14px; }
.payment-field { max-width: 235px; }
.summary-box { align-self: start; padding: 18px 20px; border: 1px solid #cbe3df; border-radius: 10px; background: #f5fbfa; }
.summary-line { display: flex; align-items: center; justify-content: space-between; gap: 15px; color: #5c6c75; font-size: 12px; }
.summary-line strong { color: var(--navy); font-size: 13px; white-space: nowrap; }
.tax-line { gap: 8px; margin-top: 14px; }
.tax-line input { width: 53px; height: 28px; padding: 0 7px; text-align: right; }
.tax-toggle, .tax-rate-label { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.tax-toggle input { width: auto; height: auto; padding: 0; accent-color: var(--teal); }
.tax-rate-label { color: #718087; font-size: 11px; }
.summary-divider { height: 1px; margin: 17px 0 14px; background: #d4e9e5; }
.grand-total span { color: var(--navy); font-size: 13px; font-weight: 750; }
.grand-total strong { color: var(--teal-dark); font-size: 19px; letter-spacing: -.03em; }
.summary-caption { margin: 6px 0 0; color: #8a9b9d; font-size: 10px; text-align: right; }

.invoice-footer { display: flex; align-items: center; justify-content: space-between; padding: 21px 36px; background: #fbfcfc; }
.invoice-footer p { margin: 0; color: #849198; font-size: 11px; }
.footer-lock { color: var(--teal); font-size: 16px; vertical-align: -1px; }
.footer-actions { display: flex; gap: 9px; }
.page-footer { margin: 19px 0 0; color: #95a1a6; font-size: 11px; text-align: center; }
.page-footer span { padding: 0 6px; color: #c3cccf; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 760px) {
  .page-shell { padding: 18px 12px 30px; }
  .invoice-heading, .form-section { padding-right: 18px; padding-left: 18px; }
  .invoice-heading { display: block; }
  .invoice-badge { min-width: 0; margin-top: 18px; text-align: left; }
  .three-columns, .party-grid, .totals-section { grid-template-columns: 1fr; }
  .totals-section { gap: 28px; }
  .summary-box { max-width: none; }
  .section-title-with-action { align-items: flex-start; gap: 12px; }
  .section-title-with-action .button { flex: 0 0 auto; }
  .invoice-footer { align-items: flex-start; flex-direction: column; gap: 17px; padding: 19px 18px; }
  .footer-actions { width: 100%; }
  .footer-actions .button { flex: 1; }
}

.print-invoice { display: none; }

@media print {
  @page { size: A4 portrait; margin: 14mm 14mm 12mm; }

  html, body {
    background: #fff;
  }

  body {
    color: #17212b;
    font-size: 10.5px;
    line-height: 1.45;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .page-shell {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
  }

  .invoice-card,
  .no-print,
  .page-footer {
    display: none !important;
  }

  .print-invoice {
    display: block;
    width: 100%;
    color: #17212b;
  }

  .print-header {
    display: grid;
    grid-template-columns: 1fr 290px;
    gap: 32px;
    align-items: start;
    padding: 0 0 18px;
    border-bottom: 3px solid #1e3545;
  }

  .print-eyebrow,
  .print-kicker {
    margin: 0 0 5px;
    color: #087f80;
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: .14em;
  }

  .print-header h1 {
    margin: 0;
    color: #1e3545;
    font-size: 29px;
    line-height: 1;
    letter-spacing: .04em;
  }

  .print-meta {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 18px;
  }

  .print-field:first-child {
    grid-column: 1 / -1;
  }

  .print-field span,
  .print-payment-terms span {
    display: block;
    margin-bottom: 2px;
    color: #687780;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
  }

  .print-field strong {
    display: block;
    color: #1e3545;
    font-size: 10px;
    overflow-wrap: anywhere;
  }

  .print-field:first-child strong {
    color: #087f80;
    font-size: 13px;
  }

  .print-parties {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    padding: 20px 0 22px;
    border-bottom: 1px solid #d7e0e3;
    break-inside: avoid;
  }

  .print-party {
    min-width: 0;
  }

  .print-party h2 {
    margin: 0 0 5px;
    color: #1e3545;
    font-size: 13px;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }

  .print-party-id,
  .print-party-address {
    margin: 0;
    color: #53636c;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .print-party-id {
    margin-bottom: 5px;
    color: #73818a;
    font-size: 9px;
  }

  .print-items-section {
    padding: 21px 0 0;
  }

  .print-section-title {
    margin: 0 0 9px;
    color: #1e3545;
    font-size: 11px;
    letter-spacing: .01em;
  }

  .print-items-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
  }

  .print-items-table thead {
    display: table-header-group;
  }

  .print-items-table th {
    padding: 8px 7px;
    border-bottom: 1px solid #aebdc2;
    background: #edf5f4;
    color: #3f565f;
    font-size: 8px;
    font-weight: 800;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: .055em;
  }

  .print-items-table td {
    padding: 9px 7px;
    border-bottom: 1px solid #dfe6e8;
    vertical-align: top;
    overflow-wrap: anywhere;
  }

  .print-items-table tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-col-number { width: 34px; }
  .print-col-quantity { width: 72px; text-align: right !important; }
  .print-col-money { width: 120px; text-align: right !important; }
  .print-number, .print-money { text-align: right; }
  .print-money { white-space: nowrap; font-variant-numeric: tabular-nums; }

  .print-closing {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 285px;
    gap: 35px;
    align-items: start;
    padding-top: 20px;
  }

  .print-notes {
    min-width: 0;
    color: #53636c;
  }

  .print-notes > p {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  .print-payment-terms {
    margin-top: 14px !important;
  }

  .print-payment-terms strong {
    color: #1e3545;
  }

  .print-summary {
    padding: 14px 16px;
    border: 1px solid #b8d9d5;
    background: #f2f9f8;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .print-summary-line {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 3px 0;
    color: #53636c;
  }

  .print-summary-line strong {
    color: #1e3545;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
  }

  .print-grand-total {
    margin-top: 9px;
    padding-top: 10px;
    border-top: 1px solid #bad8d4;
    color: #1e3545;
    font-size: 11px;
    font-weight: 800;
  }

  .print-grand-total strong {
    color: #056466;
    font-size: 15px;
  }

  .print-footer {
    display: flex;
    justify-content: space-between;
    gap: 25px;
    margin-top: 28px;
    padding-top: 10px;
    border-top: 1px solid #d7e0e3;
    color: #718087;
    font-size: 8.5px;
    break-inside: avoid;
  }

  .print-footer p {
    margin: 0;
  }

  .print-footer strong {
    color: #53636c;
    white-space: nowrap;
  }
}
