:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #5b5a56;
  --faint: #8a8984;
  --line: #e4e2dc;
  --hover: #f0eee9;
  --accent: #c4613f;
  --danger: #c43b3b;
  --ok: #1d7f4e;
  /* palette di riferimento per grafici (superficie chiara) */
  --chart-1: #2a78d6;
  --chart-2: #eb6834;
  --chart-grid: #ebeae6;
  --chart-base: #c9c7c0;
  --chart-axis: #6b6a66;
  --chart-text: #2b2a28;
  --chart-surface: #ffffff;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #181b21;
    --text: #e8e9ec;
    --muted: #a3a8b3;
    --faint: #737a87;
    --line: #2a2f38;
    --hover: #20242c;
    --accent: #e07c57;
    --danger: #e66767;
    --ok: #4cc38a;
    --chart-1: #3987e5;
    --chart-2: #d95926;
    --chart-grid: #252a33;
    --chart-base: #3a404c;
    --chart-axis: #8a919e;
    --chart-text: #d6d9df;
    --chart-surface: #181b21;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
}
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
h2 { font-size: 14px; margin: 0 0 12px; font-weight: 600; }
.mt { margin-top: 22px; }

.btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  cursor: pointer;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--hover); }
input, select {
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

/* intestazione */
.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.top-nav { display: flex; gap: 4px; }
.tab-btn { height: 32px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.tab-btn:hover { background: var(--hover); color: var(--text); }
.tab-btn.on { background: var(--hover); color: var(--text); font-weight: 600; }
.top-user { margin-left: auto; display: flex; align-items: center; gap: 6px; }

main { max-width: 1240px; margin: 0 auto; padding: 20px 24px 48px; }

/* filtri: una sola riga sopra i grafici */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { height: 32px; padding: 0 11px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button:hover { background: var(--hover); color: var(--text); }
.seg button.on { background: var(--hover); color: var(--text); font-weight: 600; }
.custom { display: inline-flex; align-items: center; gap: 6px; }
.custom[hidden] { display: none; }
#f-user, #f-project { max-width: 220px; }
.scope { margin: 12px 0 0; color: var(--muted); }

/* riquadri */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
@media (max-width: 1000px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.tile .l { color: var(--muted); font-size: 12.5px; }
.tile .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--faint); font-size: 12px; margin-top: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-top: 14px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 14px; }
.grid2 > .card { margin-top: 14px; }
.chart-box { min-height: 240px; }
.note { color: var(--faint); font-size: 12px; margin-top: 18px; line-height: 1.6; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* grafici */
.chart { position: relative; }
.chart svg { display: block; overflow: visible; }
.c-grid { stroke: var(--chart-grid); stroke-width: 1; }
.c-base { stroke: var(--chart-base); stroke-width: 1; }
.c-axis { fill: var(--chart-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-label { fill: var(--chart-text); font-size: 11.5px; font-weight: 600; }
.c-bar { fill: var(--chart-1); }
.c-hit { fill: transparent; }
.c-hit.on { fill: color-mix(in srgb, var(--chart-text) 5%, transparent); }
.chart-tip {
  position: absolute; z-index: 5; pointer-events: none;
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px;
  background: var(--surface); color: var(--text); font-size: 12.5px; line-height: 1.5; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .12);
}
.chart-tip[hidden] { display: none; }
.hbars { display: flex; flex-direction: column; gap: 3px; }
.hb-row { display: grid; grid-template-columns: minmax(110px, 32%) 1fr auto; grid-template-rows: auto auto; column-gap: 10px; align-items: center; padding: 4px 6px; border-radius: 6px; }
.hb-row.clickable { cursor: pointer; }
.hb-row.clickable:hover { background: var(--hover); }
.hb-label { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.hb-track { height: 8px; }
.hb-fill { display: block; height: 100%; background: var(--chart-1); border-radius: 0 4px 4px 0; }
.hb-value { text-align: right; font-variant-numeric: tabular-nums; }
.hb-sub { grid-column: 2 / 4; color: var(--faint); font-size: 11.5px; }

/* tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; }
.pill.warn { background: color-mix(in srgb, #fab219 22%, transparent); color: var(--text); }
.pill.ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }

.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.notice { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--ok) 12%, transparent); }
.error { color: var(--danger); margin: 6px 0; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px 22px; background: var(--surface); color: var(--text); width: 380px; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog label, .login-card label { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; color: var(--muted); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* login */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 340px; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px 26px 22px; }
.login-card .brand { font-size: 17px; }
.login-card .btn { width: 100%; height: 38px; margin-top: 8px; }

@media (max-width: 700px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
}
