/* AV2 – interfaccia 2.0 "Il fascicolo". Token e regole: design-system/av2/MASTER.md */
:root {
  --paper: #f4efe6;
  --paper-2: #e9e2d5;
  --sheet: #fffcf6;
  --ink: #1d2230;
  --ink-2: #5b6274;
  --line: #d9d0c0;
  --blue: #2b4c7e;
  --blue-2: #1f3a62;
  --ok: #2e7d4f;
  --warn: #b7791f;
  --danger: #b3261e;
  --for: #f078b7; --for-ink: #9c2a6d;
  --es: #9d8dff;  --es-ink: #4d3fb3;
  --vis: #79ceef; --vis-ink: #176d8c;
  --r-card: 10px;
  --r-ctrl: 8px;
  --shadow: 0 1px 2px rgba(29,34,48,.06), 0 8px 24px -16px rgba(29,34,48,.25);
  --font-body: "IBM Plex Sans", system-ui, sans-serif;
  --font-head: "Fraunces", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  min-height: 100%; margin: 0;
  background: var(--paper); color: var(--ink);
  font: 400 15px/1.5 var(--font-body);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 26px; line-height: 1.2; }
h3 { font-size: 18px; }
p { margin: 0; }
a { color: var(--blue); }
button { font: inherit; }
.mono { font-family: var(--font-mono); font-size: 13px; }
.muted { color: var(--ink-2); }
.hidden, [hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- intestazione (copertina) */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 0 28px; height: 60px;
  background: var(--ink); color: #f4efe6;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand h1 { font-size: 21px; font-weight: 600; }
.brand .v { font: 500 11px/1 var(--font-mono); letter-spacing: .12em; padding: 5px 7px; border: 1px solid rgba(244,239,230,.35); border-radius: 999px; }
.top-center { display: flex; align-items: center; gap: 14px; color: rgba(244,239,230,.75); font-size: 14px; }
.top-center .pir { color: #f4efe6; font-size: 13px; }
.top-right { display: flex; align-items: center; gap: 10px; font-size: 14px; color: rgba(244,239,230,.75); }
.top-right .who { margin-right: 8px; }
.top .btn-ghost { color: #f4efe6; border-color: rgba(244,239,230,.3); }
.top .btn-ghost:hover { border-color: #f4efe6; background: rgba(244,239,230,.08); }

/* ---------- bottoni e campi */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px;
  border-radius: var(--r-ctrl); border: 1px solid transparent;
  font-weight: 500; color: var(--ink); background: transparent; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-2); }
.btn-ghost { border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-2); background: var(--paper-2); }
.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: rgba(179,38,30,.08); }
.btn-lg { min-height: 48px; padding: 10px 22px; font-size: 16px; }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .field select:focus-visible, .field input:focus-visible, a:focus-visible, .doc-name:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}
.field { display: grid; gap: 6px; }
.field label, .lbl { font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
.field input, .field select {
  min-height: 42px; padding: 8px 12px; width: 100%;
  background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-ctrl);
  font: 400 15px/1.4 var(--font-body);
}
.alert { padding: 10px 14px; border-radius: var(--r-ctrl); border: 1px solid; font-size: 14px; }
.alert-danger { color: var(--danger); border-color: rgba(179,38,30,.35); background: rgba(179,38,30,.06); }

/* ---------- fogli */
.sheet {
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-card);
  box-shadow: var(--shadow); padding: 24px;
}
.main { max-width: 1440px; margin: 0 auto; padding: 28px 28px 72px; }

/* ---------- login e inizio */
.center { max-width: 460px; margin: 9vh auto 0; }
.center h2 { margin-bottom: 6px; }
.center .lead { color: var(--ink-2); margin-bottom: 22px; }
.center form, .center .stack { display: grid; gap: 16px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.kv .v { font-weight: 500; }

/* ---------- lavorazione */
.work { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.desk { display: grid; gap: 18px; min-width: 0; }

.drop {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 14px;
  min-height: 92px; padding: 16px 20px;
  border: 1.5px dashed var(--line); border-radius: var(--r-card);
  background: var(--paper-2); color: var(--ink-2); text-align: center;
  transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--blue); background: #e6edf7; color: var(--blue); }
.drop strong { color: var(--ink); font-weight: 500; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop .btn { position: relative; z-index: 1; pointer-events: none; }

.progress { height: 3px; background: var(--paper-2); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--blue); transition: width .2s; }
.status { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-2); min-height: 20px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); animation: pulse 1.2s infinite; }
.status.done .dot { background: var(--ok); animation: none; }
@keyframes pulse { 0%,100% { opacity: .25 } 50% { opacity: 1 } }

.folders { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.folder { min-width: 0; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px 8px; border-radius: 8px 8px 0 0;
  font-weight: 600; font-size: 14px; color: var(--ink);
  border: 1px solid var(--line); border-bottom: 0; background: var(--paper-2);
}
.tab .n { font: 500 12px/1 var(--font-mono); padding: 3px 7px; border-radius: 999px; background: rgba(29,34,48,.08); }
.folder-body {
  display: grid; gap: 10px; padding: 12px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: 0 var(--r-card) var(--r-card) var(--r-card);
  box-shadow: var(--shadow); min-height: 140px;
}
.folder.vis .tab { background: var(--vis); }
.folder.es  .tab { background: var(--es); color: #fff; }
.folder.for .tab { background: var(--for); color: #fff; }
.folder.es .tab .n, .folder.for .tab .n { background: rgba(255,255,255,.25); }
.folder-empty { padding: 28px 12px; text-align: center; color: var(--ink-2); font-size: 14px; }

/* scheda documento */
.doc {
  position: relative; display: grid; gap: 4px; padding: 10px 12px 10px 14px;
  background: #fff; border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px;
}
.folder.vis .doc { border-left-color: var(--vis); }
.folder.es  .doc { border-left-color: var(--es); }
.folder.for .doc { border-left-color: var(--for); }
.doc-kind { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.folder.vis .doc-kind { color: var(--vis-ink); }
.folder.es  .doc-kind { color: var(--es-ink); }
.folder.for .doc-kind { color: var(--for-ink); }
.doc-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); text-decoration: none; }
.doc-name:hover { text-decoration: underline; }
.doc-id { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); word-break: break-all; }
.doc-actions { display: flex; gap: 4px; justify-content: flex-end; margin-top: 2px; }
.doc.pending { border-style: dashed; color: var(--ink-2); }
.doc.pending .doc-name { color: var(--ink-2); }
.doc.rejected { border-left-color: var(--warn) !important; background: #fbf5ea; }
.doc.rejected .doc-kind { color: var(--warn); }

/* formalità dentro un elenco sintetico */
.forlist { display: grid; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); }
.forlist-title { font-size: 12px; color: var(--ink-2); display: flex; justify-content: space-between; }
.fi {
  display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 2px 10px; align-items: center;
  padding: 6px 8px; border-radius: 6px; background: var(--paper); border: 1px solid transparent;
}
.fi .t { font-size: 13px; font-weight: 500; }
.fi .m { font-family: var(--font-mono); font-size: 12px; color: var(--ink-2); grid-column: 1; }
.fi .a { grid-row: 1 / span 2; display: flex; align-items: center; gap: 4px; }
.fi.missing { opacity: .6; }
.fi.missing .t::after { content: " · non presente"; font-weight: 400; color: var(--ink-2); }
.fi.added { background: rgba(46,125,79,.08); border-color: rgba(46,125,79,.35); }
.fi.added .t::after { content: " · aggiunta"; font-weight: 500; color: var(--ok); }

/* pannello destro */
.rail { position: sticky; top: 20px; display: grid; gap: 14px; }
.rail .sheet { padding: 18px 20px; }
.rail h3 { margin-bottom: 12px; }
.meta { display: grid; gap: 10px; }
.meta .row { display: grid; gap: 2px; }
.meta .row .v { font-weight: 500; }
.counts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.count { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); border-top: 3px solid; background: #fff; }
.count b { display: block; font: 600 20px/1.1 var(--font-head); }
.count span { font-size: 11px; color: var(--ink-2); letter-spacing: .04em; text-transform: uppercase; }
.count.vis { border-top-color: var(--vis); } .count.es { border-top-color: var(--es); } .count.for { border-top-color: var(--for); }
.notes { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.notes li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; padding: 8px 10px; border-radius: 6px; background: var(--paper); }
.notes li.warn { color: #7a4f0f; background: #fbf3e2; }
.notes li.err { color: var(--danger); background: rgba(179,38,30,.06); }
.notes li.ok { color: var(--ok); background: rgba(46,125,79,.08); }
.actions { display: grid; gap: 8px; }
.actions .btn-primary { width: 100%; }
.actions .secondary { display: flex; gap: 6px; justify-content: space-between; }

/* esito */
.result { max-width: 760px; margin: 6vh auto 0; }
.result .ok-line { display: flex; align-items: center; gap: 10px; color: var(--ok); font-weight: 500; margin-bottom: 6px; }
.downloads { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 22px 0; }
.dl {
  display: grid; gap: 6px; padding: 16px; border: 1px solid var(--line); border-radius: var(--r-card);
  background: #fff; color: var(--ink); text-decoration: none; transition: border-color .15s, background .15s;
}
.dl:hover { border-color: var(--blue); background: #f6f8fc; }
.dl b { font-weight: 600; }
.dl span { font-size: 13px; color: var(--ink-2); }
.dl .ext { font: 500 11px/1 var(--font-mono); letter-spacing: .1em; color: var(--blue); }

@media (max-width: 1100px) {
  .work { grid-template-columns: 1fr; }
  .rail { position: static; }
  .folders { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
