:root {
  --bg: #f6f7f9; --surface: #ffffff; --text: #1d2329; --muted: #5f6b76; --border: #dde1e6;
  --accent: #1f5fae; --accent-text: #ffffff; --ok: #1e7a46; --warn: #a15c00; --danger: #b3261e;
  --ok-bg: #e5f4ec; --warn-bg: #fdf1df; --danger-bg: #fbe9e7; --hover: #eef2f7;
  --radius: 6px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1e2125; --text: #e6e8eb; --muted: #9aa4ae; --border: #33383e;
    --accent: #6ea8ff; --accent-text: #0d1420; --ok: #5fcf8c; --warn: #f0b45a; --danger: #ff8a80;
    --ok-bg: #18301f; --warn-bg: #352710; --danger-bg: #3a1a18; --hover: #262a30;
  }
}
* { box-sizing: border-box; }
html { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
h1 { font-size: 1.4rem; margin: 0 0 16px; font-weight: 600; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 8px; font-weight: 600; }
.card > h2:first-child, form > h2:first-of-type { margin-top: 0; }
.muted { color: var(--muted); font-weight: normal; }
.small, small { font-size: .85rem; }
.num, .tiles b, .bars b { font-variant-numeric: tabular-nums; }
.error { color: var(--danger); }
.empty { color: var(--muted); padding: 16px 0; }
code { background: var(--hover); padding: 0 4px; border-radius: 4px; }

.topbar { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 8px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a, .tabs a { text-decoration: none; color: var(--text); padding: 6px 10px; border-radius: var(--radius); }
.topbar nav a:hover, .tabs a:hover { background: var(--hover); }
.topbar nav a[aria-current], .tabs a[aria-current] { background: var(--hover); color: var(--accent); font-weight: 600; }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; margin: 0; }

main { max-width: 1200px; margin: 0 auto; padding: 24px 16px; }
main.wide { max-width: none; }
main.narrow { max-width: 400px; padding-top: 12vh; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.flash { background: var(--ok-bg); color: var(--ok); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 16px; }
.errors { background: var(--danger-bg); color: var(--danger); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 16px; }
.errors ul { margin: 0; padding-left: 20px; }

.btn { display: inline-flex; align-items: center; gap: 4px; font: inherit; padding: 7px 14px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { padding: 3px 10px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions form { margin: 0; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; font-weight: 600; text-decoration: none; background: var(--hover); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }

label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 8px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.login { display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-decoration: none; color: var(--text); display: flex; flex-direction: column; }
.tile:hover { background: var(--hover); }
.tile b { font-size: 2rem; line-height: 1.1; }
.tile span { color: var(--muted); }
.tile.warn b { color: var(--warn); }
.tile.ok b { color: var(--ok); }
.queue { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.queue p { margin: 0; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid3 .card { margin: 0 0 16px; }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.bars li { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr auto; gap: 8px; align-items: center; }
.bars a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; color: var(--text); }
.bars a:hover { color: var(--accent); }
.bar { height: 8px; border-radius: 4px; background: var(--accent); opacity: .7; width: 0; }

.scroll { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; }
.data th, .data td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data th { font-size: .8rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.data th a { color: inherit; text-decoration: none; }
.data tbody tr:hover { background: var(--hover); }
.data.compact td { padding: 3px 8px; font-size: .9rem; }
.results td { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.results tr[data-href] { cursor: pointer; }
.filters th { padding: 4px; }
.filters input { padding: 3px 6px; font-size: .85rem; font-weight: normal; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.searchbar { display: flex; gap: 8px; }
.searchbar input { flex: 1; font-size: 1rem; padding: 8px 10px; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; }

.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 32px 16px; text-align: center; }
.dropzone.over { border-color: var(--accent); background: var(--hover); }
.dropzone .actions { justify-content: center; }
.progress progress { width: 100%; height: 12px; }
td.st-queued { color: var(--ok); } td.st-duplicate { color: var(--muted); } td.st-error { color: var(--danger); } td.st-sending { color: var(--warn); }

.person-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.person-head h1 { margin-bottom: 4px; }
.person-head p { margin: 0 0 16px; }
.split { display: grid; gap: 16px; }
@media (min-width: 1100px) {
  .split { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .viewer { position: sticky; top: 64px; }
}
.viewer iframe { width: 100%; height: 78vh; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.doctext { white-space: pre-wrap; max-height: 78vh; overflow: auto; font-size: .85rem; }
.doc-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.doc-tabs a { font-size: .85rem; padding: 3px 8px; border-radius: var(--radius); border: 1px solid var(--border); text-decoration: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-tabs a[aria-current] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.doc-admin { margin-top: 12px; font-size: .9rem; }
.doc-admin summary { cursor: pointer; color: var(--muted); }
.doc-admin form.inline { display: flex; gap: 8px; align-items: flex-end; margin: 8px 0; flex-wrap: wrap; }
.doc-admin form.inline label { flex-direction: row; align-items: center; gap: 8px; }
.doc-admin form.inline input { width: 6em; }

.fields { display: grid; gap: 8px; grid-template-columns: 1fr; }
/* Person form: one field per row, label on the left. */
@media (min-width: 600px) {
  .editor .fields > label, .editor > label { display: grid; grid-template-columns: 10.5em minmax(0, 1fr); align-items: center; gap: 12px; }
  .editor .fields > label:has(textarea), .editor > label:has(textarea) { align-items: start; }
  .editor .fields > label:has(textarea) > :first-child { padding-top: 6px; }
  .editor input[type=date], .editor select, .editor input[name=province], .editor input[name=years_experience] { max-width: 12em; }
}
.editor label small { display: block; }
fieldset.row { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0 0 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
fieldset.row .fields { width: 100%; }
fieldset.kv { flex-direction: row; align-items: flex-end; }
fieldset.kv label { flex: 1; }
.repeat > template + button { margin-bottom: 8px; }
.editor > label { margin-top: 8px; }
.savebar { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); margin: 16px -16px -16px; padding: 12px 16px;
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; border-radius: 0 0 var(--radius) var(--radius); }
.danger-zone { text-align: right; margin-top: 8px; }

@media (min-width: 768px) { main { padding: 24px; } }

.tags { display: flex; flex-direction: column; gap: 8px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-list:empty::before { content: "Nessuna competenza"; color: var(--muted); font-size: .9rem; }
.tag { display: inline-flex; align-items: center; gap: 4px; background: var(--hover); border: 1px solid var(--border);
  border-radius: 99px; padding: 2px 4px 2px 10px; font-size: .9rem; }
.tag button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 4px; border-radius: 99px; }
.tag button:hover { color: var(--danger); background: var(--danger-bg); }
.tags .muted.small { margin: 0; }

.history { margin-top: 16px; }
.changes td { font-size: .9rem; }
.changes .val { white-space: pre-wrap; max-width: 420px; }
.nowrap { white-space: nowrap; }
.del { color: var(--danger); text-decoration: line-through; text-decoration-thickness: 1px; }
.ins { color: var(--ok); }
div.del, div.ins { white-space: pre-wrap; }
.filters-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.filters-bar label { min-width: 150px; }

.tag .suggest { color: var(--accent); font-size: .85rem; padding: 0 6px; border-radius: 99px; }
.tag .suggest:hover { color: var(--accent-text); background: var(--accent); }
.suggest-all { margin: 0; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.section-head form { margin: 0; }
.section-head input { max-width: 240px; }
.skill-groups td:nth-child(2) { display: flex; flex-wrap: wrap; gap: 4px; }
.skill-groups form.tag { margin: 0; }
.inline-edit { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-edit input { min-width: 12em; }
textarea.autogrow { overflow: hidden; resize: none; }
