:root {
  --accent: #1f4e79;
  --accent-light: #2e6da4;
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #24292f;
  --muted: #6a737d;
  --good: #1a7f37;
  --bad: #c62828;
  --border: #d9dee4;
  --content-width: 960px; /* larghezza massima pagina = larghezza dei grafici */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}

header h1 { font-size: 1.15rem; margin: 0; font-weight: 600; }
header h1 span { font-weight: 300; opacity: 0.85; margin-left: 0.4rem; }

.header-controls { display: flex; align-items: center; gap: 0.6rem; }
.header-controls label { font-size: 0.85rem; opacity: 0.9; }

select, input[type="text"], input[type="file"] {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

button {
  font: inherit;
  padding: 0.42rem 0.9rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: filter 0.15s;
}
button:hover { filter: brightness(1.08); }
button.primary { background: #ff9800; color: #fff; font-weight: 600; }
button.secondary { background: rgba(255, 255, 255, 0.16); color: #fff; border: 1px solid rgba(255,255,255,0.4); }
.modal button.secondary { background: #eef1f4; color: var(--text); border: 1px solid var(--border); }

nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem;
  padding: 0.5rem 1.2rem 0;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 52px;
  z-index: 10;
}

nav button {
  background: transparent;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  padding: 0.5rem 0.85rem;
  font-size: 0.9rem;
}
nav button.active {
  color: var(--accent);
  font-weight: 600;
  border-bottom: 3px solid var(--accent);
}

main { padding: 1.2rem 1.4rem 3rem; max-width: var(--content-width); margin: 0 auto; }

.empty-state {
  text-align: center;
  margin-top: 4rem;
  color: var(--muted);
}

h2.section { font-size: 1rem; color: var(--accent); margin: 1.6rem 0 0.6rem; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.8rem;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.kpi-card .label { font-size: 0.78rem; color: var(--muted); }
.kpi-card .value { font-size: 1.45rem; font-weight: 700; }
.kpi-card .value.nd { color: var(--muted); font-weight: 400; }
.kpi-card .vars { display: flex; gap: 0.7rem; font-size: 0.75rem; align-items: center; }
.kpi-card .var.good { color: var(--good); }
.kpi-card .var.bad { color: var(--bad); }
.kpi-card .var.neutral { color: var(--muted); }
.kpi-card svg { margin-top: 0.2rem; }

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem;
  margin-top: 0.8rem;
}

.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem;
}
table.data th, table.data td {
  text-align: left;
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.data th { background: #eef2f6; color: var(--accent); font-weight: 600; white-space: nowrap; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data a { color: var(--accent-light); text-decoration: none; }
table.data a:hover { text-decoration: underline; }
td.txt { max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.note {
  background: #fff8e6;
  border: 1px solid #f0dfa8;
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  color: #6d5900;
  margin-top: 0.9rem;
}

.grid-2 { display: flex; flex-wrap: wrap; gap: 1rem; }
.grid-2 > div { flex: 1 1 320px; min-width: 0; }

.stack-col { display: flex; flex-direction: column; gap: 1rem; }

/* --- modale ------------------------------------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 50, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem;
  z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--card);
  border-radius: 12px;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.2rem 0;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; color: var(--accent); }
.modal-header .close { background: transparent; font-size: 1.5rem; color: var(--muted); padding: 0 0.4rem; }
.modal-body { padding: 0.9rem 1.2rem 1.2rem; display: flex; flex-direction: column; gap: 0.7rem; }
.modal-body label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.88rem; font-weight: 600; }
.modal-body .row { display: flex; gap: 1rem; }
.modal-body .row label { flex: 1; }
.hint { font-size: 0.78rem; color: var(--muted); margin: 0; }
.error { color: var(--bad); font-size: 0.85rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.4rem; }

.preview-block h4 { margin: 0.8rem 0 0.3rem; font-size: 0.9rem; color: var(--accent); }
.preview-list { margin: 0; padding-left: 1.2rem; font-size: 0.82rem; }
.preview-list.warn li { color: #9a6700; }
.preview-list.unparsed li { color: var(--bad); }
.badge { display: inline-block; background: #eef2f6; border-radius: 20px; padding: 0.1rem 0.6rem; font-size: 0.78rem; margin-right: 0.4rem; }
.badge-accent { background: var(--accent); color: #fff; }

/* ---------- account / utenti ---------- */
.user-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: 0.6rem;
  padding-left: 0.8rem;
  border-left: 1px solid rgba(255, 255, 255, 0.35);
}
.user-email {
  font-size: 0.82rem;
  opacity: 0.9;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.modal .sep { border: none; border-top: 1px solid var(--border); margin: 0.4rem 0; }
.modal-body h3 { margin: 0; font-size: 0.95rem; color: var(--accent); }
.users-list { display: flex; flex-direction: column; gap: 0.4rem; }
.user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.user-row-main { font-size: 0.88rem; min-width: 0; }
.user-row-main b { margin-right: 0.4rem; }
.user-row-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
button.small { padding: 0.25rem 0.6rem; font-size: 0.8rem; }
.modal button.danger { color: var(--bad); border-color: var(--bad); }
.auth-msg { margin: 0; padding: 0.55rem 0.7rem; border-radius: 6px; font-size: 0.85rem; }
.auth-msg.ko { color: var(--bad); border: 1px solid var(--bad); background: #fff5f5; }
.auth-msg.ok { color: var(--good); border: 1px solid var(--good); background: #f3fbf5; }
.modal-body input[type="email"] {
  font: inherit;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}
