/* ── RESET & BASE ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d1117;
  --surface:  #161b22;
  --surface2: #1f2937;
  --border:   #30363d;
  --accent:   #58a6ff;
  --accent2:  #3b82f6;
  --text:     #e6edf3;
  --muted:    #8b949e;
  --success:  #3fb950;
  --warning:  #d29922;
  --danger:   #f85149;
  --orange:   #fb923c;

  --govern:   #818cf8;
  --identify: #34d399;
  --protect:  #60a5fa;
  --detect:   #fbbf24;
  --respond:  #f87171;
  --recover:  #a78bfa;

  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.4);
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── SCROLLBAR ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── HEADER ───────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
}
.logo svg { width: 28px; height: 28px; }

.header-subtitle {
  color: var(--muted);
  font-size: .8rem;
  margin-left: .2rem;
}

/* ── NAV ──────────────────────────────────────────────────────────── */
nav {
  display: flex;
  gap: .25rem;
  margin-left: auto;
}

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: .45rem .9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: rgba(88,166,255,.15); color: var(--accent); }

/* ── MAIN ─────────────────────────────────────────────────────────── */
main {
  flex: 1;
  padding: 2rem;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.page { display: none; }
.page.active { display: block; }

/* ── SECTION TITLE ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}
.page-header .actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── BUTTONS ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary { background: var(--accent2); color: #fff; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: #166534; color: var(--success); border: 1px solid #16a34a; }
.btn-success:hover { background: #14532d; }
.btn-danger  { background: rgba(248,81,73,.15); color: var(--danger); border: 1px solid rgba(248,81,73,.3); }
.btn-danger:hover  { background: rgba(248,81,73,.25); }
.btn-ghost   { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--border); }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-icon { padding: .4rem; border-radius: 6px; }

/* ── CARDS / STAT GRID ────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
}
.stat-card.green::before  { background: var(--success); }
.stat-card.yellow::before { background: var(--warning); }
.stat-card.red::before    { background: var(--danger); }
.stat-card.purple::before { background: var(--recover); }

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: .3rem;
}
.stat-label {
  font-size: .8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

/* ── TABLE ────────────────────────────────────────────────────────── */
.table-wrapper {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .9rem 1.1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.search-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .35rem .75rem;
  flex: 1;
  min-width: 180px;
}
.search-box input {
  background: none;
  border: none;
  color: var(--text);
  font-size: .875rem;
  outline: none;
  width: 100%;
}
.search-box svg { color: var(--muted); flex-shrink: 0; }

table {
  width: 100%;
  border-collapse: collapse;
}
th {
  background: var(--surface2);
  padding: .65rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  white-space: nowrap;
}
td {
  padding: .75rem 1rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.td-actions { display: flex; gap: .3rem; }

/* ── BADGES ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-blue   { background: rgba(88,166,255,.15);  color: var(--accent); }
.badge-green  { background: rgba(63,185,80,.15);   color: var(--success); }
.badge-yellow { background: rgba(210,153,34,.15);  color: var(--warning); }
.badge-red    { background: rgba(248,81,73,.15);   color: var(--danger); }
.badge-purple { background: rgba(167,139,250,.15); color: var(--recover); }
.badge-orange { background: rgba(251,146,60,.18);  color: #fb923c; }
.badge-gray   { background: rgba(139,148,158,.15); color: var(--muted); }

/* ── RATING ───────────────────────────────────────────────────────── */
.rating-A { color: var(--success); font-weight: 700; }
.rating-B { color: #22c55e;        font-weight: 700; }
.rating-C { color: var(--warning); font-weight: 700; }
.rating-D { color: var(--orange);  font-weight: 700; }
.rating-E { color: var(--danger);  font-weight: 700; }

/* ── SCORE BAR ────────────────────────────────────────────────────── */
.score-bar {
  display: flex;
  align-items: center;
  gap: .6rem;
  min-width: 140px;
}
.score-bar-track {
  flex: 1;
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
.score-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width .4s ease;
}
.score-num { font-size: .8rem; font-weight: 600; min-width: 36px; text-align: right; color: var(--muted); }

/* ── MODAL ────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 92vh;            /* fit viewport */
  display: flex;               /* stack header / scroll-body / footer */
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: fadeIn .15s ease;
  overflow: hidden;            /* radius clipping for child scroll */
}
@keyframes fadeIn { from { opacity:0; transform:scale(.96); } to { opacity:1; transform:scale(1); } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.3rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: .25rem;
  border-radius: 5px;
}
.modal-close:hover { color: var(--text); background: var(--surface2); }

.modal-body {
  padding: 1.3rem;
  overflow-y: auto;            /* scroll long content */
  flex: 1 1 auto;              /* fill available space */
  min-height: 0;               /* required for flex children to scroll */
}
.modal-footer {
  padding: .9rem 1.3rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  flex-shrink: 0;              /* never collapse — always visible */
  background: var(--surface);
}

/* ── Help icon (?) inline accanto a label/intestazioni ────────────── */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: rgba(88,166,255,.15);
  color: #58a6ff;
  border: 1px solid rgba(88,166,255,.4);
  font-size: .7rem;
  font-weight: 700;
  cursor: pointer;
  margin-left: .35rem;
  vertical-align: middle;
  transition: background .12s, color .12s;
  line-height: 1;
  padding: 0;
}
.help-icon:hover { background: #58a6ff; color: #fff; }

/* ── Info icon (ⓘ) — variante più ricca per tooltip ricchi ────────── */
.info-icon {
  background: none;
  border: none;
  color: #58a6ff;
  font-size: 16px;
  line-height: 1;
  padding: 0 .25rem;
  margin-left: .4rem;
  cursor: pointer;
  vertical-align: middle;
  border-radius: 4px;
  transition: color .12s, background .12s;
}
.info-icon:hover { color: #2563eb; background: rgba(88,166,255,.12); }
.info-icon:focus-visible { outline: 2px solid #58a6ff; outline-offset: 2px; }

/* ── FORM ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: .35rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-control {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .55rem .8rem;
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color .15s;
}
.form-control:focus { border-color: var(--accent); }
select.form-control option { background: var(--surface2); }

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

/* ── EMPTY STATE ──────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}
.empty-state svg { width: 48px; height: 48px; margin-bottom: 1rem; opacity: .4; }
.empty-state h3 { font-size: 1rem; margin-bottom: .4rem; }
.empty-state p  { font-size: .85rem; }

/* ── REPORT ───────────────────────────────────────────────────────── */
.report-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.report-score-circle {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 3px solid;
  flex-shrink: 0;
}
.report-score-circle .big-num { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.report-score-circle .pct     { font-size: .7rem; color: var(--muted); }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.cat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  border-left: 3px solid;
}
.cat-card-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: .5rem;
}

/* ── TOAST ────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  box-shadow: var(--shadow);
  animation: slideIn .2s ease;
  max-width: 320px;
}
@keyframes slideIn { from { transform: translateX(40px); opacity:0; } to { transform: translateX(0); opacity:1; } }
.toast.success { border-left: 3px solid var(--success); }
.toast.error   {
  border-left: 3px solid var(--danger);
  /* error toast: persistent, può essere più largo per messaggi lunghi */
  max-width: 480px;
  align-items: flex-start;
}
.toast.info    { border-left: 3px solid var(--accent); }
.toast .toast-close:hover { opacity: 1 !important; color: var(--danger) !important; }

/* ── LINK BOX ─────────────────────────────────────────────────────── */
.link-box {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .5rem .75rem;
  margin-top: .5rem;
}
.link-box input {
  flex: 1;
  background: none;
  border: none;
  color: var(--accent);
  font-size: .8rem;
  outline: none;
  font-family: monospace;
}
.link-box button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: .2rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
}
.link-box button:hover { color: var(--text); }

/* ── RESPONSIVE ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  main { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  header { padding: 0 1rem; }
  .header-subtitle { display: none; }
}

/* ─── NIS Module — Wizard step indicator ──────────────────── */
.wizard-step {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: .5rem .4rem;
  font-size: .75rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.wizard-step.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.wizard-step.done {
  color: var(--success, #3fb950);
}
.wizard-step.done::before {
  content: '✓ ';
}
.cpv-tab-btn { border-radius: 6px; }
.cpv-tab-btn.active { background: var(--accent2); color: #fff; }
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
