:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --ink: #1f2a37;
  --muted: #667085;
  --line: #e4e7ec;
  --accent: #0d7d73;
  --accent-scuro: #0a5f57;
  --rosso: #b42318;
  --rosso-bg: #fee4e2;
  --ambra: #b54708;
  --ambra-bg: #fef0c7;
  --verde: #067647;
  --verde-bg: #dcfae6;
  --viola: #5925dc;
  --viola-bg: #ece9fe;
  --grigio: #475467;
  --grigio-bg: #f2f4f7;
  --radius: 10px;
  --ombra: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  background: #1f2a37;
  color: #cdd5df;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
  margin-bottom: 4px;
}

.brand .mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #14b8a6);
  display: grid; place-items: center; color: #fff; font-size: 16px;
}

.brand small { display: block; font-weight: 400; font-size: 11px; color: #8a97a8; letter-spacing: .4px; text-transform: uppercase; }

.nav { margin-top: 26px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  color: #cdd5df; padding: 9px 12px; border-radius: 8px;
  display: flex; align-items: center; gap: 10px; font-weight: 500;
}
.nav a:hover { background: #2b3849; text-decoration: none; color: #fff; }
.nav a.attivo { background: var(--accent); color: #fff; }
.nav .sezione { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #6b7787; margin: 18px 0 6px 12px; }

.main { flex: 1; min-width: 0; }

.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 650; }

.content { padding: 28px; max-width: 100%; }

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--accent); color: #fff; border: none;
  padding: 9px 15px; border-radius: 8px; font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.btn:hover { background: var(--accent-scuro); text-decoration: none; }
.btn.ghost { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--grigio-bg); }
.btn.pericolo { background: #fff; color: var(--rosso); border: 1px solid #f4c9c4; }
.btn.pericolo:hover { background: var(--rosso-bg); }
.btn.piccolo { padding: 6px 11px; font-size: 12px; }

.riepilogo-scadenze { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 20px; }
.riepilogo { border-radius: var(--radius); padding: 20px; display: flex; align-items: baseline; gap: 12px; }
.riepilogo .numero { font-size: 34px; font-weight: 750; letter-spacing: -.5px; }
.riepilogo .etichetta { font-size: 13px; font-weight: 600; }
.riepilogo.rosso { background: var(--rosso-bg); }
.riepilogo.rosso .numero, .riepilogo.rosso .etichetta { color: var(--rosso); }
.riepilogo.ambra { background: var(--ambra-bg); }
.riepilogo.ambra .numero, .riepilogo.ambra .etichetta { color: var(--ambra); }

.sezione-titolo { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin: 26px 0 12px; padding-bottom: 6px; border-bottom: 2px solid; }
.sezione-titolo.rosso { color: var(--rosso); border-color: var(--rosso); }
.sezione-titolo.ambra { color: var(--ambra); border-color: var(--ambra); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--ombra);
}
.kpi .valore { font-size: 30px; font-weight: 720; letter-spacing: -.5px; }
.kpi .etichetta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.kpi .valore.rosso { color: var(--rosso); }
.kpi .valore.ambra { color: var(--ambra); }
.kpi .nota { font-size: 12px; margin-top: 6px; }
.kpi .nota.ambra { color: var(--ambra); }
.kpi .nota.rosso { color: var(--rosso); }
.kpi .nota.muted { color: var(--muted); }

.barra-riga { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.barra-riga:last-child { margin-bottom: 0; }
.barra-etichetta { width: 170px; font-size: 12px; color: var(--grigio); flex-shrink: 0; }
.barra-track { flex: 1; background: var(--grigio-bg); border-radius: 6px; height: 10px; overflow: hidden; }
.barra-fill { height: 100%; background: var(--accent); border-radius: 6px; }
.barra-valore { width: 150px; text-align: right; font-size: 12px; font-weight: 600; flex-shrink: 0; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--ombra); margin-bottom: 20px; overflow: hidden;
}
.card-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.card-head h2 { font-size: 15px; margin: 0; font-weight: 640; }
.card-head .conta { background: var(--grigio-bg); color: var(--grigio); border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.card-body { padding: 4px 0; }
.card-vuoto { padding: 26px 18px; color: var(--muted); text-align: center; }

table { width: 100%; border-collapse: collapse; }
.tabella-scroll { overflow-x: auto; }
.storico-scroll { max-height: 400px; overflow-y: auto; }
.storico-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600; padding: 10px 18px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.targa {
  font-family: "SF Mono", "Roboto Mono", monospace; font-weight: 700; letter-spacing: .5px;
  background: var(--ink); color: #fff; padding: 3px 8px; border-radius: 5px; font-size: 12px; white-space: nowrap;
}

.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.scaduta, .badge.critica, .badge.assente { color: var(--rosso); background: var(--rosso-bg); }
.badge.attenzione { color: var(--ambra); background: var(--ambra-bg); }
.badge.valida, .badge.completata { color: var(--verde); background: var(--verde-bg); }
.badge.sospesa { color: var(--viola); background: var(--viola-bg); }
.badge.disdetta { color: var(--grigio); background: var(--grigio-bg); }

.pill { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 6px; background: var(--grigio-bg); color: var(--grigio); white-space: nowrap; }
.pill.uso { background: var(--verde-bg); color: var(--verde); }
.pill.permuta { background: var(--viola-bg); color: var(--viola); }
.pill.venduto, .pill.dismesso { background: var(--grigio-bg); color: var(--grigio); }

.filtri { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.filtri input, .filtri select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
  font-family: inherit; background: #fff; color: var(--ink);
}
.filtri input[type=search] { min-width: 240px; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.campo { display: flex; flex-direction: column; gap: 5px; }
.campo.full { grid-column: 1 / -1; }
.campo label { font-size: 12px; font-weight: 600; color: var(--grigio); }
.campo input, .campo select, .campo textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
  font-family: inherit; background: #fff; color: var(--ink);
}
.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
.campo textarea { resize: vertical; min-height: 60px; }
.form-azioni { display: flex; gap: 10px; margin-top: 22px; }

.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-weight: 500; }
.flash.ok { background: var(--verde-bg); color: var(--verde); }
.flash.errore { background: var(--rosso-bg); color: var(--rosso); }
.flash.errore.ambra { background: var(--ambra-bg); color: var(--ambra); }

.dettaglio-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 16px; flex-wrap: wrap; }
.dettaglio-titolo { display: flex; align-items: center; gap: 14px; }
.dettaglio-titolo h1 { margin: 0; font-size: 22px; }
.meta { display: flex; gap: 26px; flex-wrap: wrap; margin: 14px 0 4px; }
.meta div { font-size: 13px; }
.meta .etichetta { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px; }
.meta .valore { font-weight: 600; }

.riga-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; align-items: end; padding: 14px 18px; background: #fafbfc; }
.riga-form .campo { gap: 4px; }
.riga-form label { font-size: 11px; }
.riga-form input, .riga-form select { padding: 7px 9px; font-size: 13px; }

.inline-form { display: inline; }
.azioni-riga { display: flex; align-items: center; justify-content: flex-end; gap: 6px; flex-wrap: nowrap; }
.select-azione { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; font-size: 12px; max-width: 130px; }
.giorni { font-weight: 600; }
.giorni.neg { color: var(--rosso); }
.muted { color: var(--muted); }
.destra { text-align: right; }
.nowrap { white-space: nowrap; }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -232px; transition: left .2s; z-index: 20; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .sidebar.aperta { left: 0; }
  .menu-toggle { display: inline-flex !important; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .riepilogo-scadenze { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 18px; }
  .topbar { padding: 0 16px; }
}
.menu-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--ink); }

.pagina-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.pagina-login .card { width: 100%; max-width: 360px; }
