/* Dashboard Admin di Robin Hood: barra laterale scura, contenuto chiaro, riquadri bianchi. */
:root {
  --side: #14241B;
  --side-text: #B9C7BE;
  --side-active: #1F3A2A;
  --bg: #F3F5F4;
  --surface: #FFFFFF;
  --ink: #16211B;
  --muted: #5F6B64;
  --line: #E2E6E3;
  --primary: #1F6B3A;
  --primary-dark: #164F2B;
  --primary-tint: #E4F0E8;
  --warn: #9A6200;
  --warn-tint: #FBF0D9;
  --danger: #B3122E;
  --danger-tint: #FBE6EA;
  --shadow: 0 1px 2px rgba(20, 36, 27, .06), 0 1px 8px rgba(20, 36, 27, .04);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 'Inter', system-ui, sans-serif; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* ---- Struttura ---- */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100%; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-size: 17px; font-weight: 700; }
.brand span { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--side-text); }
.side h3 { margin: 16px 10px 6px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: #7E9085; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border-radius: 8px; color: var(--side-text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a[aria-current=page] { background: var(--side-active); color: #fff; }
.badge { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: #E0A83A; color: #2A1C00; font-size: 12px; font-weight: 700; text-align: center; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.top h1 { flex: 1; font-size: 18px; }
.btn.menu-btn { display: none; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 18px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 5; transform: translateX(-100%); transition: transform .2s; }
  .layout.open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .4); }
  .btn.menu-btn { display: inline-flex; }
  .top { padding: 12px 16px; }
  .content { padding: 16px; }
}

/* ---- Componenti ---- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { flex: 1; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.two { grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
a.kpi { text-decoration: none; color: inherit; }
a.kpi:hover { border-color: var(--primary); }

.todo { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: 10px; background: var(--warn-tint); color: #4A3000; font-weight: 500; text-decoration: none; }
.todo b { font-size: 16px; }
.todo span:last-child { margin-left: auto; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg); }
.btn.danger { background: transparent; color: var(--danger); border-color: #E7B5BF; }
.btn.danger:hover { background: var(--danger-tint); }
.btn.sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: default; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input[type=text], input[type=search], select, textarea {
  min-height: 36px; padding: 6px 10px; background: var(--surface); border: 1px solid #CBD2CD; border-radius: 8px; min-width: 0;
}
textarea { min-height: 72px; resize: vertical; }
.search { width: 240px; max-width: 100%; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; font-size: 13px; cursor: pointer; }
.chip[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: #fff; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 12px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #FAFBFA; }
td.right, th.right { text-align: right; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.who b { display: block; font-weight: 600; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #ECEFED; color: var(--muted); }
.pill.good { background: var(--primary-tint); color: var(--primary-dark); }
.pill.warn { background: var(--warn-tint); color: var(--warn); }
.pill.bad { background: var(--danger-tint); color: var(--danger); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.err { color: var(--danger); font-weight: 600; font-size: 13px; }
.err:empty { display: none; }

/* ---- Finestra di dialogo e avvisi ---- */
.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(20, 36, 27, .45); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; overflow-y: auto; }
.dialog { width: 100%; max-width: 520px; background: var(--surface); border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.dialog.wide { max-width: 760px; }
.dialog header { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dialog header h2 { flex: 1; font-size: 16px; }
.dialog .body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.dialog footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.x { border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 20; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); }
.toast.bad { background: var(--danger); }
.timeline { margin: 0; padding: 0; list-style: none; max-height: 280px; overflow-y: auto; font-size: 13px; }
.timeline li { display: grid; grid-template-columns: 76px 130px 1fr; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline code { overflow-wrap: anywhere; color: var(--muted); font-size: 12px; }

/* ---- Grafici ---- */
.chart { position: relative; padding: 14px 20px 18px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .bar { fill: var(--primary); }
.chart .hit { fill: transparent; }
.chart .hit:hover + .bar, .chart .bar.on { fill: var(--primary-dark); }
.tip { position: absolute; pointer-events: none; padding: 6px 10px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 12.5px; white-space: nowrap; transform: translate(-50%, -100%); }
.tip b { font-variant-numeric: tabular-nums; }
details.table-view { padding: 0 20px 16px; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 12.5px; font-weight: 600; }
details.table-view table { margin-top: 8px; }
details.table-view td, details.table-view th { padding: 4px 8px 4px 0; border: 0; }

/* ---- Accesso ---- */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login .card { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.match { font-size: 56px; font-weight: 700; letter-spacing: .08em; font-variant-numeric: tabular-nums; }
.settings-row { display: grid; grid-template-columns: 1fr minmax(160px, 240px) auto; gap: 16px; align-items: center; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: 0; }
.settings-row .unit { display: flex; align-items: center; gap: 8px; }
.settings-row input[type=text] { width: 100%; }
@media (max-width: 700px) { .settings-row { grid-template-columns: 1fr; } }
