:root {
  --background: #f4f6f2;
  --foreground: #1b1f22;
  --panel: #ffffff;
  --panel-strong: #fdfcf7;
  --line: #d8ded5;
  --muted: #66736b;
  --brand: #176b59;
  --brand-dark: #0f4d40;
  --danger: #b94242;
  --ink-soft: #2e3538;
  --shadow: 0 18px 45px rgba(32, 43, 37, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(23, 107, 89, 0.08), transparent 360px),
    var(--background);
  color: var(--foreground);
  font-family: Arial, Helvetica, sans-serif;
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 700;
  padding: 0 14px;
}

button:hover:not(:disabled) {
  background: var(--brand-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.secondary {
  background: #edf2ed;
  color: var(--ink-soft);
  border: 1px solid var(--line);
}

.secondary:hover:not(:disabled) {
  background: #e3ebe4;
  color: var(--foreground);
}

.danger {
  background: #f8e8e5;
  color: var(--danger);
  border: 1px solid #efc8c0;
}

.icon {
  width: 40px;
  padding: 0;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.toolbar,
.workspace,
.notice {
  width: min(1760px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--brand);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.8rem);
  line-height: 0.95;
  margin-bottom: 0;
}

h2 {
  font-size: 1.05rem;
  margin-bottom: 0;
}

h3 {
  font-size: 0.95rem;
  margin-bottom: 0;
}

.toolbar-actions,
.compact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.notice {
  color: var(--muted);
  font-weight: 700;
  min-height: 20px;
  margin-bottom: 14px;
}

.notice[data-type="error"] {
  color: var(--danger);
}

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 0;
}

.metrics article,
.invoice-list,
.editor {
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metrics article {
  min-height: 90px;
  padding: 16px;
}

.metrics span,
label,
.invoice-row small,
.invoice-row i,
.invoice-parties span,
footer span {
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
  font-weight: 700;
}

.metrics strong {
  display: block;
  font-size: clamp(1.25rem, 2vw, 2rem);
  margin-top: 12px;
}

.workspace {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  align-items: start;
}

.content-column {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.workbench {
  align-items: start;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}

.invoice-list,
.editor {
  overflow: hidden;
}

.panel-heading,
.line-heading {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 14px 16px;
}

.panel-heading span {
  align-items: center;
  background: #eef3ee;
  border-radius: 999px;
  color: var(--brand);
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-width: 34px;
  min-height: 28px;
}

.list-scroll {
  max-height: calc(100vh - 280px);
  overflow: auto;
  padding: 8px;
}

.invoice-row {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--foreground);
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  min-height: 72px;
  padding: 12px;
  text-align: left;
  width: 100%;
}

.invoice-row:hover,
.invoice-row.active {
  background: #f4f8f4;
  border-color: var(--line);
}

.invoice-row span {
  display: grid;
  gap: 4px;
}

.invoice-row span:last-child {
  justify-items: end;
}

.field-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 16px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding-top: 0;
}

label {
  display: grid;
  gap: 7px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(27, 31, 34, 0.52);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 20;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(20, 24, 25, 0.28);
  max-width: 520px;
  width: min(520px, 100%);
}

.preview-modal {
  max-height: calc(100vh - 36px);
  max-width: 920px;
  overflow: auto;
  width: min(920px, 100%);
}

.modal-heading {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 58px;
  padding: 12px 16px;
}

.modal form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.modal-grid {
  padding: 0 !important;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

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

input,
select,
textarea {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--foreground);
  min-height: 40px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

textarea {
  line-height: 1.35;
  min-height: 82px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 89, 0.14);
}

.line-items {
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  margin: 0 16px 16px;
  padding-bottom: 10px;
}

.line-heading {
  border-bottom: 0;
  min-height: 56px;
  padding: 10px 0;
}

.line-row {
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(150px, 1fr) 86px 108px 98px 40px;
  margin-bottom: 8px;
}

.line-labels {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.line-row strong {
  align-items: center;
  display: flex;
  justify-content: flex-end;
  min-height: 40px;
}

.paper {
  background: white;
  border: 1px solid #e5e2d7;
  box-shadow: 0 24px 60px rgba(35, 37, 32, 0.15);
  aspect-ratio: 8.5 / 11;
  display: flex;
  flex-direction: column;
  padding: clamp(34px, 4vw, 58px);
  width: min(7.5in, 100%);
}

.invoice-head {
  align-items: center;
  display: flex;
  justify-content: flex-start;
  gap: 24px;
  padding-bottom: 12px;
}

.invoice-title-wrap h2 {
  color: #171b21;
  font-size: clamp(2.4rem, 5vw, 4rem);
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1;
  margin: 0;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-block strong {
  display: block;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
}

.brand-block p {
  color: var(--muted);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  margin: 2px 0 0;
  text-transform: uppercase;
}

.brand-mark {
  align-items: center;
  background: #323743;
  border-radius: 9px;
  color: #ffc61a;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 900;
  height: 42px;
  justify-content: center;
  width: 42px;
}

.invoice-title-wrap {
  align-items: center;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) auto 58px;
  margin-bottom: 16px;
  width: 100%;
}

.invoice-title-wrap span {
  background: #ffc61a;
  height: 28px;
}

.invoice-meta {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 210px;
  padding: 8px 0 24px;
}

.invoice-to,
.invoice-facts {
  display: grid;
  gap: 3px;
}

.invoice-to span,
.invoice-facts span,
.invoice-message span {
  color: #171b21;
  font-size: 0.74rem;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.invoice-to strong {
  font-size: 0.9rem;
}

.invoice-to p,
.invoice-message p,
.invoice-facts p {
  color: var(--ink-soft);
  font-size: 0.72rem;
  line-height: 1.3;
  margin: 0;
}

.invoice-facts p {
  display: grid;
  gap: 18px;
  grid-template-columns: 80px 1fr;
}

.invoice-facts strong {
  font-size: 0.82rem;
  text-align: right;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid #c9cdd2;
  width: 100%;
}

.invoice-body {
  display: flex;
  flex: 1;
  flex-direction: column;
}

th {
  background: #343946;
  color: white;
  font-size: 0.66rem;
  padding: 9px 12px;
  text-align: left;
}

td {
  border-bottom: 0;
  font-size: 0.72rem;
  padding: 10px 12px;
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background: #f1f1f1;
}

th:not(:first-child),
td:not(:first-child) {
  text-align: right;
  white-space: nowrap;
}

.invoice-bottom {
  align-items: end;
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 1fr) max-content;
  margin-top: auto;
  padding-top: 26px;
}

.invoice-message {
  display: grid;
  gap: 18px;
}

.invoice-message > p {
  color: #171b21;
  font-weight: 800;
}

.totals {
  display: grid;
  justify-self: end;
  margin: 0;
  padding-top: 0;
  width: 300px;
}

.totals p {
  display: grid;
  gap: 24px;
  grid-template-columns: 96px 132px;
  justify-content: end;
  margin: 0;
  padding: 8px 0;
}

.totals strong {
  text-align: right;
}

.grand-total {
  background: #ffc61a;
  border-top: 0;
  font-size: 1.15rem;
  margin-top: 8px !important;
  padding: 10px 18px !important;
}

.invoice-footer {
  align-items: end;
  border-top: 4px solid #ffc61a;
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, auto) 1fr;
  margin-top: 26px;
  padding-top: 16px;
}

.invoice-footer span,
.invoice-footer strong {
  color: #171b21;
  font-size: 0.72rem;
  font-weight: 800;
}

.invoice-footer span + span {
  border-left: 1px solid #171b21;
  padding-left: 14px;
}

.invoice-footer strong {
  border-top: 1px solid #8b8f96;
  justify-self: end;
  min-width: 150px;
  padding-top: 10px;
  text-align: center;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 16px;
  }

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

  .toolbar-actions {
    justify-content: stretch;
  }

  .toolbar-actions button {
    flex: 1;
  }

  .metrics,
  .workspace,
  .workbench,
  .field-grid,
  .field-grid.two,
  .invoice-parties {
    grid-template-columns: 1fr;
  }

  .list-scroll {
    max-height: 280px;
  }

  .line-row {
    grid-template-columns: 1fr 78px 96px 84px 40px;
  }

  .paper {
    overflow-x: auto;
  }
}

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .compact-actions {
    justify-content: stretch;
  }

  .compact-actions button {
    flex: 1;
  }

  .line-row {
    grid-template-columns: 1fr 1fr;
  }

  .line-row input:first-child {
    grid-column: 1 / -1;
  }

  .line-row strong {
    justify-content: flex-start;
  }
}

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

  body {
    background: white;
  }

  .no-print,
  .toolbar,
  .notice,
  .workspace,
  .modal-heading {
    display: none !important;
  }

  .app-shell {
    padding: 0;
  }

  .modal-backdrop,
  .preview-modal {
    background: white !important;
    display: block;
    inset: auto !important;
    max-height: none !important;
    max-width: none !important;
    overflow: visible !important;
    padding: 0 !important;
    position: static !important;
    width: auto !important;
  }

  .modal-backdrop[hidden] {
    display: none !important;
  }

  .preview-modal {
    border: 0 !important;
    box-shadow: none !important;
  }

  .paper {
    border: 0;
    box-shadow: none;
    height: 10in;
    min-height: 10in;
    overflow: visible;
    padding: 0;
    width: 7.5in;
  }
}
