.inv-head {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}

.inv-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}

.inv-back .material-symbols-outlined {
  font-size: 1.2rem;
}

.inv-title {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.inv-title h1 {
  margin: 0;
  font-size: clamp(1.9rem, 6vw, 2.6rem);
  line-height: 1.05;
}

.inv-date {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 600;
}

.inv-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 800;
  border: 2px solid currentColor;
  border-radius: 999px;
  background: var(--surface);
}

button.inv-status {
  cursor: pointer;
}

.inv-status .material-symbols-outlined {
  font-size: 1.15rem;
}

.inv-status.status-ok {
  color: #147a2e;
  background: #e8f8ec;
}

.inv-status.status-warning {
  color: #8a5a00;
  background: #fff4cc;
}

.inv-status.status-cancelled {
  color: #9b1c1c;
  background: #fde8e8;
}

.inv-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.inv-actions .button-form {
  margin: 0;
}

.inv-actions > * {
  flex: 0 0 auto;
}

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

.inv-card {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.inv-card h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.inv-card h2 .material-symbols-outlined {
  font-size: 1.1rem;
}

.inv-card p {
  margin: 0;
  color: var(--text);
}

.inv-card-main {
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

a.inv-card-main {
  text-decoration: none;
}

a.inv-card-main:hover {
  color: var(--link);
}

.inv-plate {
  justify-self: start;
  padding: 2px 10px;
  letter-spacing: 0.04em;
  border: 2px solid var(--text);
  border-radius: 6px;
}

.inv-mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.inv-card-total {
  border-color: var(--text);
}

.inv-brutto {
  font-size: 1.9rem;
}

.inv-card-total p {
  color: var(--muted);
}

.inv-card-total p strong {
  color: var(--text);
}

.inv-empty {
  margin: 0;
  color: var(--muted);
}

.inv-section-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.inv-count {
  min-width: 26px;
  padding: 1px 8px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  border-radius: 999px;
  background: var(--surface-soft);
}

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

.inv-items thead {
  display: table-header-group;
  position: static;
  width: auto;
  height: auto;
  overflow: visible;
  clip: auto;
}

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

.inv-items tfoot {
  display: table-footer-group;
}

.inv-items tr {
  display: table-row;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.inv-items th,
.inv-items td {
  display: table-cell;
  min-height: 0;
}

.inv-items td::before {
  content: none;
}

.inv-items th,
.inv-items td {
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

.inv-items thead th {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.inv-items .num {
  text-align: right;
  white-space: nowrap;
}

.inv-item-name strong {
  display: block;
  font-size: 1.02rem;
}

.inv-item-name small {
  display: block;
  color: var(--muted);
}

.inv-item-calc {
  display: none !important;
}

.inv-item-total {
  font-weight: 800;
}

.inv-totals {
  display: grid;
  justify-content: end;
  gap: 4px;
  margin: 12px 0 0;
  padding-right: 8px;
}

.inv-totals div {
  display: grid;
  grid-template-columns: 120px minmax(110px, auto);
  gap: 16px;
  color: var(--muted);
}

.inv-totals dt,
.inv-totals dd {
  margin: 0;
  text-align: right;
}

.inv-totals .inv-totals-sum {
  margin-top: 4px;
  padding-top: 8px;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 900;
  border-top: 2px solid var(--text);
}

.inv-add {
  margin-top: 14px;
}

.inv-add > summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  font-weight: 800;
  color: var(--accent-strong);
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  list-style: none;
}

.inv-add > summary::-webkit-details-marker {
  display: none;
}

.inv-add[open] > summary {
  margin-bottom: 4px;
}

.inv-docs {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.inv-doc {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.inv-doc:hover {
  border-color: var(--accent);
}

.inv-doc-icon {
  color: var(--accent);
}

.inv-doc-text {
  display: grid;
  min-width: 0;
}

.inv-doc-text small {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-docs .ocr-details {
  margin: 4px 0 0 14px;
}

.inv-doc-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px 16px;
}

.inv-doc-actions .inv-add {
  flex: 1 1 320px;
}

.inv-add-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-top: 14px;
  font-weight: 800;
  color: var(--accent-strong);
  text-decoration: none;
}

.inv-danger {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 24px;
}

@media (max-width: 760px) {
  .inv-cards {
    grid-template-columns: minmax(0, 1fr);
  }

  .inv-card-total {
    order: -1;
  }

  .inv-actions > * {
    flex: 1 1 auto;
  }

  .inv-actions .button,
  .inv-actions button {
    width: 100%;
    justify-content: center;
  }

  .inv-items .inv-col-wide,
  .inv-items thead th:nth-child(2),
  .inv-items thead th:nth-child(3) {
    display: none;
  }

  .inv-items .inv-item-calc {
    display: block !important;
  }

  .inv-items th,
  .inv-items td {
    padding: 10px 4px;
  }

  .inv-danger {
    justify-content: stretch;
  }

  .inv-danger form,
  .inv-danger button {
    width: 100%;
    justify-content: center;
  }
}

.inv-doc-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface-soft);
}

.inv-doc-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

body.inv-viewer-open {
  overflow: hidden;
}

.inv-viewer[hidden] {
  display: none;
}

.inv-viewer {
  position: fixed;
  inset: 0;
  z-index: 10080;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(15, 15, 15, 0.94);
}

.inv-viewer-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  color: #fff;
}

.inv-viewer-count {
  color: #bbb;
  font-weight: 700;
}

.inv-viewer-tools {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.inv-viewer-tools button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.inv-viewer-tools button[hidden] {
  display: none;
}

.inv-viewer-tools .inv-viewer-close {
  width: 52px;
  height: 52px;
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.inv-viewer-tools .inv-viewer-close .material-symbols-outlined {
  font-size: 32px;
}

.inv-viewer-stage img {
  touch-action: pan-x pan-y;
}

.inv-viewer-stage {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
  padding: 0 12px 12px;
}

.inv-viewer.is-zoomed .inv-viewer-stage {
  display: block;
}

.inv-viewer-stage img {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: calc(100dvh - 92px - env(safe-area-inset-top));
  background: #fff;
  cursor: zoom-in;
}

.inv-viewer.is-zoomed .inv-viewer-stage img {
  max-width: none;
  max-height: none;
  height: auto;
  margin: 0 auto;
  cursor: zoom-out;
}

.receipt-add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
}

.receipt-add-row .inv-add-link {
  margin-top: 0;
}

.receipt-status {
  color: var(--muted);
  font-weight: 700;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.receipt-tile {
  display: grid;
  gap: 6px;
  padding: 6px;
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.receipt-tile:hover {
  border-color: var(--accent);
  text-decoration: none;
}

.receipt-tile-image {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  color: var(--accent);
  border-radius: 6px;
  background: var(--surface-soft);
}

.receipt-tile-image img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.receipt-tile-label {
  overflow: hidden;
  font-size: 0.85rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inv-viewer-tools .inv-viewer-close {
  width: 52px;
  height: 52px;
  margin-left: 4px;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85);
}

.inv-viewer-tools .inv-viewer-close .material-symbols-outlined {
  font-size: 32px;
  font-weight: 700;
}

.receipt-dock {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 26;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scroll-snap-type: x proximity;
  padding: 8px max(12px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.12);
}

.receipt-dock-item {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 64px;
  height: 80px;
  overflow: hidden;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  scroll-snap-align: start;
}

.receipt-dock-item:hover,
.receipt-dock-item:focus-visible {
  border-color: var(--accent);
  text-decoration: none;
}

.receipt-dock-item img {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.receipt-dock-label {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2;
  overflow: hidden;
  padding: 2px 4px;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.55);
}

.receipt-dock-spacer {
  height: calc(112px + env(safe-area-inset-bottom));
}

body:has(.receipt-dock) .scan-jobs-dock {
  bottom: calc(112px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .receipt-dock-item {
    width: 76px;
    height: 96px;
  }

  .receipt-dock-spacer {
    height: calc(128px + env(safe-area-inset-bottom));
  }

  body:has(.receipt-dock) .scan-jobs-dock {
    bottom: calc(128px + env(safe-area-inset-bottom));
  }
}

.receipt-item,
.inv-docs > li {
  position: relative;
}

.inv-docs .inv-doc {
  padding-right: 64px;
}

.receipt-item .receipt-tile {
  height: 100%;
}

.receipt-delete {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 40px;
  min-width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  color: #fff;
  border: 0;
  border-radius: 999px;
  background: rgba(185, 28, 28, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.receipt-delete:hover {
  background: #991b1b;
}

.receipt-delete:disabled {
  opacity: 0.5;
}

.receipt-delete .material-symbols-outlined {
  font-size: 22px;
}
