:root {
  --bg: #1a0a2e;
  --bg-soft: #24103f;
  --sidebar: #16082a;
  --card: #2a1548;
  --card-hover: #341a58;
  --text: #f3eefc;
  --muted: #b9a8d4;
  --accent: #9b5cff;
  --purple: #7c3aed;
  --blue: #3b82f6;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "Nunito Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 10% -10%, #3b1a6d 0%, transparent 50%),
              radial-gradient(900px 500px at 100% 0%, #1e3a8a33 0%, transparent 45%),
              var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #1c0b33 0%, #12061f 100%);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 10px;
}
.brand-logo {
  width: min(100%, 180px);
  height: auto;
  max-height: 72px;
  object-fit: contain;
  border-radius: 12px;
  background: transparent;
  padding: 0;
  flex-shrink: 0;
  display: block;
}

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--muted);
  transition: 0.2s ease;
}
.nav a:hover, .nav a.active {
  background: rgba(155, 92, 255, 0.16);
  color: #fff;
}
.nav .ico { width: 22px; text-align: center; opacity: 0.9; }

.sidebar-promo {
  background: linear-gradient(135deg, #5b21b6, #312e81);
  border-radius: 16px;
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.sidebar-promo strong { display: block; margin-bottom: 6px; font-size: 0.95rem; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: rgba(22, 8, 42, 0.55);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-slogan { color: var(--muted); font-weight: 600; }
.user-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: right;
}
.user-chip .meta { color: var(--muted); font-size: 0.8rem; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.content { padding: 28px; }

.page-title { margin: 0 0 6px; font-size: 1.55rem; }
.page-sub { margin: 0 0 22px; color: var(--muted); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}
.filters select, .filters input, .form-control {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.filters select:focus, .form-control:focus {
  border-color: var(--accent);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.kpi {
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-height: 118px;
}
.kpi::after {
  content: "";
  position: absolute;
  right: -20px;
  top: -20px;
  width: 90px;
  height: 90px;
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.kpi .label { font-size: 0.86rem; opacity: 0.9; margin-bottom: 10px; }
.kpi .value { font-size: 1.8rem; font-weight: 800; letter-spacing: -0.02em; }
.kpi .delta { margin-top: 8px; font-size: 0.8rem; opacity: 0.85; }
.kpi.purple { background: linear-gradient(145deg, #7c3aed, #5b21b6); }
.kpi.blue { background: linear-gradient(145deg, #3b82f6, #1d4ed8); }
.kpi.green { background: linear-gradient(145deg, #22c55e, #15803d); }
.kpi.orange { background: linear-gradient(145deg, #f59e0b, #c2410c); }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
  margin-bottom: 16px;
}
.panel {
  background: rgba(42, 21, 72, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.panel h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel h3 a { color: var(--accent); font-size: 0.85rem; font-weight: 600; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.action-btn {
  border: 0;
  border-radius: 14px;
  padding: 18px 14px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  display: block;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.action-btn:hover { transform: translateY(-2px); filter: brightness(1.08); }
.action-btn.purple { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.action-btn.blue { background: linear-gradient(135deg, #60a5fa, #2563eb); }
.action-btn.green { background: linear-gradient(135deg, #4ade80, #16a34a); }
.action-btn.orange { background: linear-gradient(135deg, #fbbf24, #ea580c); }
.action-btn small { display: block; font-weight: 500; opacity: 0.85; margin-top: 4px; }

.chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 180px;
  padding-top: 10px;
}
.bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  height: 100%;
  justify-content: flex-end;
}
.bar {
  width: 100%;
  border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, #c4b5fd, #7c3aed);
  min-height: 4px;
  transition: height 0.3s ease;
}
.bar-label { font-size: 0.72rem; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: rgba(255,255,255,0.03); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}
.badge.ok { background: rgba(34,197,94,0.18); color: #86efac; }
.badge.warn { background: rgba(245,158,11,0.18); color: #fcd34d; }
.badge.err { background: rgba(239,68,68,0.18); color: #fca5a5; }
.badge.info { background: rgba(59,130,246,0.18); color: #93c5fd; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: var(--purple);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn.danger { background: var(--red); }
.btn.sm { padding: 7px 12px; font-size: 0.85rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-group label { color: var(--muted); font-size: 0.85rem; }
.form-actions { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }

.alert {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: 0.92rem;
}
.alert.success { background: rgba(34,197,94,0.15); color: #bbf7d0; }
.alert.error { background: rgba(239,68,68,0.15); color: #fecaca; }
.alert.info { background: rgba(59,130,246,0.15); color: #bfdbfe; }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: rgba(42, 21, 72, 0.85);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; font-size: 1.5rem; }
.login-brand {
  display: flex;
  justify-content: center;
  margin: 0 0 12px;
}
.login-logo {
  width: min(180px, 70%);
  height: auto;
  max-height: 90px;
  object-fit: contain;
  display: block;
}
.login-card p { margin: 0 0 20px; color: var(--muted); text-align: center; }
.login-card .form-group { margin-bottom: 12px; }
.login-card .btn { width: 100%; margin-top: 8px; }

.validate-card {
  width: min(520px, 100%);
  margin: 40px auto;
  background: rgba(42, 21, 72, 0.9);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.validate-card .status-title {
  font-size: 1.35rem;
  margin: 0 0 18px;
}
.validate-card .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.validate-card .checks { margin-top: 18px; }
.validate-card .checks li { margin: 8px 0; color: #86efac; }

.cards-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.game-card {
  background: rgba(42, 21, 72, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.game-card h3 { margin: 0 0 12px; }
.game-card .meta { color: var(--muted); margin: 4px 0; font-size: 0.92rem; }

/* ===== Página Jogos ===== */
.jogos-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.jogos-head-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.game-create-panel {
  margin-bottom: 18px;
}
.game-create-panel h3 {
  margin: 0 0 6px;
}
.modality-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 20px;
}
.modality-filter a {
  padding: 10px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  transition: 0.2s ease;
}
.modality-filter a:hover {
  color: #fff;
  border-color: rgba(155, 92, 255, 0.45);
}
.modality-filter a.active {
  background: linear-gradient(135deg, #8b5cf6, #5b21b6);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 20px rgba(91, 33, 182, 0.35);
}

.games-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.game-card-v2 {
  background: linear-gradient(160deg, rgba(52, 26, 88, 0.95), rgba(26, 10, 46, 0.92));
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.game-card-v2:hover {
  transform: translateY(-2px);
  border-color: rgba(155, 92, 255, 0.35);
}
.game-card-v2.rasp { --accent-line: #3b82f6; }
.game-card-v2.velha { --accent-line: #a855f7; }
.game-card-v2.is-editing {
  border-color: rgba(155, 92, 255, 0.55);
  box-shadow: 0 0 0 1px rgba(155, 92, 255, 0.25), var(--shadow);
}

.game-card-media {
  position: relative;
  height: 160px;
  background: #0f0720;
  overflow: hidden;
}
.game-card-media::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 4px;
  background: var(--accent-line, var(--accent));
}
.game-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  opacity: 0.92;
}
.game-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
}
.game-badge.rasp { background: rgba(37, 99, 235, 0.92); }
.game-badge.velha { background: rgba(124, 58, 237, 0.92); }
.game-status {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  background: rgba(0,0,0,0.45);
  color: #fff;
}
.game-status.on { color: #86efac; }
.game-status.off { color: #fca5a5; }

.game-card-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}
.game-card-body h3 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
}
.game-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.game-price {
  font-size: 1.35rem;
  font-weight: 800;
  color: #fbbf24;
}
.game-max {
  color: var(--muted);
  font-size: 0.85rem;
}
.game-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 10px;
  border-radius: 14px;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--border);
}
.game-stats div {
  text-align: center;
}
.game-stats strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
}
.game-stats span {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.game-revenue {
  color: var(--muted);
  font-size: 0.9rem;
}
.game-revenue strong { color: #86efac; }
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: auto;
}
.game-actions .btn { flex: 1 1 auto; text-align: center; }

.game-edit-panel {
  border-top: 1px solid var(--border);
  padding: 16px 18px 18px;
  background: rgba(0,0,0,0.18);
}
.game-edit-panel h4 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  color: #e9d5ff;
}

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .cards-2, .games-grid { grid-template-columns: 1fr; }
}

/* ===== MOBILE / TABLET ===== */
.menu-toggle {
  display: none;
  border: 0;
  background: rgba(155, 92, 255, 0.2);
  color: #fff;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.25rem;
  cursor: pointer;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 40;
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .menu-toggle { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(300px, 86vw);
    height: 100dvh;
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  body.menu-open .sidebar { transform: translateX(0); }
  body.menu-open .sidebar-backdrop { display: block; }
  body.menu-open { overflow: hidden; }

  .sidebar-promo { display: none; }

  .topbar {
    padding: 12px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
  }
  .topbar-slogan {
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .user-chip {
    width: 100%;
    justify-content: space-between;
    order: 3;
  }
  .user-chip .meta { font-size: 0.72rem; }

  .content { padding: 16px 12px 28px; }
  .page-title { font-size: 1.25rem; }
  .page-sub { font-size: 0.9rem; margin-bottom: 14px; }

  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { min-height: 96px; padding: 14px; }
  .kpi .value { font-size: 1.35rem; }
  .kpi .label { font-size: 0.78rem; }

  .grid-2, .cards-2, .form-grid, .games-grid { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; }

  .filters {
    flex-direction: column;
    align-items: stretch;
  }
  .filters select,
  .filters input,
  .filters .form-control,
  .filters .btn {
    width: 100%;
  }

  .panel { padding: 14px; }
  .table-wrap {
    margin: 0 -4px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  table { min-width: 560px; }
  th, td { padding: 10px 8px; font-size: 0.85rem; }

  .chart { height: 140px; gap: 4px; }
  .bar-label { font-size: 0.62rem; }

  .login-page { padding: 16px; align-items: flex-start; padding-top: 10vh; }
  .login-card { padding: 22px 18px; }

  .form-actions {
    flex-direction: column;
  }
  .form-actions .btn { width: 100%; }
  .gen-checks label { font-size: 0.88rem; }
}

@media (max-width: 560px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .topbar-slogan { display: none; }
  .kpi .value { font-size: 1.5rem; }
  .action-btn { padding: 16px 14px; }
  .badge { font-size: 0.7rem; }
  .content { padding: 14px 10px 24px; }
}

@media (max-width: 380px) {
  .avatar { width: 34px; height: 34px; font-size: 0.85rem; }
  .page-title { font-size: 1.12rem; }
}

/* Safe area (iPhone notch) */
@supports (padding: max(0px)) {
  .sidebar {
    padding-left: max(18px, env(safe-area-inset-left));
    padding-bottom: max(18px, env(safe-area-inset-bottom));
  }
  .content {
    padding-bottom: max(28px, env(safe-area-inset-bottom));
  }
  .validate-wrap {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
}

