:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #68727d;
  --line: #dde2e8;
  --accent: #1d4ed8;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --warn: #b54708;
  --ok: #067647;
  --radius: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; }
h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 1.1rem; }
h2 { font-size: 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.42rem 0.7rem;
  cursor: pointer;
}
button:hover { border-color: #b8c2cc; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
input, select, textarea {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 0.42rem 0.55rem;
  min-width: 0;
}
textarea { width: 100%; min-height: 5rem; resize: vertical; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 0.75rem; }
.tabs { display: flex; gap: 0.35rem; }
.tab { border-color: transparent; background: transparent; }
.tab.active { background: #e8eefc; border-color: #c7d6fb; color: #133a9a; }

main { padding: 1rem 1.25rem 4rem; }
.view { display: grid; gap: 0.85rem; }
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
  padding: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.filters label { display: grid; gap: 0.25rem; font-size: 0.78rem; color: var(--muted); }
.filters input, .filters select { min-width: 9rem; }

.bulk {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  background: #eef3ff;
  border: 1px solid #c7d6fb;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.table-wrap {
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { text-align: left; padding: 0.55rem 0.65rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; background: #fbfcfd; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
tbody tr:hover { background: #fafbfc; }
.check { width: 2rem; }
td.clip { max-width: 22rem; }
.clip span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.muted { color: var(--muted); font-size: 0.82rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; }
.badge { display: inline-block; padding: 0.12rem 0.45rem; border-radius: 999px; font-size: 0.72rem; border: 1px solid transparent; white-space: nowrap; }
.badge.da_verificare { background: #fff4e5; color: var(--warn); border-color: #fed7aa; }
.badge.in_rimozione { background: #eef3ff; color: #133a9a; border-color: #c7d6fb; }
.badge.rimosso, .badge.autorizzato { background: #e9f7ef; color: var(--ok); border-color: #b7e4c9; }
.badge.falso_positivo { background: #f2f4f7; color: var(--muted); }
.badge.riapparso { background: #fdecea; color: var(--danger); border-color: #f6c6c1; }
.score { font-variant-numeric: tabular-nums; font-weight: 650; }
.row-actions { display: flex; gap: 0.35rem; }

.detail {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(34rem, 100vw);
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -12px 0 30px rgba(16, 24, 40, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
}
#detail-body { overflow: auto; padding: 1rem; display: grid; gap: 1rem; }
.section { display: grid; gap: 0.5rem; }
.section h3 { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 9rem 1fr; gap: 0.35rem 0.75rem; font-size: 0.86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.events { display: grid; gap: 0.45rem; }
.event { border-left: 3px solid var(--line); padding: 0.25rem 0.55rem; font-size: 0.82rem; }
.event time { color: var(--muted); font-size: 0.75rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 0.85rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem; display: grid; gap: 0.5rem; }
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  background: #101828;
  color: #fff;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  z-index: 30;
  max-width: min(36rem, calc(100vw - 2rem));
}

@media (max-width: 720px) {
  .filters { flex-direction: column; align-items: stretch; }
  .filters input, .filters select { width: 100%; }
  .detail { width: 100vw; }
  .kv { grid-template-columns: 7rem 1fr; }
}
