/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --bg: #0B0F14;
  --surface: #121820;
  --surface-raised: #161D26;
  --border: #1E2733;
  --text: #E8EDF2;
  --text-muted: #7C8895;
  --text-faint: #4B5563;

  --status-online: #4ADE80;
  --status-provisioning: #F59E0B;
  --status-offline: #F87171;

  --accent: #4FD1C5;
  --accent-dim: rgba(79, 209, 197, 0.12);

  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  --font-sans: 'IBM Plex Sans', system-ui, sans-serif;

  --radius: 10px;
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  min-height: 100vh;
}

/* ==========================================================================
   Signature background: faint mesh of nodes/lines
   ========================================================================== */
.mesh-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 12% 18%, rgba(79,209,197,0.05) 0, transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(79,209,197,0.04) 0, transparent 45%),
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: auto, auto, 42px 42px, 42px 42px;
}

/* ==========================================================================
   Shell / layout
   ========================================================================== */
.shell {
  position: relative;
  z-index: 1;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 28px 80px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.brand-mark { color: var(--accent); font-size: 14px; }

.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.tabs { display: flex; gap: 4px; }
.tab {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.tab.active { color: var(--bg); background: var(--accent); }

/* ==========================================================================
   Panels
   ========================================================================== */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.2s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
.panel-head h1 {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.sub { color: var(--text-muted); font-size: 14px; margin: 0; max-width: 46ch; }

.section-title {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 36px 0 16px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  padding: 9px 16px;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #05201C; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }
.btn-small {
  font-size: 12px;
  padding: 5px 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
}
.btn-small:hover { color: var(--text); border-color: var(--text-faint); }
.btn-danger:hover { color: var(--status-offline); border-color: var(--status-offline); }
.btn-small:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-small:disabled:hover { color: var(--text-muted); border-color: var(--border); }

.utenti-azioni { display: flex; gap: 6px; flex-wrap: wrap; }

.btn-primary-outline {
  border: 1px solid var(--accent);
  color: var(--accent);
  background: transparent;
}
.btn-primary-outline:hover { background: var(--accent-dim); }

/* ==========================================================================
   Riepilogo statistiche (Case)
   ========================================================================== */
.stat-pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.stat-pill {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255,255,255,0.02);
}
.stat-pill-valore {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.stat-pill-valore.stat-ok { color: var(--status-online); }
.stat-pill-valore.stat-error { color: var(--status-offline); }
.stat-pill-valore.stat-warn { color: var(--status-provisioning); }
.stat-pill-etichetta {
  font-size: 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   Node grid (Case)
   ========================================================================== */
.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.node-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.node-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 2px;
  background: var(--status-color, var(--text-faint));
  opacity: 0.6;
}

.node-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.node-name {
  font-weight: 600;
  font-size: 15px;
}
.status-dot-wrap { display: flex; align-items: center; gap: 6px; }
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--status-color, var(--text-faint));
}
.status-dot.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 var(--status-color, transparent); }
  50% { box-shadow: 0 0 0 4px transparent; }
}
.status-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--status-color, var(--text-muted));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.node-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 8px;
  border-radius: 5px;
  margin-bottom: 12px;
}

.node-meta { font-size: 12px; color: var(--text-muted); line-height: 1.7; }
.node-meta span { color: var(--text-faint); }

.node-card-foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ==========================================================================
   Table (Utenti)
   ========================================================================== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.data-table th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.data-table tr:last-child td { border-bottom: none; }
.role-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.role-badge.admin { background: rgba(245,158,11,0.12); color: var(--status-provisioning); }
.role-badge.standard { background: rgba(124,136,149,0.15); color: var(--text-muted); }
.status-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.status-badge.attivo { background: rgba(52,211,153,0.12); color: var(--status-online, #34D399); }
.status-badge.disattivato { background: rgba(248,113,113,0.12); color: var(--status-offline); }
.mono { font-family: var(--font-mono); font-size: 13px; color: var(--text-muted); }

/* ==========================================================================
   Assegnazioni
   ========================================================================== */
.assign-card {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  flex-wrap: wrap;
}
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 160px; }
.field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
select, input[type="text"], input[type="email"] {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 10px;
  border-radius: 7px;
  font-family: var(--font-sans);
  font-size: 14px;
}
select:focus, input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.assign-list { display: flex; flex-direction: column; gap: 10px; }
.assign-user-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.assign-user-block .assign-user-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
}
.assign-chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.assign-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px 5px 10px;
  font-size: 13px;
}
.assign-chip .chip-role {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
}
.assign-chip button {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 13px;
  padding: 2px 4px;
  line-height: 1;
}
.assign-chip button:hover { color: var(--status-offline); }
.assign-chip button.chip-toggle:hover { color: var(--accent); }
.assign-chip button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ==========================================================================
   Empty states
   ========================================================================== */
.empty-state {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
}
.empty-state p:first-child { color: var(--text); font-weight: 500; margin: 0 0 4px; }
.empty-sub { font-size: 13px; }
.hidden { display: none !important; }

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5,8,11,0.7);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 {
  font-family: var(--font-mono);
  font-size: 17px;
  margin: 0 0 16px;
}
.modal .field { margin-bottom: 14px; }
.modal-desc { color: var(--text-muted); font-size: 13px; line-height: 1.6; margin: -6px 0 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.key-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.key-box code {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  overflow-x: auto;
  white-space: nowrap;
}
.btn-copy {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-copy:hover { color: var(--text); }

.key-cmd {
  background: #05080B;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 12px;
}
.key-cmd-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-faint);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.key-cmd code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-all;
}

/* ==========================================================================
   Log attività
   ========================================================================== */
.log-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 18px;
}
.log-filter-row .field { flex: 0 1 150px; min-width: 130px; }
.log-filter-row input {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
}
.log-filter-row .btn-small { flex-shrink: 0; }
.log-azione {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  background: var(--accent-dim);
  color: var(--accent);
}

/* ==========================================================================
   Stato sistema
   ========================================================================== */
.status-card-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 26px;
}
.status-card {
  flex: 1 1 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
}
.status-card-label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}
.status-card-value {
  font-family: var(--font-mono);
  font-size: 15px;
}
.status-card-value.status-ok { color: var(--status-online); }
.status-card-value.status-error { color: var(--status-offline); }
.status-card-sub {
  font-size: 11px;
  color: var(--text-muted);
  word-break: break-word;
}

.log-panel {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #05080B;
  padding: 12px 14px;
  max-height: 420px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.log-line {
  font-size: 12px;
  display: flex;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}
.log-line:last-child { border-bottom: none; }
.log-line-ts { color: var(--text-faint); flex-shrink: 0; }
.log-line-lvl { flex-shrink: 0; width: 52px; color: var(--text-muted); }
.log-line-logger { flex-shrink: 0; width: 90px; color: var(--accent); opacity: 0.8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-line-msg { color: var(--text-muted); word-break: break-word; }
.log-line-warning .log-line-lvl { color: var(--status-provisioning); }
.log-line-error .log-line-lvl,
.log-line-critical .log-line-lvl { color: var(--status-offline); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 14px; }
  .panel-head { flex-direction: column; }
  .assign-card { flex-direction: column; align-items: stretch; }
  .status-card-row { flex-direction: column; }
}
