:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --ok: #1d7a46;     --ok-bg: #e7f5ed;
  --ko: #b42318;     --ko-bg: #fdecea;
  --warn: #8a5a00;   --warn-bg: #fff4dc;
  --info: #3b4a66;   --info-bg: #eef1f6;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c; --surface: #1c2027; --text: #e7e9ee; --muted: #9aa3b2; --line: #2c323c;
    --accent: #6d8ff0; --accent-ink: #0d1117;
    --ok: #5cc98b; --ok-bg: #16281e; --ko: #f08a80; --ko-bg: #2e1715;
    --warn: #f0c060; --warn-bg: #2b2412; --info: #b3bfd6; --info-bg: #222833;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); }
code, .mono { font-family: ui-monospace, Consolas, monospace; font-size: .9em; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem 1.25rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.top nav { display: flex; gap: 1rem; align-items: center; }
.top nav a { text-decoration: none; }
.who { color: var(--muted); font-size: .9em; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1.25rem; }
.card.narrow { max-width: 420px; margin: 3rem auto; }
.muted { color: var(--muted); }
.note { color: var(--muted); font-size: .9em; margin: .5rem 0 0; }
.crumbs { margin: 0 0 .5rem; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.head-row h1 { margin: 0; }
.meta { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; color: var(--muted); }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.tile { display: flex; flex-direction: column; gap: .35rem; padding: 1.25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--text); transition: border-color .15s, transform .15s; }
a.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile-ico { font-size: 1.6rem; color: var(--accent); }
.tile-title { font-weight: 700; font-size: 1.1rem; }
.tile-sub { color: var(--muted); font-size: .9em; }
.tile-links { display: flex; flex-direction: column; gap: .4rem; margin-top: auto; padding-top: .75rem; }
.tile-links .btn { display: flex; justify-content: space-between; align-items: center; padding: .45rem .75rem; font-size: .9em; }
.tile-links .btn::after { content: "↗"; font-weight: 400; opacity: .6; }
.tile-links .btn:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.wa-esito { margin: 0; font-weight: 600; font-size: .92em; }
.wa-esito.ok { color: var(--ok); }
.wa-esito.ko { color: var(--ko); }
.wa-esito.warn { color: var(--warn); }
.wa-list { list-style: none; margin: .35rem 0 0; padding: 0; font-size: .88em; max-height: 220px; overflow-y: auto; }
.wa-list li { padding: .3rem 0; border-top: 1px solid var(--line); }
.wa-list li:first-child { border-top: 0; }
.wa-list .badge { margin-left: .35rem; }
.wa-list small { display: block; color: var(--muted); font-family: ui-monospace, Consolas, monospace; word-break: break-word; }
.hd-titolo { margin: .35rem 0 0; font-weight: 600; font-size: .92em; }
.hd-titolo:first-of-type { margin-top: 0; }
.att-cont { list-style: none; margin: .35rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: .3rem .75rem; font-size: .88em; }
.att-cont .badge { margin-left: .15rem; }
.tile.placeholder { border-style: dashed; background: transparent; }
/* card Tabellone CRM: voci una sotto l'altra, valori incolonnati a destra */
.crm-list { list-style: none; margin: .2rem 0 0; padding: 0; font-size: .9em; }
.crm-list li { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .22rem 0; }
.crm-list .badge { min-width: 2.2rem; text-align: center; font-variant-numeric: tabular-nums; font-size: .85em; }

/* form */
form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 600; font-size: .92em; }
form label small { font-weight: 400; color: var(--muted); }
textarea { resize: vertical; min-height: 5rem; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0 0 1.25rem; padding: 1rem 0 0; }
fieldset:first-of-type { border-top: 0; padding-top: 0; }
legend { font-weight: 700; padding: 0 .25rem 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.grid .span2 { grid-column: span 2; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
label.full { margin-top: 1rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
label.check input { width: auto; }
.flags { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .5rem 1rem; }
.card.narrow form { display: flex; flex-direction: column; gap: 1rem; }
form.inline { display: inline; margin-left: .5rem; }

.btn { display: inline-block; font: inherit; font-weight: 600; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); text-decoration: none; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.big { padding: .75rem 1.4rem; font-size: 1.05em; }
.btn:disabled { opacity: .6; cursor: progress; }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: .75rem; }

.danger { margin-top: 2rem; padding: 1rem; border: 1px solid var(--ko); border-radius: var(--radius); background: var(--ko-bg); display: flex; flex-direction: column; gap: .75rem; }
.danger h2 { color: var(--ko); margin: 0; }
.danger p { margin: 0; }
.danger-btn { background: var(--ko); border-color: var(--ko); color: #fff; align-self: flex-start; }

/* alert e badge */
.alert { padding: .85rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid transparent; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: var(--ok); }
.alert.ko   { background: var(--ko-bg);   color: var(--ko);   border-color: var(--ko); }
.alert.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.alert code { color: inherit; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8em; font-weight: 600; white-space: nowrap; }
.badge.ok    { background: var(--ok-bg);   color: var(--ok); }
.badge.ko    { background: var(--ko-bg);   color: var(--ko); }
.badge.warn  { background: var(--warn-bg); color: var(--warn); }
.badge.info, .badge.muted { background: var(--info-bg); color: var(--info); }
.pill { font-family: ui-monospace, Consolas, monospace; font-size: .82em; padding: .1rem .45rem; border-radius: 6px; background: var(--info-bg); color: var(--info); }

/* esito operazioni */
.runlog { list-style: none; margin: .5rem 0 0; padding: 0; color: var(--text); }
.runlog li { padding: .4rem 0; border-top: 1px solid var(--line); }
.runlog li:first-child { border-top: 0; }
.runlog .esito { display: inline-block; min-width: 4.5rem; font-weight: 700; font-size: .8em; }
.runlog li.ok .esito { color: var(--ok); }
.runlog li.ko .esito { color: var(--ko); }
.runlog li.info .esito { color: var(--info); }
pre { white-space: pre-wrap; word-break: break-word; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; margin: .4rem 0 0; font-size: .85em; max-height: 340px; overflow: auto; }

/* tabelle */
.filter-row { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filter { max-width: 360px; }
.filter-row label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; white-space: nowrap; }
.filter-row label.check input { width: auto; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; font-size: .92em; }
table.list th { text-align: left; font-size: .8em; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .65rem .75rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: .6rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tbody tr:last-child td { border-bottom: 0; }
#lista tbody tr { cursor: pointer; }
#lista tbody tr:hover { background: var(--bg); }
td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.scaduto { color: var(--ko); font-weight: 600; }
td.empty { text-align: center; color: var(--muted); padding: 2rem; }
table.log td { font-size: .9em; }
details summary { cursor: pointer; color: var(--muted); font-size: .85em; }

/* scadenze */
.scad-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: 0; }
.scad-form input[type=date] { width: auto; padding: .35rem .5rem; }
.scad-form .btn { padding: .35rem .8rem; }
.btn.primary:disabled { background: var(--surface); border-color: var(--line); color: var(--muted); }
#scad tbody tr:target { background: var(--warn-bg); }
main > .alert.ok, main > .alert.ko { position: sticky; top: .5rem; z-index: 5; }
td .badge + .badge, td a + .badge { margin-left: .35rem; }

/* attivazioni: pagina piu' larga, cosi' la tabella sta tutta senza barra orizzontale */
main:has(#att) { max-width: 1520px; }
table.att td:first-child { min-width: 150px; }
table.att th.c, table.att td.c { text-align: center; }
table.att td { vertical-align: middle; }
table.att th .sort { font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
table.att th .sort:hover, table.att th .sort.attivo { color: var(--accent); text-decoration: underline; }
.att-chk { width: 1.15rem; height: 1.15rem; cursor: pointer; accent-color: var(--ok); }
.spunta { display: inline-flex; align-items: center; justify-content: center; width: 1.5rem; height: 1.5rem; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-weight: 700; cursor: default; }
.att-note { min-width: 320px; font-size: .9em; padding: .35rem .5rem; min-height: 0; resize: vertical; }
.att-chk:disabled { cursor: not-allowed; opacity: .45; }
.att-note[readonly] { background: transparent; border-style: dashed; }
.att-note.salvata { outline: 2px solid var(--ok); }
.att-note.errore { outline: 2px solid var(--ko); }

/* server */
.add-server { display: flex; gap: .5rem; align-items: center; }
.add-server input { width: 9rem; }
.cell-form { display: flex; gap: .4rem; align-items: center; margin: 0; }
.cell-form input, .cell-form select { padding: .35rem .5rem; min-width: 0; }
.cell-form .btn { padding: .35rem .7rem; }
table.srv td { vertical-align: middle; }
a.rdp { text-decoration: none; white-space: nowrap; }
a.rdp:hover strong { text-decoration: underline; }#srv tbody tr:target { background: var(--warn-bg); }

/* utenti */
#utenti tbody tr { cursor: pointer; }
#utenti tbody tr:hover, #utenti tbody tr.sel { background: var(--bg); }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.perm-gruppo h3 { font-size: .95rem; margin: 0 0 .4rem; }
.perm-gruppo label.check { margin: .2rem 0; }
#permessi.spento .perm-grid { opacity: .45; }
fieldset.adm { border: 1px dashed var(--warn); border-radius: var(--radius); padding: .75rem 1rem; margin: 1rem 0; background: var(--warn-bg); }
fieldset.adm legend { padding: 0 .35rem; color: var(--warn); }
fieldset.adm .note { margin: 0 0 .5rem; }

@media (max-width: 640px) {
  .grid .span2 { grid-column: auto; }
  .grid3 { grid-template-columns: 1fr; }
  .top { flex-wrap: wrap; }
}
