:root {
  --bg: #f5f4ee;
  --surface: #ffffff;
  --text: #2c2c2a;
  --text-muted: #5f5e5a;
  --border: #d3d1c7;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --success: #0f6e56;
  --warning: #854f0b;
  --danger: #a32d2d;
  --radius: 8px;
  --radius-lg: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  margin-bottom: 1.5rem;
}
.topbar .container { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; font-weight: 500; margin: 0; }
.status { font-size: 13px; color: var(--text-muted); }

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.tab {
  font: inherit;
  font-weight: 500;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.55rem 1rem;
  margin-bottom: -1px;
  cursor: pointer;
  border-radius: 0;
}
.tab:hover { color: var(--text); background: transparent; opacity: 1; }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card h2 { font-size: 17px; font-weight: 500; margin: 0 0 1rem; }
.card h3 { font-size: 15px; font-weight: 500; margin: 0 0 0.5rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.9rem 1rem;
  margin-bottom: 1rem;
}
label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 13px; color: var(--text-muted); }
label > span { font-weight: 500; color: var(--text); }
label > small { color: var(--text-muted); font-size: 11px; }

input[type="number"], select {
  font: inherit;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.actions { display: flex; gap: 0.75rem; }
button {
  font: inherit;
  font-weight: 500;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { opacity: 0.9; }
button.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.hidden { display: none !important; }

.riepilogo-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}
.riepilogo-row > div { display: flex; flex-direction: column; gap: 2px; }
.riepilogo-row .muted { font-size: 12px; color: var(--text-muted); }
.riepilogo-row strong { font-size: 22px; font-weight: 500; }

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

#risultati { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.5rem; }

.offerta {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.1rem;
  display: grid;
  grid-template-columns: 40px 1fr auto auto;
  gap: 0.75rem 1rem;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s;
}
.offerta:hover { border-color: var(--accent); }
.offerta .rank { font-weight: 500; font-size: 16px; color: var(--text-muted); text-align: center; }
.offerta .rank.top1 { color: var(--success); }
.offerta .titolo { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.offerta .titolo .nome { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offerta .titolo .meta { font-size: 12px; color: var(--text-muted); display: flex; gap: 0.5rem; flex-wrap: wrap; }
.offerta .badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-muted);
}
.offerta .badge.fixed { background: var(--accent-bg); color: var(--accent); }
.offerta .badge.variable { background: #faeeda; color: var(--warning); }
.offerta .spesa { text-align: right; }
.offerta .spesa .valore { font-size: 20px; font-weight: 500; }
.offerta .spesa .label { font-size: 11px; color: var(--text-muted); }
.offerta .arrow { color: var(--text-muted); }

@media (max-width: 600px) {
  .offerta { grid-template-columns: 30px 1fr auto; }
  .offerta .arrow { display: none; }
}

.note p { font-size: 13px; color: var(--text); margin: 0.5rem 0; }
.note p.muted { color: var(--text-muted); }

#dettaglio { position: relative; }
#dettaglio .close {
  position: absolute; top: 0.75rem; right: 0.75rem;
  background: transparent; color: var(--text-muted); border: none;
  font-size: 22px; cursor: pointer; padding: 0 0.35rem;
}
#dettaglio h2 { margin-top: 0; }
.dett-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin: 1rem 0;
}
@media (max-width: 700px) { .dett-grid { grid-template-columns: 1fr; } }
.dett-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.dett-table td { padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.dett-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.dett-table tr.totale td { font-weight: 500; border-bottom: 2px solid var(--text); padding-top: 0.6rem; }
.dett-componenti li { font-size: 13px; padding: 0.25rem 0; }

.scheda-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent);
  padding-bottom: 1px;
}
.scheda-link:hover { background: var(--accent-bg); }

.scheda-h4 { font-size: 13px; font-weight: 500; margin: 1rem 0 0.4rem; color: var(--text-muted); }
.scheda-table { margin-bottom: 0.75rem; font-size: 13px; }
.scheda-table th { text-align: left; font-weight: 500; color: var(--text-muted); padding: 0.3rem 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.scheda-desc { font-size: 12px; margin-top: 0.25rem; }
.scheda-table-wrap { overflow-x: auto; margin-bottom: 0.75rem; }
.scheda-matrice { min-width: 540px; font-variant-numeric: tabular-nums; }
.scheda-matrice th, .scheda-matrice td { padding: 0.35rem 0.6rem; }
.scheda-matrice th + th, .scheda-matrice td + td { text-align: right; }
.scheda-matrice tbody tr:hover { background: var(--bg); }
.dett-actions { display: flex; gap: 0.5rem; margin-top: 1rem; flex-wrap: wrap; }
.dett-actions a {
  text-decoration: none; color: var(--accent); padding: 0.4rem 0.8rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; font-weight: 500;
}
.dett-actions a:hover { background: var(--accent-bg); border-color: var(--accent); }

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}
.loading { padding: 1rem; text-align: center; color: var(--text-muted); }
