:root {
  --bg: #f5f6f8; --panel: #ffffff; --ink: #1d2430; --muted: #667085; --line: #e3e6eb;
  --accent: #1f4e79; --accent-soft: #e6eef7; --ok: #1e7a3c; --ok-soft: #d5f0d8;
  --warn: #8a6d00; --warn-soft: #fff2a8; --err: #a12b1f; --err-soft: #f8c9c4;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --panel: #1a2029; --ink: #e6e9ee; --muted: #9aa4b2; --line: #2c3440;
    --accent: #7fb0e0; --accent-soft: #1f2d3d; --ok: #7fd49a; --ok-soft: #1e3a27;
    --warn: #f0d264; --warn-soft: #3d3514; --err: #f29b90; --err-soft: #4a201b;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
a { color: var(--accent); }

header { display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
header h1 { font-size: 16px; margin: 0 8px 0 0; }
header .spazio { flex: 1; }

.layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 14px; padding: 14px; align-items: start; }
.menu { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; position: sticky; top: 66px; }
.menu a { display: block; padding: 8px 10px; border-radius: 6px; color: inherit; text-decoration: none; }
.menu a:hover { background: var(--bg); }
.menu a.sel { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; min-height: 70vh; min-width: 0; }
main h2 { margin: 0; font-size: 18px; }
@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; padding: 10px; }
  .menu { position: static; display: flex; flex-wrap: wrap; }
  main { padding: 12px; }
}

.barra { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.barra .spazio { flex: 1; }
.muted { color: var(--muted); }

label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
input, textarea, select { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); font: inherit; }
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.modificato { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

button, .btn { font: inherit; cursor: pointer; border-radius: 6px; padding: 7px 14px; text-decoration: none; display: inline-block; }
.primario { background: var(--accent); color: #fff; border: 0; font-weight: 600; }
@media (prefers-color-scheme: dark) { .primario { color: #10161d; } }
.secondario { background: none; border: 1px solid var(--line); color: inherit; }
.pericolo { background: none; border: 1px solid var(--err); color: var(--err); }
button.piccolo, .btn.piccolo { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

table.dati { border-collapse: collapse; width: 100%; font-size: 13px; }
table.dati th, table.dati td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
table.dati th { position: sticky; top: 0; background: var(--panel); font-size: 12px; color: var(--muted); white-space: nowrap; }
table.dati td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.dati tr.link { cursor: pointer; }
table.dati tr.link:hover td { background: var(--accent-soft); }
.tabella { overflow: auto; max-height: calc(100vh - 220px); border: 1px solid var(--line); border-radius: 8px; }
.tabella.bassa { max-height: 320px; }

.kpi { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; margin: 12px 0 18px; }
.kpi a { display: block; text-decoration: none; color: inherit; border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.kpi a:hover { border-color: var(--accent); }
.kpi b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 12.5px; }
.kpi a.allarme b { color: var(--err); }

fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 4px 14px 14px; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }
.campi { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 14px; }
.campi .largo { grid-column: 1 / -1; }
.obbl { color: var(--err); }
.salvabar { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 10px 0 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; z-index: 2; }
h3 { margin: 22px 0 8px; font-size: 14px; }
.vuoto { color: var(--muted); padding: 16px 0; }

.msg { display: inline-block; padding: 5px 10px; border-radius: 6px; font-size: 13px; }
.msg.ok { background: var(--ok-soft); }
.msg.ko { background: var(--err-soft); }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--ink); padding: 18px 20px; width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
#login-dlg::backdrop { background: var(--bg); }
dialog h2 { font-size: 16px; margin: 0 0 6px; }
.schede { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 10px 0; }
.schede button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 8px 10px; }
.schede button.sel { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.due { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 600px) { .due { grid-template-columns: 1fr; } }

details.storico summary { cursor: pointer; font-weight: 600; margin-top: 22px; }
details.storico li { margin: 4px 0; font-size: 13px; }
