:root {
  --bg-top: #f2efe8;
  --bg-bottom: #e3e8ef;
  --card: rgba(255, 255, 255, 0.92);
  --card-strong: #ffffff;
  --border: rgba(24, 35, 52, 0.12);
  --text: #172033;
  --muted: #657186;
  --accent: #0f4c81;
  --accent-soft: #e6f0f8;
  --brand-orange: #b2551d;
  --brand-teal: #6b9fb1;
  --danger: #a14444;
  --shadow: 0 24px 70px rgba(22, 31, 45, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Aptos, "Segoe UI", "Helvetica Neue", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.88), transparent 28%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
}

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

.page {
  padding: 40px 20px;
}

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 24px;
}

.hero-actions {
  display: flex;
  gap: 12px;
}

.inline-action-field {
  display: flex;
  gap: 10px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.75rem;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  max-width: 560px;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
  letter-spacing: -0.04em;
}

.invoice-card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.invoice-topbar,
.invoice-intro,
.details-grid,
.services-panel,
.invoice-footer {
  padding: 28px;
}

.invoice-topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  border-bottom: 1px solid var(--border);
}

.brand-lockup {
  display: flex;
  align-items: center;
}

.brand-logo {
  display: block;
  width: min(100%, 360px);
  height: auto;
}

.company-contact {
  text-align: right;
  font-size: 0.95rem;
  color: var(--muted);
}

.company-contact p {
  margin: 0;
}

.company-contact a,
.remit-box a {
  color: var(--accent);
}

.intro-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.field {
  display: block;
}

.field span,
.label {
  display: block;
  margin: 0 0 10px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
}

.field-wide {
  grid-column: 1 / -1;
}

.text-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--card-strong);
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.text-input:focus {
  outline: none;
  border-color: rgba(15, 76, 129, 0.45);
  box-shadow: 0 0 0 4px rgba(15, 76, 129, 0.12);
}

.stacked-field {
  display: grid;
  gap: 10px;
}

.hidden {
  display: none;
}

.print-only,
.print-intro {
  display: none;
}

.appreciation {
  margin: 24px 0 0;
  font-weight: 700;
}

.details-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(240, 245, 252, 0.4));
}

.details-card {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
}

.details-card h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
}

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-header-row h2 {
  margin: 0;
}

.preset-field {
  margin-bottom: 14px;
}

.text-area {
  resize: vertical;
  min-height: 150px;
}

.bill-to-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 14px;
}

.detail-list {
  display: grid;
  gap: 14px;
}

.detail-field {
  display: grid;
  gap: 8px;
}

.detail-field span {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--muted);
}

.payment-note {
  margin: 4px 0 0;
  font-weight: 600;
}

.remit-box p {
  margin: 0;
  line-height: 1.5;
}

.services-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}

.services-header h2 {
  margin: 2px 0 0;
  font-size: 1.4rem;
}

.table-wrap {
  overflow-x: auto;
}

.line-items-table {
  width: 100%;
  border-collapse: collapse;
}

.line-items-table th {
  text-align: left;
  padding: 0 0 12px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.line-items-table td {
  padding: 14px 10px 14px 0;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.line-items-table td:nth-child(1) {
  min-width: 220px;
}

.line-items-table td:nth-child(2) {
  min-width: 280px;
}

.line-items-table td:nth-child(3),
.line-items-table td:nth-child(4),
.line-items-table td:nth-child(5) {
  min-width: 120px;
}

.line-items-table td:nth-child(6) {
  min-width: 120px;
}

.description-input {
  min-height: 84px;
  resize: vertical;
}

.print-button,
.secondary-button,
.ghost-button,
.mini-button,
.icon-button {
  border: 0;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, background 0.2s ease;
}

.print-button {
  padding: 14px 18px;
  color: #fff;
  background: linear-gradient(135deg, #15385e, #0f4c81);
  border-radius: 999px;
  box-shadow: 0 16px 28px rgba(15, 76, 129, 0.18);
}

.secondary-button {
  padding: 14px 18px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  font-weight: 600;
}

.ghost-button {
  padding: 14px 18px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.72);
  border-radius: 999px;
  border: 1px solid rgba(24, 35, 52, 0.08);
  font-weight: 600;
}

.mini-button {
  flex: 0 0 auto;
  padding: 12px 14px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 14px;
  font-weight: 600;
}

.icon-button {
  padding: 10px 14px;
  color: var(--danger);
  background: rgba(161, 68, 68, 0.1);
  border-radius: 999px;
}

.print-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.mini-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.value-pill {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: flex-start;
  padding: 14px 16px;
  border-radius: 16px;
  background: #eef3fb;
  border: 1px solid rgba(15, 76, 129, 0.08);
}

.invoice-footer {
  display: flex;
  justify-content: flex-end;
}

.summary-grid {
  width: min(100%, 360px);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-weight: 600;
}

.summary-value {
  min-width: 120px;
}

.summary-card {
  padding: 18px 22px;
  border-radius: 20px;
  background: linear-gradient(145deg, #15273f, #20375a);
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.summary-card span {
  color: rgba(255, 255, 255, 0.76);
}

.summary-card strong {
  font-size: 1.7rem;
  letter-spacing: -0.04em;
}

.actions-cell {
  width: 110px;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

body.print-preview {
  background: #fff;
  color: #111;
}

body.print-preview .invoice-card {
  box-shadow: none;
  border: 0;
  border-radius: 0;
  background: #fff;
  backdrop-filter: none;
}

body.print-preview .invoice-topbar,
body.print-preview .invoice-intro,
body.print-preview .details-grid,
body.print-preview .services-panel,
body.print-preview .invoice-footer {
  padding: 12px 0;
}

body.print-preview .invoice-topbar {
  gap: 18px;
  align-items: flex-start;
}

body.print-preview .brand-logo {
  width: 300px;
}

body.print-preview .company-contact {
  margin-top: 0 !important;
  text-align: right !important;
  color: #444;
}

body.print-preview .intro-grid,
body.print-preview .preset-field,
body.print-preview .bill-to-actions,
body.print-preview #newPresetButton,
body.print-preview .table-actions,
body.print-preview .actions-cell,
body.print-preview th.screen-only,
body.print-preview .inline-action-field .mini-button {
  display: none !important;
}

body.print-preview .print-intro {
  display: grid;
  gap: 6px;
}

body.print-preview .print-field-line {
  display: grid;
  grid-template-columns: 1.45in 1fr;
  align-items: end;
  gap: 10px;
}

body.print-preview .print-label {
  font-size: 0.86rem;
  font-weight: 700;
  color: #111;
}

body.print-preview .print-value {
  min-height: 20px;
  padding: 0 0 2px;
  border-bottom: 1px solid #777;
  color: #111;
}

body.print-preview .details-grid {
  grid-template-columns: 1.2fr 0.9fr 1fr;
  gap: 10px;
  border-top: 1px solid #bbb;
  border-bottom: 1px solid #bbb;
  background: transparent;
}

body.print-preview .details-card {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #ddd;
  background: #fff;
}

body.print-preview .service-row .service-select,
body.print-preview .service-row .service-custom {
  display: none !important;
}

body.print-preview .service-row .print-service-value {
  display: block;
  line-height: 1.25;
}

body.print-preview .text-input,
body.print-preview .value-pill,
body.print-preview .summary-value,
body.print-preview .summary-card,
body.print-preview .line-amount {
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  color: #111 !important;
  min-height: 0;
}

body.print-preview textarea.text-input,
body.print-preview .description-input,
body.print-preview .text-area {
  min-height: 0 !important;
  height: auto !important;
  overflow: visible !important;
  resize: none !important;
}

body.print-preview .summary-card {
  border-top: 2px solid #111 !important;
  padding-top: 6px !important;
}

@media (max-width: 920px) {
  .page {
    padding: 22px 14px;
  }

  .hero,
  .invoice-topbar {
    display: block;
  }

  .hero-actions {
    margin-top: 16px;
    flex-wrap: wrap;
  }

  .inline-action-field,
  .card-header-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .invoice-topbar {
    text-align: left;
  }

  .company-contact {
    margin-top: 16px;
    text-align: left;
  }

  .intro-grid,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .bill-to-actions,
  .table-actions {
    justify-content: stretch;
  }

  .bill-to-actions button,
  .table-actions button,
  .hero-actions button {
    width: 100%;
  }
}

@media print {
  @page {
    size: letter portrait;
    margin: 0.4in;
  }

  body {
    background: #fff;
    color: #111;
    font-size: 10.5pt;
  }

  .page {
    padding: 0;
  }

  .hero,
  .screen-only {
    display: none !important;
  }

  .preset-field,
  .bill-to-actions,
  #newPresetButton {
    display: none !important;
  }

  .app-shell {
    max-width: none;
  }

  .invoice-card {
    box-shadow: none;
    border: 0;
    border-radius: 0;
    background: #fff;
    backdrop-filter: none;
  }

  .invoice-topbar,
  .invoice-intro,
  .details-grid,
  .services-panel,
  .invoice-footer {
    padding: 12px 0;
  }

  .invoice-topbar {
    display: flex !important;
    gap: 18px;
    align-items: flex-start;
  }

  .brand-logo {
    width: 300px;
  }

  .company-contact {
    margin-top: 0 !important;
    font-size: 9.5pt;
    color: #444;
    text-align: right !important;
  }

  .intro-grid {
    display: none !important;
  }

  .print-intro {
    display: grid;
    gap: 6px;
  }

  .print-field-line {
    display: grid;
    grid-template-columns: 1.45in 1fr;
    align-items: end;
    gap: 10px;
    break-inside: avoid;
  }

  .print-label {
    font-size: 9pt;
    font-weight: 700;
    color: #111;
  }

  .print-value {
    min-height: 20px;
    padding: 0 0 2px;
    border-bottom: 1px solid #777;
    font-size: 10pt;
    color: #111;
  }

  .intro-grid,
  .details-grid {
    gap: 10px;
  }

  .field span,
  .label,
  .detail-field span {
    margin-bottom: 4px;
    color: #333;
    font-size: 8.5pt;
  }

  .appreciation {
    margin-top: 12px;
    font-size: 9.5pt;
  }

  .details-grid {
    grid-template-columns: 1.2fr 0.9fr 1fr;
    border-top: 1px solid #bbb;
    border-bottom: 1px solid #bbb;
    background: transparent;
  }

  .details-card {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #ddd;
    background: #fff;
  }

  .details-card h2 {
    margin-bottom: 8px;
    font-size: 10pt;
  }

  .detail-list {
    gap: 8px;
  }

  .payment-note {
    margin-top: 2px;
    font-size: 9pt;
  }

  .services-header {
    margin-bottom: 8px;
  }

  .services-header h2 {
    font-size: 1rem;
  }

  .table-wrap {
    overflow: visible;
  }

  .line-items-table {
    table-layout: fixed;
  }

  .line-items-table th {
    padding-bottom: 6px;
    font-size: 8pt;
  }

  .line-items-table td {
    padding: 8px 8px 8px 0;
    font-size: 9pt;
  }

  .line-items-table td:nth-child(1) {
    min-width: 0;
    width: 22%;
  }

  .line-items-table td:nth-child(2) {
    min-width: 0;
    width: 34%;
  }

  .line-items-table td:nth-child(3),
  .line-items-table td:nth-child(4),
  .line-items-table td:nth-child(5),
  .line-items-table td:nth-child(6) {
    min-width: 0;
  }

  .service-row {
    break-inside: avoid;
  }

  .service-row .service-select,
  .service-row .service-custom {
    display: none !important;
  }

  .service-row .print-service-value {
    display: block;
    line-height: 1.25;
  }

  .text-input,
  .value-pill,
  .summary-value,
  .summary-card,
  .line-amount {
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: #111 !important;
    min-height: 0;
  }

  input.text-input,
  select.text-input,
  textarea.text-input {
    appearance: none;
    -webkit-appearance: none;
  }

  textarea.text-input,
  .description-input,
  .text-area {
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
    resize: none !important;
    line-height: 1.25;
  }

  .stacked-field {
    gap: 4px;
  }

  .summary-grid {
    width: 280px;
  }

  .summary-row {
    margin-bottom: 4px;
  }

  .summary-card {
    border-top: 2px solid #111 !important;
    padding-top: 6px !important;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    align-items: baseline;
  }

  .summary-card span {
    color: #111 !important;
  }

  .summary-card strong {
    font-size: 14pt;
    letter-spacing: 0;
  }
}
