: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-magazzino-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); }
.hidden { display: none; }

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 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; }

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

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

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

.tab-filter { display: flex; gap: 8px; align-items: end; }
.tab-btn {
  color: #244532;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}
.tab-btn.active { background: var(--green); border-color: var(--green); color: #fff; }
.tab-btn span { opacity: 0.75; }

.table-head { align-items: end; display: flex; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.table-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }
.detail-meta { color: #53665a; font-size: 0.88rem; }
.table-scroll { overflow-x: auto; }

.stock-table { border-collapse: collapse; min-width: 940px; width: 100%; }
.stock-table th, .stock-table td { border-bottom: 1px solid #d8e4db; padding: 10px; text-align: left; vertical-align: middle; }
.stock-table th { color: #244532; font-size: 0.78rem; text-transform: uppercase; }
.stock-table tbody tr { cursor: pointer; }
.stock-table tbody tr:hover { background: #f8fcf9; }

.product-name { color: #1a2a20; font-weight: 800; overflow-wrap: anywhere; }
.product-technical { color: #53665a; font-size: 0.82rem; margin-top: 4px; overflow-wrap: anywhere; }
.balance-cell { font-weight: 800; white-space: nowrap; }
.balance-cell.negative { color: var(--error-text); }
.negative-note { color: var(--error-text); display: block; font-size: 0.78rem; margin-top: 4px; }

.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); }

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

.card-list { display: none; gap: 10px; }
.stock-card { padding: 12px; display: grid; gap: 8px; cursor: pointer; }
.stock-card:hover { background: #f8fcf9; }
.stock-card-head { align-items: start; display: flex; justify-content: space-between; gap: 10px; }
.stock-card-meta { color: #53665a; display: grid; gap: 4px; font-size: 0.86rem; }

.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: 860px; 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; }

.btn {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}
.btn.secondary { background: #fff; color: var(--green); }
.btn:disabled { cursor: wait; opacity: 0.65; }

.modal-actions { align-items: center; display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn { width: auto; }
.movement-panel { max-width: 760px; }
.movement-form { display: grid; gap: 12px; }
.movement-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.movement-notes-field { grid-column: 1 / -1; }
textarea {
  width: 100%;
  border: 1px solid #c7d7cc;
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  resize: vertical;
}
.form-actions { display: flex; justify-content: flex-end; }
.form-actions .btn { width: auto; min-width: 180px; }
.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; }

.table-head.compact { align-items: center; margin-bottom: 8px; margin-top: 14px; }
.table-head.compact h3 { color: var(--green); font-size: 1rem; margin: 0; }
.movements-section { border-top: 1px solid #d8e4db; margin-top: 14px; padding-top: 4px; }
.movements-table { border-collapse: collapse; min-width: 720px; width: 100%; }
.movements-table th, .movements-table td { border-bottom: 1px solid #d8e4db; padding: 9px 8px; text-align: left; vertical-align: top; }
.movements-table th { color: #244532; font-size: 0.74rem; text-transform: uppercase; }
.movement-positive { color: var(--success-text); font-weight: 800; white-space: nowrap; }
.movement-negative { color: var(--error-text); font-weight: 800; white-space: nowrap; }
.source-reference { color: #53665a; font-size: 0.82rem; margin-top: 3px; }
.movement-source { display: grid; gap: 2px; min-width: 0; }
.movement-source strong { color: #1a2a20; overflow-wrap: anywhere; }
.source-link { color: var(--green); display: inline-flex; font-size: 0.82rem; font-weight: 800; margin-top: 4px; text-decoration: none; }
.source-link:hover { text-decoration: underline; }
.movement-card-list { display: none; gap: 10px; }
.movement-card { border: 1px solid #d8e4db; border-radius: 8px; display: grid; gap: 6px; padding: 10px; }
.movement-card-head { align-items: baseline; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; }
.movement-card-head span { color: #244532; font-weight: 800; }

@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tab-filter { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .page { padding: 12px; }
  .summary-grid, .filters, .detail-grid, .movement-grid { grid-template-columns: 1fr; }
  .summary-card strong { font-size: 1.45rem; }
  .tab-filter { flex-direction: column; align-items: stretch; }
  .table-head, .modal-head { align-items: start; flex-direction: column; }
  .modal-actions { justify-content: space-between; width: 100%; }
  .table-scroll { display: none; }
  .card-list { display: grid; }
  .movements-section .table-scroll { display: none; }
  .movement-card-list { display: grid; }
  .movements-table { min-width: 640px; }
}
