:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2f6fed;
  --accent-dark: #1f56c4;
  --ok: #148a4e;
  --ok-bg: #e6f5ec;
  --warn: #b45309;
  --warn-bg: #fdf3e3;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
}
.topbar-inner {
  max-width: 1050px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 22px;
  height: 58px;
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 18px; flex: 1; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a.active, .nav a:hover { color: var(--text); text-decoration: none; }
.topbar .user { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 12px; }

.container { max-width: 1050px; margin: 26px auto; padding: 0 20px; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 18px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat { text-align: center; }
.stat .num { font-size: 30px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
.stat.ok .num { color: var(--ok); }
.stat.warn .num { color: var(--warn); }
.stat.danger .num { color: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }
.right { text-align: right; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; color: #fff; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--border); }
.btn.ghost:hover { background: #f0f4ff; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a5281b; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row .field { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge.bassa { background: #eef2f7; color: #475569; }
.badge.media { background: #e7f0fe; color: #1f56c4; }
.badge.alta { background: var(--warn-bg); color: var(--warn); }
.badge.urgente { background: var(--danger-bg); color: var(--danger); }
.badge.aperto { background: #e7f0fe; color: #1f56c4; }
.badge.in_lavorazione { background: var(--warn-bg); color: var(--warn); }
.badge.chiuso { background: #eef2f7; color: #475569; }

.alert { padding: 12px 15px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.err { background: var(--danger-bg); color: var(--danger); }

.msg { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.msg.staff { background: #f0f4ff; border-color: #d9e4ff; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* Login */
.login-wrap { max-width: 380px; margin: 90px auto; padding: 0 20px; }
.login-wrap .brand { font-size: 24px; text-align: center; display: block; margin-bottom: 22px; }

/* Tabs login/registrazione */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tabs .tab {
  flex: 1; text-align: center; padding: 11px; border-radius: 8px;
  background: #f0f2f5; color: var(--muted); font-weight: 600; font-size: 14px;
  text-decoration: none;
}
.tabs .tab.active { background: var(--accent); color: #fff; }
.tabs .tab:hover { text-decoration: none; }

/* Allegati */
.allegati { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.allegato {
  display: inline-flex; align-items: center; gap: 8px;
  background: #f0f4ff; border: 1px solid #d9e4ff; border-radius: 8px;
  padding: 7px 11px; font-size: 13px; width: fit-content; max-width: 100%;
}
.allegato a { font-weight: 600; }
.allegato .dim { color: var(--muted); font-size: 12px; }
