:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1b1f28;
  --bg-card-soft: #20242f;
  --border: #2a2f3a;
  --text: #e7e9ee;
  --text-muted: #8b93a3;
  --accent: #ff9d3d;
  --accent-hover: #ffb15e;
  --accent-soft: rgba(255, 157, 61, 0.14);
  --purple: #8b6cf5;
  --purple-hover: #a48af8;
  --purple-soft: rgba(139, 108, 245, 0.16);
  --danger: #e85c5c;
  --success: #4ade80;
  --radius: 10px;
  --sidebar-bg: #0a0b0f;
  --sidebar-width: 240px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1100px 600px at 15% -10%, rgba(255, 157, 61, 0.07), transparent 60%),
    radial-gradient(900px 700px at 100% 0%, rgba(139, 108, 245, 0.08), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-muted); }
.small { font-size: 0.85em; }
code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}

/* ── Login ── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 340px;
  text-align: center;
}
.login-logo { font-size: 42px; margin-bottom: 8px; }
.login-card h1 { font-size: 1.3rem; margin: 0 0 4px; }
.login-card label { display: block; text-align: left; margin: 20px 0 6px; font-size: 0.9rem; }
.login-card input { width: 100%; }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo { font-size: 22px; }
.title { font-weight: 600; font-size: 1.05rem; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.status-pill {
  font-size: 0.8rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.status-online { color: var(--success); }
.status-offline { color: var(--danger); }
.status-unknown { color: var(--text-muted); }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 10px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--text);
  border-bottom: 2px solid var(--accent);
}

.content { max-width: 1180px; margin: 0 auto; padding: 28px 28px 80px; }
.content-narrow { max-width: 900px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-header h2 { margin: 0 0 4px; }
.panel-header { margin-bottom: 18px; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: 0 10px 24px -16px rgba(0, 0, 0, 0.5);
}
.stat-card, .entity-card, .log-viewer, .user-row, .bot-status-card {
  box-shadow: 0 10px 24px -16px rgba(0, 0, 0, 0.5);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 14px;
}
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--text-muted); }

input[type="text"], input[type="number"], input[type="password"], textarea, select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}
input[type="color"] {
  width: 100%;
  height: 38px;
  padding: 2px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 60px; }

.switch-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 0.95rem; }
.switch-label input { width: 18px; height: 18px; }

.field-row { margin-bottom: 6px; }

/* ── Buttons ── */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.92rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-primary { background: var(--accent); color: #1a1200; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); }
.btn-ghost { background: none; color: var(--text-muted); text-decoration: none; padding: 8px 12px; border-radius: 8px; }
.btn-ghost:hover { color: var(--text); background: var(--bg-card); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: rgba(232, 92, 92, 0.1); }
.btn-block { width: 100%; margin-top: 20px; }
.btn-small { padding: 5px 10px; font-size: 0.8rem; }

.panel-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 16px;
}
.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 14px 0;
  border-top: 1px solid var(--border);
}
.save-feedback { font-size: 0.88rem; }
.save-feedback.ok { color: var(--success); }
.save-feedback.err { color: var(--danger); }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.88rem; margin-bottom: 4px; }
.alert-error { background: rgba(232, 92, 92, 0.12); color: var(--danger); border: 1px solid rgba(232,92,92,0.3); }

/* ── Reaction role panels / live streamers ── */
.entity-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.entity-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.entity-card-head .field { flex: 1; margin-right: 12px; }

.role-row, .streamer-tags {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
@media (max-width: 640px) { .role-row { grid-template-columns: 1fr; } }

.role-row-header {
  display: grid;
  grid-template-columns: 1.3fr 1.3fr 1fr auto;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
@media (max-width: 640px) { .role-row-header { display: none; } }

.subsection-title { font-size: 0.85rem; color: var(--text-muted); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.03em; }

/* ── Visualizzatore log (stile "canali" Discord) ── */
.log-viewer { padding: 0; overflow: hidden; }
.log-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  min-height: 460px;
}
.log-sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 10px;
  overflow-y: auto;
  max-height: 620px;
}
.log-channel-list { display: flex; flex-direction: column; gap: 2px; }
.log-channel-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: inherit;
}
.log-channel-item:hover { background: var(--bg-card); color: var(--text); }
.log-channel-item.active { background: var(--accent); color: #1a1200; font-weight: 600; }

.log-content { padding: 20px; display: flex; flex-direction: column; min-width: 0; }
.log-content-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.log-content-icon { font-size: 1.3rem; line-height: 1; }
.log-content-title { font-weight: 600; font-size: 1rem; }
.log-content-topic { margin-top: 2px; }
.log-content-actions { margin-left: auto; }

@media (max-width: 640px) {
  .log-layout { grid-template-columns: 1fr; }
  .log-sidebar { max-height: 220px; border-right: none; border-bottom: 1px solid var(--border); }
}

.log-entries-list {
  margin-top: 16px;
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.log-entry {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.log-entry-time { font-size: 0.76rem; color: var(--text-muted); }
.log-entry-title { font-size: 0.92rem; font-weight: 600; margin: 2px 0 4px; }
.log-entry-desc { font-size: 0.88rem; white-space: pre-wrap; }
.log-entry-field { font-size: 0.82rem; margin-top: 4px; }
.log-entry-field .field-name { color: var(--text-muted); }

/* ═══════════════════════════════════════════════════════════════
   APP SHELL — sidebar + topbar (Overview e navigazione)
   ═══════════════════════════════════════════════════════════════ */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 20px; position: relative; }
.brand-logo {
  width: 64px; height: 64px; object-fit: contain; flex-shrink: 0;
  filter: brightness(0.82);
}
.sidebar-close-btn {
  display: none; margin-left: auto; background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text-muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 0.9rem;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.menu-toggle-btn { display: none; }
.brand-name {
  font-family: 'Creepster', 'Manrope', sans-serif;
  font-weight: 400; font-size: 1.7rem; letter-spacing: 0.03em; line-height: 1;
}
.brand-name .brand-version { color: var(--accent); }
.brand-sub { font-size: 0.8rem; color: var(--purple); margin-top: 2px; font-weight: 500; }

.sidebar-nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; flex: 1; }
.sidebar-nav .nav-item {
  display: flex; align-items: center; gap: 11px;
  background: none; border: none; color: var(--text-muted);
  padding: 10px 12px; border-radius: 9px; font-size: 0.9rem; font-family: inherit;
  cursor: pointer; text-align: left; width: 100%; border-bottom: none;
}
.sidebar-nav .nav-item:hover { background: var(--bg-elevated); color: var(--text); }
.sidebar-nav .nav-item.active { background: var(--purple-soft); color: var(--text); font-weight: 600; }
.sidebar-nav .nav-item.active .nav-icon { filter: none; }
.nav-icon { font-size: 1.05rem; width: 20px; text-align: center; flex-shrink: 0; }

.sidebar-bottom { margin-top: auto; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.bot-status-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px;
}
.bot-status-card-head { display: flex; align-items: center; gap: 10px; }
.bot-status-icon {
  width: 64px; height: 64px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem; flex-shrink: 0;
}
.bot-status-icon img {
  width: 64px; height: 64px; object-fit: contain;
  filter: brightness(0.82);
}
.bot-status-label { font-size: 0.78rem; color: var(--text-muted); }
.bot-status-value { font-size: 0.88rem; font-weight: 600; margin-top: 1px; }
.bot-status-uptime {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.bot-status-uptime-value { font-weight: 700; color: var(--accent); font-size: 0.92rem; }
.sidebar-logout { text-align: center; border: 1px solid var(--border); }
.sidebar-copy { text-align: center; line-height: 1.5; padding: 4px 4px 0; }

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

/* ── Topbar v2 ── */
.topbar {
  gap: 20px;
}
.topbar-search { flex: 1; max-width: 380px; }
.topbar-search input {
  width: 100%; background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 14px; color: var(--text); font-size: 0.88rem; font-family: inherit;
}
.topbar-search input:focus { outline: none; border-color: var(--purple); }
.icon-btn {
  position: relative; background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-muted); width: 36px; height: 36px; border-radius: 10px;
  font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--purple); }
.badge {
  position: absolute; top: -5px; right: -5px; background: var(--purple); color: #fff;
  font-size: 0.62rem; font-weight: 700; min-width: 16px; height: 16px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}
.badge[hidden] { display: none; }
.admin-chip { display: flex; align-items: center; gap: 9px; padding-left: 6px; border-left: 1px solid var(--border); }
.admin-avatar {
  width: 34px; height: 34px; border-radius: 10px; background: var(--purple-soft);
  display: flex; align-items: center; justify-content: center; font-size: 1rem;
}
.admin-name { font-size: 0.85rem; font-weight: 600; }
.admin-role { line-height: 1.3; }

/* ── Overview: intestazione ── */
.overview-head {
  display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px;
  margin-bottom: 22px;
}
.overview-head h1 { margin: 0 0 4px; font-size: 1.5rem; }
.date-range-pill {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: 0.85rem; color: var(--text-muted); white-space: nowrap;
}

/* ── Stat cards ── */
.stat-cards {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 20px;
}
@media (max-width: 1100px) { .stat-cards { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.stat-card-top { display: flex; align-items: center; gap: 10px; }
.stat-card-icon {
  width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; font-size: 1.05rem; flex-shrink: 0;
}
.stat-card-icon.icon-orange { background: var(--accent-soft); }
.stat-card-icon.icon-purple { background: var(--purple-soft); }
.stat-card-label { font-size: 0.78rem; color: var(--text-muted); }
.stat-card-value { font-size: 1.4rem; font-weight: 700; margin-top: 1px; line-height: 1.1; }
.stat-card-trend { font-size: 0.74rem; display: inline-flex; align-items: center; gap: 3px; margin-top: 2px; }
.stat-card-trend.up { color: var(--success); }
.stat-card-trend.down { color: var(--danger); }
.stat-card-trend.flat { color: var(--text-muted); }
.stat-card-sub { font-size: 0.74rem; color: var(--text-muted); }
.stat-card-sparkline { width: 100%; height: 34px; }
.stat-card-sparkline svg { display: block; width: 100%; height: 100%; }
.stat-card.status-card { justify-content: center; }
.stat-card.status-card .stat-card-top { justify-content: space-between; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 999px; background: var(--success); margin-right: 5px; }
.status-dot.offline { background: var(--danger); }

/* ── Righe di card (grafico + eventi / comandi + risorse + info) ── */
.overview-row-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 16px; align-items: stretch; }
@media (max-width: 900px) { .overview-row-2 { grid-template-columns: 1fr; } }
.overview-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .overview-row-3 { grid-template-columns: 1fr; } }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 0.98rem; }
.chart-card, .events-card { display: flex; flex-direction: column; }

.activity-chart-wrap { position: relative; width: 100%; }
.activity-chart-wrap svg { display: block; width: 100%; height: auto; }
.chart-legend { display: flex; gap: 18px; margin-top: 10px; font-size: 0.8rem; color: var(--text-muted); }
.chart-legend .dot { width: 9px; height: 9px; border-radius: 999px; display: inline-block; margin-right: 6px; }
.dot-events { background: var(--accent); }
.dot-commands { background: var(--purple); }
.chart-tooltip {
  position: absolute; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; font-size: 0.78rem; pointer-events: none;
  transform: translate(-50%, -110%); white-space: nowrap; z-index: 5; display: none; box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}
.chart-tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip .tt-row + .tt-row { margin-top: 2px; }
.ov-hover-col { cursor: pointer; }

/* ── Eventi recenti ── */
.recent-events-list { display: flex; flex-direction: column; gap: 12px; max-height: 340px; overflow-y: auto; }
.recent-event-item { display: flex; align-items: flex-start; gap: 10px; }
.recent-event-bar { width: 3px; align-self: stretch; border-radius: 3px; flex-shrink: 0; min-height: 32px; }
.recent-event-title { font-size: 0.85rem; font-weight: 600; }
.recent-event-desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
.recent-event-time { font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; margin-left: auto; padding-left: 8px; }
.recent-event-row { display: flex; align-items: center; width: 100%; gap: 8px; }

/* ── Comandi più utilizzati ── */
.top-commands-list { display: flex; flex-direction: column; gap: 12px; }
.top-command-row { display: flex; align-items: center; gap: 10px; }
.top-command-rank { font-size: 0.78rem; color: var(--text-muted); width: 14px; flex-shrink: 0; }
.top-command-name { font-size: 0.85rem; font-family: "SFMono-Regular", Consolas, monospace; width: 92px; flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-command-bar-track { flex: 1; height: 7px; background: var(--bg-elevated); border-radius: 999px; overflow: hidden; }
.top-command-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--purple), var(--accent)); }
.top-command-count { font-size: 0.8rem; color: var(--text-muted); width: 48px; text-align: right; flex-shrink: 0; }

/* ── Risorse di sistema (gauge circolari) ── */
.resources-gauges { display: flex; justify-content: space-around; align-items: center; gap: 8px; }
.gauge { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gauge svg { width: 76px; height: 76px; }
.gauge-value { font-size: 1.05rem; font-weight: 700; }
.gauge-label { font-size: 0.72rem; color: var(--text-muted); }
.resources-footer { grid-column: 1 / -1; margin-top: 14px; text-align: center; font-size: 0.82rem; color: var(--success); }

/* ── Info bot ── */
.bot-info-panel { display: flex; align-items: center; gap: 14px; }
.bot-info-avatar { font-size: 3rem; line-height: 1; flex-shrink: 0; display: flex; }
.bot-info-avatar img { width: 90px; height: 90px; object-fit: contain; filter: brightness(0.82); }
.bot-info-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.bot-info-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; }
.bot-info-row .k { color: var(--text-muted); }
.bot-info-row .v { font-weight: 600; }

/* ── Utenti ── */
.users-list { display: flex; flex-direction: column; gap: 10px; }
.user-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-card-soft); border: 1px solid var(--border); border-radius: 9px;
  padding: 12px 14px; flex-wrap: wrap;
}
.user-row-identity { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 160px; }
.user-row-avatar {
  width: 34px; height: 34px; border-radius: 9px; background: var(--purple-soft);
  display: flex; align-items: center; justify-content: center; font-size: 1rem; flex-shrink: 0;
}
.user-row-name { font-weight: 600; font-size: 0.92rem; }
.user-row-name .you-tag { color: var(--accent); font-size: 0.72rem; font-weight: 600; margin-left: 6px; }
.user-row-role { min-width: 150px; }
.user-row-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-reset-form { display: none; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; width: 100%; padding-top: 10px; border-top: 1px solid var(--border); }
.user-reset-form.open { display: flex; }
.user-reset-form input { width: 160px; }

.ov-offline-banner {
  background: rgba(232, 92, 92, 0.1); border: 1px solid rgba(232,92,92,0.3); color: var(--danger);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px; font-size: 0.88rem;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — tablet & mobile (verticale e orizzontale)
   La sidebar diventa un drawer scorrevole sotto i 1024px; sopra
   resta fissa come su desktop. Tutte le funzioni restano invariate,
   cambia solo come vengono mostrate.
   ═══════════════════════════════════════════════════════════════ */

.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(5, 5, 8, 0.6);
  backdrop-filter: blur(2px);
  z-index: 40;
}

/* ── Tablet e mobile: sotto i 1024px la sidebar diventa un drawer ── */
@media (max-width: 1024px) {
  .menu-toggle-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100dvh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    box-shadow: 20px 0 50px -20px rgba(0, 0, 0, 0.6);
    width: min(var(--sidebar-width), 82vw);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }

  .sidebar-backdrop.open { display: block; }

  .main-area { width: 100%; }

  .content { padding: 20px 18px 70px; }

  .topbar { padding: 12px 16px; position: sticky; top: 0; z-index: 20; }
  .topbar-search { max-width: none; }
}

/* ── Tablet: griglie a 2 colonne, topbar più compatta ── */
@media (max-width: 1024px) and (min-width: 641px) {
  .stat-cards { grid-template-columns: repeat(3, 1fr); }
  .overview-row-3 { grid-template-columns: 1fr 1fr; }
  .overview-row-3 .card:last-child { grid-column: 1 / -1; }
}

/* ── Tablet in verticale / mobile in orizzontale ── */
@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ── Mobile ── */
@media (max-width: 640px) {
  .topbar { gap: 10px; }
  .topbar-search { display: none; }
  .admin-chip .admin-role { display: none; }
  .admin-chip { padding-left: 0; border-left: none; }

  .overview-head { flex-direction: column; align-items: stretch; }
  .overview-head h1 { font-size: 1.25rem; }
  .date-range-pill { align-self: flex-start; }

  .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 13px; }
  .stat-card-value { font-size: 1.15rem; }

  .card { padding: 16px; }

  .resources-gauges { flex-wrap: wrap; row-gap: 14px; }
  .bot-info-panel { flex-direction: column; align-items: flex-start; text-align: left; }

  .log-content { padding: 14px; }

  .user-row { flex-direction: column; align-items: stretch; }
  .user-row-role { width: 100%; }
  .user-row-actions { width: 100%; }
  .user-row-actions .btn { flex: 1; }
}

/* ── Schermi molto piccoli ── */
@media (max-width: 380px) {
  .stat-cards { grid-template-columns: 1fr; }
}

/* ── Orientamento orizzontale su telefono: la sidebar-drawer è alta,
   ottimizziamola per non far scomparire il logout/uptime fuori schermo ── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 480px) {
  .sidebar { padding: 12px 12px; overflow-y: auto; }
  .sidebar-brand { padding-bottom: 10px; }
  .sidebar-nav .nav-item { padding: 7px 12px; }
  .bot-status-card { padding: 10px; }
}

/* ── Tablet landscape / desktop piccolo: leggermente più compatto ── */
@media (min-width: 1025px) and (max-width: 1280px) {
  .content { padding: 24px 24px 70px; }
}

/* ── Gestione Bot ─────────────────────────────────────────────────── */
.bot-control-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  align-items: stretch;
}
@media (max-width: 900px) {
  .bot-control-layout { grid-template-columns: 1fr; }
}

.bot-uptime-card { display: flex; flex-direction: column; }
.bot-uptime-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.85rem; color: var(--text-muted); margin-bottom: 18px;
}
.bot-status-dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0;
  box-shadow: 0 0 0 rgba(0,0,0,0);
}
.bot-status-dot.on { background: var(--success); box-shadow: 0 0 8px rgba(74, 222, 128, 0.6); }
.bot-status-dot.off { background: var(--danger); box-shadow: 0 0 8px rgba(232, 92, 92, 0.5); }
.bot-status-dot.pending { background: var(--accent); box-shadow: 0 0 8px rgba(255, 157, 61, 0.6); animation: bc-pulse 1s infinite; }
@keyframes bc-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.bot-uptime-stack { display: flex; flex-direction: column; gap: 14px; }
.bot-uptime-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 10px 14px; background: var(--bg-card-soft); border: 1px solid var(--border); border-radius: var(--radius);
}
.bot-uptime-value { font-size: 1.6rem; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.bot-uptime-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.bot-console-card { display: flex; flex-direction: column; min-width: 0; }
.bot-console {
  flex: 1; min-height: 360px; max-height: 480px; overflow-y: auto;
  background: #06070a; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; font-family: 'Consolas', 'Courier New', monospace; font-size: 0.8rem; line-height: 1.5;
  color: #b9f5c8; white-space: pre-wrap; word-break: break-word;
}
.bot-console::-webkit-scrollbar { width: 8px; }
.bot-console::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

.bot-control-buttons { display: flex; flex-direction: row; gap: 16px; margin-top: 16px; }
.btn-bot-action {
  flex: 1; aspect-ratio: 1 / 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius); cursor: pointer;
  font-family: inherit; font-size: 0.95rem; font-weight: 700; color: #fff;
  transition: filter 0.15s, transform 0.1s;
}
.btn-bot-action .nav-icon { font-size: 1.8rem; line-height: 1; }
.btn-bot-action:active { transform: scale(0.98); }
.btn-bot-action:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-bot-start { background: var(--success); color: #0b1a10; }
.btn-bot-restart { background: var(--accent); color: #2b1706; }
.btn-bot-stop { background: var(--danger); }
.btn-bot-action:not(:disabled):hover { filter: brightness(1.08); }

/* ── Dropdown notifiche (campanella) ─────────────────────────────── */
.notif-wrap { position: relative; }
.notif-dropdown {
  position: absolute; top: calc(100% + 10px); right: 0; width: 340px; max-width: calc(100vw - 32px);
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 16px 36px rgba(0,0,0,0.45); z-index: 60; overflow: hidden;
}
.notif-dropdown-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 0.85rem; font-weight: 700; color: var(--text);
}
.notif-mark-read-btn {
  background: none; border: 1px solid var(--border); color: var(--purple);
  font-family: inherit; font-size: 0.72rem; font-weight: 600; cursor: pointer;
  padding: 5px 9px; border-radius: 7px; white-space: nowrap;
}
.notif-mark-read-btn:hover { background: var(--purple-soft); border-color: var(--purple); }
.notif-dropdown-list { max-height: 360px; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.notif-dropdown-item {
  display: flex; align-items: flex-start; gap: 10px; padding: 8px 6px; border-radius: 8px;
}
.notif-dropdown-item:hover { background: var(--bg-card-soft); }
@media (max-width: 480px) {
  .notif-dropdown { position: fixed; top: var(--topbar-h); left: 12px; right: 12px; width: auto; }
}

/* ── HUD stile Jarvis (banner Home, sopra le stat card) ────────────
   Palette e animazioni ricostruite dal video di riferimento:
   - archi + nuvola di particelle ruotano insieme, lenti, antiorari (~1.6°/s misurati)
   - sfera wireframe (icosfera) sostanzialmente ferma
   - raggi radiali con rotazione più rapida ed erratica (flicker indipendente)
   - fascio orizzontale quasi fisso in stile lens-flare
   - nucleo che pulsa e con un flash periodico più marcato               ── */
.hud-banner {
  position: relative;
  width: 100%;
  min-height: 168px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  padding: 20px 40px;
  display: flex;
  align-items: center;
  gap: 36px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 55% 90% at 14% 50%, rgba(255, 122, 26, 0.20), transparent 70%),
    radial-gradient(ellipse 45% 80% at 90% 15%, rgba(155, 48, 255, 0.16), transparent 70%),
    repeating-linear-gradient(180deg, rgba(255, 140, 40, 0.035) 0px, rgba(255, 140, 40, 0.035) 1px, transparent 1px, transparent 3px),
    #0a0508;
  border: 1px solid rgba(255, 140, 40, 0.32);
  box-shadow: 0 0 0 1px rgba(255, 140, 40, 0.07) inset, 0 12px 32px rgba(155, 48, 255, 0.08);
  font-family: 'Consolas', 'Courier New', monospace;
}

.hud-scanline {
  position: absolute; left: 0; right: 0; top: 0; height: 2px;
  background: linear-gradient(90deg, transparent, rgba(255, 140, 40, 0.9), transparent);
  filter: blur(0.3px);
  animation: hud-scan 5s linear infinite;
  pointer-events: none;
}
@keyframes hud-scan {
  0% { top: 0%; opacity: 0; }
  8% { opacity: .9; }
  92% { opacity: .9; }
  100% { top: 100%; opacity: 0; }
}

.hud-corner { position: absolute; width: 20px; height: 20px; border-color: rgba(255, 140, 40, 0.6); pointer-events: none; }
.hud-corner-tl { top: 9px; left: 9px; border-top: 2px solid; border-left: 2px solid; }
.hud-corner-tr { top: 9px; right: 9px; border-top: 2px solid; border-right: 2px solid; }
.hud-corner-bl { bottom: 9px; left: 9px; border-bottom: 2px solid; border-left: 2px solid; }
.hud-corner-br { bottom: 9px; right: 9px; border-bottom: 2px solid; border-right: 2px solid; }

/* Contenitore icona: cupola radar 3D (Three.js) */
.hud-rings { position: relative; width: 220px; height: 220px; flex-shrink: 0; }

.hud3d-canvas { position: absolute; display: block; }

/* Il nucleo CSS piatto resta il fallback: visibile finché hud3d.js non avvia
   con successo la scena WebGL (assenza rete/Three.js, WebGL non supportato, ecc.). */
.hud-rings.hud3d-active .hud-core { opacity: 0 !important; animation: none !important; pointer-events: none; }

/* Nucleo: fallback CSS piatto, sostituito dalla cupola 3D (Three.js) quando disponibile.
   Resta compatibile con updateBotStatusUI() in app.js, che continua a gestirne lo stato. */
.hud-core {
  position: absolute; inset: 50px; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle, #fff4d6 0%, #ffb347 25%, #ff7a1a 55%, rgba(255, 122, 26, 0) 100%);
  box-shadow: 0 0 26px 10px rgba(255, 140, 40, 0.55), 0 0 60px 24px rgba(155, 48, 255, 0.28);
  animation: hud-pulse 2.4s ease-in-out infinite;
}
.hud-core.offline {
  background: radial-gradient(circle, rgba(200, 90, 255, 0.9), rgba(120, 30, 180, 0.12) 72%);
  box-shadow: 0 0 22px 6px rgba(155, 48, 255, 0.4);
  animation: hud-pulse 2.6s ease-in-out infinite;
}

@keyframes hud-pulse {
  0%, 100% { opacity: .85; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1); }
}

.hud-readout { display: flex; flex-direction: column; gap: 11px; z-index: 2; }
.hud-readout-row { display: flex; align-items: baseline; gap: 16px; }
.hud-label {
  font-size: 0.68rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: rgba(255, 150, 60, 0.65); width: 100px; flex-shrink: 0;
}
.hud-value { font-size: 1.05rem; font-weight: 700; color: #ffe9cf; letter-spacing: 0.02em; text-shadow: 0 0 10px rgba(255, 140, 40, 0.5); }
.hud-value-status.hud-online { color: #9dff5c; text-shadow: 0 0 10px rgba(157, 255, 92, 0.55); }
.hud-value-status.hud-offline { color: #c76bff; text-shadow: 0 0 10px rgba(199, 107, 255, 0.5); }

.hud-ticks {
  position: absolute; right: 26px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 7px; opacity: 0.5; pointer-events: none;
}
.hud-ticks span { width: 26px; height: 2px; background: rgba(255, 140, 40, 0.55); }
.hud-ticks span:nth-child(3n) { width: 14px; background: rgba(155, 48, 255, 0.55); }

@media (max-width: 720px) {
  .hud-banner { flex-direction: column; align-items: flex-start; gap: 18px; padding: 20px; text-align: left; }
  .hud-ticks { display: none; }
}
