/* Studio Contratti — design system
   Ancoraggio cromatico: il blu inchiostro dei contratti generati (#1e3a5f) e l'arancio delle note legali.
   Un solo elemento memorabile: la libreria. Il resto resta quieto. */

@font-face { font-family: "Plex"; src: url("../fonts/plex-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/plex-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("../fonts/plex-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "DocSans"; src: url("../fonts/DejaVuSans.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "DocSans"; src: url("../fonts/DejaVuSans-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --bg: #e9edf2; --surface: #ffffff; --surface-2: #f5f7fa; --sunken: #dfe4eb;
  --ink: #15202e; --ink-2: #3f4b5c; --mute: #667185; --line: #d9dfe7; --line-2: #c3cbd6;
  --acc: #1e3a5f; --acc-hover: #17304f; --acc-ink: #ffffff; --acc-soft: #e2e9f2; --focus: #2f6fd1;
  --note: #b4410c; --note-soft: #fff4ea; --ph: #9a5b08; --ph-soft: #fdf1dc;
  --ok: #1d7048; --ok-soft: #e3f3ea; --danger: #b42318; --danger-soft: #fdecea;
  --desk: #cfd6df; --paper-shadow: 0 1px 2px rgba(21,32,46,.08), 0 8px 24px rgba(21,32,46,.10);
  --wood: #8a6a4b; --wood-top: #a5845f; --wood-shadow: #5b4430; --shelf-back: #f0ebe4;
  --r-sm: 6px; --r-md: 10px; --r-lg: 14px;
  --ease-out: cubic-bezier(.23, 1, .32, 1); --ease-io: cubic-bezier(.77, 0, .175, 1); --ease-drawer: cubic-bezier(.32, .72, 0, 1);
  --fs-xs: .75rem; --fs-sm: .8125rem; --fs-md: .9375rem; --fs-lg: 1.125rem; --fs-xl: 1.5rem;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f141b; --surface: #161d27; --surface-2: #1b2430; --sunken: #0b1016;
  --ink: #e6eaf0; --ink-2: #b9c2ce; --mute: #8d98a8; --line: #263141; --line-2: #354253;
  --acc: #9dbbe3; --acc-hover: #b6cdec; --acc-ink: #0f141b; --acc-soft: #1c2a3c; --focus: #7fb0ff;
  --note: #f59a5b; --note-soft: #2b1d14; --ph: #f0b45a; --ph-soft: #2d2414;
  --ok: #5fc08e; --ok-soft: #15291f; --danger: #f28b82; --danger-soft: #2e1716;
  --desk: #0a0e13; --paper-shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
  --wood: #4a3626; --wood-top: #5e4531; --wood-shadow: #24190f; --shelf-back: #121820;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body { margin: 0; font: 400 var(--fs-md)/1.5 "Plex", system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink); background: var(--bg);
  min-height: 100dvh; transition: background-color .2s ease, color .2s ease; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: var(--fs-xl); letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); letter-spacing: -.005em; }
h3 { font-size: var(--fs-md); }
p { margin: 0; }
a { color: var(--acc); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--mute); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Barra superiore */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  padding-top: calc(10px + env(safe-area-inset-top)); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px) saturate(160%); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--acc); color: var(--acc-ink); font: 600 18px/1 "DocSans", serif; flex-shrink: 0; }
.switcher { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; max-width: 620px; }
.switcher select { flex: 1; min-width: 0; }
.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.save-state { font-size: var(--fs-xs); color: var(--mute); white-space: nowrap; min-width: 92px; text-align: right; }
.save-state[data-state="error"] { color: var(--danger); }

.tabs { display: flex; gap: 2px; padding: 8px 20px 0; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 57px; z-index: 29; }
.tabs a { position: relative; padding: 10px 14px 12px; color: var(--mute); text-decoration: none; font-weight: 500; font-size: var(--fs-sm); border-radius: 8px 8px 0 0; }
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); }
.tabs a[aria-current="page"]::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--acc); border-radius: 2px; }
.tabs .tab-ico { display: none; }

main { padding: 24px 20px 64px; max-width: 1480px; margin: 0 auto; }

/* ---------- Controlli */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 500; font-size: var(--fs-sm); cursor: pointer;
  text-decoration: none; white-space: nowrap; user-select: none; -webkit-user-select: none; touch-action: manipulation;
  transition: transform 120ms var(--ease-out), background-color 120ms ease, border-color 120ms ease; }
.btn:active { transform: scale(.97); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.btn-danger { color: var(--danger); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { min-height: 32px; padding: 0 10px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none; }
.icon-btn { width: 36px; height: 36px; padding: 0; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--ink-2);
  display: inline-grid; place-items: center; cursor: pointer; flex-shrink: 0; touch-action: manipulation; transition: transform 120ms var(--ease-out), background-color 120ms ease; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:active { transform: scale(.94); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { background: var(--surface-2); border-color: var(--line-2); }
  .btn-primary:hover { background: var(--acc-hover); border-color: var(--acc-hover); }
  .btn-ghost:hover { background: var(--surface-2); }
  .icon-btn:hover { background: var(--surface-2); color: var(--ink); }
}

label { display: block; font-size: var(--fs-sm); font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.field { min-width: 0; }
.field .hint { font-size: var(--fs-xs); color: var(--mute); margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface);
  font-size: 16px; line-height: 1.4; transition: border-color 120ms ease, box-shadow 120ms ease; }
@media (pointer: fine) { input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], select, textarea { font-size: var(--fs-sm); } }
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
select { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%), linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }

.switch { --w: 38px; --h: 22px; position: relative; display: inline-flex; flex-shrink: 0; width: var(--w); height: var(--h); border-radius: 999px; border: 0; padding: 0;
  background: var(--line-2); cursor: pointer; transition: background-color 160ms ease; touch-action: manipulation; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: calc(var(--h) - 6px); height: calc(var(--h) - 6px); border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform 160ms var(--ease-out); }
.switch[aria-checked="true"] { background: var(--acc); }
.switch[aria-checked="true"]::after { transform: translateX(calc(var(--w) - var(--h))); }
[data-theme="dark"] .switch[aria-checked="true"]::after { background: var(--acc-ink); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: var(--fs-sm); color: var(--ink-2); }
.check-row .switch { --w: 34px; --h: 20px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 500; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .8; }
.pill[data-status="modello"] { color: var(--mute); }
.pill[data-status="bozza"] { color: var(--ph); }
.pill[data-status="generato"] { color: var(--acc); }
.pill[data-status="inviato"] { color: #2f6fd1; }
.pill[data-status="firmato"] { color: var(--ok); }
.pill[data-status="archiviato"] { color: var(--mute); }

/* ---------- Pannelli */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.panel-head p { font-size: var(--fs-sm); color: var(--mute); margin-top: 2px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 16px; }
.span-2 { grid-column: span 2; }
.stack { display: grid; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { color: var(--mute); margin-top: 4px; font-size: var(--fs-sm); max-width: 70ch; }

/* ---------- Schermata 1 */
.layout-contract { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.aside-sticky { position: sticky; top: 124px; display: grid; gap: 16px; }
.mini-paper { background: #fff; color: #1f2937; border-radius: 4px; box-shadow: var(--paper-shadow); aspect-ratio: 210 / 297; padding: 9% 9% 0; overflow: hidden; font-family: "DocSans", sans-serif; position: relative; }
.mini-paper .mp-head { position: absolute; top: 3.2%; left: 9%; right: 9%; display: flex; justify-content: space-between; font-size: 5px; color: #6b7280; border-bottom: 1px solid #cbd5e1; padding-bottom: 2px; }
.mini-paper .mp-logos { display: flex; justify-content: center; gap: 18px; margin-top: 6%; min-height: 0; }
.mini-paper .mp-logos img { max-height: 26px; max-width: 90px; object-fit: contain; }
.mini-paper .mp-title { margin-top: 14%; text-align: center; color: #1e3a5f; font-weight: 700; font-size: 12px; line-height: 1.25; }
.mini-paper .mp-sub { text-align: center; color: #6b7280; font-size: 6.5px; margin-top: 4px; line-height: 1.35; }
.mini-paper .mp-h { font-weight: 700; font-size: 6.5px; margin: 14px 0 3px; }
.mini-paper table { width: 100%; border-collapse: collapse; font-size: 5px; }
.mini-paper th { background: #1e3a5f; color: #fff; text-align: left; padding: 2px 3px; }
.mini-paper td { border: 1px solid #cbd5e1; padding: 2px 3px; vertical-align: top; }
.mini-paper tr:nth-child(even) td { background: #f1f5f9; }
.mini-paper .mp-foot { position: absolute; bottom: 3%; left: 9%; right: 9%; display: flex; justify-content: space-between; font-size: 4.5px; color: #6b7280; }
.facts { display: grid; gap: 8px; font-size: var(--fs-sm); }
.facts div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--mute); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.logo-box { display: flex; align-items: center; gap: 12px; }
.logo-box .logo-prev { width: 96px; height: 52px; border: 1px dashed var(--line-2); border-radius: var(--r-sm); display: grid; place-items: center; background: var(--surface-2); overflow: hidden; flex-shrink: 0; }
.logo-box .logo-prev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.sched-row { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr) auto; gap: 8px; align-items: start; }
.sched-row + .sched-row { margin-top: 8px; }
.sched-row textarea { min-height: 40px; }

/* ---------- Allegati */
.att-list { display: grid; gap: 8px; }
.att { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.att-ico { width: 34px; height: 40px; border-radius: 4px; background: var(--surface); border: 1px solid var(--line-2); display: grid; place-items: center; font-size: 10px; font-weight: 600; color: var(--mute); flex-shrink: 0; }
.att input[type="text"] { min-height: 34px; }
.att .att-meta { font-size: var(--fs-xs); color: var(--mute); overflow-wrap: anywhere; }
.drop { border: 1.5px dashed var(--line-2); border-radius: var(--r-md); padding: 18px; text-align: center; color: var(--mute); font-size: var(--fs-sm); cursor: pointer; transition: border-color 120ms ease, background-color 120ms ease; }
.drop.is-over { border-color: var(--acc); background: var(--acc-soft); color: var(--ink); }

/* ---------- Schermata 2: albero e anteprima */
.layout-clauses { display: grid; grid-template-columns: minmax(380px, 46%) minmax(0, 1fr); gap: 20px; align-items: start; }
.tree-panel { padding: 0; overflow: hidden; }
.tree-tools { position: sticky; top: 0; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface); display: grid; gap: 10px; z-index: 2; }
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 6px; font-size: var(--fs-xs); font-weight: 500; color: var(--mute); cursor: pointer; white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.tree { list-style: none; margin: 0; padding: 6px 0 14px; }
.tree ul { list-style: none; margin: 0; padding: 0; }
.t-section > .t-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px 6px; position: sticky; top: 0; }
.t-section > .t-head h3 { font-size: var(--fs-sm); color: var(--acc); }
.t-count { font-size: var(--fs-xs); color: var(--mute); margin-left: auto; }
.t-topic { margin: 2px 8px; border-radius: var(--r-md); }
.t-topic > .t-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: 8px; }
.t-toggle { border: 0; background: transparent; display: flex; align-items: center; gap: 6px; padding: 4px 2px; cursor: pointer; font-weight: 500; font-size: var(--fs-sm); color: var(--ink); text-align: left; min-width: 0; }
.t-toggle svg { width: 14px; height: 14px; color: var(--mute); transition: transform 160ms var(--ease-out); flex-shrink: 0; }
.t-toggle[aria-expanded="false"] svg { transform: rotate(-90deg); }
.t-topic > ul { padding: 2px 0 6px; }
.t-topic[data-collapsed] > ul { display: none; }
.t-row { display: grid; grid-template-columns: 16px auto minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 6px 8px 6px 6px; border-radius: 8px; min-height: 42px; }
.t-row .grip { cursor: grab; color: var(--line-2); display: grid; place-items: center; touch-action: none; }
.t-row .grip svg { width: 14px; height: 14px; }
.t-row { align-items: start; }
.t-row > .grip, .t-row > .switch, .t-row > .t-acts { margin-top: 5px; }
.t-row .t-main { min-width: 0; display: grid; gap: 4px; padding-top: 4px; }
.t-line { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.t-code { font-size: 11px; font-weight: 600; color: var(--mute); background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.t-text { font-size: 11.5px; line-height: 1.5; color: var(--mute); overflow-wrap: anywhere; display: grid; gap: 3px; padding-right: 4px; }
.t-text p { margin: 0; }
.t-text .li { padding-left: 10px; }
.t-text .nt { color: var(--note); }
.t-row[data-on="false"] .t-text { opacity: .75; }
.t-row .t-title { overflow-wrap: anywhere; font-size: var(--fs-sm); cursor: pointer; border: 0; background: transparent; padding: 0; text-align: left; line-height: 1.35; }
.t-row[data-on="false"] .t-title { color: var(--mute); }
.t-badge { font-size: 11px; font-weight: 600; color: var(--acc); background: var(--acc-soft); border-radius: 5px; padding: 1px 6px; white-space: nowrap; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.t-flag { width: 14px; height: 14px; color: var(--note); flex-shrink: 0; }
.t-acts { display: flex; align-items: center; gap: 0; }
.t-ver { color: var(--mute); }
.t-row.is-dragging { opacity: .5; }
.t-row.drop-before { box-shadow: inset 0 2px 0 var(--acc); }
.t-row.drop-after { box-shadow: inset 0 -2px 0 var(--acc); }
@media (hover: hover) and (pointer: fine) { .t-row:hover { background: var(--surface-2); } .t-row:hover .grip { color: var(--mute); } }
.t-empty { padding: 28px 20px; text-align: center; color: var(--mute); font-size: var(--fs-sm); }

.preview-wrap { position: sticky; top: 124px; height: calc(100dvh - 148px); display: flex; flex-direction: column; border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--desk); overflow: hidden; }
.preview-bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--line); }
.preview-bar .grow { flex: 1; min-width: 0; }
.preview-scroll { flex: 1; overflow: auto; padding: 24px; overscroll-behavior: contain; scroll-behavior: smooth; }
.warn-btn { color: var(--note); }

/* Foglio documento (anteprima): riproduce la grafica del PDF */
.doc { --s: 1; font-family: "DocSans", "DejaVu Sans", Verdana, sans-serif; color: #1f2937; }
.sheet { background: #fff; width: 100%; max-width: 760px; margin: 0 auto 22px; padding: 56px 64px 60px; box-shadow: var(--paper-shadow); border-radius: 2px; position: relative; }
.sheet .s-head { position: absolute; top: 22px; left: 64px; right: 64px; display: flex; justify-content: space-between; gap: 12px; font-size: 9px; color: #6b7280; border-bottom: 1px solid #cbd5e1; padding-bottom: 4px; }
.sheet .s-head span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .d-title { text-align: center; color: #1e3a5f; font-weight: 700; font-size: 24px; line-height: 1.26; margin: 40px 0 8px; }
.doc .d-sub { text-align: center; color: #6b7280; font-size: 13px; line-height: 1.4; margin-bottom: 4px; }
.doc .d-h1 { color: #1e3a5f; font-weight: 700; font-size: 17px; line-height: 1.33; margin: 0 0 12px; }
.doc .d-h2 { font-weight: 700; font-size: 13.4px; line-height: 1.33; margin: 14px 0 5px; }
.doc .d-p { font-size: 11.5px; line-height: 1.44; text-align: justify; margin: 0 0 5px; hyphens: auto; }
.doc .d-p b { font-weight: 700; }
.doc .d-li { display: grid; grid-template-columns: 18px 1fr; font-size: 11.5px; line-height: 1.44; text-align: justify; margin: 0 0 3px; }
.doc .d-li::before { content: "•"; text-align: center; }
.doc .d-note { background: #fff7ed; border-left: 3px solid #ea580c; color: #7c2d12; font-size: 10.6px; line-height: 1.38; padding: 7px 9px; margin: 4px 0 7px; text-align: justify; }
.doc .d-note b { font-weight: 700; }
.doc .ph { background: #fdf1dc; color: #8a4b05; border-radius: 2px; padding: 0 1px; }
.doc .ref-miss { background: #fde2dd; color: #9b1c12; border-radius: 2px; padding: 0 2px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 10px; line-height: 1.28; margin: 0 0 8px; }
.doc th { background: #1e3a5f; color: #fff; text-align: left; padding: 3px 5px; font-weight: 700; border: 1px solid #cbd5e1; }
.doc td { border: 1px solid #cbd5e1; padding: 3px 5px; vertical-align: top; }
.doc tbody tr:nth-child(even) td { background: #f1f5f9; }
.doc .sig td { height: 52px; vertical-align: bottom; }
.doc .art { border-radius: 3px; transition: background-color .9s ease; scroll-margin-top: 24px; }
.doc .art.is-new { background: color-mix(in srgb, #1e3a5f 9%, transparent); transition: none; }
.doc .page-note { text-align: center; font: 500 11px "Plex", sans-serif; color: var(--mute); margin: -8px 0 14px; }

/* ---------- Schermata 3: documenti */
.doc-rows { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.doc-rows th { text-align: left; font-weight: 500; color: var(--mute); font-size: var(--fs-xs); padding: 8px 10px; border-bottom: 1px solid var(--line); }
.doc-rows td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.doc-rows tr:last-child td { border-bottom: 0; }
.doc-rows .acts { display: flex; gap: 4px; justify-content: flex-end; }
.gen-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 16px; align-items: center; }
.progress { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; display: none; }
.progress.on { display: block; }
.progress span { display: block; height: 100%; width: 30%; background: var(--acc); border-radius: 4px; animation: indet 1.1s var(--ease-io) infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

/* ---------- La libreria */
.library { margin-top: 28px; }
.library > .panel-head { margin-bottom: 12px; }
.bookcase { background: var(--shelf-back); border-radius: var(--r-lg); padding: 8px 20px 24px; border: 1px solid var(--line);
  background-image: linear-gradient(180deg, rgba(0,0,0,.03), transparent 40px); }
.shelf { position: relative; padding-top: 30px; }
.shelf-label { position: absolute; top: 8px; left: 2px; display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--ink-2); }
.shelf-label i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }
.shelf-label .muted { font-weight: 400; }
.books { display: flex; align-items: flex-end; gap: 3px; min-height: 196px; padding: 0 10px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.plank { height: 14px; border-radius: 2px; background: linear-gradient(180deg, var(--wood-top), var(--wood) 45%, var(--wood-shadow)); box-shadow: 0 6px 10px -6px rgba(0,0,0,.45); position: relative; }
.plank::after { content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 10px; background: linear-gradient(180deg, rgba(0,0,0,.14), transparent); }
.book { --c: #1e3a5f; position: relative; flex-shrink: 0; width: var(--w, 34px); height: var(--h, 170px); border: 0; padding: 0; cursor: pointer;
  border-radius: 3px 3px 1px 1px; color: #fff; background:
    linear-gradient(90deg, rgba(255,255,255,.16) 0 2px, transparent 2px calc(100% - 3px), rgba(0,0,0,.28) calc(100% - 3px)),
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(0,0,0,.12)), var(--c);
  box-shadow: inset 0 -10px 0 rgba(0,0,0,.12), 1px 0 0 rgba(0,0,0,.18);
  transform-origin: 50% 100%; transition: transform 200ms var(--ease-out); touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.book .b-band { position: absolute; top: 12px; left: 0; right: 0; height: 5px; background: rgba(255,255,255,.35); }
.book[data-status="firmato"] .b-band { background: #f4d98a; }
.book[data-status="inviato"] .b-band { background: #bcd6ff; }
.book[data-status="bozza"] .b-band { background: repeating-linear-gradient(90deg, rgba(255,255,255,.5) 0 4px, transparent 4px 7px); }
.book .b-name { position: absolute; left: 50%; top: 28px; bottom: 34px; writing-mode: vertical-rl; transform: translateX(-50%) rotate(180deg); font-size: 12px; font-weight: 600; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-height: calc(100% - 62px); text-shadow: 0 1px 0 rgba(0,0,0,.25); }
.book .b-code { position: absolute; bottom: 14px; left: 0; right: 0; text-align: center; font-size: 8.5px; opacity: .85; font-variant-numeric: tabular-nums; overflow: hidden; white-space: nowrap; }
.book:active { transform: translateY(-3px) scale(.99); }
@media (hover: hover) and (pointer: fine) { .book:hover { transform: translateY(-8px); } }
.book:focus-visible { outline-offset: 3px; }
.books:has(.shelf-empty) { min-height: 0; padding: 10px; }
.shelf-empty { align-self: center; margin: auto 0; padding: 14px 18px; border: 1.5px dashed color-mix(in srgb, var(--ink-2) 30%, transparent); border-radius: var(--r-md); color: var(--mute); font-size: var(--fs-sm); max-width: 360px; }

/* Faldoni dei documenti di terzi */
.bookcase.binders { background: var(--surface-2); }
.binder { --c: #b9a07a; position: relative; flex-shrink: 0; width: 58px; height: 178px; border: 0; padding: 0; cursor: pointer; border-radius: 4px 4px 2px 2px;
  background: linear-gradient(90deg, rgba(0,0,0,.12), transparent 18%, transparent 82%, rgba(0,0,0,.16)), var(--c); color: #2b2216;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.12), 1px 0 0 rgba(0,0,0,.15); transition: transform 200ms var(--ease-out); user-select: none; -webkit-user-select: none; }
[data-theme="dark"] .binder { --c: #6f5d43; color: #f3ead9; }
.binder .bd-label { position: absolute; top: 18px; left: 9px; right: 9px; bottom: 46px; background: #fbf7ef; border-radius: 2px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); overflow: hidden; }
[data-theme="dark"] .binder .bd-label { background: #e9dfcc; }
.binder .bd-label span { position: absolute; left: 50%; top: 8px; bottom: 8px; writing-mode: vertical-rl; transform: translateX(-50%) rotate(180deg); font-size: 11px; font-weight: 600; color: #2b2216; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.binder .bd-hole { position: absolute; bottom: 18px; left: 50%; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: rgba(0,0,0,.28); box-shadow: inset 0 2px 3px rgba(0,0,0,.4); }
@media (hover: hover) and (pointer: fine) { .binder:hover { transform: translateY(-8px); } }
.binder:active { transform: translateY(-3px); }

/* ---------- Pannello laterale e finestre */
.drawer { position: fixed; inset: 0 0 0 auto; width: min(460px, 100vw); background: var(--surface); border-left: 1px solid var(--line); z-index: 60;
  box-shadow: -24px 0 48px rgba(0,0,0,.18); transform: translateX(104%); transition: transform 260ms var(--ease-drawer); display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); }
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 18px 14px; padding-top: calc(18px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-head h2 { overflow-wrap: anywhere; }
.drawer-body { padding: 18px; overflow: auto; flex: 1; overscroll-behavior: contain; display: grid; gap: 18px; align-content: start; }
.scrim { position: fixed; inset: 0; background: rgba(9, 14, 20, .38); z-index: 59; opacity: 0; pointer-events: none; transition: opacity 200ms ease; }
.scrim.open { opacity: 1; pointer-events: auto; }

dialog.modal { border: 1px solid var(--line); border-radius: var(--r-lg); padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); background: var(--surface); color: var(--ink);
  box-shadow: 0 30px 80px rgba(0,0,0,.28); }
dialog.modal.wide { width: min(980px, calc(100vw - 24px)); }
dialog.modal[open] { animation: modal-in 200ms var(--ease-out); }
dialog.modal::backdrop { background: rgba(9, 14, 20, .42); }
@keyframes modal-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; }
.modal-head p { font-size: var(--fs-sm); color: var(--mute); margin-top: 3px; }
.modal-body { padding: 4px 20px 16px; overflow: auto; max-height: calc(100dvh - 190px); display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); flex-wrap: wrap; }
.modal-foot .left { margin-right: auto; }
.editor-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.editor-area { font-family: "Plex", sans-serif; min-height: 260px; line-height: 1.55; tab-size: 2; }
.edit-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.edit-prev { border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; padding: 14px 16px; max-height: 420px; overflow: auto; }
.syntax-help { font-size: var(--fs-xs); color: var(--mute); line-height: 1.6; }
.syntax-help code { background: var(--surface-2); border: 1px solid var(--line); padding: 0 4px; border-radius: 4px; color: var(--ink-2); }
.ver-list { display: grid; gap: 6px; max-height: 420px; overflow: auto; }
.ver-item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.ver-item[aria-pressed="true"] { border-color: var(--acc); background: var(--acc-soft); }
.ver-item .v-no { font-weight: 600; font-variant-numeric: tabular-nums; }
.ver-item .v-meta { font-size: var(--fs-xs); color: var(--mute); }
.diff { font-size: var(--fs-sm); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px; max-height: 420px; overflow: auto; background: var(--surface-2); }
.diff ins { background: var(--ok-soft); color: var(--ok); text-decoration: none; }
.diff del { background: var(--danger-soft); color: var(--danger); }
.model-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.model-pick label { margin: 0; border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; cursor: pointer; display: grid; gap: 4px; font-weight: 400; color: var(--ink); }
.model-pick input { position: absolute; opacity: 0; }
.model-pick label:has(input:checked) { border-color: var(--acc); box-shadow: inset 0 0 0 1px var(--acc); background: var(--acc-soft); }
.model-pick b { font-size: var(--fs-xs); color: var(--acc); }
.model-pick span { font-size: var(--fs-sm); line-height: 1.35; }

/* ---------- Notifiche */
.toasts { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); display: grid; gap: 8px; z-index: 80; width: min(460px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--ink); color: var(--bg); padding: 11px 14px; border-radius: var(--r-md); font-size: var(--fs-sm); box-shadow: 0 12px 30px rgba(0,0,0,.25);
  display: flex; gap: 10px; align-items: flex-start; animation: toast-in 220ms var(--ease-out); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity 180ms ease, transform 180ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.empty { text-align: center; padding: 28px 16px; color: var(--mute); font-size: var(--fs-sm); }
.empty strong { display: block; color: var(--ink); font-size: var(--fs-md); margin-bottom: 4px; }

/* ---------- Accesso */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth .panel { width: min(400px, 100%); padding: 28px; }
.auth .brand { margin-bottom: 22px; }
.err { color: var(--danger); font-size: var(--fs-sm); margin-top: 6px; }

/* ---------- Impostazioni */
.settings-grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-nav { position: sticky; top: 124px; display: grid; gap: 2px; }
.settings-nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: var(--fs-sm); }
@media (hover: hover) and (pointer: fine) { .settings-nav a:hover { background: var(--surface); color: var(--ink); } }
.theme-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 460px; }
.theme-switch button { border: 1px solid var(--line-2); border-radius: var(--r-md); padding: 10px; background: var(--surface); cursor: pointer; text-align: left; display: grid; gap: 8px; font-size: var(--fs-sm); font-weight: 500; }
.theme-switch button[aria-pressed="true"] { border-color: var(--acc); box-shadow: inset 0 0 0 1px var(--acc); }
.theme-switch .sw { height: 64px; border-radius: 6px; border: 1px solid rgba(0,0,0,.1); display: grid; grid-template-columns: 28% 1fr; overflow: hidden; }
.theme-switch .sw.light { background: #e9edf2; } .theme-switch .sw.light i { background: #fff; }
.theme-switch .sw.dark { background: #0f141b; } .theme-switch .sw.dark i { background: #161d27; }
.sector-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto auto; gap: 10px; align-items: center; }
.sector-row + .sector-row { margin-top: 8px; }
.sector-row input[type="color"] { width: 44px; height: 38px; padding: 2px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); }
.version-item + .version-item { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 12px; }

/* ---------- Mobile */
@media (max-width: 1100px) {
  .layout-contract { grid-template-columns: minmax(0, 1fr); }
  .aside-sticky { position: static; grid-template-columns: minmax(0, 280px) minmax(0, 1fr); align-items: start; }
  .layout-clauses { grid-template-columns: minmax(0, 1fr); }
  .layout-clauses[data-view="tree"] .preview-wrap, .layout-clauses[data-view="preview"] .tree-panel { display: none; }
  .preview-wrap { position: static; height: calc(100dvh - 210px); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .settings-nav { position: static; display: flex; overflow-x: auto; }
}
.view-switch { display: none; }
@media (max-width: 1100px) { .view-switch { display: inline-flex; } }
@media (max-width: 720px) {
  .topbar { padding-left: 14px; padding-right: 14px; gap: 10px; flex-wrap: wrap; }
  .brand > span:last-child { display: none; }
  .switcher { order: 3; flex-basis: 100%; max-width: none; }
  .save-state { display: none; }
  .tabs { position: fixed; top: auto; bottom: 0; left: 0; right: 0; justify-content: space-around; padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-bottom: 0;
    background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px) saturate(160%); }
  .tabs a { display: grid; justify-items: center; gap: 2px; padding: 6px 8px; font-size: 11px; border-radius: 8px; }
  .tabs .tab-ico { display: block; width: 22px; height: 22px; }
  .tabs a[aria-current="page"]::after { display: none; }
  .tabs a[aria-current="page"] { color: var(--acc); }
  main { padding: 16px 12px calc(96px + env(safe-area-inset-bottom)); }
  .grid-2, .grid-3, .edit-split { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .aside-sticky { grid-template-columns: minmax(0, 1fr); }
  .aside-sticky .mini-paper { max-width: 300px; }
  .preview-wrap { height: calc(100dvh - 240px); }
  .preview-scroll { padding: 12px; }
  .sheet { padding: 40px 22px 40px; }
  .sheet .s-head { left: 22px; right: 22px; top: 14px; }
  .sched-row { grid-template-columns: minmax(0, 1fr) auto; }
  .sched-row textarea { grid-column: 1 / -1; grid-row: 2; }
  .att { grid-template-columns: auto minmax(0, 1fr) auto; }
  .att .att-switch { grid-column: 2 / -1; }
  .gen-card { grid-template-columns: minmax(0, 1fr); }
  .doc-rows .hide-sm { display: none; }
  .bookcase { padding: 6px 10px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  .progress span { animation: none; width: 100%; opacity: .6; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar, .tabs { backdrop-filter: none; background: var(--surface); }
}
@media print { .topbar, .tabs, .preview-bar { display: none; } }

/* ---------- Guida contestuale (1.2.0) */
.help-btn { color: var(--acc); }
.help-panel { position: fixed; z-index: 70; width: min(440px, calc(100vw - 16px)); max-height: min(72dvh, 680px); display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: 0 24px 60px rgba(0,0,0,.25);
  opacity: 0; transform: scale(.97); transform-origin: top right; transition: opacity 160ms ease, transform 160ms var(--ease-out); }
.help-panel.open { opacity: 1; transform: none; }
.help-panel.dragging { transition: none; box-shadow: 0 30px 70px rgba(0,0,0,.32); }
.help-head { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-bottom: 1px solid var(--line); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.help-panel.dragging .help-head { cursor: grabbing; }
.help-head h2 { font-size: var(--fs-md); flex: 1; }
.help-grip { width: 14px; height: 14px; background: radial-gradient(circle, var(--line-2) 1.5px, transparent 1.6px) 0 0 / 5px 5px; flex-shrink: 0; }
.help-body { padding: 14px 18px 18px; overflow: auto; overscroll-behavior: contain; font-size: var(--fs-sm); line-height: 1.6; }
.help-body h1 { font-size: var(--fs-lg); margin: 0 0 8px; }
.help-body h2 { font-size: var(--fs-md); margin: 18px 0 6px; color: var(--acc); }
.help-body h3 { font-size: var(--fs-sm); margin: 14px 0 4px; }
.help-body p, .help-body ul, .help-body ol { margin: 0 0 8px; }
.help-body ul, .help-body ol { padding-left: 18px; }
.help-body li + li { margin-top: 3px; }
.help-body table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; font-size: var(--fs-xs); }
.help-body th, .help-body td { border: 1px solid var(--line); padding: 5px 7px; text-align: left; vertical-align: top; }
.help-body th { background: var(--surface-2); }
.help-body code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: .92em; }
@media (max-width: 720px) { .help-panel { width: calc(100vw - 16px); max-height: 62dvh; } }

/* ---------- Clienti (1.3.0) */
.layout-clients { display: grid; grid-template-columns: minmax(280px, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.client-list { list-style: none; margin: 0; padding: 6px; max-height: calc(100dvh - 260px); overflow: auto; }
.client-item { width: 100%; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.client-item[aria-current="true"] { background: var(--acc-soft); }
@media (hover: hover) and (pointer: fine) { .client-item:hover { background: var(--surface-2); } .client-item[aria-current="true"]:hover { background: var(--acc-soft); } }
.c-name { min-width: 0; font-size: var(--fs-sm); font-weight: 500; overflow-wrap: anywhere; line-height: 1.3; }
.c-name small { display: block; font-weight: 400; color: var(--mute); font-size: var(--fs-xs); }
.c-count { font-size: var(--fs-xs); color: var(--mute); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 7px; }
.c-dot { --cc: #3d5a80; width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; background: var(--cc); color: #fff; font-size: 11px; font-weight: 600; flex-shrink: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.c-dot.lg { width: 44px; height: 44px; font-size: 15px; }
.color-in { width: 52px; height: 38px; padding: 2px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--surface); cursor: pointer; }
@media (max-width: 1100px) { .layout-clients { grid-template-columns: minmax(0, 1fr); } .client-list { max-height: 320px; } }

/* ---------- Condizioni economiche (1.4.0) */
.eco-head, .eco-row { display: grid; grid-template-columns: minmax(0, 1fr) 64px 130px 140px 30px; gap: 8px; align-items: center; }
.eco-head { font-size: var(--fs-xs); color: var(--mute); font-weight: 500; }
.eco-row + .eco-row { margin-top: 8px; }
.eco-row input:nth-child(2), .eco-row input:nth-child(3) { text-align: right; font-variant-numeric: tabular-nums; }
.eco-totals { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; }
@media (max-width: 720px) { .eco-head { display: none; } .eco-row { grid-template-columns: minmax(0, 1fr) 70px auto; } .eco-row input:first-child { grid-column: 1 / -1; } .eco-row select { grid-column: 1 / 3; } }
.pill[data-dl="scaduto"] { color: var(--danger); }
.pill[data-dl="imminente"] { color: var(--note); }
.pill[data-dl="rinnovo"] { color: #2f6fd1; }
.pill[data-dl="regolare"] { color: var(--ok); }

/* ---------- Pacchetti (1.7.0) */
.bundle-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.bundle { --bc: #1e3a5f; border: 1px solid var(--line); border-left: 4px solid var(--bc); border-radius: var(--r-md); padding: 12px 14px; display: grid; gap: 8px; background: var(--surface); }
.bundle-top { display: flex; align-items: center; gap: 8px; }
.bundle-top h3 { flex: 1; font-size: var(--fs-sm); }
.bundle-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--bc); }
.bundle-pick { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 12px; }
.bundle-pick fieldset { border: 0; margin: 0; padding: 6px 0; }
.bundle-pick legend { font-size: var(--fs-xs); font-weight: 600; color: var(--acc); padding: 0; margin-bottom: 4px; }
.bundle-pick .check-row { min-height: 30px; margin: 0; font-weight: 400; }
.bundle-pick input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--acc); }

/* ---------- Firmato e integrità (1.8.0 - 1.9.0) */
.hash { border: 0; background: none; padding: 0; margin-top: 2px; font: 500 10.5px/1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; color: var(--mute); cursor: copy; }
.verify { border-radius: var(--r-md); padding: 12px 14px; font-size: var(--fs-sm); overflow-wrap: anywhere; }
.verify.ok { background: var(--ok-soft); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); }
.verify.ko { background: var(--danger-soft); border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); }

/* ---------- Ricerca globale (1.10.0) */
.search-btn { color: var(--mute); min-width: 0; }
.search-btn kbd { font: 500 10px/1 "Plex", sans-serif; border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 4px; color: var(--mute); }
dialog.search-dlg { align-self: start; margin-top: 8vh; }
.search-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.search-head > svg { width: 18px; height: 18px; color: var(--mute); flex-shrink: 0; }
.search-head input { border: 0; box-shadow: none !important; font-size: 17px; padding: 6px 0; background: transparent; }
.search-filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.search-filters select, .search-filters input { width: auto; min-height: 32px; padding-top: 4px; padding-bottom: 4px; }
.sf-date { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; color: var(--mute); }
.search-results { max-height: 60dvh; overflow: auto; padding: 6px 8px 12px; }
.search-results h3 { font-size: var(--fs-xs); color: var(--acc); padding: 10px 8px 4px; }
.search-hint { padding: 18px 10px; font-size: var(--fs-sm); }
.sr-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; color: var(--ink); text-decoration: none; font-size: var(--fs-sm); }
.sr-item small { display: block; color: var(--mute); font-size: var(--fs-xs); overflow-wrap: anywhere; }
.sr-item:focus-visible { background: var(--acc-soft); }
@media (hover: hover) and (pointer: fine) { .sr-item:hover { background: var(--surface-2); } }
.sr-ico { font-size: 9px; font-weight: 600; color: var(--mute); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 4px; }
.sr-date { font-size: var(--fs-xs); white-space: nowrap; }
.c-dot.sm { width: 12px; height: 12px; }
mark { background: color-mix(in srgb, #f59e0b 35%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
@media (max-width: 720px) { .search-btn span, .search-btn kbd { display: none; } .search-btn { width: 36px; padding: 0; border-color: transparent; } dialog.search-dlg { margin-top: 2vh; } }

/* ---------- Confronto revisioni (1.11.0) */
.cmp-sum { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.cmp-n { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px; text-align: center; font-size: var(--fs-xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.cmp-n small { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--mute); }
.cmp-n.add { color: var(--ok); } .cmp-n.del { color: var(--danger); } .cmp-n.chg { color: var(--note); }
.cmp-h { font-size: var(--fs-sm); margin: 16px 0 6px; }
.cmp-list { margin: 0; padding-left: 18px; font-size: var(--fs-sm); }
.cmp-list.add li::marker { content: "+  "; color: var(--ok); } .cmp-list.del li::marker { content: "−  "; color: var(--danger); }
@media (max-width: 720px) { .cmp-sum { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

/* ---------- Revisione legale e pagine esterne (1.12.0) */
.rv-ico { position: relative; color: var(--line-2); }
.rv-ico[data-rv="da_rivedere"] { color: var(--note); } .rv-ico[data-rv="in_discussione"] { color: #2f6fd1; } .rv-ico[data-rv="approvata"] { color: var(--ok); }
.rv-n { position: absolute; top: 1px; right: 0; min-width: 14px; height: 14px; border-radius: 7px; background: var(--ink-2); color: var(--surface); font: 600 9px/14px "Plex", sans-serif; font-style: normal; text-align: center; padding: 0 3px; }
.pill.rv[data-rv="none"] { color: var(--mute); } .pill.rv[data-rv="da_rivedere"] { color: var(--note); } .pill.rv[data-rv="in_discussione"] { color: #2f6fd1; } .pill.rv[data-rv="approvata"] { color: var(--ok); } .pill.rv[data-rv="commento"] { color: var(--mute); }
.rv-thread { display: grid; gap: 8px; max-height: 320px; overflow: auto; }
.rv-msg { border-left: 3px solid var(--line-2); padding: 4px 10px; font-size: var(--fs-sm); }
.rv-msg[data-role="legale"] { border-color: #2f6fd1; } .rv-msg[data-role="admin"] { border-color: var(--acc); } .rv-msg[data-role="cliente"] { border-color: var(--ok); }
.rv-msg p { margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
body.external { background: var(--bg); }
.ext-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; padding-top: calc(14px + env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.ext-head p { font-size: var(--fs-xs); }
.ext-main { max-width: 900px; margin: 0 auto; padding: 20px 16px 80px; }
.ext-sec { font-size: var(--fs-md); color: var(--acc); margin: 26px 0 10px; }
.lw-art { margin-bottom: 12px; display: grid; gap: 12px; }
.lw-art h3 { font-size: var(--fs-md); }
.lw-text { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; }
.rv-form { display: grid; gap: 8px; }

/* ---------- Area cliente (1.13.0 - 1.14.0) */
.ca-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; }
.ca-pdf { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--desk); height: min(78dvh, 900px); }
.ca-pdf iframe { width: 100%; height: 100%; border: 0; }
.ca-check { align-items: flex-start; font-size: var(--fs-sm); font-weight: 400; color: var(--ink); margin: 0; }
.ca-check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--acc); flex-shrink: 0; }
.ca-appr { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; background: var(--surface-2); max-height: 260px; overflow: auto; }
.acc { margin-top: 6px; }

/* ---------- Statistiche (1.15.0) */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 14px 16px; display: grid; gap: 2px; }
.kpi span { font-size: var(--fs-xs); color: var(--mute); }
.kpi strong { font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; }
.kpi small { font-size: var(--fs-xs); color: var(--mute); }
.stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.stats-grid .panel + .panel { margin-top: 0; }
.span-all { grid-column: 1 / -1; }
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 150px) minmax(0, 1fr) 32px; gap: 10px; align-items: center; font-size: var(--fs-sm); }
.bar { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 6px; transform-origin: left; animation: grow 600ms var(--ease-out) both; }
@keyframes grow { from { transform: scaleX(0); } }
.stack-bar { display: flex; height: 18px; border-radius: 9px; overflow: hidden; background: var(--surface-2); gap: 2px; }
.stack-bar i, .legend i { display: block; }
.st-bozza { background: #c8892b; } .st-generato { background: #1e3a5f; } .st-inviato { background: #2f6fd1; } .st-firmato { background: #1d7048; } .st-archiviato { background: #8a94a5; }
.legend { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: var(--fs-sm); }
.legend li { display: flex; align-items: center; gap: 6px; } .legend i { width: 10px; height: 10px; border-radius: 3px; }
.cols { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 6px; height: 170px; align-items: end; }
.col { display: grid; grid-template-rows: auto 1fr auto; height: 100%; text-align: center; font-size: 10.5px; color: var(--mute); }
.col i { align-self: end; display: block; background: var(--acc); border-radius: 4px 4px 0 0; min-height: 2px; transform-origin: bottom; animation: rise 600ms var(--ease-out) both; }
@keyframes rise { from { transform: scaleY(0); } }
.col b { color: var(--ink-2); font-size: 11px; }
@media (max-width: 1100px) { .stats-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Multilingua (1.17.0) */
.t-lang { font-size: 9.5px; font-weight: 600; color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent); border-radius: 4px; padding: 0 4px; flex-shrink: 0; }
.en-box { border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.en-box summary { cursor: pointer; font-weight: 500; font-size: var(--fs-sm); }

/* ---------- Libreria grafica (1.18.0) */
.bookcase { position: relative; background:
    linear-gradient(180deg, rgba(0,0,0,.05), transparent 30px),
    repeating-linear-gradient(90deg, transparent 0 140px, rgba(0,0,0,.025) 140px 141px),
    var(--shelf-back);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 18px 30px -24px rgba(0,0,0,.35); border: 0; }
.books { gap: 2px; perspective: 900px; padding: 0 14px; min-height: 238px; }
.book { border-radius: 4px 4px 2px 2px; overflow: visible;
  background:
    linear-gradient(90deg, rgba(0,0,0,.28) 0, rgba(255,255,255,.18) 3px, transparent 7px, transparent calc(100% - 7px), rgba(255,255,255,.08) calc(100% - 5px), rgba(0,0,0,.35) 100%),
    linear-gradient(180deg, rgba(255,255,255,.10), rgba(0,0,0,.14)), var(--c);
  box-shadow: 1px 0 0 rgba(0,0,0,.25), 2px 3px 6px -3px rgba(0,0,0,.45);
  transition: transform 220ms var(--ease-out), opacity 200ms ease, filter 200ms ease; }
.book::before { content: ""; position: absolute; left: 1px; right: 1px; top: -5px; height: 6px; border-radius: 2px 2px 0 0; background: linear-gradient(180deg, #f6f1e6, #e2d8c4); box-shadow: inset 0 -1px 0 rgba(0,0,0,.15); opacity: .9; }
[data-theme="dark"] .book::before { background: linear-gradient(180deg, #cfc6b4, #b3a993); }
.book.is-dim { opacity: .28; filter: saturate(.3); }
.book .b-rib { position: absolute; top: -5px; right: 5px; width: 6px; height: 26px; background: var(--rib); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 82%, 0 100%); z-index: 2; box-shadow: 0 1px 1px rgba(0,0,0,.2); }
.book .b-band { top: 14px; height: 5px; }
.book .b-deco { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; }
.book[data-type="WEB"] .b-deco { background:
    linear-gradient(180deg, transparent 26px, #d8b76a 26px 28px, transparent 28px 32px, #d8b76a 32px 33px, transparent 33px),
    linear-gradient(0deg, transparent 40px, #d8b76a 40px 41px, transparent 41px 45px, #d8b76a 45px 47px, transparent 47px); }
.book[data-type="HOST"] .b-deco { background: radial-gradient(circle at 50% 50%, #e8eaee 0 3px, #8c939e 3.5px 4.5px, transparent 5px) 50% 34px / 100% 30px repeat-y; opacity: .9; mask: linear-gradient(180deg, transparent 30px, #000 30px calc(100% - 48px), transparent calc(100% - 48px)); }
.book[data-type="SW"] .b-deco { background: repeating-linear-gradient(0deg, rgba(255,255,255,.12) 0 2px, transparent 2px 8px); mask: linear-gradient(90deg, transparent 0 30%, #000 30% 70%, transparent 70%); }
.book[data-type="SOC"] .b-deco { background: repeating-linear-gradient(135deg, rgba(255,255,255,.14) 0 6px, transparent 6px 14px); }
.book[data-type="SAAS"] .b-deco { background: linear-gradient(#f6f3ec, #f6f3ec) 50% 32px / calc(100% - 8px) calc(100% - 82px) no-repeat; border-radius: 3px; }
.book[data-type="SAAS"] .b-name { color: #1f2937; text-shadow: none; }
.book .b-series { position: absolute; bottom: 30px; left: 50%; transform: translateX(-50%); font: 600 8.5px/1 "Plex", sans-serif; background: rgba(0,0,0,.28); color: #fff; border-radius: 6px; padding: 2px 4px; white-space: nowrap; }
@media (hover: hover) and (pointer: fine) { .book:hover { transform: translateY(-10px) rotateY(-8deg); } .book.is-dim:hover { opacity: .6; } }
.bookend { flex-shrink: 0; width: 10px; height: 92px; margin-left: 6px; border-radius: 3px 3px 0 0; background: linear-gradient(90deg, #6c7480, #9aa1ab 40%, #5d646f); box-shadow: 2px 2px 4px rgba(0,0,0,.3); align-self: flex-end; }
.plank { height: 16px; background: linear-gradient(180deg, var(--wood-top) 0, var(--wood) 30%, var(--wood-shadow) 100%), repeating-linear-gradient(90deg, rgba(0,0,0,.05) 0 2px, transparent 2px 9px); background-blend-mode: multiply; }
.lib-legend { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: var(--fs-xs); cursor: pointer; color: var(--ink-2); }
.chip i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.chip[aria-pressed="true"] { border-color: var(--acc); background: var(--acc-soft); color: var(--ink); }
.book-edit { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 14px; align-items: end; }
.book-prev { display: flex; justify-content: center; align-items: flex-end; height: 250px; padding-top: 10px; background: var(--shelf-back); border-radius: var(--r-md); border-bottom: 10px solid var(--wood); }
.book-prev .book { pointer-events: none; }
input[type="range"] { width: 100%; accent-color: var(--acc); }
.binder .bd-strip { position: absolute; top: 8px; left: 9px; right: 9px; height: 6px; border-radius: 2px; background: var(--rib); }
.library .bookcase { border-left: 12px solid var(--wood); border-right: 12px solid var(--wood); border-top: 14px solid var(--wood-top); border-radius: 6px 6px 4px 4px;
  box-shadow: inset 6px 0 10px -6px rgba(0,0,0,.5), inset -6px 0 10px -6px rgba(0,0,0,.5), inset 0 18px 30px -24px rgba(0,0,0,.35), 0 10px 24px -14px rgba(0,0,0,.45); }
.library .bookcase.binders { border-color: #8c939e; border-top-color: #a5abb4; }
[data-theme="dark"] .library .bookcase.binders { border-color: #3a4250; border-top-color: #4a5262; }
@media (max-width: 720px) { .library .bookcase { border-left-width: 6px; border-right-width: 6px; } }

/* ---------- Siti e servizi (1.19.0) */
@media (max-width: 720px) { .tabs { justify-content: flex-start; overflow-x: auto; scrollbar-width: none; gap: 0; } .tabs::-webkit-scrollbar { display: none; } .tabs a { flex: 0 0 auto; min-width: 56px; } }
.site-tree { list-style: none; margin: 0; padding: 6px; }
.site-tree ul { list-style: none; margin: 0 0 0 18px; padding: 0; border-left: 1px solid var(--line); }
.site-kind { font-size: 9.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--mute); }
.kind-group + .kind-group { margin-top: 16px; }
.kind-group h3 { font-size: var(--fs-sm); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.kind-badge { font-size: 10px; font-weight: 600; border-radius: 4px; padding: 1px 6px; color: #fff; }
.kind-badge[data-kind="contratto"] { background: #1e3a5f; } .kind-badge[data-kind="privacy"] { background: #2c5e4f; } .kind-badge[data-kind="consenso"] { background: #7a4b1e; } .kind-badge[data-kind="condizioni"] { background: #4b3a78; }
.book[data-type="PRIV"] .b-deco { background: linear-gradient(90deg, transparent 4px, rgba(255,255,255,.55) 4px 5px, transparent 5px calc(100% - 5px), rgba(255,255,255,.55) calc(100% - 5px) calc(100% - 4px), transparent calc(100% - 4px)); }
.book[data-type="CONS"] .b-deco { background: linear-gradient(rgba(255,255,255,.7), rgba(255,255,255,.7)) 50% calc(100% - 46px) / 12px 12px no-repeat, linear-gradient(var(--c), var(--c)) 50% calc(100% - 46px) / 8px 8px no-repeat; }
.book[data-type="CDU"] .b-deco { background: radial-gradient(circle, rgba(255,255,255,.35) 1px, transparent 1.5px) 0 0 / 6px 6px; mask: linear-gradient(180deg, transparent 24px, #000 24px calc(100% - 40px), transparent calc(100% - 40px)); }
