/* Sistema CMD Teramo-Atri */
:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --ink: #1d2430;
  --ink-2: #5b6474;
  --line: #e2e5ea;
  --line-2: #eef0f3;
  /* colori del logo Missio / CMD */
  --missio-red: #e2001a;
  --missio-blue: #0062aa;
  --missio-yellow: #f5d200;
  --missio-green: #009035;
  --primary: #c8161d;
  --primary-ink: #ffffff;
  --primary-soft: #fdecec;
  --ok: #007a2e;
  --ok-soft: #e7f5ec;
  --no: #c40017;
  --no-soft: #fdeaec;
  --warn: #8a6a00;
  --warn-soft: #fff8d6;
  --info-soft: #fdf1f1;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.55rem; margin: 0; font-weight: 650; letter-spacing: -.01em; color: var(--ink); }
h2 { font-size: 1.08rem; margin: 0 0 .8rem; font-weight: 650; }
h3 { font-size: .98rem; margin: 1.2rem 0 .6rem; }
code { background: var(--line-2); padding: .05rem .35rem; border-radius: 4px; font-size: .9em; }
code.big { font-size: 1.15rem; padding: .2rem .5rem; letter-spacing: .04em; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--no); }
[hidden] { display: none !important; }

/* ---------- barra superiore */
.topbar {
  display: flex; align-items: center; gap: 1.75rem; padding: .45rem 1.5rem;
  background: #fff; color: var(--ink); position: sticky; top: 0; z-index: 10;
}
.stripe { display: flex; height: 4px; position: sticky; top: 65px; z-index: 10; }
.stripe span { flex: 1; }
.stripe span:nth-child(1) { background: var(--missio-green); }
.stripe span:nth-child(2) { background: var(--missio-blue); }
.stripe span:nth-child(3) { background: var(--missio-yellow); }
.stripe span:nth-child(4) { background: var(--missio-red); }
.stripe.fixed { position: fixed; top: 0; left: 0; right: 0; height: 6px; }
.brand { display: flex; align-items: center; }
.brand-logo { height: 52px; width: auto; display: block; }
.nav { display: flex; gap: .1rem; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--ink-2); padding: .5rem .75rem; border-radius: 6px; font-weight: 550; font-size: .93rem; position: relative; }
.nav a:hover { color: var(--ink); background: var(--line-2); text-decoration: none; }
.nav a.active { color: var(--primary); }
.nav a.active::after { content: ""; position: absolute; left: .75rem; right: .75rem; bottom: -.48rem; height: 3px; background: var(--primary); border-radius: 2px 2px 0 0; }
.user { display: flex; align-items: center; gap: .6rem; font-size: .88rem; }
.user a { color: var(--ink); font-weight: 600; }
.user .role { color: var(--ink-2); }
.nav-toggle { display: none; background: none; border: 0; color: var(--ink); font-size: 1.4rem; cursor: pointer; }
button.link { background: none; border: 0; color: var(--primary); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
form.inline { display: inline; margin: 0; }

.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem; }
.footer { text-align: center; color: var(--ink-2); font-size: .8rem; padding: 1rem 0 2rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; flex-wrap: wrap; }

/* ---------- card e griglie */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid2.wide-left { grid-template-columns: 1.6fr 1fr; align-items: start; }
.grid2.tight { gap: .6rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; }
.span2 { grid-column: span 2; }

/* ---------- indicatori */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; display: flex; flex-direction: column; gap: .2rem; color: var(--ink); box-shadow: var(--shadow); }
a.kpi:hover { border-color: var(--primary); text-decoration: none; }
.kpi-label { font-size: .82rem; color: var(--ink-2); font-weight: 500; }
.kpi { border-top: 3px solid var(--line); }
.kpi-value { font-size: 1.55rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: .9rem; color: var(--ink-2); font-weight: 500; }
.kpi-sub { font-size: .82rem; color: var(--ink-2); }
.bar { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.bar > span { display: block; height: 100%; background: var(--missio-green); border-radius: 99px; }

/* ---------- tabelle */
.table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table th, .table td { padding: .55rem .6rem; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: top; }
.table thead th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); font-weight: 600; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 69px; }
.table tfoot th { border-top: 2px solid var(--line); border-bottom: 0; }
.table.compact th, .table.compact td { padding: .35rem .5rem; }
.table .num { text-align: right; white-space: nowrap; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f8fafc; }
.table tr.group th { background: var(--line-2); font-size: .85rem; padding: .45rem .6rem; text-transform: none; letter-spacing: 0; }
.table tr.annullato td { color: var(--ink-2); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.table tr.saldo-row td { background: #fafbfc; font-weight: 600; }
.table tr.disattivo td { color: var(--ink-2); }
.table input, .table select { width: 100%; }
.cell-ok { color: var(--ok); }
.cell-no { color: var(--ink-2); }
.monit td.cell-no { color: var(--no); font-size: .85rem; }
.monit td.cell-ok { background: var(--ok-soft); }
.actions { text-align: right; }

/* ---------- schede */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .6rem .95rem; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-amount { font-variant-numeric: tabular-nums; color: var(--ink-2); font-weight: 400; margin-left: .3rem; font-size: .88rem; }

/* ---------- moduli */
.form label, .filters label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--ink-2); font-weight: 500; margin-bottom: .75rem; }
.form label small { font-weight: 400; }
.form label.check, .filters label.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--ink); }
input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfd4dc; border-radius: 7px; padding: .5rem .6rem; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(200, 22, 29, .2); border-color: var(--primary); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input[type=checkbox] { width: auto; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select { background: var(--line-2); }
.filters { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.filters label { margin-bottom: 0; }
.filters .grow { flex: 1; min-width: 180px; }
.row-btn { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .5rem .95rem; border-radius: 7px; border: 1px solid #cfd4dc;
  background: #fff; color: var(--ink); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #f6f7f9; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: #a51117; }
.btn.danger { color: var(--no); border-color: #f1b8b3; }
.btn.ghost { border-color: transparent; color: var(--primary); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.icon { padding: .4rem .65rem; font-size: 1.1rem; line-height: 1; }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); border-color: #b9e1c9; }
.alert-error { background: var(--no-soft); border-color: #f5c2bd; }
.alert-warn { background: var(--warn-soft); border-color: #ecd56a; }
.alert-info { background: var(--info-soft); border-color: #f3c4c6; }
.badge { display: inline-block; font-size: .72rem; padding: .1rem .45rem; border-radius: 99px; background: var(--line-2); color: var(--ink-2); font-weight: 600; text-decoration: none; vertical-align: middle; }
.badge.info { background: var(--info-soft); color: var(--primary); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.dl { display: grid; grid-template-columns: 9rem 1fr; gap: .4rem .8rem; margin: 0; }
.dl dt { color: var(--ink-2); font-size: .88rem; }
.dl dd { margin: 0; }

/* ---------- movimento */
.tipo-switch { display: inline-flex; border: 1px solid #cfd4dc; border-radius: 8px; overflow: hidden; margin-bottom: 1rem; }
.tipo-switch label { flex-direction: row; margin: 0; padding: .5rem 1.1rem; cursor: pointer; color: var(--ink); font-weight: 550; font-size: .93rem; }
.tipo-switch label + label { border-left: 1px solid #cfd4dc; }
.tipo-switch input { display: none; }
.tipo-switch label.on { background: var(--missio-blue); color: #fff; }
.riga { border: 1px solid var(--line); border-radius: 8px; padding: .75rem .75rem 0; margin-bottom: .6rem; background: #fcfcfd; }
.riga-main { display: grid; grid-template-columns: 1.2fr 1.6fr .6fr auto; gap: .6rem; align-items: end; }
.riga-main .btn-del { margin-bottom: .75rem; }
.riga-extra { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; }
.riga-extra label { flex: 1 1 140px; }
.riga-extra .f-note { flex: 3 1 220px; }
.riga-extra .f-cum { flex: 2 1 220px; }
.riga-extra .badge { margin-bottom: .9rem; }
.righe-foot { display: flex; justify-content: space-between; align-items: center; margin: .4rem 0 1.2rem; }
.totale { font-size: 1.05rem; }
.totale strong { font-variant-numeric: tabular-nums; margin-left: .4rem; }
.inline-actions { margin: 0 0 .5rem; }

/* ---------- accesso */
body.auth { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 1rem; background: var(--bg); }
.auth-box { background: #fff; border-radius: 12px; padding: 2rem 2.2rem; width: 100%; max-width: 400px; border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(16,24,40,.08); }
.auth-box.wide { max-width: 560px; }
.auth-box h1 { font-size: 1.2rem; margin: 1.2rem 0 1rem; color: var(--ink); text-align: center; }
.brand-big { display: flex; justify-content: center; }
.brand-big img { height: 120px; width: auto; }

/* ---------- schermi stretti */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; padding: .4rem 1rem; gap: .6rem; }
  .brand-logo { height: 40px; }
  .stripe { top: 0; position: relative; }
  .nav a.active::after { display: none; }
  .nav a.active { background: var(--primary-soft); }
  .nav-toggle { display: block; margin-left: auto; }
  .nav, .user { display: none; width: 100%; }
  body.nav-open .nav { display: flex; flex-direction: column; }
  body.nav-open .user { display: flex; padding: .4rem .75rem; }
  .container { padding: 1rem; }
  .grid2, .grid2.wide-left { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .riga-main { grid-template-columns: 1fr auto; }
  .riga-main .f-voce, .riga-main .f-ente { grid-column: 1 / -1; }
  .righe-foot { flex-wrap: wrap; gap: .6rem; }
  .table thead th { position: static; }
  .card { padding: 1rem; overflow-x: auto; }
}
@media (max-width: 560px) {
  .grid4 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
}
@media print {
  .nav, .user, .nav-toggle, .stripe, .filters, .row-btn, .footer, .btn { display: none !important; }
  .topbar { position: static; }
  body { background: #fff; }
  .card { border: 0; box-shadow: none; padding: 0; }
}
.riga select, .riga input { width: 100%; max-width: 100%; }
.riga-extra label, .riga-main label { min-width: 0; }

/* ---------- annuario */
.topbar { border-bottom: 3px solid var(--primary); }
.brand { gap: .7rem; }
.brand-logo { height: 48px; width: auto; }
.stripe { display: none; }
.table thead th { top: 64px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; color: var(--ink); padding: .35rem 0; }
.brand-text small { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); }
.brand-text strong { font-size: 1.05rem; color: var(--primary); }
.brand-text.big { align-items: center; margin-top: .4rem; }
body.auth { border-top: 6px solid var(--primary); }
.brand-text.big small { font-size: .8rem; }
.brand-text.big strong { font-size: 1.5rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; color: var(--ink); box-shadow: var(--shadow); }
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile-n { font-size: 1.6rem; font-weight: 650; color: var(--primary); font-variant-numeric: tabular-nums; }
.tile-l { color: var(--ink-2); font-size: .9rem; }
/* menu compatto: tutte le voci su una riga */
.topbar { gap: 1.1rem; }
.nav a { padding: .45rem .5rem; font-size: .9rem; }
.nav a.active::after { left: .5rem; right: .5rem; }
@media (max-width: 1360px) { .user .role { display: none; } }
@media (max-width: 1180px) { .brand-text small { display: none; } .nav a { padding: .45rem .4rem; font-size: .86rem; } }
/* ---------- gestione interventi */
.badge.stato-aperto { background: var(--rosso-tenue, #fdecec); color: #a51117; }
.badge.stato-in_carico { background: #fff3d6; color: #8a5a00; }
.badge.stato-risolto { background: #e6f4ea; color: #1e6b35; }
.desc { white-space: pre-wrap; background: #fafafa; border: 1px solid var(--line); border-radius: 8px; padding: 1rem; margin: 0; font: inherit; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .5rem 0 .5rem 1rem; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .85rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.actions-bar { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
