:root {
  --bg: #080a10;
  --panel: #11141d;
  --panel-soft: #171b27;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f7f8fb;
  --muted: #969daf;
  --accent: #745cff;
  --accent-soft: rgba(116, 92, 255, 0.16);
  --success: #42d392;
  --warning: #ffb648;
  --danger: #ff5d73;
  --sidebar-width: 270px;
  --radius: 18px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, rgba(116, 92, 255, 0.11), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button {
  color: inherit;
}

[hidden] {
  display: none !important;
}

.admin-shell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  background: rgba(12, 14, 21, 0.96);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 24px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, #8a74ff, #573dea);
  font-weight: 900;
  box-shadow: 0 12px 32px rgba(116, 92, 255, 0.28);
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.sidebar-nav {
  display: grid;
  gap: 7px;
}

.nav-item {
  width: 100%;
  min-height: 48px;
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  transition: 0.2s ease;
}

.nav-item:hover,
.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(116, 92, 255, 0.27);
  color: white;
}

.nav-icon {
  font-size: 1.15rem;
}

.nav-badge {
  min-width: 25px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.72rem;
  text-align: center;
}

.nav-badge.alert {
  background: rgba(255, 93, 115, 0.16);
  color: #ff91a1;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
  padding-top: 20px;
}

.back-site,
.logout-button {
  min-height: 43px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  text-decoration: none;
}

.back-site {
  color: var(--muted);
  border: 1px solid var(--line);
}

.logout-button {
  border: 0;
  background: rgba(255, 93, 115, 0.11);
  color: #ff8ea0;
}

.page {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 84px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(8, 10, 16, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.topbar h1,
.card h2,
.modal h2 {
  margin: 0;
}

.eyebrow {
  margin: 0 0 5px;
  color: #a89bff;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.menu-button {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.refresh-button,
.notification-button {
  position: relative;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.notification-button span {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 21px;
  height: 21px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--danger);
  font-size: 0.68rem;
  font-weight: 800;
}

.admin-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 4px;
}

.admin-profile strong,
.admin-profile span {
  display: block;
}

.admin-profile span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.75rem;
}

.admin-avatar {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(145deg, #745cff, #34259d);
  font-weight: 800;
}

.content {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.global-message {
  margin-bottom: 20px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
}

.global-message.success {
  border-color: rgba(66, 211, 146, 0.35);
  color: #75eab4;
}

.global-message.error {
  border-color: rgba(255, 93, 115, 0.35);
  color: #ff98a7;
}

.panel-section {
  display: none;
}

.panel-section.active {
  display: block;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.stat-card,
.card {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(23, 27, 39, 0.92), rgba(17, 20, 29, 0.94));
  box-shadow: var(--shadow);
}

.stat-card {
  min-height: 145px;
  padding: 21px;
  border-radius: var(--radius);
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin: 12px 0 6px;
  font-size: clamp(2rem, 4vw, 2.75rem);
  line-height: 1;
}

.card {
  padding: 22px;
  border-radius: var(--radius);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 16px;
  margin-top: 16px;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.card-heading h2 {
  font-size: 1.25rem;
}

.text-button {
  border: 0;
  background: transparent;
  color: #a99cff;
}

.stack-list,
.timeline,
.claim-list {
  display: grid;
  gap: 11px;
}

.empty-state,
.table-empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.stack-item,
.timeline-item,
.claim-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.022);
}

.stack-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
}

.stack-item .item-main {
  min-width: 0;
  flex: 1;
}

.stack-item strong,
.stack-item span {
  display: block;
}

.stack-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.mini-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: #c0b7ff;
  font-weight: 800;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.status-pill.pending {
  background: rgba(255, 182, 72, 0.12);
  color: #ffd08d;
}

.status-pill.approved,
.status-pill.active {
  background: rgba(66, 211, 146, 0.12);
  color: #78e9b6;
}

.status-pill.rejected,
.status-pill.suspended {
  background: rgba(255, 93, 115, 0.12);
  color: #ff9ba9;
}

.timeline-item {
  position: relative;
  padding: 13px 14px 13px 42px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 19px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
}

.timeline-item strong,
.timeline-item span {
  display: block;
}

.timeline-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.8rem;
}

.timeline.large .timeline-item {
  padding-block: 17px;
}

.toolbar {
  display: flex;
  gap: 10px;
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: #0d1018;
  color: white;
}

input:focus,
select:focus {
  border-color: rgba(116, 92, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(116, 92, 255, 0.12);
}

#userSearch {
  width: min(320px, 48vw);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.user-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-action {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin-top: 18px;
}

.pagination button {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
}

.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.claim-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  padding: 17px;
}

.claim-item h3 {
  margin: 0;
}

.claim-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.83rem;
}

.claim-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary-button,
.secondary-button,
.danger-button,
.approve-button,
.reject-button {
  min-height: 42px;
  padding: 0 15px;
  border-radius: 11px;
  font-weight: 700;
}

.primary-button,
.approve-button {
  border: 0;
  background: var(--accent);
  color: white;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.reject-button,
.danger-button {
  border: 1px solid rgba(255, 93, 115, 0.3);
  background: rgba(255, 93, 115, 0.1);
  color: #ff9aa9;
}

.roles-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.role-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(255, 255, 255, 0.02);
}

.role-card.featured {
  border-color: rgba(116, 92, 255, 0.45);
  background: var(--accent-soft);
}

.role-card h3 {
  margin: 0 0 9px;
}

.role-card p,
.role-card li {
  color: var(--muted);
  line-height: 1.55;
}

.role-card ul {
  padding-left: 18px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(7px);
}

.modal {
  position: relative;
  width: min(520px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #11141d;
  box-shadow: 0 35px 90px rgba(0, 0, 0, 0.46);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
}

.modal form {
  display: grid;
  gap: 15px;
  margin-top: 22px;
}

.modal label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.switch-row {
  grid-template-columns: 1fr auto;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
}

.switch-row strong,
.switch-row small {
  display: block;
}

.switch-row small {
  margin-top: 4px;
  color: var(--muted);
}

.switch-row input {
  width: 20px;
  min-height: auto;
  aspect-ratio: 1;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 5px;
}

@media (max-width: 1100px) {
  .stats-grid,
  .roles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .sidebar {
    transform: translateX(-102%);
    transition: transform 0.22s ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .page {
    margin-left: 0;
  }

  .menu-button {
    display: grid;
    place-items: center;
  }

  .admin-profile div:last-child {
    display: none;
  }

  .content {
    padding: 18px;
  }

  .responsive-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
  }

  #userSearch {
    width: 100%;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding-inline: 14px;
  }

  .topbar h1 {
    font-size: 1.25rem;
  }

  .stats-grid,
  .roles-grid {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 16px;
  }

  .toolbar,
  .claim-actions {
    flex-direction: column;
  }

  .toolbar select,
  .claim-actions button {
    width: 100%;
  }

  .claim-item {
    grid-template-columns: 1fr;
  }

  .refresh-button {
    display: none;
  }
}


/* Pannello staff unificato */
body[data-role="moderator"] .super-only,
body[data-role="admin"] .super-only {
  display: none !important;
}

body[data-role="moderator"] .admin-only {
  display: none !important;
}

.moderation-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.permission-note {
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255,255,255,.025);
}

@media (max-width: 900px) {
  .moderation-grid {
    grid-template-columns: 1fr;
  }
}


/* =========================================================
   AUDIT LOG
   ========================================================= */

.audit-toolbar {
  flex-wrap: wrap;
  justify-content: flex-end;
}

#logSearch {
  width: min(360px, 46vw);
}

.audit-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -5px 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.022);
  color: var(--muted);
}

.audit-summary small {
  text-align: right;
}

.audit-log-item {
  position: relative;
  padding: 17px 18px 17px 48px;
}

.audit-log-item::before {
  top: 22px;
}

.audit-log-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.audit-log-title {
  line-height: 1.45;
}

.audit-log-title strong {
  display: inline;
  color: var(--text);
}

.audit-log-target {
  color: #c2b9ff;
  font-weight: 750;
}

.audit-log-date {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

.audit-log-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.audit-chip {
  display: inline-flex;
  min-height: 25px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  font-size: 0.7rem;
}

.audit-chip.action {
  border-color: rgba(116, 92, 255, 0.26);
  background: var(--accent-soft);
  color: #c1b8ff;
}

.audit-details {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

@media (max-width: 820px) {
  .audit-toolbar,
  #logSearch,
  .audit-toolbar select {
    width: 100%;
  }

  .audit-summary,
  .audit-log-top {
    align-items: flex-start;
    flex-direction: column;
  }

  .audit-summary small {
    text-align: left;
  }
}
