:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #172026;
  --muted: #66737d;
  --line: #d9dee3;
  --accent: #1f6f68;
  --accent-strong: #14534e;
  --danger: #b42318;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

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

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

button.secondary:hover {
  background: #eef2f3;
}

button.danger {
  border: 1px solid #f2b8b5;
  background: #fff;
  color: var(--danger);
}

button.danger:hover {
  background: #fff1f0;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label select,
label textarea {
  color: var(--text);
  font-size: 15px;
}

.hidden {
  display: none !important;
}

.shell {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 0;
}

.login-box {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

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

h1 {
  font-size: 28px;
  font-weight: 720;
}

h2 {
  font-size: 18px;
  font-weight: 680;
}

h3 {
  font-size: 15px;
  font-weight: 680;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar p {
  color: var(--muted);
  margin-top: 4px;
}

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

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab-button {
  min-height: 44px;
  border-radius: 6px 6px 0 0;
  border: 1px solid transparent;
  border-bottom: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 18px;
}

.tab-button:hover {
  background: #eef2f3;
  color: var(--text);
}

.tab-button.active {
  border-color: var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 680;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.panel-head,
.table-editor-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

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

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

.table-editor {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.rows {
  display: grid;
  gap: 8px;
}

.row {
  display: grid;
  gap: 8px;
  align-items: center;
}

.iva-row {
  grid-template-columns: 120px 1fr 1fr 40px;
}

.linea-row {
  grid-template-columns: 2fr 110px 130px 130px 100px 40px;
}

.icon-button {
  width: 40px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--danger);
}

.icon-button:hover {
  background: #fff1f0;
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.supplier-form,
.payment-form {
  display: grid;
  grid-template-columns: 1.4fr 170px 1.2fr 170px;
  gap: 10px;
}

.payment-form {
  grid-template-columns: 130px 110px 120px 1fr 1fr 1fr 1.4fr 160px 170px 130px 110px;
}

.payments-scroll {
  margin-top: 12px;
}

.payment-filters {
  display: grid;
  grid-template-columns: 150px 180px 130px 110px minmax(220px, 1fr) 110px;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

tr.selected-row {
  background: #eef7f6;
}

tr.highlight-row {
  background: #fff8df;
  outline: 2px solid #d8a720;
  outline-offset: -2px;
}

tbody tr {
  cursor: pointer;
}

.detail-grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 8px 14px;
  margin: 0 0 18px;
}

.detail-grid dt {
  color: var(--muted);
}

.detail-grid dd {
  margin: 0;
}

.detail-table {
  margin: 10px 0 18px;
}

.pagination {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  padding-top: 12px;
}

.pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.search {
  max-width: 260px;
}

.table-panel {
  padding-bottom: 8px;
}

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

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
  text-transform: uppercase;
}

td.money {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.status-select {
  min-width: 136px;
}

.error {
  color: var(--danger);
  min-height: 20px;
}

.muted {
  color: var(--muted);
}

@media (max-width: 860px) {
  .shell {
    width: min(100vw - 16px, 1180px);
    padding-top: 12px;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions button {
    flex: 1;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-button {
    flex: 1 0 auto;
  }

  .form-grid,
  .supplier-form,
  .payment-form,
  .payment-filters,
  .iva-row,
  .linea-row {
    grid-template-columns: 1fr;
  }

  .pagination {
    justify-content: stretch;
  }

  .pagination button {
    flex: 1;
  }

  .icon-button {
    width: 100%;
  }

  .search {
    max-width: none;
  }
}
