:root {
  --bg: #0a0a0a;
  --bg-elev: #141414;
  --bg-card: #1a1a1a;
  --border: #2a2a2a;
  --border-strong: #3a3a3a;
  --text: #f5f5f5;
  --text-dim: #a0a0a0;
  --text-muted: #6b6b6b;
  --gold: #FFD600;
  --gold-soft: #FFEB3B;
  --gold-deep: #C9A900;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ===== LAYOUT ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 24px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  flex-shrink: 0;
}

.logo {
  padding: 0 24px 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.logo-box {
  display: inline-block;
  background: var(--gold);
  color: #000;
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1px;
  padding: 6px 12px;
  border-radius: 4px;
}
.logo-img {
  display: block;
  max-width: 140px;
  height: auto;
  border-radius: 6px;
}
.logo-sub {
  display: block;
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 6px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.nav { padding: 0 12px; }
.nav-section {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 16px 12px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  font-size: 14px;
  transition: all .15s;
}
.nav-item:hover { background: var(--bg-card); color: var(--text); }
.nav-item.active { background: rgba(255,214,0,.12); color: var(--gold); }
.nav-item.disabled { opacity: 0.4; pointer-events: none; }
.nav-icon { width: 18px; text-align: center; font-size: 16px; }
.nav-badge {
  margin-left: auto;
  font-size: 10px;
  background: var(--gold);
  color: #000;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}

.main {
  flex: 1;
  padding: 24px 32px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.topbar h1 {
  font-size: 24px;
  font-weight: 700;
}
.topbar h1 small {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 14px;
  margin-left: 8px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ===== PERIOD PICKER ===== */
.period-picker {
  display: inline-flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.period-picker button {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.period-picker button:hover { color: var(--text); }
.period-picker button.active { background: var(--gold); color: #000; font-weight: 700; }

.month-picker {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}
.month-picker:focus { outline: none; border-color: var(--gold); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  text-decoration: none;
}
.btn:hover { background: var(--border); }
.btn-primary { background: var(--gold); color: #000; border-color: var(--gold); font-weight: 700; }
.btn-primary:hover { background: var(--gold-soft); }
.btn-ghost { background: transparent; }

/* ===== CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(255,214,0,.05), transparent 60%);
  pointer-events: none;
}
.kpi-label {
  color: var(--text-dim);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.kpi-value {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.kpi-sub {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 6px;
}
.kpi.featured { border-color: var(--gold); }
.kpi.featured .kpi-value { color: var(--gold); }

/* Role badges */
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.role-admin { background: rgba(255,214,0,.18); color: var(--gold); border: 1px solid var(--gold); }
.role-editor { background: rgba(6,147,227,.15); color: #0693E3; border: 1px solid rgba(6,147,227,.4); }
.role-viewer { background: rgba(160,160,160,.15); color: var(--text-muted); border: 1px solid var(--text-muted); }

/* Permissões checkboxes */
.perm-opt {
  display: flex !important;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.perm-opt:hover { border-color: var(--gold); }
.perm-opt input { margin: 0; }

/* ============================================================
   MOBILE — Sidebar drawer + ajustes responsivos
   ============================================================ */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 50;
  width: 42px; height: 42px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--gold);
  font-size: 22px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 900px) {
  .app { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    transform: translateX(-100%);
    transition: transform .25s ease;
    width: 80%;
    max-width: 300px;
    z-index: 45;
    height: 100vh;
    box-shadow: 0 0 30px rgba(0,0,0,.6);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .menu-toggle { display: inline-flex; }

  .main {
    padding: 60px 14px 20px;
    min-width: 0;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .topbar h1 { font-size: 22px; padding-left: 50px; }
  .topbar-actions {
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }
  .topbar-actions .btn { font-size: 12px; padding: 8px 12px; }

  /* Tabelas com scroll horizontal */
  .card { padding: 14px; overflow-x: auto; }
  table { min-width: 600px; }

  /* Modais ocupam tela toda */
  .modal {
    max-width: 100% !important;
    width: 100%;
    margin: 0;
    border-radius: 0;
    height: 100vh;
    overflow-y: auto;
  }
  .modal-overlay { padding: 0; }

  /* Period picker compacto */
  .period-picker { flex-wrap: wrap; }
  .period-picker button { font-size: 11px; padding: 6px 10px; }
  .month-picker { width: 100%; }

  /* KPIs */
  .kpi { padding: 14px; }
  .kpi-value { font-size: 20px; }
  .kpi-label { font-size: 10px; }
  .kpi-sub { font-size: 11px; }

  /* Charts menores */
  .chart-wrap { height: 220px !important; }

  /* Login centralizado */
  .login-box { padding: 24px; }
}

@media (max-width: 480px) {
  .topbar h1 { font-size: 18px; }
  .kpi { padding: 10px; }
  .kpi-value { font-size: 18px; }
  .nav-item { padding: 12px 18px; font-size: 14px; }
  .modal-head h3 { font-size: 16px; }
  .row-action button { padding: 6px 8px; font-size: 12px; }
}

.delta {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 8px;
  margin-left: 6px;
  letter-spacing: .3px;
}
.delta-up { background: rgba(34,197,94,.15); color: var(--green); }
.delta-down { background: rgba(239,68,68,.15); color: var(--red); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 {
  font-size: 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .muted { color: var(--text-muted); font-weight: 400; font-size: 12px; }

/* ===== TABLE ===== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-elev);
}
tr:hover td { background: var(--bg-elev); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th.num { text-align: right; }
.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.status-pill.active { background: rgba(34,197,94,.2); color: var(--green); }
.status-pill.paused { background: rgba(160,160,160,.2); color: var(--text-dim); }
.status-pill.deleted { background: rgba(239,68,68,.2); color: var(--red); }

/* ===== CHART ===== */
.chart-wrap { position: relative; height: 300px; }
canvas { max-width: 100%; }

/* ===== LOGIN ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1a1a1a 0%, var(--bg) 70%);
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.login-box .logo-box { font-size: 24px; padding: 8px 14px; margin-bottom: 6px; }
.login-box h2 { margin: 20px 0 6px; font-size: 18px; }
.login-box .hint { color: var(--text-dim); font-size: 12px; margin-bottom: 20px; }
.login-box label { display: block; margin-bottom: 14px; }
.login-box label span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.login-box input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}
.login-box input:focus { outline: none; border-color: var(--gold); }
.login-box button { width: 100%; margin-top: 6px; padding: 11px; }
.login-err { color: var(--red); font-size: 12px; margin-top: 10px; min-height: 18px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--gold);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  z-index: 1000;
  font-size: 13px;
  transform: translateX(400px);
  transition: transform .3s;
}
.toast.show { transform: translateX(0); }
.toast.error { border-left-color: var(--red); }
.toast.success { border-left-color: var(--green); }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

/* Clickable rows */
table.clickable tbody tr { cursor: pointer; transition: background .12s; }
table.clickable tbody tr:hover td { background: rgba(255,214,0,.08); }
table.clickable tbody tr:hover td:first-child { color: var(--gold); }

/* Filter chip */
.filter-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,214,0,.08);
  border: 1px solid rgba(255,214,0,.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 13px;
}
.filter-chip .chip-label { color: var(--text-dim); }
.filter-chip strong { color: var(--gold); }
.filter-chip .chip-meta { color: var(--text-muted); font-size: 12px; }
.filter-chip button {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.filter-chip button:hover { background: var(--red); border-color: var(--red); }

/* Ads Grid */
.ads-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}
.ad-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform .15s, border-color .15s;
}
.ad-card:hover { transform: translateY(-2px); border-color: var(--gold); }
.ad-thumb {
  position: relative;
  background: #000;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.ad-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.ad-noimg {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.ad-thumb .status-pill {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,.7);
}
.ad-body { padding: 12px 14px; }
.ad-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.ad-adset {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 10px;
}
.ad-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.ad-stats > div { display: flex; flex-direction: column; }
.ad-stat-label {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 2px;
}
.ad-stats strong { font-size: 14px; color: var(--text); }

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
