:root {
  --bg: #eef3fb;
  --card: #ffffff;
  --text: #162033;
  --muted: #667085;
  --border: #d8e1ec;
  --primary: #123b7a;
  --primary-hover: #0e2e61;
  --secondary: #e9f0ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
  --radius: 24px;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", Arial, Helvetica, sans-serif;
  background:
    radial-gradient(circle at top left, rgba(18, 59, 122, 0.08), transparent 28%),
    linear-gradient(180deg, #f6f9ff 0%, var(--bg) 100%);
  color: var(--text);
  overflow-x: hidden;
}

.invoice-tool-shell {
  padding: 2rem 0 3rem;
}

.app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 2rem;
  overflow-wrap: anywhere;
}

.powered-by {
  margin: 6px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.invoice-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 34px;
  border: 1px solid rgba(18, 59, 122, 0.08);
}

.bottom-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.invoice-section + .invoice-section {
  margin-top: 24px;
  padding-top: 24px;
}

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

.line-items-section {
  display: flex;
  flex-direction: column;
}

.add-item-btn {
  align-self: flex-start;
  margin-top: 18px;
}

.section-header h2,
.meta-card h2 {
  margin: 0 0 1rem 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 18px;
}

.two-col {
  grid-template-columns: 1fr 1fr;
}

.three-col {
  grid-template-columns: repeat(3, 1fr);
}

label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
  margin-bottom: 16px;
}

input,
textarea {
  width: 100%;
  margin-top: 8px;
  padding: 13px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 0.95rem;
  color: var(--text);
  background: #fbfdff;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

textarea {
  resize: vertical;
}

.invoice-header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.8fr);
  gap: 24px;
  align-items: start;
}

.invoice-brand {
  display: grid;
  gap: 10px;
}

.invoice-brand-field {
  margin: 0;
}

.field-kicker {
  display: block;
  margin-bottom: 10px;
  font-size: 0.74rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.invoice-brand-name input,
.invoice-brand-phone input {
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.invoice-brand-name input {
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.98;
}

.invoice-brand-phone input {
  font-size: 1.08rem;
  font-weight: 500;
  color: #42526b;
}

.invoice-doc-mark {
  padding: 20px 22px;
  border-radius: 22px;
  background: linear-gradient(145deg, #123b7a 0%, #1d4f95 100%);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

.doc-label {
  margin: 0;
  font-size: 0.82rem;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  opacity: 0.78;
}

.doc-subtitle {
  margin: 0.65rem 0 0;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.15;
}

.invoice-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.invoice-footer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.meta-card {
  height: 100%;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(180deg, #fcfdff 0%, #f8fbff 100%);
}

.invoice-notes-section .notes-card textarea {
  min-height: 180px;
}

.totals-section {
  width: 100%;
}

.invoice-brand-footer {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--muted);
}

.invoice-brand-footer-logo {
  height: 1.5em;
  width: auto;
  flex: 0 0 auto;
}

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

.items-table {
  border-collapse: collapse;
  min-width: 0;
  table-layout: fixed;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}

.items-table th,
.items-table td {
  border-bottom: 1px solid var(--border);
  padding: 14px 12px;
  text-align: left;
  vertical-align: middle;
}

.items-table th {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  background: #f8fbff;
}

.items-table td input {
  margin-top: 0;
  min-height: 46px;
}

.description-col {
  width: 58%;
}

.qty-col,
.rate-col,
.total-col,
.action-col {
  width: 14%;
}

.items-table th:not(:first-child),
.items-table td:not(:first-child) {
  white-space: nowrap;
}

.description-input {
  width: 100%;
}

.line-total {
  display: flex;
  align-items: center;
  min-height: 46px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
}

.primary-btn,
.secondary-btn,
.remove-btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s ease;
}

.primary-btn:hover,
.secondary-btn:hover,
.remove-btn:hover {
  transform: translateY(-1px);
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover {
  background: var(--primary-hover);
}

.secondary-btn {
  background: var(--secondary);
  color: var(--primary);
}

.remove-btn {
  background: #fee2e2;
  color: var(--danger);
  padding: 10px 12px;
}

.remove-btn:hover {
  background: #fecaca;
  color: var(--danger-hover);
}

.totals-layout {
  align-items: start;
}

.summary-card {
  width: 100%;
  background: linear-gradient(180deg, #f8fbff 0%, #f3f7ff 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 16px 32px rgba(18, 59, 122, 0.08);
}

.tax-input-wrap {
  margin-bottom: 18px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-size: 1rem;
}

.summary-row + .summary-row {
  border-top: 1px solid var(--border);
}

.grand-total {
  margin-top: 6px;
  font-size: 1.2rem;
}

.invoice-card.is-dense .items-table th,
.invoice-card.is-dense .items-table td {
  padding-top: 10px;
  padding-bottom: 10px;
  font-size: 0.84rem;
}

.invoice-card.is-dense .summary-card {
  padding: 18px;
}

.invoice-card.is-ultra-dense .items-table th,
.invoice-card.is-ultra-dense .items-table td {
  padding-top: 8px;
  padding-bottom: 8px;
  font-size: 0.76rem;
}

.invoice-card.is-ultra-dense .summary-card,
.invoice-card.is-ultra-dense .meta-card {
  padding: 15px;
}

.invoice-card.is-ultra-dense .notes-card textarea {
  min-height: 130px;
}

@media (max-width: 800px) {
  .invoice-tool-shell {
    padding: 1.25rem 0 2rem;
    width: 100%;
    overflow-x: clip;
  }

  .app {
    width: 100%;
    padding: 10px;
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar > div {
    width: 100%;
  }

  .topbar h1 {
    font-size: 1.6rem;
  }

  .powered-by {
    font-size: 0.9rem;
  }

  .invoice-card {
    width: 100%;
    padding: 14px;
  }

  .bottom-actions {
    margin-top: 16px;
  }

  .invoice-header-grid,
  .invoice-summary-grid,
  .invoice-footer-grid {
    grid-template-columns: 1fr;
  }

  .invoice-doc-mark {
    order: -1;
  }

  .invoice-section + .invoice-section {
    margin-top: 20px;
    padding-top: 18px;
  }

  .invoice-brand-footer {
    margin-top: 18px;
    padding-top: 16px;
    font-size: 0.74rem;
  }

  .section-header {
    flex-direction: column;
    align-items: stretch;
  }

  .primary-btn,
  .secondary-btn {
    width: 100%;
  }

  .add-item-btn {
    align-self: stretch;
    margin-top: 16px;
  }

  .table-wrap {
    overflow: visible;
  }

  .items-table {
    width: 100%;
    min-width: 0;
    border: none;
    background: transparent;
  }

  .items-table thead {
    display: none;
  }

  .items-table,
  .items-table tbody,
  .items-table tr,
  .items-table td {
    display: block;
    width: 100%;
  }

  .items-table tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "description description description"
      "qty cost total"
      "remove remove remove";
    gap: 10px 6px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
  }

  .items-table tr + tr {
    margin-top: 12px;
  }

  .items-table td {
    padding: 0;
    border-bottom: none;
  }

  .items-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 5px;
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
  }

  .items-table td:nth-child(1) {
    grid-area: description;
  }

  .items-table td:nth-child(2) {
    grid-area: qty;
  }

  .items-table td:nth-child(3) {
    grid-area: cost;
  }

  .items-table td:nth-child(4) {
    grid-area: total;
  }

  .items-table td:nth-child(5) {
    grid-area: remove;
  }

  .items-table td input {
    width: 100%;
    padding: 9px 8px;
    min-height: 38px;
    font-size: 0.78rem;
  }

  .description-input {
    font-size: 0.84rem;
  }

  .line-total {
    min-height: 38px;
    padding: 9px 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fbfdff;
    font-size: 0.8rem;
  }

  .items-table .remove-btn {
    width: 100%;
    min-height: 38px;
    padding: 8px 6px;
    font-size: 0.74rem;
  }

  .section-header h2,
  .meta-card h2 {
    letter-spacing: 0.1em;
  }

  .summary-row {
    gap: 12px;
  }

  .summary-card {
    width: 100%;
  }
}

@media print {
  @page {
    size: Letter;
    margin: 0.34in 0.38in;
  }

  html,
  body {
    background: #fff;
    font-size: 9pt;
    line-height: 1.24;
    color: #111827;
  }

  .header,
  .footer,
  .topbar,
  .nav,
  .mobile-nav,
  .nav-toggle {
    display: none !important;
  }

  .invoice-tool-shell {
    padding: 0;
  }

  .app {
    max-width: 100%;
    padding: 0;
  }

  .invoice-card {
    box-shadow: none;
    border-radius: 0;
    padding: 0;
    border: none;
  }

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

  .invoice-section + .invoice-section {
    margin-top: 12px;
    padding-top: 12px;
  }

  .invoice-brand-footer {
    margin-top: 0.12in;
    padding-top: 0.09in;
    border-top: 1px solid #d6dee8;
    font-size: 7pt;
    color: #64748b;
  }

  .section-header {
    margin-bottom: 6px;
  }

  .section-header h2,
  .meta-card h2 {
    margin-bottom: 8px;
    font-size: 8pt;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #475569;
  }

  .invoice-header-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(1.2in, 1fr);
    gap: 0.2in;
    align-items: end;
  }

  .invoice-summary-grid {
    grid-template-columns: minmax(2.3in, 1fr) minmax(2.3in, 1fr);
    gap: 0.18in;
  }

  .invoice-footer-grid {
    grid-template-columns: minmax(2.3in, 1fr) minmax(2.3in, 1fr);
    gap: 0.18in;
  }

  .no-print {
    display: none !important;
  }

  input,
  textarea {
    margin-top: 3px;
    padding: 5px 7px;
    border: 1px solid #d4dce8;
    border-radius: 8px;
    box-shadow: none !important;
    background: #fff;
    color: #000;
    font-size: 8.6pt;
  }

  textarea {
    min-height: 1.25in;
    resize: none;
  }

  label {
    font-size: 7.1pt;
    font-weight: 700;
    color: #334155;
    margin-bottom: 8px;
    letter-spacing: 0.1em;
  }

  .field-kicker {
    margin-bottom: 0.06in;
    font-size: 6.8pt;
    color: #64748b;
  }

  .invoice-brand {
    gap: 0.06in;
  }

  .invoice-brand-name input,
  .invoice-brand-phone input {
    border: none;
    padding: 0;
    background: transparent;
  }

  .invoice-brand-name input {
    font-size: 22pt;
    font-weight: 800;
    line-height: 0.95;
  }

  .invoice-brand-phone input {
    font-size: 10pt;
    color: #334155;
  }

  .invoice-doc-mark {
    padding: 0.14in 0.16in;
    border-radius: 14px;
    background: #163b72;
    color: #fff;
    box-shadow: none;
  }

  .doc-label {
    font-size: 7pt;
  }

  .doc-subtitle {
    margin-top: 0.08in;
    font-size: 14pt;
  }

  .meta-card {
    padding: 0.11in;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #d7dfeb;
  }

  .invoice-notes-section .notes-card textarea {
    min-height: 1.1in;
  }

  .table-wrap {
    overflow: visible;
  }

  .items-table {
    min-width: 0;
    width: 100%;
    table-layout: fixed;
    border-radius: 0;
    border: 1px solid #d7dfeb;
    display: table !important;
  }

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

  .items-table tbody {
    display: table-row-group !important;
  }

  .items-table tr {
    display: table-row !important;
    width: auto !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  .items-table th,
  .items-table td {
    display: table-cell !important;
    padding: 0.035in 0.04in;
    border-bottom: 1px solid #e1e7f0;
    font-size: 8.2pt;
    vertical-align: middle;
  }

  .items-table th {
    color: #475569;
    font-size: 6.9pt;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    background: #f7faff;
  }

  .items-table td input {
    margin-top: 0;
    padding: 0.028in 0.04in;
    min-height: 0.22in;
    font-size: 8pt;
  }

  .items-table td::before {
    content: none !important;
    display: none !important;
  }

  .items-table th.no-print,
  .items-table td.no-print {
    display: none !important;
  }

  .qty-col,
  .rate-col,
  .total-col,
  .action-col {
    width: 11%;
  }

  .description-col {
    width: 67%;
  }

  .items-table th:first-child,
  .items-table td:first-child {
    width: 67%;
  }

  .items-table th:not(:first-child),
  .items-table td:not(:first-child) {
    white-space: nowrap;
  }

  .line-total {
    display: flex;
    align-items: center;
    min-height: 0.22in;
    padding: 0.028in 0.04in;
    border: 1px solid #d4dce8;
    border-radius: 8px;
    background: #fff;
    font-weight: 700;
  }

  .summary-card {
    width: 100%;
    padding: 0.12in 0.13in;
    border-radius: 12px;
    background: #f7faff;
    border: 1px solid #d7dfeb;
    box-shadow: none;
  }

  .tax-input-wrap {
    margin-bottom: 0.08in;
  }

  .summary-row {
    padding: 0.05in 0;
    font-size: 8.5pt;
  }

  .grand-total {
    margin-top: 0.03in;
    font-size: 11pt;
  }

  .invoice-card.is-dense .invoice-brand-name input {
    font-size: 20pt;
  }

  .invoice-card.is-dense .items-table th,
  .invoice-card.is-dense .items-table td,
  .invoice-card.is-dense .items-table td input,
  .invoice-card.is-dense .summary-row,
  .invoice-card.is-dense textarea,
  .invoice-card.is-dense input {
    font-size: 7.7pt;
  }

  .invoice-card.is-dense .items-table th {
    font-size: 6.5pt;
  }

  .invoice-card.is-ultra-dense .invoice-header-grid {
    gap: 0.14in;
  }

  .invoice-card.is-ultra-dense .invoice-section + .invoice-section {
    margin-top: 0.08in;
    padding-top: 0.08in;
  }

  .invoice-card.is-ultra-dense .invoice-brand-name input {
    font-size: 18pt;
  }

  .invoice-card.is-ultra-dense .meta-card,
  .invoice-card.is-ultra-dense .summary-card {
    padding: 0.09in 0.1in;
  }

  .invoice-card.is-ultra-dense .items-table th,
  .invoice-card.is-ultra-dense .items-table td,
  .invoice-card.is-ultra-dense .items-table td input,
  .invoice-card.is-ultra-dense .summary-row,
  .invoice-card.is-ultra-dense textarea,
  .invoice-card.is-ultra-dense input {
    font-size: 7pt;
  }

  .invoice-card.is-ultra-dense .items-table th {
    font-size: 6.1pt;
  }

  .invoice-card.is-ultra-dense .notes-card textarea {
    min-height: 0.82in;
  }
}
