:root {
  --bg: #f4f6f8; --card: #ffffff; --ink: #1e2a35; --muted: #6b7a89;
  --line: #dde4ea; --primary: #145a8a; --primary-ink: #ffffff;
  --ok: #1e7d4f; --warn: #b26a00; --info: #145a8a; --neutral: #5a6b7a;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--ink); }
main { max-width: 1180px; margin: 1.2rem auto; padding: 0 1rem; }
a { color: var(--primary); text-decoration: none; }

.topbar { display: flex; align-items: center; gap: 1.2rem; background: var(--card);
  border-bottom: 1px solid var(--line); padding: .6rem 1.2rem; position: sticky; top: 0; z-index: 5; }
.topbar .brand a { font-weight: 700; color: var(--ink); font-size: 1.05rem; }
.topbar nav { display: flex; gap: .9rem; }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.badge-user { background: #e8f0f7; border-radius: 999px; padding: .2rem .7rem; font-size: .85rem; }

.btn { border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 7px; padding: .45rem .9rem; font-size: .9rem; cursor: pointer; }
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-small { padding: .25rem .6rem; font-size: .8rem; }
.btn-ghost { background: transparent; }
.inline { display: inline; }

.flash { max-width: 1180px; margin: .8rem auto 0; padding: 0 1rem; }
.flash p { background: #fff6df; border: 1px solid #ecd9a0; border-radius: 7px; padding: .5rem .8rem; }

.schede { display: flex; gap: .3rem; margin-bottom: .8rem; border-bottom: 1px solid var(--line); }
.schede .scheda { padding: .45rem .9rem; border-radius: 8px 8px 0 0; color: var(--muted);
  font-size: .92rem; border: 1px solid transparent; border-bottom: none; }
.schede .scheda:hover { background: #eef3f8; }
.schede .scheda.attiva { background: var(--card); border-color: var(--line); color: var(--ink);
  font-weight: 600; margin-bottom: -1px; }
.schede .conta { background: #e8f0f7; border-radius: 999px; padding: .05rem .45rem;
  font-size: .8rem; margin-left: .25rem; }

.stats { display: flex; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.stat { flex: 1; min-width: 140px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem 1rem; color: var(--ink); }
.stat.active { border-color: var(--primary); box-shadow: 0 0 0 2px #145a8a22; }
.stat .num { display: block; font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: .85rem; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type=text], .filters select, .azioni select, .nota-form input, .login-box input, .login-box select {
  border: 1px solid var(--line); border-radius: 7px; padding: .45rem .6rem; font-size: .9rem; background: var(--card); }
.filters input[type=text] { min-width: 260px; }
.chk { font-size: .85rem; color: var(--muted); }

.tabella { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tabella th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: .55rem .7rem; border-bottom: 1px solid var(--line); background: #fafbfc; }
.tabella td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.riga { cursor: pointer; }
.riga:hover { background: #f0f5fa; }
.ellipsis { max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: Consolas, monospace; font-size: .85rem; }
.center { text-align: center; }
.muted { color: var(--muted); }
.footer-note { margin-top: 1rem; font-size: .85rem; }

.tag { border-radius: 999px; padding: .15rem .6rem; font-size: .78rem; color: #fff; white-space: nowrap; }
.tag-da_assegnare { background: var(--warn); }
.tag-assegnata { background: var(--info); }
.tag-in_lavorazione { background: var(--neutral); }
.tag-chiusa { background: var(--ok); }
.tag-anomalia { background: #c62828; }

.verso { border-radius: 6px; padding: .1rem .45rem; font-size: .78rem; font-weight: 600;
  white-space: nowrap; display: inline-block; }
.verso-entrata { background: #e4f1e8; color: #1e7d4f; }
.verso-uscita { background: #fdeee0; color: #b26a00; }
.mezzo { background: #eef3f8; color: var(--muted); border-radius: 6px; padding: .05rem .4rem;
  font-size: .74rem; margin-left: .3rem; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.voce-azione { font-weight: 600; }

.modulo { display: flex; flex-direction: column; gap: .9rem; margin-top: 1rem; }
.modulo label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.modulo input[type=text], .modulo input[type=datetime-local], .modulo select, .modulo input[type=file] {
  border: 1px solid var(--line); border-radius: 7px; padding: .45rem .6rem;
  font-size: .95rem; color: var(--ink); background: var(--card); }
.riga-campi { display: flex; gap: .9rem; flex-wrap: wrap; }
.riga-campi > label { flex: 1; min-width: 200px; }
.modulo .largo { width: 100%; }
.modulo .cresce { flex: 2; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 1.2rem 1.4rem; margin-top: .8rem; }
.card-head { display: flex; align-items: center; gap: 1rem; }
.card h1 { margin: 0; font-size: 1.3rem; }
.card h2 { font-size: 1rem; margin: 1.3rem 0 .5rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dettagli { display: grid; grid-template-columns: 130px 1fr; gap: .3rem .8rem; margin: .8rem 0 0; }
.dettagli dt { color: var(--muted); font-size: .85rem; }
.dettagli dd { margin: 0; }
.allegati, .eventi { list-style: none; padding: 0; margin: 0; }
.allegati li, .eventi li { padding: .3rem 0; border-bottom: 1px dashed var(--line); font-size: .9rem; }
.azioni { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.nota-form { display: flex; gap: .5rem; margin-top: .6rem; }
.nota-form input { flex: 1; }

.form-riga { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin: .5rem 0 0; }
.form-riga input[type=text], .form-riga input[type=email], .form-riga input[type=password], .form-riga select,
.tabella input[type=password], .tabella select {
  border: 1px solid var(--line); border-radius: 7px; padding: .4rem .6rem; font-size: .88rem; background: var(--card); }
.card h3 { font-size: .9rem; margin: 1.1rem 0 .3rem; color: var(--muted); }
.azioni-cella { display: flex; gap: .35rem; white-space: nowrap; }
.cond { background: #eef3f8; border-radius: 6px; padding: .1rem .45rem; margin-right: .3rem;
  font-size: .82rem; display: inline-block; }
.giorni { display: flex; gap: .5rem; flex-wrap: wrap; }
.tabella-stretta { max-width: 320px; }
.card-attenzione { border-color: #e6c9a8; background: #fffdf9; }
.card-stretta { max-width: 640px; margin-left: auto; margin-right: auto; }
.passi { padding-left: 1.2rem; }
.passi li { margin-bottom: 1.1rem; line-height: 1.5; }
.qr { background: #fff; padding: .6rem; display: inline-block; border: 1px solid var(--line);
  border-radius: 8px; margin: .6rem 0; }
.qr svg { width: 210px; height: 210px; display: block; }
.chiave { background: #f2f6fa; border-radius: 7px; padding: .5rem .7rem; letter-spacing: .12em;
  display: inline-block; }
.codici { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; margin-top: 1rem; }
.codici span { background: #f6f9fc; border: 1px solid var(--line); border-radius: 7px;
  padding: .5rem; text-align: center; font-size: 1.05rem; letter-spacing: .08em; }
@media print { .topbar, .azioni, .flash { display: none !important; } }
.btn-attenzione { background: #b26a00; border-color: #b26a00; color: #fff; }
.btn-attenzione:hover { border-color: #8f5500; }
.stato-ascolto { list-style: none; padding: .4rem .7rem; margin: .4rem 0; font-size: .88rem;
  background: #f6f9fc; border: 1px solid var(--line); border-radius: 7px; }
.stato-ascolto li { padding: .12rem 0; }
.esito { background: #eef6f0; border: 1px solid #cfe3d6; border-radius: 7px;
  padding: .5rem .8rem; font-size: .9rem; }

.vis-form { display: flex; flex-direction: column; gap: .3rem; align-items: flex-start; }
.vis-form .elenco-aziende { display: none; padding: .3rem .5rem; background: #f6f9fc;
  border: 1px solid var(--line); border-radius: 7px; }
.vis-form .elenco-aziende label { display: block; }

.login-box { max-width: 360px; margin: 8vh auto; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 2rem; }
.login-box h1 { margin: 0 0 .2rem; }
.login-box label { display: block; margin: .9rem 0; font-size: .9rem; color: var(--muted); }
.login-box input, .login-box select { width: 100%; margin-top: .3rem; }
.login-box .btn { width: 100%; margin-top: .5rem; }

@media (max-width: 720px) {
  .ellipsis { max-width: 130px; }
  .dettagli { grid-template-columns: 1fr; }
}
