/* ============ Design system ============ */
:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --ink: #0f172a;          /* testo principale (alto contrasto) */
  --ink-2: #475569;        /* testo secondario */
  --muted: #94a3b8;
  --line: #e2e8f0;
  --line-2: #cbd5e1;
  --primary: #4f46e5;      /* indaco */
  --primary-d: #4338ca;
  --primary-soft: #eef2ff;
  --green: #059669;        /* netto / finale */
  --green-d: #047857;
  --green-soft: #ecfdf5;
  --green-soft-2: #d1fae5;
  --blue: #2563eb;         /* €/m */
  --amber: #b45309;        /* aumento */
  --red: #dc2626;          /* limitazioni */
  --head: #1e293b;         /* header tabella scuro */
  --head-2: #334155;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.05);
  --shadow: 0 1px 2px rgba(15,23,42,.04), 0 10px 30px rgba(15,23,42,.08);
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  margin: 0; padding: 0 26px 60px; color: var(--ink);
  background:
    radial-gradient(1100px 380px at 85% -140px, #e3e8fb 0%, transparent 62%),
    radial-gradient(900px 320px at 0% -120px, #e6f7ef 0%, transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}

/* ============ Header (barra brand + utente) ============ */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 14px 0 12px; padding: 12px 20px 12px 22px;
  background: linear-gradient(180deg, #ffffff, #fbfcff);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.app-header::before {                    /* stripe-accento a sinistra */
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px;
  background: linear-gradient(180deg, var(--primary), var(--green));
}
.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-div { width: 1px; height: 34px; background: var(--line); flex-shrink: 0; }
.brand-title { min-width: 0; }
.apptitle { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em;
  color: var(--ink); line-height: 1.15; white-space: nowrap; }
.apptitle-sub { margin: 2px 0 0; font-size: 12px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* chip utente */
.userchip { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), var(--green)); color: #fff;
  font-weight: 800; font-size: 14px; box-shadow: 0 3px 8px rgba(79,70,229,.35); flex-shrink: 0; }
.uname { font-weight: 700; color: var(--ink); font-size: 13.5px; }
.userchip .logout { color: var(--ink-2); text-decoration: none; font-weight: 700; font-size: 12.5px;
  padding: 6px 14px; border: 1px solid var(--line-2); border-radius: 999px; background: #fff; transition: .15s; }
.userchip .logout:hover { background: #fff5f5; border-color: #fca5a5; color: var(--red); }

/* ============ Coverage / limitazioni ============ */
.stato { margin: 8px 0 0; font-size: 12px; }
.stato > summary {
  cursor: pointer; color: var(--ink-2); padding: 7px 13px; border-radius: 999px;
  background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  display: inline-block; list-style: none; font-weight: 600; transition: .15s;
}
.stato > summary:hover { border-color: var(--line-2); color: var(--ink); }
.stato > summary::-webkit-details-marker { display: none; }
.stato > summary b { color: var(--primary-d); }
.stato-body {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 18px; max-width: 780px; margin-top: 10px; box-shadow: var(--shadow-sm);
}
.stato-body p { margin: 8px 0 5px; color: var(--ink); font-weight: 700; font-size: 12.5px; }
.stato-body ul { margin: 0 0 10px; padding-left: 0; list-style: none; }
.stato-body .campi li {
  display: inline-flex; gap: 6px; margin: 3px 8px 3px 0; padding: 3px 9px;
  background: var(--green-soft); border-radius: 999px; align-items: center;
}
.stato-body .campi b { color: var(--green-d); }
.stato-body .limiti li {
  position: relative; padding-left: 18px; margin: 4px 0; color: var(--ink-2); line-height: 1.4;
}
.stato-body .limiti li::before {
  content: ""; position: absolute; left: 4px; top: 8px; width: 6px; height: 6px;
  border-radius: 50%; background: var(--red);
}

/* ============ Barre filtri ============ */
.bar {
  display: flex; flex-wrap: wrap; gap: 11px 14px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 16px; margin: 8px 0; box-shadow: var(--shadow);
}
.bar.filtri { background: linear-gradient(180deg, #fff, #fbfcfe); }
.field { display: flex; flex-direction: column; gap: 5px; position: relative; }
.field.grow { flex: 1 1 240px; }
.field.autocomplete { min-width: 260px; }
label { font-size: 11.5px; color: var(--ink-2); font-weight: 700; letter-spacing: .01em; }
select, input {
  padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 10px;
  font-size: 14px; background: #fff; min-width: 150px; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 32px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.field.grow input { width: 100%; }
input::placeholder { color: var(--muted); }
input:hover, select:hover { border-color: var(--line-2); }
input:focus, select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.18);
}
#reset {
  padding: 10px 18px; border: 1px solid var(--line-2); border-radius: 10px;
  background: #fff; color: var(--ink-2); font-size: 13px; font-weight: 600;
  cursor: pointer; height: 40px; transition: .15s;
}
#reset:hover { background: #fff5f5; border-color: #fca5a5; color: var(--red); }

/* ============ Autocomplete socio ============ */
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  margin: 6px 0 0; padding: 6px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 34px rgba(15,23,42,.16); max-height: 340px; overflow-y: auto;
}
.ac-list li { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; border-radius: 8px; }
.ac-list li[data-num] { cursor: pointer; }
.ac-list li[data-num]:hover, .ac-list li[data-num].active { background: var(--primary-soft); }
.ac-list .prov { font-size: 11px; color: var(--muted); }
.ac-list li.hint { color: var(--muted); font-size: 12px; font-style: italic; }

/* ============ Meta ============ */
.meta { color: var(--ink-2); font-size: 13px; margin: 4px 2px 8px; min-height: 16px; font-weight: 500; }
.meta b { color: var(--ink); }

/* ============ Tabella ============ */
.table-wrap {
  overflow: auto; max-height: calc(100vh - 300px);   /* raffinata via JS (fitTable) */
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* ============ Scrollbar custom (moderna, sottile) ============ */
* { scrollbar-width: thin; scrollbar-color: #b9c2d6 transparent; }   /* Firefox */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #c2cbdd; border-radius: 10px;
  border: 3px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: #97a3bd; background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1060px; }

thead th {
  position: sticky; z-index: 4;                       /* header sticky su scroll verticale */
  background: var(--head); color: #cbd5e1; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; padding: 12px 11px;
  text-align: left; white-space: nowrap; border-bottom: 1px solid var(--head-2);
  vertical-align: middle; box-shadow: 0 6px 10px -9px rgba(15,23,42,.5);
}
thead tr:first-child th { top: 0; }
thead tr:nth-child(2) th { top: var(--h1, 40px); }     /* --h1 = altezza riga 1 (via JS) */
th.sortable { cursor: pointer; user-select: none; transition: background .12s, color .12s; }
th.sortable:hover { background: var(--head-2); color: #fff; }
th.sort-asc, th.sort-desc { color: #a5b4fc; }
th.sort-asc::after { content: " ▲"; font-size: 9px; }
th.sort-desc::after { content: " ▼"; font-size: 9px; }
th.group {
  text-align: center; color: #6ee7b7; letter-spacing: .06em;
  border-left: 1px solid var(--head-2); border-right: 1px solid var(--head-2);
  background: #17233a;
}
th.sub { font-size: 10px; }

td {
  padding: 10px 11px; font-size: 13px; white-space: nowrap; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
td:first-child { font-weight: 700; }                               /* fornitore */
td:nth-child(3) { white-space: normal; min-width: 230px; color: var(--ink-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; color: var(--green-d); }
.ml { color: var(--blue); font-weight: 600; }
.au { color: var(--amber); font-size: 11px; font-weight: 700; }

tbody tr:nth-child(even) { background: #f8fafc; }
tbody tr:hover { background: var(--primary-soft); }

/* gruppo "Finale per peso" — blocco verde ad alto contrasto */
td.fin {
  border-left: 1px solid var(--line); background: var(--green-soft);
  color: var(--green-d); font-weight: 700; line-height: 1.2; font-size: 16.5px;
}
tbody tr:hover td.fin { background: var(--green-soft-2); }
/* cella "più conveniente" (finale minimo): bordo intero colorato */
td.fin.best {
  background: var(--green-soft-2); font-weight: 800;
  box-shadow: inset 0 0 0 2px var(--green); border-radius: 7px;
}
.fin .pw {                               /* sotto-riga: peso · premio% */
  display: block; font-size: 10px; color: var(--muted); font-weight: 500;
  font-variant-numeric: normal; margin-top: 1px;
}
.fin .pw em { font-style: normal; font-size: 13px; font-weight: 700; color: var(--ink-2); }  /* peso */
.fin .pw i { font-style: normal; color: #cbd5e1; margin: 0 3px; }
.fin .pw b { font-weight: 600; color: var(--ink-2); }   /* premio */

/* Download listino */
td.dl a {
  color: var(--primary-d); text-decoration: none; font-weight: 700; font-size: 12px;
  border: 1px solid #c7d2fe; border-radius: 8px; padding: 3px 9px; background: var(--primary-soft);
  transition: .15s; display: inline-block;
}
td.dl a:hover { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============ Login ============ */
.login-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  padding: 24px; position: relative; overflow: hidden; }
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 360px; margin: auto 0; background: var(--surface);
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  padding: 26px 26px 28px; display: flex; flex-direction: column; gap: 5px;
}
.login-logos { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 0 0 14px; }
.login-logos .logo { height: 30px; width: auto; display: block; }
.login-logos .sep { width: 1px; height: 26px; background: var(--line-2); }

/* sfondo dinamico: orbs colorati sfocati in lento movimento (brand DEC/Reterea) */
.orbs { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.orbs span { position: absolute; border-radius: 50%; filter: blur(70px); will-change: transform; }
.orbs span:nth-child(1) { width: 460px; height: 460px; left: -130px; top: -120px;
  background: #6366f1; opacity: .5; animation: orb 17s ease-in-out infinite; }
.orbs span:nth-child(2) { width: 540px; height: 540px; right: -160px; bottom: -170px;
  background: #0d9488; opacity: .48; animation: orb 23s ease-in-out infinite reverse; }
.orbs span:nth-child(3) { width: 380px; height: 380px; left: 42%; top: 48%;
  background: #dc2626; opacity: .24; animation: orb 29s ease-in-out infinite; }
@keyframes orb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%      { transform: translate(70px, -50px) scale(1.14); }
  66%      { transform: translate(-55px, 45px) scale(.94); }
}
@media (prefers-reduced-motion: reduce) { .orbs span { animation: none; } }
.login-brand { display: flex; align-items: center; gap: 10px; font-size: 18px;
  font-weight: 800; letter-spacing: -.01em; color: var(--ink); }
.login-mark { width: 9px; height: 22px; border-radius: 4px;
  background: linear-gradient(180deg, var(--primary), var(--green)); }
.login-sub { margin: 2px 0 14px; color: var(--ink-2); font-size: 13px; }
.login-card label { margin-top: 8px; }
.login-card input { min-width: 0; width: 100%; }
.login-btn { margin-top: 18px; padding: 11px 16px; border: none; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 14px; font-weight: 700; cursor: pointer;
  transition: background .15s; }
.login-btn:hover { background: var(--primary-d); }
.login-error { margin: 6px 0 2px; padding: 9px 12px; border-radius: 9px; font-size: 13px;
  background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

/* barra utente / logout */
.logos { display: flex; align-items: center; gap: 14px; }
.logos .logo { height: 30px; width: auto; display: block; }
.logos .sep { width: 1px; height: 24px; background: var(--line); }

/* ============ Footer ============ */
.site-footer {
  position: relative; z-index: 1; margin: 10px 0 0; padding: 13px 20px;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--ink-2);
  background: linear-gradient(180deg, #ffffff, #fbfcff);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-sm); overflow: hidden;
}
.site-footer::before {                   /* linea-accento sfumata in alto */
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--green) 55%, var(--red));
}
.site-footer .foot-brand { font-weight: 800; color: var(--ink); letter-spacing: .03em; }
.site-footer .foot-brand .x { color: var(--primary); margin: 0 4px; font-weight: 900; }
.site-footer .foot-sep { color: var(--line-2); }
.site-footer .foot-copy { color: var(--muted); }

@media (max-width: 720px) {
  body { padding: 0 14px 48px; }
  .app-header { padding: 12px 14px; gap: 10px; }
  .brand-div, .apptitle-sub, .uname { display: none; }
  .apptitle { font-size: 16px; }
}
