/* PMGest: interfaccia da strumento di lavoro. Barra superiore, pagina a colonna, pannelli, tabelle dense. */
:root {
  --bg: #F3F5F8; --surface: #FFFFFF; --sunken: #EBEEF3; --ink: #18212C; --muted: #5D6877; --line: #D9DEE6;
  --accent: #2C5A8C; --accent-ink: #FFFFFF; --accent-soft: #E3ECF6;
  --ext: #2C5A8C; --int: #6A4BA8;
  --ok: #217A45; --ok-soft: #E1F2E7; --warn: #9A6200; --warn-soft: #FBF0D9; --bad: #B23A2A; --bad-soft: #F9E3DF;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161D; --surface: #19202A; --sunken: #141A22; --ink: #E5EAF0; --muted: #98A4B3; --line: #2C3644;
    --accent: #7FAEE0; --accent-ink: #0E1620; --accent-soft: #1D2B3C;
    --ext: #7FAEE0; --int: #B39CEB;
    --ok: #63C68A; --ok-soft: #173023; --warn: #E3B04F; --warn-soft: #33290F; --bad: #F08473; --bad-soft: #3A1C18;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 var(--font); }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14.5px; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-size: 15px; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: var(--ink); color: var(--bg); font: 700 12px var(--mono); }
.topbar-note { color: var(--muted); font-size: 12.5px; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; display: flex; flex-direction: column; gap: 20px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; max-width: 70ch; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn { font: 500 13.5px var(--font); padding: 7px 13px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--surface); }
.seg button { font: 500 13px var(--font); padding: 6px 12px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.badge { font: 600 11px var(--font); letter-spacing: .04em; text-transform: uppercase; padding: 2px 7px; border-radius: 4px; border: 1px solid currentColor; white-space: nowrap; }
.badge.t-esterno { color: var(--ext); }
.badge.t-interno { color: var(--int); }
.pill { display: inline-block; font: 500 12px var(--font); padding: 1px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); white-space: nowrap; }
.pill.st-verde, .pill.s-approvato, .pill.s-superato, .pill.s-incassata, .pill.s-chiusa { background: var(--ok-soft); color: var(--ok); }
.pill.st-giallo, .pill.s-in-bozza, .pill.s-in-analisi, .pill.s-fatturata, .pill.s-rinviata { background: var(--warn-soft); color: var(--warn); }
.pill.st-rosso, .pill.s-non-superato, .pill.s-eccezione, .pill.s-aperta, .pill.s-respinta { background: var(--bad-soft); color: var(--bad); }
.pill.s-in-corso, .pill.s-esecuzione, .pill.s-iniziazione, .pill.s-aperto { background: var(--accent-soft); color: var(--accent); }

/* lista progetti */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card { display: flex; flex-direction: column; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); color: var(--ink); text-decoration: none; min-width: 0; }
.card:hover { border-color: var(--accent); }
.card-top { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.card h3 { font-size: 16px; }
.card-foot { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line); padding-top: 8px; }

.budget { display: flex; flex-direction: column; gap: 6px; }
.budget-line { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px; flex-wrap: wrap; }
.bar { position: relative; height: 10px; background: var(--sunken); border-radius: 3px; overflow: hidden; }
.bar .spent { position: absolute; inset: 0 auto 0 0; background: var(--accent); }
.bar .etc { position: absolute; top: 0; bottom: 0; background: repeating-linear-gradient(135deg, var(--accent-soft) 0 4px, transparent 4px 8px); border: 1px solid var(--accent); border-left: 0; }
.bar .mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.bar .mark.limit { background: var(--bad); }
.nobudget { font-size: 12.5px; color: var(--muted); background: var(--sunken); border-radius: 6px; padding: 6px 10px; }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* dettaglio progetto */
.p-head { display: flex; flex-direction: column; gap: 8px; }
.p-head .row { gap: 10px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.tabs a .count { font: 500 11px var(--mono); background: var(--sunken); border-radius: 999px; padding: 0 6px; margin-left: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }

.stepper { display: flex; gap: 0; overflow-x: auto; padding-bottom: 2px; }
.step { flex: 1 0 96px; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px 8px 0; border-top: 3px solid var(--line); margin-right: 4px; min-width: 96px; }
.step .k { font: 600 11px var(--mono); color: var(--muted); }
.step .n { font-size: 12.5px; line-height: 1.3; }
.step.done { border-top-color: var(--ok); }
.step.current { border-top-color: var(--accent); }
.step.current .n { font-weight: 650; }
.step.exc { border-top-color: var(--bad); }

.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.alerts li { padding: 8px 10px; border-radius: 6px; font-size: 13px; border-left: 3px solid; }
.alerts .al-rosso { background: var(--bad-soft); border-color: var(--bad); }
.alerts .al-giallo { background: var(--warn-soft); border-color: var(--warn); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13.5px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.kv dd.left { text-align: left; }

.actions-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; }
.action { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.action-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.proc { font: 600 11px var(--mono); padding: 1px 6px; border-radius: 4px; background: var(--ink); color: var(--bg); }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.checks li::before { content: "• "; }
.checks .miss { color: var(--bad); }
.checks .warn { color: var(--warn); }
.checks .ok { color: var(--ok); }
.action form { display: flex; flex-direction: column; gap: 8px; }

/* tabelle */
.table-box { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--sunken); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.long { min-width: 220px; max-width: 420px; }
td.acts { white-space: nowrap; text-align: right; }
td.dates { white-space: nowrap; }
tfoot td { font-weight: 600; background: var(--sunken); }
.score { display: inline-block; min-width: 26px; text-align: center; border-radius: 4px; font: 600 12px var(--mono); padding: 1px 4px; background: var(--sunken); }
.score.hi { background: var(--bad-soft); color: var(--bad); }
.score.mid { background: var(--warn-soft); color: var(--warn); }
select.inline { font: 13px var(--font); padding: 2px 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface); color: var(--ink); }

/* modulo */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--surface); color: var(--ink); width: min(680px, calc(100vw - 24px)); max-height: 90vh; }
dialog::backdrop { background: rgba(10, 15, 22, .55); }
.form { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; }
.field .req { color: var(--bad); }
.field .help { font-size: 12px; color: var(--muted); }
input, select, textarea { font: 14px var(--font); padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); width: 100%; }
textarea { min-height: 80px; resize: vertical; }
.errors { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: 10px 12px; font-size: 13px; }
.errors ul { margin: 0; padding-left: 18px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.callout { background: var(--accent-soft); border-radius: 6px; padding: 10px 12px; font-size: 13px; }

/* accesso e amministrazione */
.user-area { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.user-area .who { margin-right: 4px; }
.auth { max-width: 420px; width: 100%; margin: 40px auto 0; display: flex; flex-direction: column; gap: 14px; }
.auth h1 { font-size: 22px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: 500 11.5px var(--mono); padding: 1px 6px; border-radius: 4px; background: var(--sunken); color: var(--ink); border: 1px solid var(--line); }
.perms { border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px 16px; margin: 0; }
.perms legend { font-size: 12.5px; font-weight: 600; padding: 0 4px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; cursor: pointer; }
.check input { width: auto; margin-top: 3px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.steps-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; font-size: 13.5px; }
.secret { margin: 6px 0 4px; padding: 8px 10px; background: var(--sunken); border-radius: 6px; font-size: 15px; letter-spacing: .06em; word-break: break-all; user-select: all; }
form.row select { width: auto; min-width: 240px; max-width: 100%; }

pre.report { background: var(--sunken); border-radius: 6px; padding: 14px; overflow-x: auto; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; margin: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 6px; font-size: 13.5px; z-index: 20; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .wrap { padding-top: 16px; }
  .cards { grid-template-columns: 1fr; }
  .grid-2, .actions-list { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
