:root {
  /* colori LA BARNINI (labarnini.com) */
  --brand: #005da9; --brand-dark: #004a87; --brand-light: #e6f0f8;
  --bg: #f1f1f1; --surface: #ffffff; --text: #262422; --muted: #6a6762; --border: #e2e2e2;
  --accent: #005da9; --accent-text: #ffffff; --user: #005da9; --user-text: #ffffff;
  --chip: #eef3f8; --ok: #15803d; --err: #b91c1c; --warn: #a16207;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,40,80,.06);
  --ease: cubic-bezier(.2,.8,.2,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418; --surface: #1a2027; --text: #e8eaed; --muted: #9aa5b3; --border: #2a323c;
    --accent: #4b9be3; --accent-text: #08131f; --user: #0b4f8c; --user-text: #eef5fc;
    --chip: #1f2a36; --ok: #4ade80; --err: #f87171; --warn: #facc15; --brand-light: #15283b;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 16px/1.5 "Work Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; -webkit-text-size-adjust: 100%;
}
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

header.top {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
}
header.top .brand { font-weight: 650; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top select {
  max-width: 45vw; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
}
.newchat {
  border: 0; background: var(--accent); color: var(--accent-text); border-radius: 8px; padding: 7px 12px;
  font-weight: 650; white-space: nowrap; line-height: 1.2;
}
@media (max-width: 380px) { .newchat { padding: 7px 9px; font-size: .9rem; } header.top select { max-width: 38vw; } }
.iconbtn {
  border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 6px 10px; line-height: 1.2;
}
.tabs { display: flex; gap: 4px; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 6px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--chip); color: var(--text); }

main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { max-width: 820px; margin: 0 auto; padding: 12px 12px 24px; }
.hidden { display: none !important; }

.empty { color: var(--muted); text-align: center; padding: 32px 12px; }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 1.2rem; }
.examples { display: grid; gap: 8px; margin-top: 16px; text-align: left; }
.examples button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; text-align: left;
}

.msg { margin: 10px 0; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 92%; padding: 10px 12px; border-radius: 14px; box-shadow: var(--shadow); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: var(--user-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; width: 100%; max-width: 100%; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble h3, .bubble h4 { margin: 10px 0 4px; font-size: 1rem; }
.bubble code { background: var(--chip); padding: 1px 4px; border-radius: 4px; font-size: .92em; }
.cite {
  display: inline-block; min-width: 1.5em; padding: 0 5px; margin: 0 1px; border-radius: 6px; font-size: .8em; font-weight: 700;
  background: var(--chip); color: var(--accent); border: 0; vertical-align: 1px;
}
.status { color: var(--muted); font-style: italic; }
.err { color: var(--err); }

.sources { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.sources .label { width: 100%; font-size: .8rem; color: var(--muted); }
.src {
  border: 1px solid var(--border); background: var(--chip); border-radius: 8px; padding: 4px 8px;
  font-size: .85rem; text-align: left; max-width: 100%;
}
.src b { color: var(--accent); }
.src.schema::after { content: " ⚡"; }
.src.foto::after { content: " 📷"; }
.fb { display: flex; gap: 6px; margin-top: 8px; align-items: center; color: var(--muted); font-size: .85rem; }
.fb button { border: 1px solid var(--border); background: transparent; border-radius: 8px; padding: 2px 10px; }
.fb button.sel { background: var(--chip); border-color: var(--accent); }

footer.ask {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom));
}
footer.ask form { display: flex; gap: 8px; max-width: 820px; margin: 0 auto; align-items: flex-end; }
footer.ask textarea {
  flex: 1; resize: none; max-height: 140px; min-height: 44px; padding: 10px 12px;
  border-radius: 12px; border: 1px solid var(--border); background: var(--bg);
}
footer.ask button {
  height: 44px; padding: 0 16px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-text); font-weight: 650;
}
footer.ask button:disabled { opacity: .5; }

.doclist h3 { margin: 16px 0 6px; font-size: .95rem; color: var(--muted); }
.doc {
  display: flex; width: 100%; gap: 10px; align-items: center; text-align: left; padding: 10px 12px; margin-bottom: 6px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.doc .t { flex: 1; min-width: 0; }
.doc small { color: var(--muted); }
.tag { font-size: .72rem; padding: 2px 6px; border-radius: 6px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.search { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }

/* visualizzatore pagine */
.viewer { position: fixed; inset: 0; background: #0b0d10; z-index: 20; display: flex; flex-direction: column; color: #e6e9ee; }
.viewer .bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); background: #15191e; }
.viewer .bar .t { flex: 1; min-width: 0; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer .bar button, .viewer .bar a { background: #262c34; border: 0; color: #e6e9ee; border-radius: 8px; padding: 6px 10px; text-decoration: none; font-size: .9rem; }
.viewer .img { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom; }
.viewer img { display: block; width: 100%; height: auto; background: #fff; margin: 0 auto; }
.viewer.zoom img { width: 250%; max-width: none; }
.viewer .nav { display: flex; gap: 8px; align-items: center; justify-content: center; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); background: #15191e; }
.viewer .nav button { background: #262c34; border: 0; color: #e6e9ee; border-radius: 8px; padding: 8px 14px; }

/* proposta di salvare un'informazione nuova */
.prop { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--accent); border-radius: 10px; background: var(--chip); }
.prop.done { border-color: var(--ok); color: var(--ok); font-weight: 600; }
.prop .ptitle { font-weight: 650; font-size: .92rem; margin-bottom: 6px; }
.prop .ptext { font-size: .92rem; white-space: pre-wrap; margin-bottom: 4px; }
.prop small { color: var(--muted); display: block; }
.prop textarea { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); margin-bottom: 4px; }
.prop .pbtn { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.prop .pbtn button { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; }
.prop .pbtn button.ok { background: var(--accent); color: var(--accent-text); border: 0; font-weight: 650; }
.prop .pbtn button:disabled { opacity: .5; }
.addnote { margin-top: 8px; border: 1px dashed var(--border); background: transparent; color: var(--muted); border-radius: 8px; padding: 4px 10px; font-size: .82rem; }
.prop.man { border-color: var(--border); }
.prop a { color: var(--accent); }

/* account */
.badge { display: inline-block; min-width: 1.3em; padding: 0 5px; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-size: .75rem; line-height: 1.3em; text-align: center; }
.acard { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin: 0 0 12px; box-shadow: var(--shadow); }
.acard label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
.acard label .opt { font-weight: 400; }
.acard input { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); font-size: 16px; }
#mustchange { border-color: var(--accent); }
.who { display: flex; flex-direction: column; gap: 2px; }
.who span { color: var(--muted); font-size: .92rem; }
.who .role { color: var(--accent); font-weight: 650; }
.abtn { margin-top: 12px; padding: 9px 16px; border: 0; border-radius: 9px; background: var(--accent); color: var(--accent-text); font-weight: 650; }
.abtn.sec { background: var(--chip); color: var(--text); border: 1px solid var(--border); margin-top: 0; }
.abtn:disabled { opacity: .6; }
.acard select { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border); background: var(--bg); color: var(--text); font-size: 16px; }
.acard .chk { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: .95rem; }
.acard .chk input { width: auto; }
.abtn.upopen { margin: 0 0 10px; }
#upform { margin-bottom: 12px; }
.amsg { margin-top: 8px; font-size: .92rem; }
.amsg.err { color: var(--err); }
.amsg.ok { color: var(--ok); }

/* cronologia chat */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; }
.dpanel { position: absolute; top: 0; bottom: 0; left: 0; width: min(340px, 88vw); background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 12px;
  padding-top: max(12px, env(safe-area-inset-top)); box-shadow: 0 0 24px rgba(0,0,0,.2); }
.dhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.dnew { width: 100%; margin-bottom: 8px; }
.dpanel .search { margin-bottom: 6px; }
#chatlist { flex: 1; overflow-y: auto; margin: 0 -4px; }
.chead { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 10px 4px 4px; }
.chatrow { display: flex; align-items: center; gap: 2px; border-radius: 8px; padding: 2px; }
.chatrow.cur { background: var(--chip); }
.chatrow .open { flex: 1; min-width: 0; border: 0; background: transparent; text-align: left; padding: 6px; }
.chatrow .ct { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.chatrow small { color: var(--muted); font-size: .78rem; }
.chatrow .ca { border: 0; background: transparent; color: var(--muted); padding: 6px 5px; font-size: .95rem; }
.chatrow .ca.del { font-size: .85rem; }
.cempty, .dnote { color: var(--muted); font-size: .85rem; padding: 4px; }
.dnote { margin: 8px 0 0; }
.pinbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--chip);
  border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; font-size: .9rem; }
.pinbar button { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 3px 9px; font-size: .82rem; }
.msg.info { justify-content: center; }
.msg.info .bubble { background: transparent; box-shadow: none; color: var(--muted); font-size: .85rem; text-align: center; padding: 2px 8px; }
body.nocopy #messages { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }

/* ================================================================ grafica LA BARNINI */
header.top { background: var(--brand); border-bottom: 0; color: #fff; box-shadow: 0 2px 10px rgba(0,40,80,.18); }
header.top .iconbtn { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
header.top select { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.3); color: #fff; }
header.top select option { color: #262422; }
header.top .newchat { background: #fff; color: var(--brand); }
.logo { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: #fff; text-decoration: none; }
.logo img { height: 34px; width: auto; display: block; flex-shrink: 0; }
header.top select { flex: 0 1 auto; min-width: 0; }
@media (max-width: 420px) { header.top select { max-width: 30vw; } header.top { gap: 6px; padding-left: 8px; padding-right: 8px; } }
.logo .lt { font-weight: 600; font-size: .8rem; letter-spacing: .08em; text-transform: uppercase; opacity: .85;
  border-left: 1px solid rgba(255,255,255,.4); padding-left: 8px; white-space: nowrap; }
.logo .ln { font-weight: 700; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .logo .lt { display: none; } }
.tabs { box-shadow: 0 1px 0 var(--border); }
.tabs button { position: relative; transition: color .2s, background .2s; }
.tabs button.active { background: transparent; color: var(--brand); }
.tabs button::after { content: ""; position: absolute; left: 20%; right: 20%; bottom: -6px; height: 3px; border-radius: 3px;
  background: var(--accent); transform: scaleX(0); transition: transform .3s var(--ease); }
.tabs button.active::after { transform: scaleX(1); }

/* titolo a fascia come sul sito */
.band { display: flex; align-items: center; gap: 10px; margin: 0 0 14px; }
.band::before, .band::after { content: ""; flex: 1; height: 3px; background: var(--accent); border-radius: 3px; }
.band span { background: var(--accent); color: var(--accent-text); font-weight: 600; text-transform: uppercase;
  letter-spacing: .03em; padding: 4px 12px; font-size: 1rem; }
.welcome-logo { width: 150px; margin: 6px auto 18px; display: block; }
.empty h2 { font-weight: 600; }
.examples button { transition: transform .2s var(--ease), border-color .2s, box-shadow .2s; }
.examples button:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }

/* marchi del gruppo */
.marchi { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-top: 8px; }
.marchi a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 76px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px; text-decoration: none; color: #262422;
  font-size: .75rem; transition: transform .25s var(--ease), box-shadow .25s, border-color .25s; }
.marchi a:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,40,80,.12); border-color: var(--brand); }
.marchi img { max-width: 100%; max-height: 42px; object-fit: contain; }
.contatti { font-size: .9rem; line-height: 1.6; }
.contatti a { color: var(--accent); }

/* ================================================================ animazioni */
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes pop { 0% { opacity: 0; transform: scale(.94); } 100% { opacity: 1; transform: none; } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes slidein { from { transform: translateX(-100%); } to { transform: none; } }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
@keyframes shimmer { from { background-position: -200% 0; } to { background-position: 200% 0; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(0,93,169,.45); } 70% { box-shadow: 0 0 0 10px rgba(0,93,169,0); } 100% { box-shadow: 0 0 0 0 rgba(0,93,169,0); } }

.msg { animation: rise .35s var(--ease) both; }
.msg.user .bubble { transform-origin: bottom right; animation: pop .3s var(--ease) both; }
.prop, .pinbar { animation: rise .4s var(--ease) both; }
.view:not(.hidden) { animation: fadein .25s ease both; }
.empty > * { animation: rise .5s var(--ease) both; }
.empty > *:nth-child(2) { animation-delay: .06s; } .empty > *:nth-child(3) { animation-delay: .12s; }
.empty > *:nth-child(4) { animation-delay: .18s; }
.examples button { animation: rise .45s var(--ease) both; }
.examples button:nth-child(2) { animation-delay: .25s; } .examples button:nth-child(3) { animation-delay: .32s; }
.examples button:nth-child(4) { animation-delay: .39s; } .examples button:nth-child(1) { animation-delay: .18s; }
.drawer:not(.hidden) { animation: fadein .2s ease both; }
.drawer:not(.hidden) .dpanel { animation: slidein .3s var(--ease) both; }
.chatrow { transition: background .15s; }
.chatrow:hover { background: var(--chip); }
.marchi a { animation: pop .4s var(--ease) both; }
.marchi a:nth-child(2) { animation-delay: .05s; } .marchi a:nth-child(3) { animation-delay: .1s; }
.marchi a:nth-child(4) { animation-delay: .15s; } .marchi a:nth-child(5) { animation-delay: .2s; }
.marchi a:nth-child(6) { animation-delay: .25s; } .marchi a:nth-child(7) { animation-delay: .3s; }

/* pulsanti: effetto pressione */
button { transition: transform .12s ease, background-color .2s, opacity .2s, box-shadow .2s; }
button:active:not(:disabled) { transform: scale(.96); }
.newchat:hover, footer.ask button:hover:not(:disabled), .abtn:hover { box-shadow: 0 4px 12px rgba(0,40,80,.2); }
footer.ask textarea { transition: border-color .2s, box-shadow .2s; }
footer.ask textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,93,169,.15); }
footer.ask button.busy { animation: pulse 1.4s infinite; }

/* "sto scrivendo": tre puntini */
.typing { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-style: italic; }
.typing .dots { display: inline-flex; gap: 4px; }
.typing .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: blink 1.2s infinite both; }
.typing .dots i:nth-child(2) { animation-delay: .15s; } .typing .dots i:nth-child(3) { animation-delay: .3s; }
/* testo che compare mentre arriva */
.bubble.streaming > :last-child::after { content: ""; display: inline-block; width: 7px; height: 1em; margin-left: 2px;
  vertical-align: -2px; background: var(--accent); border-radius: 2px; animation: blink 1s infinite; }
.badge { animation: pop .4s var(--ease) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* memoria della chat */
.memo { background: var(--brand-light); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; font-size: .88rem; animation: rise .4s var(--ease) both; }
.memo summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.memo #memotext { margin-top: 6px; color: var(--text); }
.memo ul { margin: 4px 0; padding-left: 20px; }

/* archivio ad albero */
details.tree { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px 10px; margin-bottom: 8px; }
details.tree.sub { border: 0; border-left: 3px solid var(--brand-light); border-radius: 0; padding: 2px 0 2px 10px; margin: 6px 0; background: transparent; }
details.tree summary { cursor: pointer; padding: 4px 0; }
details.tree .cnt { font-size: .75rem; background: var(--chip); color: var(--muted); border-radius: 8px; padding: 0 7px; margin-left: 4px; }
.kindh { font-size: .75rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin: 8px 0 4px; }
.vtext { background: #fff; color: #262422; padding: 16px; max-width: 820px; margin: 0 auto; line-height: 1.55; }
.vtext table { border-collapse: collapse; font-size: .9rem; }
.vtext td, .vtext th { border: 1px solid #ddd; padding: 3px 6px; }

/* ---- v27: foto allegate e pagine sotto la risposta */
footer.ask button.fotobtn { background: var(--chip); color: inherit; padding: 0 12px; font-size: 1.2rem; }
.fotoprev { display: flex; gap: 8px; max-width: 820px; margin: 0 auto 8px; flex-wrap: wrap; }
.fotoprev .th { position: relative; }
.fotoprev img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.fotoprev .th button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; padding: 0; border-radius: 50%;
  border: 0; background: #333; color: #fff; font-size: .75rem; line-height: 22px; }
.ufoto { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.ufoto img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; cursor: zoom-in; display: block; }
.msg.user .bubble .utext:empty { display: none; }
.pagine { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.pagine { gap: 12px; }
.pagine figure { margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--chip); cursor: zoom-in; }
.pagine figure img { display: block; width: 100%; height: auto; background: #fff; min-height: 120px; }
.pagine figcaption { padding: 6px 10px; font-size: .9rem; }
.pagine figcaption small { color: var(--muted); display: block; }
.viewer.single .nav, .viewer.single #vpdf { display: none; }
/* ---- v31: motivi del pollice in giu' e conferma matricola */
.fbm { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.fbm button { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: .85rem; }
.fbm button.sel { background: var(--chip); border-color: var(--accent); font-weight: 600; }
.fbask textarea { width: 100%; }
.msg.info .pbtn { margin-top: 6px; }
