:root {
  --navy: #1f3a5f;
  --navy-dark: #0f2440;
  --ink: #141b2d;
  --ink-2: #3d4451;
  --muted: #5b6475;
  --line: #e3e6ec;
  --line-2: #eef0f3;
  --field: #d5d9e0;
  --ground: #f5f6f8;
  --card: #ffffff;
  --soft: #eef2f8;
  --blue-bg: #e6edfb; --blue-fg: #1a43a0;
  --orange-bg: #fdeedc; --orange-fg: #8a4200;
  --gray-bg: #eceef1; --gray-fg: #3d4451;
  --teal-bg: #dff3f1; --teal-fg: #0b5c55;
  --purple-bg: #eee8fb; --purple-fg: #5a2ea6;
  --ok-bg: #e3f1ec; --ok-fg: #0b5c43;
  --danger: #8a2b1f;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); font-size: 14px; line-height: 1.45; }
a { color: var(--navy); }
a:hover { color: var(--navy-dark); }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 17px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Barra superiore */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; padding: 12px 24px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 36px; height: 36px; border-radius: 8px; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text b { font-size: 15px; }
.brand-text span { font-size: 12px; color: var(--muted); }
.topbar .spacer { flex: 1; }
.avatar { height: 40px; padding: 0 14px; border-radius: 20px; background: var(--blue-bg); color: var(--navy); display: flex; align-items: center; font-weight: 600; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 24px 64px; display: flex; flex-direction: column; gap: 20px; }

/* Bottoni e campi */
button, .btn { font: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--field); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 500; }
button:hover, .btn:hover { border-color: #b8bfcb; }
button.primary, .btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--navy-dark); }
button.danger { color: var(--danger); }
button.icon { min-height: 32px; padding: 0 8px; font-size: 13px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-2); }
input[type=text], input[type=email], input[type=date], input[type=search], select, textarea { font: inherit; min-height: 40px; padding: 0 12px; border: 1px solid var(--field); border-radius: 8px; background: #fff; color: var(--ink); }
textarea { padding: 10px 12px; }

/* Schede */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-body { padding: 16px 20px; }
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: #f9fafb; padding: 10px 14px; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid var(--line-2); vertical-align: middle; }
td.num { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }

/* Etichette */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.prep { background: var(--orange-bg); color: var(--orange-fg); }
.pill.closed { background: var(--gray-bg); color: var(--gray-fg); }
.tag { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.c-blue { background: var(--blue-bg); color: var(--blue-fg); }
.c-orange { background: var(--orange-bg); color: var(--orange-fg); }
.c-gray { background: var(--gray-bg); color: var(--gray-fg); }
.c-teal { background: var(--teal-bg); color: var(--teal-fg); }
.c-purple { background: var(--purple-bg); color: var(--purple-fg); }

/* Schede di navigazione */
.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 12px 14px; color: var(--ink-2); text-decoration: none; }
.tabs a[aria-current=page] { color: var(--navy); font-weight: 600; border-bottom: 2px solid var(--navy); margin-bottom: -1px; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 8px; }
.crumbs a { text-decoration: none; }

/* Data room: indice + documenti */
.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.split > aside { flex: 1 1 260px; max-width: 340px; }
.split > section { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.tree { padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.tree button.node { justify-content: flex-start; width: 100%; border: none; background: transparent; text-align: left; font-weight: 400; color: var(--ink-2); }
.tree button.node:hover { background: var(--ground); }
.tree button.node.active { background: var(--soft); color: var(--navy); font-weight: 600; }
.tree .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.drop { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border: 2px dashed #c3cad5; border-radius: 12px; background: var(--card); color: var(--ink-2); }
.drop.over { border-color: var(--navy); background: var(--soft); }
.drop input { display: none; }

/* Messaggi */
.notice { padding: 12px 16px; border-radius: 10px; background: var(--soft); color: var(--navy); }
.notice.warn { background: var(--orange-bg); color: var(--orange-fg); }
.notice.err { background: #fbe9e7; color: var(--danger); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: calc(100% - 32px); }

/* Finestre */
dialog { border: none; border-radius: 12px; padding: 0; width: min(560px, calc(100% - 32px)); box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
dialog::backdrop { background: rgba(20,27,45,0.45); }
dialog form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }

/* Visualizzatore PDF */
.viewer { position: fixed; inset: 0; background: #262e3d; z-index: 40; display: flex; flex-direction: column; }
.viewer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 20px; background: #1a2130; color: #fff; }
.viewer-bar button { background: transparent; color: #fff; border-color: #3a4458; }
.viewer-bar .title { font-weight: 600; }
.viewer-bar .sub { font-size: 12px; color: #b8c1d1; }
.viewer-pages { flex: 1; overflow: auto; padding: 24px; display: flex; flex-direction: column; align-items: center; gap: 16px; user-select: none; -webkit-user-select: none; }
.viewer-pages canvas { max-width: 100%; height: auto; background: #fff; box-shadow: 0 8px 32px rgba(0,0,0,0.35); }
.viewer-badge { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 15px; background: #2f3a4f; color: #dce4f2; font-size: 13px; }

/* Accesso esterni */
.login { max-width: 420px; margin: 64px auto; padding: 0 16px; }
.login .card { padding: 28px; display: flex; flex-direction: column; gap: 16px; }

@media print { body { display: none; } }
