:root {
  --invoice-sand: #e8dcc7;
  --invoice-oat: #d4b895;
  --invoice-sage: #8b9d83;
  --invoice-moss: #606c38;
  --invoice-clay: #b08b6e;
  --invoice-terracotta: #c66b3d;
  --invoice-ink: #3b342b;
  --invoice-muted: #6f6559;
  --invoice-line: rgba(96, 108, 56, 0.24);
  --invoice-panel: rgba(232, 220, 199, 0.82);
}

.invoice-app {
  min-height: 100vh;
  color: var(--invoice-ink);
  background:
    radial-gradient(circle at 8% 10%, rgba(198, 107, 61, 0.22), transparent 26%),
    radial-gradient(circle at 94% 16%, rgba(96, 108, 56, 0.2), transparent 24%),
    var(--invoice-sand);
}

.invoice-app::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
}

.invoice-app button,
.invoice-app input,
.invoice-app select,
.invoice-app textarea {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

.invoice-shell {
  width: min(1500px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.invoice-header {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) auto;
  gap: 28px;
  align-items: center;
  margin-bottom: 22px;
}

.invoice-brand {
  display: grid;
  place-items: center;
  min-height: 132px;
  border-radius: 28px;
  background: rgba(212, 184, 149, 0.44);
}

.invoice-brand img {
  width: 132px;
  height: auto;
}

.invoice-heading h1,
.invoice-archive h2,
.editor-section h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
}

.invoice-heading h1 {
  max-width: 740px;
  font-size: clamp(2.2rem, 4.5vw, 5.1rem);
  line-height: 0.94;
}

.invoice-heading p:last-child {
  max-width: 720px;
  margin: 16px 0 0;
  color: var(--invoice-muted);
  line-height: 1.55;
}

.invoice-kicker,
.editor-section-heading span,
.archive-heading > div > span,
.invoice-status-label {
  display: block;
  margin-bottom: 7px;
  color: var(--invoice-moss);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.invoice-header-actions,
.invoice-toolbar-actions,
.archive-actions,
.fy-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.invoice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  border: 1px solid var(--invoice-moss);
  border-radius: 18px;
  padding: 0 17px;
  color: var(--invoice-ink);
  font-weight: 750;
  text-decoration: none;
  background: transparent;
  transition: transform 320ms ease, background 320ms ease, color 320ms ease;
}

.invoice-button:hover {
  transform: translateY(-2px);
}

.invoice-button.primary {
  border-color: var(--invoice-moss);
  color: var(--invoice-sand);
  background: var(--invoice-moss);
}

.invoice-button.secondary:hover {
  background: rgba(139, 157, 131, 0.22);
}

.invoice-button.small {
  min-height: 35px;
  border-radius: 14px;
  padding: 0 12px;
  font-size: 0.82rem;
}

.invoice-button.danger {
  border-color: var(--invoice-terracotta);
  color: var(--invoice-terracotta);
}

.invoice-toolbar {
  position: sticky;
  top: 12px;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  margin-bottom: 18px;
  border: 1px solid var(--invoice-line);
  border-radius: 24px;
  padding: 14px 16px 14px 20px;
  background: rgba(232, 220, 199, 0.92);
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 36px rgba(59, 52, 43, 0.1);
}

.invoice-toolbar > div:first-child {
  min-width: 170px;
}

.invoice-toolbar strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.18rem;
}

.invoice-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.76fr) minmax(560px, 1.24fr);
  gap: 18px;
  align-items: start;
}

.invoice-editor {
  display: grid;
  gap: 14px;
}

.editor-section,
.invoice-archive {
  border: 1px solid var(--invoice-line);
  border-radius: 28px;
  padding: 22px;
  background: var(--invoice-panel);
  box-shadow: 0 18px 48px rgba(59, 52, 43, 0.08);
}

.editor-section-heading,
.archive-heading,
.item-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.editor-section h2,
.invoice-archive h2 {
  margin: 0;
  font-size: 1.52rem;
}

.fy-badge,
.tax-chip,
.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 14px;
  padding: 0 11px;
  color: var(--invoice-moss);
  font-size: 0.75rem;
  font-weight: 800;
  background: rgba(139, 157, 131, 0.2);
}

.editor-grid {
  display: grid;
  gap: 14px;
}

.editor-grid.two-up {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-grid .full-width {
  grid-column: 1 / -1;
}

.invoice-editor label,
.archive-search {
  display: grid;
  gap: 7px;
  color: var(--invoice-muted);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.invoice-editor input,
.invoice-editor select,
.invoice-editor textarea,
.archive-search input {
  width: 100%;
  border: 1px solid var(--invoice-line);
  border-radius: 16px;
  padding: 11px 13px;
  color: var(--invoice-ink);
  outline: none;
  background: rgba(232, 220, 199, 0.58);
}

.invoice-editor textarea {
  resize: vertical;
  line-height: 1.45;
}

.invoice-editor input:focus,
.invoice-editor select:focus,
.invoice-editor textarea:focus,
.archive-search input:focus {
  border-color: var(--invoice-terracotta);
  box-shadow: 0 0 0 3px rgba(198, 107, 61, 0.13);
}

.tax-rule {
  margin-top: 14px;
  border-radius: 16px;
  padding: 11px 13px;
  color: var(--invoice-muted);
  font-size: 0.84rem;
  line-height: 1.45;
  background: rgba(139, 157, 131, 0.14);
}

.item-list {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px 68px;
  gap: 9px;
  align-items: end;
  border-radius: 20px;
  padding: 12px;
  background: rgba(212, 184, 149, 0.26);
}

.item-row .remove-item {
  width: 68px;
  min-height: 40px;
  border: 1px solid rgba(198, 107, 61, 0.4);
  border-radius: 14px;
  color: var(--invoice-terracotta);
  font-weight: 800;
  background: transparent;
}

.preview-stage {
  position: sticky;
  top: 94px;
  border-radius: 30px;
  padding: clamp(14px, 2.2vw, 30px);
  overflow: auto;
  background: var(--invoice-oat);
  box-shadow: inset 0 0 0 1px rgba(96, 108, 56, 0.18);
}

.invoice-preview {
  width: min(100%, 790px);
  min-height: 1080px;
  margin: 0 auto;
  color: var(--invoice-ink);
  background: var(--invoice-sand);
  box-shadow: 0 24px 70px rgba(59, 52, 43, 0.19);
}

.preview-topbar {
  height: 12px;
  background: var(--invoice-terracotta);
}

.preview-content {
  display: grid;
  gap: 30px;
  padding: clamp(30px, 5vw, 62px);
}

.preview-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 30px;
  align-items: start;
}

.preview-brand img {
  width: 150px;
  height: auto;
  margin-bottom: 14px;
}

.preview-brand p,
.preview-client p,
.preview-footer p {
  margin: 4px 0;
  color: var(--invoice-muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.preview-meta {
  min-width: 190px;
  text-align: right;
}

.preview-meta h2 {
  margin: 0 0 17px;
  color: var(--invoice-moss);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2rem;
  font-weight: 500;
}

.preview-meta div,
.preview-summary-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  margin-top: 8px;
}

.preview-meta span,
.preview-client span,
.preview-summary-row span {
  color: var(--invoice-muted);
  font-size: 0.75rem;
}

.preview-meta strong,
.preview-client strong {
  font-size: 0.84rem;
}

.preview-client {
  border-left: 4px solid var(--invoice-sage);
  border-radius: 0 18px 18px 0;
  padding: 17px 20px;
  background: rgba(139, 157, 131, 0.13);
}

.preview-client span {
  display: block;
  margin-bottom: 5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-client strong {
  display: block;
  margin-bottom: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
  font-weight: 500;
}

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

.preview-table th {
  border-bottom: 2px solid var(--invoice-moss);
  padding: 10px 8px;
  color: var(--invoice-moss);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-align: left;
  text-transform: uppercase;
}

.preview-table th:last-child,
.preview-table td:last-child {
  text-align: right;
}

.preview-table th:last-child { width: 150px; }

.preview-table td {
  border-bottom: 1px solid var(--invoice-line);
  padding: 14px 8px;
  font-size: 0.84rem;
  vertical-align: top;
}

.preview-table .description-cell {
  white-space: pre-line;
  line-height: 1.5;
}

.preview-totals {
  width: min(320px, 100%);
  margin-left: auto;
}

.preview-summary-row {
  border-bottom: 1px solid var(--invoice-line);
  padding: 8px 2px;
}

.preview-summary-row.total {
  align-items: center;
  margin-top: 7px;
  border: 0;
  border-radius: 16px;
  padding: 15px 16px;
  color: var(--invoice-sand);
  background: var(--invoice-moss);
}

.preview-summary-row.total span,
.preview-summary-row.total strong {
  color: var(--invoice-sand);
  font-size: 1rem;
}

.preview-footer {
  margin-top: auto;
  border-top: 1px solid var(--invoice-line);
  padding-top: 20px;
}

.preview-thanks {
  margin-top: 18px;
  color: var(--invoice-terracotta);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
}

.invoice-archive {
  margin-top: 20px;
}

.archive-heading p {
  margin: 8px 0 0;
  color: var(--invoice-muted);
}

.archive-search {
  width: min(300px, 100%);
}

.fy-tabs {
  margin: 6px 0 16px;
}

.fy-tab {
  min-height: 38px;
  border: 1px solid var(--invoice-line);
  border-radius: 16px;
  padding: 0 14px;
  color: var(--invoice-ink);
  font-weight: 800;
  background: transparent;
}

.fy-tab.active {
  border-color: var(--invoice-moss);
  color: var(--invoice-sand);
  background: var(--invoice-moss);
}

.archive-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.archive-summary div {
  border-radius: 18px;
  padding: 14px 16px;
  background: rgba(212, 184, 149, 0.23);
}

.archive-summary span {
  display: block;
  margin-bottom: 5px;
  color: var(--invoice-muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.archive-summary strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.32rem;
  font-weight: 500;
}

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

.archive-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.archive-table th,
.archive-table td {
  border-bottom: 1px solid var(--invoice-line);
  padding: 13px 10px;
  text-align: left;
}

.archive-table th {
  color: var(--invoice-muted);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.archive-table td {
  font-size: 0.86rem;
}

.archive-table .amount-column {
  text-align: right;
}

.archive-table td:last-child {
  width: 240px;
}

.archive-empty {
  padding: 38px 12px !important;
  color: var(--invoice-muted);
  text-align: center !important;
}

.invoice-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: 360px;
  border-radius: 18px;
  padding: 14px 18px;
  color: var(--invoice-sand);
  background: var(--invoice-moss);
  box-shadow: 0 18px 40px rgba(59, 52, 43, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(14px);
  transition: opacity 300ms ease, transform 300ms ease;
}

.invoice-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1080px) {
  .invoice-header { grid-template-columns: 130px 1fr; }
  .invoice-header-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .invoice-workspace { grid-template-columns: 1fr; }
  .preview-stage { position: static; }
}

@media (max-width: 720px) {
  .invoice-shell { width: min(100% - 22px, 1500px); padding-top: 14px; }
  .invoice-header { grid-template-columns: 90px 1fr; gap: 16px; }
  .invoice-brand { min-height: 90px; border-radius: 22px; }
  .invoice-brand img { width: 82px; }
  .invoice-heading h1 { font-size: 2.45rem; }
  .invoice-toolbar { position: static; align-items: flex-start; flex-direction: column; border-radius: 22px; }
  .invoice-toolbar-actions { width: 100%; }
  .invoice-toolbar-actions .invoice-button { flex: 1 1 140px; }
  .editor-grid.two-up { grid-template-columns: 1fr; }
  .editor-grid .full-width { grid-column: auto; }
  .item-row { grid-template-columns: 1fr 72px; }
  .item-row label:first-child { grid-column: 1 / -1; }
  .item-row .remove-item { grid-column: 2; grid-row: 2; justify-self: end; }
  .preview-stage { padding: 10px; }
  .invoice-preview { min-height: 820px; }
  .preview-content { padding: 28px 22px; gap: 22px; }
  .preview-header { grid-template-columns: 1fr; }
  .preview-meta { text-align: left; }
  .archive-heading { flex-direction: column; }
  .archive-summary { grid-template-columns: 1fr; }
}

@media print {
  .invoice-header,
  .invoice-toolbar,
  .invoice-editor,
  .invoice-archive,
  .invoice-toast {
    display: none !important;
  }
  .invoice-shell { width: 100%; padding: 0; }
  .invoice-workspace { display: block; }
  .preview-stage { padding: 0; background: transparent; box-shadow: none; }
  .invoice-preview { width: 100%; min-height: 0; box-shadow: none; }
}

/* Keep the invoice studio visually native to the existing Knotty Affair workspace. */
:root {
  --invoice-sand: var(--paper);
  --invoice-oat: #efe6da;
  --invoice-sage: var(--sage);
  --invoice-moss: var(--charcoal);
  --invoice-clay: var(--sand);
  --invoice-terracotta: var(--sand-deep);
  --invoice-ink: var(--ink);
  --invoice-muted: rgba(21, 19, 15, 0.64);
  --invoice-line: var(--line);
  --invoice-panel: rgba(255, 250, 242, 0.78);
}

.invoice-app {
  background:
    linear-gradient(rgba(255, 250, 242, 0.08), rgba(255, 250, 242, 0.08)),
    url("assets/contract-background.jpg") center top / min(100vw, 900px) auto repeat-y fixed;
}

.archive-only .invoice-toolbar,
.archive-only .invoice-workspace { display: none; }

.archive-only .invoice-archive { margin-top: 0; }

/* The archive is deliberately a separate route: Create stays focused on one document. */
.invoice-app:not(.archive-only) .invoice-archive { display: none; }

/* View invoices follows the Team workspace layout: a focused dark rail and year cards. */
.archive-only .invoice-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  gap: 48px;
  width: min(1540px, calc(100% - 64px));
  min-height: calc(100vh - 56px);
  padding: 28px;
  border-radius: 22px;
  background: rgba(255, 250, 242, 0.84);
  box-shadow: 0 24px 72px rgba(21, 19, 15, 0.13);
}

.archive-only .invoice-header {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  margin: 0;
  padding: 22px 16px;
  border-radius: 14px;
  background: var(--charcoal);
}

.archive-only .invoice-brand {
  min-height: 148px;
  padding: 12px 8px 26px;
  border-bottom: 1px solid rgba(255, 250, 242, 0.18);
}

.archive-only .invoice-brand img {
  width: 154px;
  max-width: 100%;
  filter: none;
}

.archive-only .invoice-heading { display: none; }
.archive-only .invoice-header-actions {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}
.archive-only #importButton,
.archive-only .invoice-header-actions a[href*="view=1"] { display: none; }
.archive-only .invoice-header-actions .invoice-button {
  justify-content: flex-start;
  border-color: rgba(255, 250, 242, 0.18);
  color: var(--paper-strong);
  background: transparent;
}
.archive-only .invoice-header-actions .invoice-button:hover { background: rgba(255, 250, 242, 0.12); }

.archive-only .invoice-archive {
  align-self: start;
  border: 0;
  padding: 24px 0 0;
  background: transparent;
  box-shadow: none;
}

.archive-only .archive-heading {
  margin-bottom: 28px;
  padding-bottom: 26px;
  border-bottom: 1px solid var(--line);
}
.archive-only .archive-heading h2 { font-size: clamp(2.7rem, 5vw, 4.65rem); line-height: .96; }
.archive-only .archive-heading > div > span { color: var(--ink); }
.archive-only .archive-search { width: min(320px, 100%); }
.archive-only .fy-invoice-archive { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.archive-only .fy-archive-card { background: rgba(255, 250, 242, 0.68); }
.archive-only .fy-archive-header { padding: 22px 20px 17px; }
.archive-only .fy-archive-header span { display: none; }
.archive-only .fy-archive-header h3 { font-size: 1.55rem; letter-spacing: -.03em; }
.archive-only .fy-archive-details summary { min-height: 52px; padding: 0 20px; }
.archive-only .fy-archive-details summary > strong { font-size: .88rem; }
.archive-only .fy-archive-details summary > span { font-size: .72rem; }

@media (max-width: 900px) {
  .archive-only .invoice-shell { grid-template-columns: 1fr; width: min(100% - 24px, 760px); gap: 16px; padding: 14px; }
  .archive-only .invoice-header { min-height: auto; padding: 14px; }
  .archive-only .invoice-brand { display: none; }
  .archive-only .invoice-header-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 0; }
  .archive-only .invoice-archive { padding-top: 8px; }
  .archive-only .archive-heading { display: grid; gap: 16px; }
  .archive-only .fy-invoice-archive { grid-template-columns: 1fr; }
}

.invoice-app::before { display: none; }

.invoice-app button,
.invoice-app input,
.invoice-app select,
.invoice-app textarea,
.invoice-heading h1,
.invoice-archive h2,
.editor-section h2,
.invoice-toolbar strong,
.archive-summary strong,
.preview-client strong,
.preview-meta h2,
.preview-thanks {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.invoice-header {
  grid-template-columns: 150px minmax(0, 1fr) auto;
  gap: 24px;
}

.invoice-brand {
  min-height: 0;
  padding: 14px;
  border-radius: 8px;
  background: transparent;
}

.invoice-brand img {
  width: 100%;
  max-width: 132px;
  filter: drop-shadow(0 14px 30px rgba(21, 19, 15, 0.12));
}

.invoice-heading h1 {
  font-size: clamp(2.15rem, 5vw, 4.85rem);
  font-weight: 700;
  letter-spacing: 0;
  line-height: 0.98;
}

.invoice-kicker,
.editor-section-heading span,
.archive-heading > div > span,
.invoice-status-label {
  color: var(--sand-deep);
  letter-spacing: 0;
}

.invoice-button {
  min-height: 42px;
  border-color: var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
  transition: background 220ms ease, border-color 220ms ease;
}

.invoice-button:hover { transform: none; }

.invoice-button.primary {
  border: 0;
  color: var(--paper-strong);
  background: var(--charcoal);
}

.invoice-button.secondary:hover {
  border-color: rgba(157, 120, 86, 0.34);
  background: #fff8ed;
}

.invoice-button.small { border-radius: 8px; }

.invoice-toolbar,
.editor-section,
.invoice-archive {
  border-color: var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.7);
  box-shadow: 0 16px 42px rgba(21, 19, 15, 0.08);
}

.invoice-toolbar {
  top: 0;
  padding: 18px 20px;
  background: rgba(255, 250, 242, 0.96);
  backdrop-filter: blur(12px);
}

.fy-badge,
.tax-chip,
.status-chip,
.fy-tab {
  border-color: var(--line);
  border-radius: 999px;
  color: rgba(21, 19, 15, 0.72);
  background: rgba(255, 255, 255, 0.62);
}

.fy-tab.active {
  border-color: transparent;
  color: var(--paper-strong);
  background: var(--sage);
}

.invoice-editor input,
.invoice-editor select,
.invoice-editor textarea,
.archive-search input {
  border-color: var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.76);
}

.invoice-editor input:focus,
.invoice-editor select:focus,
.invoice-editor textarea:focus,
.archive-search input:focus {
  border-color: var(--sand-deep);
  box-shadow: 0 0 0 3px rgba(198, 162, 125, 0.24);
}

.archive-actions {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  justify-content: end;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.archive-table td:last-child { width: 290px; }

.fy-tabs {
  display: grid;
  gap: 9px;
  margin: 8px 0 16px;
}

.fy-tab {
  display: block;
  min-height: 0;
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.5);
}

.fy-tab summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}

.fy-tab summary::-webkit-details-marker { display: none; }
.fy-tab summary::after { content: "+"; color: var(--sand-deep); font-size: 1.2rem; }
.fy-tab[open] summary { color: var(--paper-strong); background: var(--sage); }
.fy-tab[open] summary::after { content: "−"; color: var(--paper-strong); }
.fy-tab-count { color: var(--invoice-muted); font-size: .8rem; font-weight: 700; }
.fy-tab[open] .fy-tab-count { color: rgba(255,250,242,.78); }

@media (max-width: 720px) {
  .archive-actions { justify-content: start; }
  .archive-table td:last-child { width: 270px; }
}

/* Financial-year archive - follows the clear, expandable Team project pattern. */
.fy-invoice-archive { display: grid; gap: 16px; }

.fy-archive-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.72);
}

.fy-archive-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
}

.fy-archive-header span,
.fy-archive-header small,
.fy-invoice-copy small {
  display: block;
  color: var(--invoice-muted);
  font-size: .78rem;
}

.fy-archive-header span { margin-bottom: 4px; font-weight: 800; text-transform: uppercase; }
.fy-archive-header h3 { margin: 0; font-size: clamp(1.6rem, 3vw, 2.3rem); letter-spacing: -.04em; }
.fy-archive-header small { margin-top: 5px; }
.fy-archive-header > strong { color: var(--sand-deep); font-size: 1.12rem; white-space: nowrap; }

.fy-archive-details { border-top: 1px solid var(--line); }
.fy-archive-details summary {
  display: grid;
  grid-template-columns: 1fr auto 18px;
  align-items: center;
  gap: 18px;
  min-height: 72px;
  padding: 0 22px;
  cursor: pointer;
  list-style: none;
}

.fy-archive-details summary::-webkit-details-marker { display: none; }
.fy-archive-details summary > strong { font-size: 1.05rem; }
.fy-archive-details summary > span { color: var(--invoice-muted); }
.fy-archive-details summary > b { color: var(--invoice-muted); font-size: 1.3rem; text-align: right; }
.fy-archive-details:not([open]) summary > b::after { content: "+"; }
.fy-archive-details:not([open]) summary > b { font-size: 0; }
.fy-archive-details:not([open]) summary > b::after { font-size: 1.3rem; }

.fy-invoice-list { border-top: 1px solid var(--line); }
.fy-invoice-row { border-bottom: 1px solid var(--line); }
.fy-invoice-row:last-child { border-bottom: 0; }
.fy-invoice-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 22px;
  align-items: center;
  gap: 18px;
  width: 100%;
  border: 0;
  padding: 18px 22px 12px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  background: transparent;
}

.fy-invoice-open:hover { background: rgba(255, 255, 255, .44); }
.fy-invoice-copy strong { display: block; font-size: 1rem; }
.fy-invoice-copy small { margin-top: 5px; }
.fy-invoice-total { color: var(--invoice-muted); font-weight: 800; white-space: nowrap; }
.fy-invoice-chevron { font-size: 2rem; font-weight: 300; line-height: .7; }
.fy-invoice-row .archive-actions { justify-content: flex-end; padding: 0 22px 16px; }
.fy-invoice-row .archive-actions .invoice-button { min-height: 32px; }

.total-dialog {
  width: min(460px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  color: var(--ink);
  background: var(--paper-strong);
  box-shadow: 0 28px 90px rgba(21, 19, 15, .24);
}

.total-dialog::backdrop { background: rgba(21, 19, 15, .35); backdrop-filter: blur(3px); }
.total-dialog-card { display: grid; gap: 18px; padding: 26px; }
.total-dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: 20px; }
.total-dialog-heading span { color: var(--sand-deep); font-size: .74rem; font-weight: 800; text-transform: uppercase; }
.total-dialog-heading h2 { margin: 5px 0 0; font-size: 1.7rem; letter-spacing: -.04em; }
.total-dialog-card > p { margin: -4px 0 0; color: var(--invoice-muted); line-height: 1.55; }
.total-dialog-card label { display: grid; gap: 8px; color: var(--invoice-muted); font-size: .8rem; font-weight: 800; }
.total-dialog-card input { height: 48px; border: 1px solid var(--line); border-radius: 8px; padding: 0 13px; color: var(--ink); font: inherit; background: rgba(255,255,255,.75); }
.dialog-close { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; color: var(--ink); font-size: 1.45rem; line-height: 1; cursor: pointer; background: transparent; }
.total-dialog-calculation { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.total-dialog-calculation div { border-radius: 8px; padding: 13px; background: rgba(198,162,125,.15); }
.total-dialog-calculation span { display: block; color: var(--invoice-muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.total-dialog-calculation strong { display: block; margin-top: 5px; font-size: 1rem; }
.total-dialog-actions { display: flex; justify-content: flex-end; gap: 9px; }

@media (max-width: 640px) {
  .fy-archive-header, .fy-archive-details summary { padding-left: 16px; padding-right: 16px; }
  .fy-archive-details summary { grid-template-columns: 1fr 18px; }
  .fy-archive-details summary > span { display: none; }
  .fy-invoice-open { grid-template-columns: minmax(0, 1fr) 18px; padding-left: 16px; padding-right: 16px; }
  .fy-invoice-total { grid-column: 1; margin-top: -8px; }
  .fy-invoice-chevron { grid-column: 2; grid-row: 1 / span 2; }
  .fy-invoice-row .archive-actions { justify-content: start; padding-left: 16px; padding-right: 16px; }
}

.tax-rule,
.item-row,
.archive-summary div {
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.item-row { border: 1px solid var(--line); }

.item-row .remove-item {
  border-radius: 8px;
  border-color: var(--line);
  color: #8f3329;
}

.preview-stage {
  border-radius: 8px;
  padding: clamp(14px, 2.2vw, 24px);
  background: rgba(255, 250, 242, 0.48);
  box-shadow: inset 0 0 0 1px var(--line);
}

.invoice-preview {
  color: var(--ink);
  background: var(--paper-strong);
  box-shadow: 0 16px 42px rgba(21, 19, 15, 0.12);
}

.preview-topbar { height: 8px; background: var(--sand); }
.preview-meta h2 { color: var(--ink); font-weight: 800; }

.preview-client {
  border-left-color: var(--sand);
  border-radius: 0 8px 8px 0;
  background: rgba(198, 162, 125, 0.16);
}

.preview-table th { border-bottom-color: var(--sand-deep); color: var(--sand-deep); }

.preview-summary-row.total {
  border-radius: 8px;
  color: var(--paper-strong);
  background: var(--charcoal);
}

.preview-summary-row.total span,
.preview-summary-row.total strong { color: var(--paper-strong); }
.preview-thanks { color: var(--sand-deep); font-weight: 800; }
