/* =====================================================================
   FARL - FdAiResearchLab: design system
   Sobrio e leggibile: token prima, componenti dopo.
   Gli elementi nativi (tabelle, moduli, pulsanti) sono già stilizzati, così ogni vista eredita la stessa qualità.
   ===================================================================== */

:root {
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --r-sm: 6px; --r-md: 10px; --r-lg: 16px; --r-pill: 999px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-base: .9375rem; --fs-md: 1.0625rem; --fs-lg: 1.375rem; --fs-xl: 1.875rem;
  --lh: 1.55;
  --ease: cubic-bezier(.2,.7,.2,1); --t-fast: 120ms; --t: 200ms;

  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #f0efeb; --surface-3: #e7e5df;
  --border: #e2e0da; --border-strong: #cfccc4;
  --text: #1b1b1a; --text-muted: #6b6963; --text-faint: #9a978f;
  --accent: #2f5d62; --accent-hover: #264d51; --accent-soft: #e3eceb; --accent-contrast: #ffffff;
  --success: #2e6b3f; --success-soft: #e3efe5;
  --warning: #8a5a0b; --warning-soft: #f6ecd8;
  --danger: #a13a2e; --danger-soft: #f6e2df;
  --info: #3b5b86; --info-soft: #e3e9f2;
  --focus: #2f5d62;
  --shadow-1: 0 1px 2px rgba(20,18,12,.06), 0 1px 1px rgba(20,18,12,.04);
  --shadow-2: 0 8px 24px rgba(20,18,12,.08), 0 2px 6px rgba(20,18,12,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141413; --surface: #1c1c1b; --surface-2: #232322; --surface-3: #2c2c2a;
    --border: #30302e; --border-strong: #42423f;
    --text: #ecebe7; --text-muted: #a3a19a; --text-faint: #75736d;
    --accent: #7fb0b3; --accent-hover: #93c0c3; --accent-soft: #1f3134; --accent-contrast: #0f1a1b;
    --success: #7fbf8f; --success-soft: #1d2d21; --warning: #d9aa5a; --warning-soft: #33291a;
    --danger: #e0877b; --danger-soft: #3a211d; --info: #8fb0da; --info-soft: #1f2836;
    --focus: #93c0c3;
    --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 8px 24px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141413; --surface: #1c1c1b; --surface-2: #232322; --surface-3: #2c2c2a;
  --border: #30302e; --border-strong: #42423f;
  --text: #ecebe7; --text-muted: #a3a19a; --text-faint: #75736d;
  --accent: #7fb0b3; --accent-hover: #93c0c3; --accent-soft: #1f3134; --accent-contrast: #0f1a1b;
  --success: #7fbf8f; --success-soft: #1d2d21; --warning: #d9aa5a; --warning-soft: #33291a;
  --danger: #e0877b; --danger-soft: #3a211d; --info: #8fb0da; --info-soft: #1f2836;
  --focus: #93c0c3;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4); --shadow-2: 0 8px 24px rgba(0,0,0,.45);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: var(--fs-base); line-height: var(--lh); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 var(--s3); font-weight: 600; letter-spacing: -.015em; }
h1 { font-size: 1.6rem; letter-spacing: -.025em; }
h2 { font-size: var(--fs-lg); margin-top: var(--s6); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--s4); }
a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--accent-hover); }
code, .mono { font-family: var(--font-mono); font-size: .9em; overflow-wrap: anywhere; }
pre { font-family: var(--font-mono); font-size: var(--fs-sm); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3) var(--s4); overflow-x: auto; }
pre.text { white-space: pre-wrap; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s5) 0; }
.note, .muted { color: var(--text-muted); font-size: var(--fs-sm); }
.skip-link { position: absolute; left: var(--s4); top: -100px; background: var(--surface); padding: var(--s2) var(--s3); border-radius: var(--r-sm); z-index: 100; box-shadow: var(--shadow-2); }
.skip-link:focus { top: var(--s3); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------- shell del laboratorio ---------- */
.lab-top { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: var(--s4); padding: 0 var(--s5); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: var(--s3); font-weight: 600; letter-spacing: -.01em; color: var(--text); text-decoration: none; }
.brand:hover { color: var(--text); }
.brand-mark { width: 22px; height: 22px; border: 2px solid currentColor; border-radius: 3px; position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; left: 3px; right: 3px; bottom: 3px; height: 45%; background: var(--accent); }
.brand .sub { font-weight: 400; color: var(--text-muted); font-size: var(--fs-sm); }
.top-tools { display: flex; align-items: center; gap: var(--s3); }
.who { color: var(--text-muted); font-size: var(--fs-sm); }
.lab-shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.lab-shell.no-sidebar { grid-template-columns: minmax(0, 1fr); }
.sidebar { border-right: 1px solid var(--border); background: var(--surface); padding: var(--s4) var(--s3); position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.nav-group { margin-bottom: var(--s3); }
.nav-group-title { font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--text-faint); padding: var(--s2) var(--s3) var(--s1); }
.nav-link { display: flex; align-items: center; gap: var(--s2); padding: 7px var(--s3); border-radius: var(--r-sm); color: var(--text-muted); text-decoration: none; font-size: var(--fs-sm); font-weight: 500; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.lab-main { padding: var(--s6) var(--s6) var(--s8); min-width: 0; max-width: 1240px; }
.site-footer { border-top: 1px solid var(--border); padding: var(--s4) var(--s5); color: var(--text-muted); font-size: var(--fs-xs); }
@media (max-width: 900px) {
  .lab-shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); display: flex; gap: var(--s2); overflow-x: auto; padding: var(--s2) var(--s3); }
  .nav-group { display: flex; gap: 2px; margin: 0; flex: none; }
  .nav-group-title { display: none; }
  .nav-link { white-space: nowrap; }
  .lab-main { padding: var(--s5) var(--s4) var(--s7); }
  .lab-top { padding: 0 var(--s3); }
  .brand .sub, .who { display: none; }
}

/* ---------- pulsanti ---------- */
button, .button, .btn {
  --btn-bg: var(--accent); --btn-fg: var(--accent-contrast); --btn-bd: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 34px; padding: 0 var(--s4); border-radius: var(--r-md); border: 1px solid var(--btn-bd);
  background: var(--btn-bg); color: var(--btn-fg); font: inherit; font-weight: 550; font-size: var(--fs-sm);
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
button:hover, .button:hover, .btn:hover { --btn-bg: var(--accent-hover); color: var(--btn-fg); }
button:active, .button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary, .button.secondary { --btn-bg: var(--surface); --btn-fg: var(--text); --btn-bd: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { --btn-bg: var(--surface-2); }
button.danger, .button.danger { --btn-bg: var(--surface); --btn-fg: var(--danger); --btn-bd: color-mix(in srgb, var(--danger) 45%, var(--border)); }
button.danger:hover, .button.danger:hover { --btn-bg: var(--danger-soft); }
button.link { --btn-bg: transparent; --btn-bd: transparent; --btn-fg: var(--accent); padding: 0; min-height: 0; }
button.link:hover { --btn-bg: transparent; text-decoration: underline; }
.icon-btn { --btn-bg: var(--surface); --btn-fg: var(--text-muted); --btn-bd: var(--border); width: 34px; padding: 0; border-radius: var(--r-pill); }
.icon-btn:hover { --btn-bg: var(--surface-2); --btn-fg: var(--text); }
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- moduli ---------- */
input, select, textarea { font: inherit; font-size: var(--fs-sm); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 6px 10px; min-height: 34px; max-width: 100%; }
textarea { min-height: 90px; resize: vertical; line-height: 1.5; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[readonly], input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-muted); }
input[type="checkbox"], input[type="radio"] { min-height: 0; width: 17px; height: 17px; accent-color: var(--accent); }
.form { display: grid; gap: var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); margin-bottom: var(--s5); box-shadow: var(--shadow-1); max-width: 860px; }
.form.narrow { max-width: 520px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-sm); font-weight: 550; }
.form label input, .form label select { width: 100%; }
.form label.chk, label.chk { flex-direction: row; display: inline-flex; gap: var(--s2); align-items: center; font-weight: 500; }
.form label.chk input, label.chk input { width: 17px; flex: none; }
.form > button { justify-self: start; }
fieldset { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s4); margin: 0; min-width: 0; display: grid; gap: var(--s3); }
legend { padding: 0 var(--s2); font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted); }
form.inline { display: inline-flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin: 0 var(--s2) var(--s2) 0; }

/* ---------- tabelle ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; margin: var(--s2) 0 var(--s5); box-shadow: var(--shadow-1); }
th { text-align: left; font-weight: 600; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 10px var(--s3); border-bottom: 1px solid var(--border); background: var(--surface); vertical-align: bottom; }
td { padding: 9px var(--s3); border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: break-word; }
td code { overflow-wrap: anywhere; }
tbody tr:hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
table a { font-weight: 550; }
.table-wrap { width: 100%; overflow-x: auto; }
@media (max-width: 720px) { table { display: block; overflow-x: auto; } }

/* ---------- superfici ---------- */
.section, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4) var(--s5); margin-bottom: var(--s5); box-shadow: var(--shadow-1); }
.section > :last-child, .card > :last-child { margin-bottom: 0; }
.section > h2:first-child, .card > h2:first-child { margin-top: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: var(--s4); }
.cards { list-style: none; padding: 0; margin: 0 0 var(--s5); display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--s3); }
.cards li a { display: block; height: 100%; padding: var(--s4) var(--s5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); text-decoration: none; color: var(--text); font-weight: 550; transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast); }
.cards li a:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); color: var(--accent); }
.cards li a small { display: block; font-weight: 400; color: var(--text-muted); margin-top: var(--s1); }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s5); }
.page-head h1 { margin: 0; }
.page-head p { margin: var(--s1) 0 0; color: var(--text-muted); max-width: 72ch; }

/* ---------- indicatori ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--s3); margin-bottom: var(--s5); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4) var(--s5); box-shadow: var(--shadow-1); }
.stat-label { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.9rem; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--s1); }

/* ---------- badge e messaggi ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 1px 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 1.7; background: var(--surface-3); color: var(--text-muted); white-space: nowrap; vertical-align: middle; }
.badge.demo { background: var(--warning-soft); color: var(--warning); }
.badge.frozen { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--success-soft); color: var(--success); }
.badge.warn { background: var(--danger-soft); color: var(--danger); }
.msg { padding: var(--s3) var(--s4); margin: 0 0 var(--s4); border-radius: var(--r-md); white-space: pre-line; font-size: var(--fs-sm); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.ok { background: var(--success-soft); color: var(--success); }
.error-list ul { margin: 0; padding-left: 1.1rem; color: var(--danger); }
/* il riepilogo di validazione vuoto usa uno style inline, bloccato dalla CSP: si nasconde via classe */
.validation-summary-valid { display: none; }

/* ---------- schede ---------- */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--border); margin: 0 0 var(--s4); overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.tabs a { padding: var(--s2) var(--s3); text-decoration: none; color: var(--text-muted); font-size: var(--fs-sm); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- workflow ---------- */
.workflow { list-style: none; padding: 0; display: grid; gap: var(--s3); }
.wf-step { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--border-strong); border-radius: var(--r-md); padding: var(--s3) var(--s4); }
.wf-step p { margin-bottom: var(--s2); }
.wf-head { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; margin-bottom: var(--s2); }
.wf-state { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; padding: 1px 8px; border-radius: var(--r-pill); background: var(--surface-3); color: var(--text-muted); }
.wf-completed { border-left-color: var(--success); } .wf-completed .wf-state { background: var(--success-soft); color: var(--success); }
.wf-inprogress { border-left-color: var(--accent); } .wf-inprogress .wf-state { background: var(--accent-soft); color: var(--accent); }
.wf-ready { border-left-color: var(--info); } .wf-ready .wf-state { background: var(--info-soft); color: var(--info); }
.wf-awaitingvalidation { border-left-color: var(--warning); } .wf-awaitingvalidation .wf-state { background: var(--warning-soft); color: var(--warning); }
.wf-blocked, .wf-invalidated { border-left-color: var(--danger); } .wf-blocked .wf-state, .wf-invalidated .wf-state { background: var(--danger-soft); color: var(--danger); }
.wf-missing { color: var(--danger); font-size: var(--fs-sm); }
.wf-ok { color: var(--success); font-size: var(--fs-sm); }
.wf-actions { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.phase-strip { list-style: none; display: flex; flex-wrap: wrap; gap: 4px; padding: 0; margin: var(--s2) 0 var(--s5); }
.phase-strip li { font-size: var(--fs-xs); border-radius: var(--r-sm); background: var(--surface-2); border-bottom: 3px solid var(--border-strong); }
.phase-strip li a { display: block; padding: 3px 8px; color: var(--text-muted); text-decoration: none; }
.phase-strip li.wf-completed { background: var(--success-soft); border-bottom-color: var(--success); }
.phase-strip li.wf-inprogress { background: var(--accent-soft); border-bottom-color: var(--accent); font-weight: 600; }
.phase-strip li.wf-inprogress a { color: var(--accent); }
.phase-strip li.wf-ready { background: var(--info-soft); border-bottom-color: var(--info); }
.phase-strip li.wf-awaitingvalidation { background: var(--warning-soft); border-bottom-color: var(--warning); }
.phase-strip li.wf-blocked, .phase-strip li.wf-invalidated { background: var(--danger-soft); border-bottom-color: var(--danger); }
@media (max-width: 720px) {
  /* telefono: la striscia degli step diventa una riga scorrevole */
  .phase-strip { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; padding-bottom: var(--s1); }
  .phase-strip li { flex: none; }
}

/* ---------- area pubblica ---------- */
.site-header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid var(--border); }
.container { width: 100%; max-width: 1120px; margin: 0 auto; padding: 0 var(--s5); }
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: var(--s4); }
.site-nav { display: flex; align-items: center; gap: var(--s4); margin-right: auto; margin-left: var(--s5); overflow-x: auto; }
.site-nav a { color: var(--text-muted); text-decoration: none; font-size: var(--fs-sm); font-weight: 550; padding: 6px 2px; border-bottom: 2px solid transparent; white-space: nowrap; }
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--text); border-bottom-color: currentColor; }
.public-main { padding: var(--s6) 0 var(--s8); }
.hero { padding: clamp(40px, 8vw, 96px) 0 var(--s6); }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); max-width: 18ch; letter-spacing: -.035em; }
.hero .lead { font-size: var(--fs-md); color: var(--text-muted); max-width: 60ch; }
.lead { font-size: var(--fs-md); }
.prose { max-width: 72ch; }
.prose p { white-space: pre-line; }
.project-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.project-card { display: flex; flex-direction: column; gap: var(--s2); height: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s5); text-decoration: none; color: var(--text); transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast); }
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); color: var(--text); }
.project-card .badge { align-self: flex-start; }
.project-card h3 { margin: 0; }
.project-card p { margin: 0; color: var(--text-muted); font-size: var(--fs-sm); }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px var(--s4); font-size: var(--fs-sm); margin: 0 0 var(--s4); }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 720px) {
  .container { padding: 0 var(--s4); }
  /* telefono: la navigazione pubblica va su una seconda riga, intera e scorrevole */
  .site-header .container { flex-wrap: wrap; height: auto; padding-top: var(--s2); padding-bottom: var(--s2); row-gap: var(--s1); }
  .site-nav { order: 3; width: 100%; margin: 0; gap: var(--s4); }
  .brand .sub { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
@media print {
  .lab-top, .sidebar, .site-header, form.inline, button { display: none !important; }
  .lab-shell { display: block; }
  body { background: #fff; }
}
