:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef3f7;
  --line: #d9e1e8;
  --text: #18212b;
  --muted: #607080;
  --primary: #0f766e;
  --primary-strong: #0b5d57;
  --danger: #b42318;
  --warn: #9a6700;
  --ok: #166534;
  --radius: 8px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0.48rem 0.72rem;
  cursor: pointer;
}

button:hover { border-color: var(--primary); }
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
button.primary:hover { background: var(--primary-strong); }
button.danger { color: var(--danger); border-color: #f0b8b3; }
button.ghost { background: transparent; }
button:disabled { opacity: .48; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.5rem 0.62rem;
  background: #fff;
  color: var(--text);
}

textarea { min-height: 4.5rem; resize: vertical; }
label { display: grid; gap: .28rem; font-weight: 650; color: #263544; }
small, .muted { color: var(--muted); font-weight: 500; }

.app-header {
  display: grid;
  gap: 1rem;
  padding: 1.1rem clamp(1rem, 3vw, 2rem);
  background: #102a43;
  color: #fff;
}
.brand {
  display: flex;
  align-items: center;
  gap: .8rem;
}
.brand img {
  width: 4rem;
  height: 4rem;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.8);
  background: #fff;
}
.app-header h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2.15rem); }
.app-header p { margin: .2rem 0 0; color: #c8d8e8; }
.main-nav { display: flex; flex-wrap: wrap; gap: .45rem; }
.main-nav button {
  background: rgba(255,255,255,.08);
  border-color: rgba(255,255,255,.22);
  color: #fff;
}
.main-nav button.active { background: #fff; color: #102a43; }

.app-shell {
  width: min(1280px, calc(100% - 2rem));
  margin: 1rem auto 2.5rem;
}
.app-shell:focus { outline: none; }

.section-head, .toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.section-head h2 { margin: 0; font-size: 1.45rem; }
.toolbar { align-items: center; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.grid { display: grid; gap: .8rem; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .8rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.stat strong { display: block; font-size: 1.7rem; margin-top: .25rem; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table { width: 100%; border-collapse: collapse; min-width: 740px; }
th, td {
  padding: .62rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th { background: var(--surface-2); font-size: .86rem; color: #33475b; }
tr:last-child td { border-bottom: 0; }

.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 1.55rem;
  padding: .16rem .48rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: #273849;
  font-size: .82rem;
  font-weight: 700;
}
.badge.ok { background: #dff4e7; color: var(--ok); }
.badge.warn { background: #fff0c2; color: var(--warn); }
.badge.danger { background: #ffe2df; color: var(--danger); }

.template-table select { min-width: 9rem; }
.template-cell { display: grid; grid-template-columns: 1fr; gap: .35rem; min-width: 10rem; }
.candidate-row.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.empty {
  padding: 1.2rem;
  text-align: center;
  color: var(--muted);
}
.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(32rem, calc(100% - 2rem));
  padding: .75rem .9rem;
  background: #102a43;
  color: #fff;
  border-radius: 8px;
  opacity: 0;
  transform: translateY(.5rem);
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* Accesso e amministrazione: stessi colori e componenti dell'applicazione. */
[hidden] { display: none !important; }
.session-bar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .6rem; }
.session-bar span { overflow-wrap: anywhere; font-size: .9rem; }
.session-bar button { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.login-shell { max-width: 30rem; margin-top: 2rem; }
.login-shell h2 { margin-top: 0; }
.check-label { display: flex; align-items: center; gap: .6rem; font-weight: 500; }
.check-label input[type="checkbox"] { width: 1.1rem; height: 1.1rem; flex: 0 0 auto; accent-color: var(--primary); }
fieldset { border: 1px solid var(--line); border-radius: 6px; padding: 1rem; min-width: 0; }
legend { font-weight: 650; padding: 0 .3rem; }
fieldset:disabled { opacity: .65; }
.notice { overflow-wrap: anywhere; }
.notice:empty { display: none; }
.notice.error { color: var(--danger); }

@media (max-width: 820px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4, .stats { grid-template-columns: 1fr; }
  .section-head, .toolbar { align-items: stretch; }
  .actions { flex-direction: column; }
  .actions button { width: 100%; }
}
