.backLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

.backLink:hover {
  text-decoration: underline;
}

.alertError {
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #b91c1c;
}

.statusChip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid transparent;
  transition: filter 0.2s;
}

.statusChipBtn {
  cursor: pointer;
  background: none;
}

.statusChipBtn:hover {
  filter: brightness(0.95);
}

.statusChipBtn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.statusChipBtn:disabled {
  cursor: wait;
  opacity: 0.7;
}

.statusOptionList {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.statusOption {
  min-height: 32px;
  padding: 6px 12px;
  font-size: 12px;
}

.statusOptionSelected {
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb) / 0.12);
}

.status_draft,
.status_issued {
  color: #0f172a;
  background: rgba(15, 23, 42, 0.08);
  border-color: rgba(15, 23, 42, 0.18);
}

.status_approved {
  color: #0e7490;
  background: rgba(6, 182, 212, 0.14);
  border-color: rgba(6, 182, 212, 0.32);
}

.status_paid {
  color: #15803d;
  background: rgba(34, 197, 94, 0.14);
  border-color: rgba(34, 197, 94, 0.32);
}

.status_cancelled {
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.28);
}

.itemTitle {
  font-weight: 600;
}

.templateBar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.templateHint {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-secondary);
}

.templateHint a {
  color: var(--primary);
  font-weight: 600;
}

.itemsStack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
  max-height: min(48vh, 420px);
  overflow: auto;
  padding-right: 2px;
}

.itemCard {
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.45);
}

.itemCardHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.removeItemBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.18);
  flex-shrink: 0;
}

.removeItemBtn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.14);
}

.removeItemBtn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/** Matches compact field height; align with input (not label). */
.removeFieldBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--field-height);
  height: var(--field-height);
  min-width: var(--field-height);
  border-radius: var(--radius-sm);
  color: #b91c1c;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.18);
  flex-shrink: 0;
}

.removeFieldBtn:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.14);
}

.repeatRow {
  display: flex;
  align-items: center;
  gap: 8px;
}

.repeatRow .field {
  flex: 1;
  min-width: 0;
}

.fieldNoLabel {
  margin: 0;
}

.fieldNoLabel label {
  display: none;
}

.itemGrid {
  display: grid;
  grid-template-columns: minmax(160px, 2fr) minmax(90px, 1fr) minmax(90px, 1fr) minmax(110px, 1.1fr) minmax(120px, 1.2fr);
  gap: 10px;
  align-items: end;
}

.metaGrid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(240px, 1.4fr);
  gap: 10px;
  margin-bottom: 14px;
}

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

.span2 {
  grid-column: span 2;
}

.publicLink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 280px;
  font-size: 12px;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.publicLink:hover {
  text-decoration: underline;
}

.copyLinkBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: rgba(var(--primary-rgb) / 0.06);
  border: 1px solid rgba(var(--primary-rgb) / 0.14);
  flex-shrink: 0;
}

.copyLinkBtn:hover {
  color: var(--primary);
  background: rgba(var(--primary-rgb) / 0.12);
}

.linkRow {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

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

.itemActionsLeft {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.compactSelect {
  width: min(260px, 100%);
  min-height: 32px;
  padding: 6px var(--select-padding-end) 6px 10px;
  font-size: 12px;
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 14px;
  cursor: pointer;
}

.compactBtn {
  padding: 6px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.createTotal {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.createTotalRow {
  display: flex;
  justify-content: flex-end;
  margin: 4px 0 14px;
}

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

.detailMeta select {
  width: 100%;
  min-height: var(--field-height);
  margin-top: 4px;
  padding: var(--field-padding-y) var(--select-padding-end) var(--field-padding-y) var(--field-padding-x);
  font-size: var(--field-font-size);
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--select-arrow-offset) center;
  background-size: var(--select-arrow-size);
  cursor: pointer;
}

.detailLabel {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.detailMeta .statusChipBtn {
  margin-top: 4px;
}

.detailNotes {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.detailItems {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detailItem {
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.4);
}

.detailItemTop {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.detailItemMeta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.detailItemDesc {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.strike {
  text-decoration: line-through;
  color: var(--text-muted);
  font-weight: 500;
}

.blockSection {
  margin: 16px 0;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.22);
}

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

.blockTitle {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.repeatStack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.flexGrow {
  flex: 1;
  min-width: 0;
}

.accountCard {
  padding: 12px;
  border: 1px solid rgba(148, 163, 184, 0.28);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.45);
}

.accountGrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.accountRow {
  display: grid;
  grid-template-columns: 2fr 2fr 3fr 5fr var(--field-height);
  align-items: end;
  gap: 8px;
}

.accountRowPlain {
  align-items: center;
}

.accountCol2,
.accountCol3,
.accountCol5 {
  min-width: 0;
}

.fullField {
  margin-bottom: 12px;
}

.keyPointList {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

@media (max-width: 900px) {
  .itemGrid,
  .metaGrid,
  .detailMeta {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 720px) {
  .templateBar,
  .itemGrid,
  .metaGrid,
  .detailMeta {
    grid-template-columns: 1fr;
  }

  .span2,
  .descField {
    grid-column: span 1;
  }

  .accountRow {
    grid-template-columns: 1fr var(--field-height);
  }

  .accountCol2,
  .accountCol3,
  .accountCol5 {
    grid-column: 1;
  }

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

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

  .compactSelect {
    width: 100%;
  }
}
