:root {
  --green: #1f7a3a;
  --green-2: #155a2b;
  --line: #d6e3da;
  --text: #1a2a20;
  --bg: #f3f8f5;
  --card: #ffffff;
  --info-bg: #f2f7ff;
  --info-line: #cdddff;
  --info-text: #1f427c;
  --success-bg: #f5fbf7;
  --success-line: #d5e7da;
  --success-text: #19472a;
  --warning-bg: #fff8e8;
  --warning-line: #f0ddb1;
  --warning-text: #7b5b00;
  --error-bg: #fff3f3;
  --error-line: #efc6c6;
  --error-text: #8a1c1c;
}

* {
  box-sizing: border-box;
}

body.app-fatture-page {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.05);
}

.header,
.filters,
.table-card,
.modal-panel {
  padding: 16px;
}

.header {
  display: grid;
  gap: 10px;
}

.section-kicker {
  color: #53665a;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.title,
.table-head h2,
.modal-head h2 {
  margin: 0;
  color: var(--green);
}

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

.badge {
  border: 1px solid #d7e6db;
  background: #f8fcf9;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.status {
  border: 1px solid var(--success-line);
  background: var(--success-bg);
  color: var(--success-text);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.88rem;
}

.status.info,
.status.loading {
  border-color: var(--info-line);
  background: var(--info-bg);
  color: var(--info-text);
}

.status.warning {
  border-color: var(--warning-line);
  background: var(--warning-bg);
  color: var(--warning-text);
}

.status.error {
  border-color: var(--error-line);
  background: var(--error-bg);
  color: var(--error-text);
}


.view-switch {
  display: inline-flex;
  gap: 6px;
}

.view-tab {
  background: #fff;
  border: 1px solid #c7d7cc;
  color: #244532;
  cursor: pointer;
  font-weight: 700;
  width: auto;
}

.view-tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.line-review-counters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.line-counter-btn {
  background: #fff;
  border: 1px solid #d7e6db;
  border-radius: 8px;
  color: #53665a;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 8px 10px;
  width: auto;
}

.line-counter-btn:hover,
.line-counter-btn:focus-visible {
  border-color: #7fb08e;
  color: #244532;
}

.line-counter-btn.active {
  background: #e8f4ec;
  border-color: var(--green);
  color: #244532;
}

.line-counter-btn strong {
  color: #244532;
  margin-left: 6px;
}

.line-review-table {
  min-width: 1180px;
}

.line-filter-check {
  align-self: end;
  border: 1px solid #d7e6db;
  border-radius: 8px;
  padding: 10px;
}

.pagination-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.pagination-actions .btn {
  width: auto;
}

.muted {
  color: #53665a;
  font-size: 0.78rem;
  line-height: 1.3;
  margin-top: 4px;
}

.highlight-line {
  outline: 2px solid var(--warning-line);
  outline-offset: -2px;
}

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

.summary-card {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.summary-card span {
  color: #53665a;
  font-size: 0.86rem;
  font-weight: 700;
}

.summary-card strong {
  color: #244532;
  font-size: 1.8rem;
  line-height: 1;
}

.warning-card {
  border-color: var(--warning-line);
}

.due-card {
  border-color: #d7d4c8;
}

.paid-card {
  border-color: var(--success-line);
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

label {
  display: block;
  margin-bottom: 6px;
  color: #244532;
  font-size: 0.82rem;
  font-weight: 700;
}

input,
select,
button,
textarea {
  width: 100%;
  border: 1px solid #c7d7cc;
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  background: #fff;
}

.btn {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  font-weight: 700;
  cursor: pointer;
}

.btn:hover {
  background: var(--green-2);
  border-color: var(--green-2);
}

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

.btn.secondary:hover {
  background: var(--green);
  color: #fff;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.filter-actions {
  align-self: end;
}

.table-head {
  align-items: end;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.detail-meta {
  color: #53665a;
  font-size: 0.88rem;
}

.table-scroll {
  overflow-x: auto;
}

.invoice-table {
  border-collapse: collapse;
  min-width: 980px;
  width: 100%;
}

.invoice-table th,
.invoice-table td {
  border-bottom: 1px solid #d8e4db;
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

.invoice-table th {
  color: #244532;
  font-size: 0.78rem;
  text-transform: uppercase;
}

.invoice-table tbody tr {
  cursor: pointer;
}

.invoice-table tbody tr:hover {
  background: #f8fcf9;
}

.amount-cell {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

.badge-pill {
  border: 1px solid var(--info-line);
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
  padding: 6px 8px;
  white-space: nowrap;
}

.badge-pill.success {
  background: var(--success-bg);
  border-color: var(--success-line);
  color: var(--success-text);
}

.badge-pill.warning {
  background: var(--warning-bg);
  border-color: var(--warning-line);
  color: var(--warning-text);
}

.badge-pill.error {
  background: var(--error-bg);
  border-color: var(--error-line);
  color: var(--error-text);
}

.payment-cell {
  min-width: 138px;
}

.payment-toggle {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  line-height: 1;
  white-space: nowrap;
}

.payment-toggle input {
  width: auto;
}

.pdf-btn,
.detail-btn {
  min-width: 68px;
  padding: 8px 10px;
}

.row-actions {
  display: flex;
  gap: 8px;
}

.empty-state {
  border: 1px dashed var(--info-line);
  background: var(--info-bg);
  border-radius: 8px;
  color: var(--info-text);
  margin-top: 12px;
  padding: 14px;
}

.hidden {
  display: none !important;
}

.modal {
  inset: 0;
  position: fixed;
  z-index: 30;
}

.modal-backdrop {
  background: rgba(16, 29, 20, 0.45);
  inset: 0;
  position: absolute;
}

.modal-panel {
  max-height: calc(100vh - 36px);
  max-width: 760px;
  overflow-y: auto;
  position: relative;
  margin: 18px auto;
  width: calc(100% - 32px);
}

.modal-head {
  align-items: start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.icon-btn {
  align-items: center;
  background: #fff;
  border: 1px solid #c7d7cc;
  color: #244532;
  display: inline-flex;
  font-size: 1.4rem;
  height: 38px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 38px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-item {
  border: 1px solid #d8e4db;
  border-radius: 8px;
  padding: 10px;
}

.detail-item span {
  color: #53665a;
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.detail-item strong {
  color: #1a2a20;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.farm-year-editor {
  border-top: 1px solid #d8e4db;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(180px, 1fr) auto;
  margin-top: 14px;
  padding-top: 14px;
}

.farm-year-editor .status {
  grid-column: 1 / -1;
}

.farm-year-editor.hidden {
  display: none;
}


@media (max-width: 900px) {

.view-switch {
  display: inline-flex;
  gap: 6px;
}

.view-tab {
  background: #fff;
  border: 1px solid #c7d7cc;
  color: #244532;
  cursor: pointer;
  font-weight: 700;
  width: auto;
}

.view-tab.active {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.line-review-counters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.line-counter-btn {
  background: #fff;
  border: 1px solid #d7e6db;
  border-radius: 8px;
  color: #53665a;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  padding: 8px 10px;
  width: auto;
}

.line-counter-btn:hover,
.line-counter-btn:focus-visible {
  border-color: #7fb08e;
  color: #244532;
}

.line-counter-btn.active {
  background: #e8f4ec;
  border-color: var(--green);
  color: #244532;
}

.line-counter-btn strong {
  color: #244532;
  margin-left: 6px;
}

.line-review-table {
  min-width: 1180px;
}

.line-filter-check {
  align-self: end;
  border: 1px solid #d7e6db;
  border-radius: 8px;
  padding: 10px;
}

.pagination-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}

.pagination-actions .btn {
  width: auto;
}

.muted {
  color: #53665a;
  font-size: 0.78rem;
  line-height: 1.3;
  margin-top: 4px;
}

.highlight-line {
  outline: 2px solid var(--warning-line);
  outline-offset: -2px;
}

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

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

@media (max-width: 640px) {
  .page {
    padding: 12px;
  }

  .summary-grid,
  .filters,
  .detail-grid,
  .farm-year-editor {
    grid-template-columns: 1fr;
  }

  .table-head {
    align-items: start;
    flex-direction: column;
  }

  .invoice-table {
    min-width: 760px;
  }

  .invoice-lines-table {
    min-width: 760px;
  }

  .mapping-form,
  .local-classification-form {
    grid-template-columns: 1fr;
  }

  .invoice-table th:nth-child(2),
  .invoice-table td:nth-child(2),
  .invoice-table th:nth-child(5),
  .invoice-table td:nth-child(5),
  .invoice-table th:nth-child(6),
  .invoice-table td:nth-child(6) {
    display: none;
  }
}


.table-head.compact {
  align-items: center;
  margin-bottom: 8px;
  margin-top: 14px;
}

.table-head.compact h3 {
  color: var(--green);
  font-size: 1rem;
  margin: 0;
}

.invoice-lines-section {
  border-top: 1px solid #d8e4db;
  margin-top: 14px;
  padding-top: 4px;
}

.lines-scroll {
  overflow-x: auto;
}

.invoice-lines-table {
  border-collapse: collapse;
  min-width: 920px;
  width: 100%;
}

.invoice-lines-table th,
.invoice-lines-table td {
  border-bottom: 1px solid #d8e4db;
  padding: 9px 8px;
  text-align: left;
  vertical-align: top;
}

.invoice-lines-table th {
  color: #244532;
  font-size: 0.74rem;
  text-transform: uppercase;
}

.line-description {
  max-width: 280px;
  overflow-wrap: anywhere;
}

.line-empty {
  border: 1px dashed var(--info-line);
  background: var(--info-bg);
  border-radius: 8px;
  color: var(--info-text);
  padding: 12px;
}

.line-action-cell {
  min-width: 96px;
}

.line-map-btn {
  min-width: 86px;
  padding: 8px 10px;
}

.mapping-summary {
  color: #53665a;
  font-size: 0.78rem;
  line-height: 1.3;
  margin-top: 6px;
  max-width: 240px;
  overflow-wrap: anywhere;
}

.mapping-panel {
  max-width: 680px;
}

.mapping-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.mapping-form .full {
  grid-column: 1 / -1;
}

.checkbox-field {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  margin: 0;
}

.checkbox-field input {
  width: auto;
}

.checkbox-field span {
  color: #244532;
  font-size: 0.88rem;
  font-weight: 700;
}

input[readonly] {
  background: #f6faf7;
  color: #53665a;
}

.stock-action-cell {
  min-width: 170px;
}

.stock-summary {
  color: #53665a;
  font-size: 0.78rem;
  line-height: 1.3;
  margin: 6px 0;
  max-width: 220px;
  overflow-wrap: anywhere;
}

.stock-load-btn {
  padding: 8px 10px;
  white-space: normal;
}

.stock-confirm-panel {
  max-width: 520px;
}


.line-review-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}

.line-review-actions .btn {
  padding: 8px 10px;
  white-space: normal;
}

.line-local-btn {
  border-color: #b8d4c1;
}

.local-classification-panel {
  max-width: 760px;
}

.local-readonly-grid {
  margin-bottom: 14px;
}

.local-readonly-grid .detail-item strong {
  overflow-wrap: anywhere;
}

.local-classification-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.local-classification-form .full {
  grid-column: 1 / -1;
}

.local-preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.local-preset-row .btn {
  width: auto;
}

.local-revoke-section {
  border-top: 1px solid #d8e4db;
  margin-top: 14px;
  padding-top: 14px;
}

.local-revoke-section .modal-actions {
  margin-top: 10px;
}

.local-history-section {
  border-top: 1px solid #d8e4db;
  margin-top: 14px;
  padding-top: 2px;
}

.local-history-section .btn {
  width: auto;
}

.local-history-list {
  display: grid;
  gap: 8px;
}

.local-history-item {
  border: 1px solid #d7e6db;
  border-radius: 8px;
  padding: 10px;
}

.local-history-item > div:first-child {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.local-history-item span,
.local-history-snapshot,
.local-history-note {
  color: #53665a;
  font-size: 0.82rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.local-history-note {
  margin-top: 6px;
}


.technical-issue-strip {
  align-items: center;
  background: var(--info-bg);
  border: 1px solid var(--info-line);
  border-radius: 8px;
  color: var(--info-text);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 10px;
}

.technical-issue-strip .btn {
  width: auto;
}

.technical-issue-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.technical-issue-card {
  border: 1px solid #d7e6db;
  border-radius: 8px;
  padding: 10px;
}

.technical-issue-card > div:first-child {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.line-technical-btn {
  border-color: var(--warning-line);
  color: var(--warning-text);
}

.line-technical-btn:hover {
  background: var(--warning-bg);
  border-color: var(--warning-line);
  color: var(--warning-text);
}

.technical-issue-panel {
  max-width: 820px;
}

.technical-readonly-grid {
  margin-bottom: 14px;
}

.technical-current-section,
.technical-note-section {
  border-top: 1px solid #d8e4db;
  margin-top: 14px;
  padding-top: 2px;
}

.technical-current-box {
  border: 1px solid #d7e6db;
  border-radius: 8px;
  padding: 10px;
}

.technical-current-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.technical-current-grid .detail-item.full {
  grid-column: 1 / -1;
}

.technical-issue-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.technical-issue-form .full {
  grid-column: 1 / -1;
}

.technical-note-section textarea {
  min-height: 86px;
}

@media (max-width: 640px) {
  .technical-issue-strip,
  .technical-issue-card > div:first-child {
    align-items: stretch;
    flex-direction: column;
  }

  .technical-current-grid,
  .technical-issue-form {
    grid-template-columns: 1fr;
  }
}
